//
//  IPSlider.m
//  Ranger
//
//  Created by Ari Krupnik on 6/8/11.
//  Copyright 2011 lib.aero. All rights reserved.
//

#import "MMSlider.h"

@implementation MMSlider

- (void)setupWithFrame:(CGRect)frame {
    track = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    CGRect trackFrame=[track frame];
    trackFrame.size.width = frame.size.width - THUMB_WIDTH;
    trackFrame.origin.x = THUMB_WIDTH / 2;
    trackFrame.origin.y = (frame.size.height-trackFrame.size.height)/2;
    [track setFrame:trackFrame];
    [self setBackgroundColor:[UIColor clearColor]];
    [self addSubview:track];
    
    [self addSubview:min=[[[MMSliderThumb alloc] initWithParent:self andOrientation:MMSliderThumbOrientationAbove] autorelease]];
    [self addSubview:max=[[[MMSliderThumb alloc] initWithParent:self andOrientation:MMSliderThumbOrientationAbove] autorelease]];
    [max setValue:1];  // out of the box, value==0; center and min need a higer upper bound than that.
    [self addSubview:center=[[[MMSliderThumb alloc] initWithParent:self andOrientation:MMSliderThumbOrientationBelow] autorelease]];
    [center setValue:0.5];  // I prefer this look to min and center sitting on top of each other, but programatically, it makes no difference
    [min setUpperBound:center];
    [center setLowerBound:min];
    [center setUpperBound:max];
    [max setLowerBound:center];
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupWithFrame:frame];
    }
    return self;
}


- (void)awakeFromNib {
    [self setupWithFrame:[self frame]];
}


- (float)value {
    return [center value];
}
- (void)setValue:(float)v {
    [center setValue:v];
}
- (float)minValue {
    return [min value];
}
- (void)setMinValue:(float)v {
    [min setValue:v];
}
- (float)maxValue {
    return [max value];
}
- (void)setMaxValue:(float)v {
    [max setValue:v];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc {
    [track release];
    [super dealloc];
}

@end
