From 2ccb8de590dc7c6c8b0ec2d0ea02d85050859a82 Mon Sep 17 00:00:00 2001 From: Ptyl Dragon Date: Fri, 1 Nov 2013 15:19:42 +0200 Subject: added linking of width and height Change-Id: I2282fcfffed5c17eb1798d3198d6f04dc27208e9 --- .../view_controllers/MLOTestingTileParameter.h | 7 +- .../view_controllers/MLOTestingTileParameter.m | 32 +++++---- .../MLOTestingTileParametersViewController.m | 83 +++++++++++++++------- 3 files changed, 81 insertions(+), 41 deletions(-) (limited to 'ios/shared') diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.h b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.h index df0f70bd592e..8465b5dadf67 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.h +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.h @@ -8,12 +8,15 @@ #import "MLOObject.h" +typedef enum {WIDTH_IS_HEIGHT,WIDTH_IS_NOT_HEIGHT} MLOTestingTileParametersMode; +#define MLOTestingTileParametersModeString(enum) [@[@"WIDTH_IS_HEIGHT",@"WIDTH_IS_NOT_HEIGHT"] objectAtIndex:enum] + typedef void (^MLOTestingTileParameterExtractor)(CGFloat value); @class MLOTestingTileParametersViewController; @interface MLOTestingTileParameter : MLOObject --(MLOTestingTileParameter *)initWithParams:(MLOTestingTileParametersViewController *) params label:(NSString *)label extractor1:(MLOTestingTileParameterExtractor) extractor extractor2:(MLOTestingTileParameterExtractor) linkedExtractor defaultValue:(NSInteger) defaultValue; --(void)extract:(BOOL) isExtractor1; +-(MLOTestingTileParameter *)initWithParams:(MLOTestingTileParametersViewController *) params label:(NSString *)label widthIsNotHeightExtractor:(MLOTestingTileParameterExtractor) widthIsNotHeightExtractor widthIsHeightExtractor:(MLOTestingTileParameterExtractor) widthIsHeightExtractor defaultValue:(NSInteger) defaultValue; +-(void)extractMode:(MLOTestingTileParametersMode) mode; -(void)setParamFrame:(CGRect) paramFrame; -(void)addToSuperview; @end diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m index b5fcd8dcefc9..9c0af4f994d9 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m @@ -11,8 +11,8 @@ @interface MLOTestingTileParameter () @property MLOTestingTileParametersViewController * params; -@property (nonatomic,strong) MLOTestingTileParameterExtractor extractor1; -@property (nonatomic,strong) MLOTestingTileParameterExtractor extractor2; +@property (nonatomic,strong) MLOTestingTileParameterExtractor widthIsHeightExtractor; +@property (nonatomic,strong) MLOTestingTileParameterExtractor widthIsNotHeightExtractor; @property UILabel * label; @property UITextField * data; @property UITextField * step; @@ -25,13 +25,13 @@ static const CGFloat DEFAULT_STEP_VALUE = 1; @implementation MLOTestingTileParameter --(MLOTestingTileParameter *)initWithParams:(MLOTestingTileParametersViewController *) params label:(NSString *)label extractor1:(MLOTestingTileParameterExtractor) extractor1 extractor2:(MLOTestingTileParameterExtractor) extractor2 defaultValue:(NSInteger) defaultValue{ +-(MLOTestingTileParameter *)initWithParams:(MLOTestingTileParametersViewController *) params label:(NSString *)label widthIsNotHeightExtractor:(MLOTestingTileParameterExtractor) widthIsNotHeightExtractor widthIsHeightExtractor:(MLOTestingTileParameterExtractor) widthIsHeightExtractor defaultValue:(NSInteger) defaultValue{ NSLog(@"Creating tile testing param %@ with default value %d",label,defaultValue); self = [self init]; if(self){ self.params = params; - self.extractor1 = extractor1; - self.extractor2 = extractor2; + self.widthIsHeightExtractor = widthIsHeightExtractor; + self.widthIsNotHeightExtractor = widthIsNotHeightExtractor; self.defaultValue = defaultValue; [self initLabel:label]; self.dataStepper = [self createStepper]; @@ -169,16 +169,20 @@ static const CGFloat DEFAULT_STEP_VALUE = 1; return [self.data.text floatValue]; } --(void)extract:(BOOL) isExtractor1{ - - NSLog(@"%@ extract %d",self,isExtractor1?1:2); - - CGFloat dataValue = [self currentDataValue]; +-(MLOTestingTileParameterExtractor) getExtractor:(MLOTestingTileParametersMode) mode{ + switch (mode) { + case WIDTH_IS_HEIGHT: + return self.widthIsHeightExtractor; + case WIDTH_IS_NOT_HEIGHT: + return self.widthIsNotHeightExtractor; + } +} - if(isExtractor1){ - self.extractor1(dataValue); - }else{ - self.extractor2(dataValue); +-(void)extractMode:(MLOTestingTileParametersMode) mode{ + MLOTestingTileParameterExtractor extractor = [self getExtractor:mode]; + if(extractor!=nil){ + NSLog(@"%@ extract %@",self,MLOTestingTileParametersModeString(mode)); + extractor([self currentDataValue]); } } @end diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m index c544f2af5596..4a235e19ffe1 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m @@ -17,6 +17,8 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; @property MLOAppRoleTileTester * tester; @property NSArray * params; @property UIButton * renderButton; +@property UIButton * modeButton; +@property MLOTestingTileParametersMode mode; @end @implementation MLOTestingTileParametersViewController @@ -24,7 +26,9 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; self = [self init]; if(self){ self.tester = tester; + self.mode = WIDTH_IS_HEIGHT; [self initParams]; + [self initModeButton]; [self initRenderButton]; } @@ -39,30 +43,30 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; -(void)initParams{ self.params = @[[self createParam:@"contextWidth" - extractor1:^(CGFloat value){self.contextWidth = value;} - extractor2:^(CGFloat value){self.contextWidth = self.contextHeight = value;} + widthIsNotHeightExtractor:^(CGFloat value){self.contextWidth = value;} + widthIsHeightExtractor:^(CGFloat value){self.contextWidth = self.contextHeight = value;} value:CONTEXT_WIDTH_DEFAULT], - [self createConditionalParam:@"contextHeight" - extractor:^(CGFloat value){self.contextHeight = value;} - value:CONTEXT_HEIGHT_DEFAULT], + [self createParam:@"contextHeight" + widthIsNotHeightExtractor:^(CGFloat value){self.contextHeight = value;} + value:CONTEXT_HEIGHT_DEFAULT], - [self createNormalParam:@"tilePosX" - extractor:^(CGFloat value){self.tilePosX = value;} - value:TILE_POS_X_DEFAULT], + [self createParam:@"tilePosX" + anyExtractor:^(CGFloat value){self.tilePosX = value;} + value:TILE_POS_X_DEFAULT], - [self createNormalParam:@"tilePosY" - extractor:^(CGFloat value){self.tilePosY = value;} - value:TILE_POS_Y_DEFAULT], + [self createParam:@"tilePosY" + anyExtractor:^(CGFloat value){self.tilePosY = value;} + value:TILE_POS_Y_DEFAULT], [self createParam:@"tileWidth" - extractor1:^(CGFloat value){self.tileWidth = value;} - extractor2:^(CGFloat value){self.tileWidth = self.tileHeight = value;} + widthIsNotHeightExtractor:^(CGFloat value){self.tileWidth = value;} + widthIsHeightExtractor:^(CGFloat value){self.tileWidth = self.tileHeight = value;} value:TILE_WIDTH_DEFAULT], - [self createConditionalParam:@"tileHeight" - extractor:^(CGFloat value){self.tileHeight = value;} - value:TILE_HEIGHT_DEFAULT] + [self createParam:@"tileHeight" + widthIsNotHeightExtractor:^(CGFloat value){self.tileHeight = value;} + value:TILE_HEIGHT_DEFAULT] ]; } @@ -73,16 +77,39 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; self.renderButton =button; } +-(void)initModeButton{ + UIButton * button =[UIButton buttonWithType:UIButtonTypeRoundedRect]; + [button addTarget:self action:@selector(changeMode) forControlEvents:UIControlEventTouchDown]; + [button setTitle:MLOTestingTileParametersModeString(self.mode) forState:UIControlStateNormal]; + self.modeButton =button; +} + +-(void)changeMode{ --(MLOTestingTileParameter *) createNormalParam:(NSString *)name extractor:(MLOTestingTileParameterExtractor) extractor value:(CGFloat)defaultValue{ - return [self createParam:name extractor1:extractor extractor2:extractor value:defaultValue];} + switch (self.mode) { + case WIDTH_IS_HEIGHT: + self.mode = WIDTH_IS_NOT_HEIGHT; + break; + case WIDTH_IS_NOT_HEIGHT: + self.mode = WIDTH_IS_HEIGHT; + break; + } --(MLOTestingTileParameter *) createConditionalParam:(NSString *)name extractor:(MLOTestingTileParameterExtractor) extractor value:(CGFloat)defaultValue{ - return [self createParam:name extractor1:extractor extractor2:nil value:defaultValue]; + [self.modeButton setTitle:MLOTestingTileParametersModeString(self.mode) forState:UIControlStateNormal]; } --(MLOTestingTileParameter *) createParam:(NSString *)name extractor1:(MLOTestingTileParameterExtractor) extractor1 extractor2:(MLOTestingTileParameterExtractor) extractor2 value:(CGFloat)defaultValue{ - return [[MLOTestingTileParameter alloc] initWithParams:self label:name extractor1:extractor1 extractor2:extractor2 defaultValue:defaultValue]; + + +-(MLOTestingTileParameter *) createParam:(NSString *)name anyExtractor:(MLOTestingTileParameterExtractor) anyExtractor value:(CGFloat)defaultValue{ + return [self createParam:name widthIsNotHeightExtractor:anyExtractor widthIsHeightExtractor:anyExtractor value:defaultValue]; +} + +-(MLOTestingTileParameter *) createParam:(NSString *)name widthIsNotHeightExtractor:(MLOTestingTileParameterExtractor) widthIsNotHeightExtractor value:(CGFloat)defaultValue{ + return [self createParam:name widthIsNotHeightExtractor:widthIsNotHeightExtractor widthIsHeightExtractor:nil value:defaultValue]; +} + +-(MLOTestingTileParameter *) createParam:(NSString *)name widthIsNotHeightExtractor:(MLOTestingTileParameterExtractor) extractor1 widthIsHeightExtractor:(MLOTestingTileParameterExtractor) extractor2 value:(CGFloat)defaultValue{ + return [[MLOTestingTileParameter alloc] initWithParams:self label:name widthIsNotHeightExtractor:extractor1 widthIsHeightExtractor:extractor2 defaultValue:defaultValue]; } @@ -103,9 +130,14 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; paramHeight)]; originY+=paramHeight; } - self.renderButton.frame = CGRectMake(0, + CGFloat halfWidth = width/2.0f; + self.modeButton.frame = CGRectMake(0, + originY, + halfWidth, + RENDER_BUTTON_HEIGHT); + self.renderButton.frame = CGRectMake(halfWidth, originY, - width, + halfWidth, RENDER_BUTTON_HEIGHT); } @@ -117,13 +149,14 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; } [self.view addSubview:self.renderButton]; + [self.view addSubview:self.modeButton]; } -(void)renderTile{ NSLog(@"%@ renderTile",self); for (MLOTestingTileParameter * param in self.params) { - [param extract]; + [param extractMode:self.mode]; } [self.tester.renderer render]; } -- cgit