// // MGMMiddleView.m // VoiceMob // // Created by Mr. Gecko on 10/11/10. // Copyright (c) 2011 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/ // #import "MGMMiddleView.h" #import NSString * const MGMMFontName = @"Helvetica"; @implementation MGMMiddleViewButton + (id)buttonWithTitle:(NSString *)theTitle image:(NSString *)theImage target:(id)theTarget action:(SEL)theAction { return [[[self alloc] initWithTitle:theTitle image:theImage target:theTarget action:theAction] autorelease]; } - (id)initWithTitle:(NSString *)theTitle image:(NSString *)theImage target:(id)theTarget action:(SEL)theAction { if ((self = [super init])) { title = [theTitle copy]; image = [theImage copy]; target = theTarget; action = theAction; } return self; } - (void)dealloc { [title release]; [image release]; [super dealloc]; } - (void)setTitle:(NSString *)theTitle { [title release]; title = [theTitle copy]; } - (NSString *)title { return title; } - (void)setImage:(NSString *)theImage { [image release]; image = [theImage copy]; } - (NSString *)image { return image; } - (void)setTarget:(id)theTarget { target = theTarget; } - (id)target { return target; } - (void)setAction:(SEL)theAction { action = theAction; } - (SEL)action { return action; } - (void)setHighlighted:(BOOL)isHighlighted { highlighted = isHighlighted; } - (BOOL)highlighted { return highlighted; } - (void)setRect:(CGRect)theRect { rect = theRect; } - (CGRect)rect { return rect; } @end @implementation MGMMiddleView - (void)dealloc { #if releaseDebug NSLog(@"%s Releasing", __PRETTY_FUNCTION__); #endif [buttons release]; [super dealloc]; } - (void)setDelegate:(id)theDelegate { delegate = theDelegate; } - (id)delegate { return delegate; } - (void)addButtonWithTitle:(NSString *)theTitle imageName:(NSString *)theImage target:(id)theTarget action:(SEL)theAction { if (buttons==nil) buttons = [NSMutableArray new]; [buttons addObject:[MGMMiddleViewButton buttonWithTitle:theTitle image:theImage target:theTarget action:theAction]]; [self updateButtonRects]; [self setNeedsDisplay]; } - (void)setButtons:(NSArray *)theButtons { [buttons release]; buttons = [theButtons mutableCopy]; [self updateButtonRects]; } - (NSArray *)buttons { return buttons; } - (void)updateButtonRects { CGRect bounds = [self bounds]; int count = [buttons count]; int row = 3; int numRow = count/row; if (numRow<=1) { row = 2; numRow = count/row; } int width = bounds.size.width/row; int height = bounds.size.height/numRow; int index = 0; for (int r=0; r