Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Animate the button when setState is called

  • Loading branch information...
commit 99143f37d7aa20980f6f91714a758d5a413160ab 1 parent 4faad1e
@mxcl authored
Showing with 19 additions and 7 deletions.
  1. +1 −0  MBSliderButton.h
  2. +17 −6 MBSliderButton.m
  3. +1 −1  main.m
View
1  MBSliderButton.h
@@ -34,5 +34,6 @@
-(NSInteger)state;
-(void)setState:(NSInteger)newstate;
+-(void)setState:(NSInteger)newstate animate:(bool)animate;
@end
View
23 MBSliderButton.m
@@ -138,22 +138,33 @@ -(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]];
}
Please sign in to comment.
Something went wrong with that request. Please try again.