Permalink
Browse files

Animate the button when setState is called

  • Loading branch information...
1 parent 4faad1e commit 99143f37d7aa20980f6f91714a758d5a413160ab @mxcl committed Nov 22, 2009
Showing with 19 additions and 7 deletions.
  1. +1 −0 MBSliderButton.h
  2. +17 −6 MBSliderButton.m
  3. +1 −1 main.m
View
@@ -34,5 +34,6 @@
-(NSInteger)state;
-(void)setState:(NSInteger)newstate;
+-(void)setState:(NSInteger)newstate animate:(bool)animate;
@end
View
@@ -137,23 +137,34 @@ -(void)setPosition:(NSNumber*)x
}
-(void)setState:(NSInteger)newstate
+{
+ [self setState:newstate animate:true];
+}
+
+-(void)setState:(NSInteger)newstate animate:(bool)animate
{
if(newstate == [self state])
return;
- //TODO animate this if we're visible and not in the awakeFromNib bit
- state = newstate ? NSOnState : NSOffState;
- location.x = state ? KNOB_MAX_X : 0;
- [self setNeedsDisplay:YES];
+ int x = newstate == NSOnState ? KNOB_MAX_X : 0;
+
+ //TODO animate if we are visible and otherwise don't
+ if(animate)
+ [self animateTo:x];
+ else
+ [self setNeedsDisplay:YES];
+
+ state = newstate == NSOnState ? true : false;
+ location.x = x;
}
-(void)offsetLocationByX:(float)x
{
location.x = location.x + x;
-
+
if (location.x < KNOB_MIN_X) location.x = KNOB_MIN_X;
if (location.x > KNOB_MAX_X) location.x = KNOB_MAX_X;
-
+
[self setNeedsDisplay:YES];
}
View
2 main.m
@@ -143,7 +143,7 @@ -(void)mainViewDidLoad
pid = playdar_pid();
if(pid){
kqueue_watch_pid(pid, self); // watch the pid for termination
- [big_switch setState:NSOnState];
+ [big_switch setState:NSOnState animate:false];
[demos setHidden:false];
[self showTrackCount:[self numFiles]];
}

0 comments on commit 99143f3

Please sign in to comment.