//// BWAnchoredButtonBarViewInspector.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWAnchoredButtonBarInspector.h"#import "BWAnchoredButtonBar.h"@implementationBWAnchoredButtonBarInspector-(NSString*)viewNibName{return@"BWAnchoredButtonBarInspector";}-(void)refresh{[superrefresh];if([[selfinspectedObjects]count]>0&&!isAnimating){BWAnchoredButtonBar*inspectedButtonBar=[[selfinspectedObjects]lastObject];if([inspectedButtonBarselectedIndex]==0)[selfselectMode:1withAnimation:NO];elseif([inspectedButtonBarselectedIndex]==1)[selfselectMode:2withAnimation:NO];else[selfselectMode:3withAnimation:NO];}}-(IBAction)selectMode1:(id)sender{[selfselectMode:1withAnimation:YES];}-(IBAction)selectMode2:(id)sender{[selfselectMode:2withAnimation:YES];}-(IBAction)selectMode3:(id)sender{[selfselectMode:3withAnimation:YES];}-(void)selectMode:(int)modeIndexwithAnimation:(BOOL)shouldAnimate{floatxOrigin;if(modeIndex==1)xOrigin=roundf(matrix.frame.origin.x-1);elseif(modeIndex==2)xOrigin=roundf(matrix.frame.origin.x+NSWidth(matrix.frame)/matrix.numberOfColumns);elsexOrigin=roundf(NSMaxX(matrix.frame)-NSWidth(matrix.frame)/matrix.numberOfColumns+matrix.numberOfColumns-1);if(shouldAnimate){floatdeltaX=fabsf(xOrigin-selectionView.frame.origin.x);floatdoubleSpaceMultiplier=1;if(deltaX>65)doubleSpaceMultiplier=1.5;floatduration=0.1*doubleSpaceMultiplier;isAnimating=YES;[NSAnimationContextbeginGrouping];[[NSAnimationContextcurrentContext]setDuration:(duration)];[[selectionViewanimator]setFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];[NSAnimationContextendGrouping];[selfperformSelector:@selector(selectionAnimationDidEnd)withObject:nilafterDelay:duration];}else{[selectionViewsetFrameOrigin:NSMakePoint(xOrigin,selectionView.frame.origin.y)];}}-(void)selectionAnimationDidEnd{isAnimating=NO;}@end