[dasher] iPhone: input filter settings by generating GUI from an SModuleSettings*



commit 72962ff582f5e0963a50972729f88a5658c35864
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Thu Feb 11 10:13:34 2010 +0000

    iPhone: input filter settings by generating GUI from an SModuleSettings*
    
    Also used for MiscSettings. (LP_NODE_BUDGET maxes at 10k as 4k too low for 3GS!)

 Src/iPhone/Classes/CDasherInterfaceBridge.h  |    2 +-
 Src/iPhone/Classes/CDasherInterfaceBridge.mm |    4 +
 Src/iPhone/Classes/COSXSettingsStore.h       |    6 +-
 Src/iPhone/Classes/COSXSettingsStore.mm      |   14 +++-
 Src/iPhone/Classes/DasherAppDelegate.mm      |    2 +-
 Src/iPhone/Classes/InputMethodSelector.h     |    3 +-
 Src/iPhone/Classes/InputMethodSelector.mm    |   68 ++++++++++----
 Src/iPhone/Classes/MiscSettings.h            |    7 +-
 Src/iPhone/Classes/MiscSettings.mm           |  128 ++-----------------------
 Src/iPhone/Classes/ParametersController.h    |   22 +++++
 Src/iPhone/Classes/ParametersController.mm   |  128 ++++++++++++++++++++++++++
 Src/iPhone/Dasher.xcodeproj/project.pbxproj  |    8 ++
 12 files changed, 243 insertions(+), 149 deletions(-)
---
diff --git a/Src/iPhone/Classes/CDasherInterfaceBridge.h b/Src/iPhone/Classes/CDasherInterfaceBridge.h
index 32acef8..1fafcd1 100644
--- a/Src/iPhone/Classes/CDasherInterfaceBridge.h
+++ b/Src/iPhone/Classes/CDasherInterfaceBridge.h
@@ -40,7 +40,7 @@ public:
   ~CDasherInterfaceBridge();
   
   void ChangeScreen(CDasherScreen *NewScreen);
-  
+  std::string GetParamName(int iParameter);
   //redefinitions to make public....
   void OnUIRealised();
   void NewFrame(unsigned long iTime, bool bForceRedraw);
diff --git a/Src/iPhone/Classes/CDasherInterfaceBridge.mm b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
index 8d3a944..04caa94 100644
--- a/Src/iPhone/Classes/CDasherInterfaceBridge.mm
+++ b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
@@ -82,6 +82,10 @@ void CDasherInterfaceBridge::ChangeScreen(CDasherScreen *pScreen) {
   m_pMouseDevice->SetScreenBounds(pScreen->GetWidth(), pScreen->GetHeight());
 }
 
+string CDasherInterfaceBridge::GetParamName(int iParameter) {
+  return static_cast<COSXSettingsStore *>(m_pSettingsStore)->GetParamName(iParameter);
+}
+
 void CDasherInterfaceBridge::SetupPaths() {
   NSString *systemDir = [NSString stringWithFormat:@"%@/", [[NSBundle mainBundle] bundlePath]];
   NSString *userDir = [NSString stringWithFormat:@"%@/", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
diff --git a/Src/iPhone/Classes/COSXSettingsStore.h b/Src/iPhone/Classes/COSXSettingsStore.h
index f3bcb83..7dcd4b7 100644
--- a/Src/iPhone/Classes/COSXSettingsStore.h
+++ b/Src/iPhone/Classes/COSXSettingsStore.h
@@ -21,10 +21,10 @@ class COSXSettingsStore:public CSettingsStore {
 public:
   COSXSettingsStore(Dasher::CEventHandler * pEventHandler);
   ~COSXSettingsStore();
-  
-  NSDictionary *ParameterDictionary();
+  std::string GetParamName(int iParameter);
+  //NSDictionary *ParameterDictionary();
 
-  int GetParameterIndex(const std::string &  Key);
+  //int GetParameterIndex(const std::string &  Key);
 
 private:
 
diff --git a/Src/iPhone/Classes/COSXSettingsStore.mm b/Src/iPhone/Classes/COSXSettingsStore.mm
index 8cd70e6..ef870ab 100644
--- a/Src/iPhone/Classes/COSXSettingsStore.mm
+++ b/Src/iPhone/Classes/COSXSettingsStore.mm
@@ -19,7 +19,17 @@ COSXSettingsStore::COSXSettingsStore(Dasher::CEventHandler *pEventHandler):CSett
 COSXSettingsStore::~COSXSettingsStore() {
 };
 
-NSDictionary *COSXSettingsStore::ParameterDictionary() {
+std::string COSXSettingsStore::GetParamName(int iParameter) {
+  if (iParameter < END_OF_BPS)
+    return s_oParamTables.BoolParamTable[iParameter - FIRST_BP].regName;
+  if (iParameter < END_OF_LPS)
+    return s_oParamTables.LongParamTable[iParameter - FIRST_LP].regName;
+  if (iParameter < END_OF_SPS)
+    return s_oParamTables.StringParamTable[iParameter - FIRST_SP].regName;
+  throw "Illegal Parameter Index";
+}
+
+/*NSDictionary *COSXSettingsStore::ParameterDictionary() {
   static NSMutableDictionary *parameterDictionary = nil;
   
   if (parameterDictionary == nil) {
@@ -64,7 +74,7 @@ int COSXSettingsStore::GetParameterIndex(const std::string & aKey) {
   }
   
   return [[parameterEntry objectForKey:@"key"] intValue];
-}
+}*/
 
 /*
  the default values for all the parameters are stored in the core.  Rather than trying to ferret out those values in order to construct a registration domain, I'm just going to get the object for the key and if it is nil, let the core know I failed to read the default and it will supply the correct default value.
diff --git a/Src/iPhone/Classes/DasherAppDelegate.mm b/Src/iPhone/Classes/DasherAppDelegate.mm
index 328bdf0..c73a422 100644
--- a/Src/iPhone/Classes/DasherAppDelegate.mm
+++ b/Src/iPhone/Classes/DasherAppDelegate.mm
@@ -232,7 +232,7 @@
   UINavigationController *settings = [[[UINavigationController alloc] initWithRootViewController:tabs] autorelease];
 
     tabs.viewControllers = [NSArray arrayWithObjects:
-							[[[InputMethodSelector alloc] initWithNavCon:settings] autorelease],
+							[[[InputMethodSelector alloc] init] autorelease],
 						    [[[CalibrationController alloc] initWithTabCon:tabs] autorelease],
 						    [[[LanguagesController alloc] init] autorelease],
                 [[[StringParamController alloc] initWithTitle:@"Colour" image:[UIImage imageNamed:@"palette.png"] settingParam:SP_COLOUR_ID] autorelease],
diff --git a/Src/iPhone/Classes/InputMethodSelector.h b/Src/iPhone/Classes/InputMethodSelector.h
index c622875..6242599 100644
--- a/Src/iPhone/Classes/InputMethodSelector.h
+++ b/Src/iPhone/Classes/InputMethodSelector.h
@@ -10,10 +10,9 @@
 
 
 @interface InputMethodSelector : UITableViewController {
-	UINavigationController *encNavCon;
 	NSIndexPath *selectedPath;
 }
 
-- (id)initWithNavCon:(UINavigationController *)encNavCon;
+- (id)init;
 
 @end
diff --git a/Src/iPhone/Classes/InputMethodSelector.mm b/Src/iPhone/Classes/InputMethodSelector.mm
index 6ec1f2e..403cd09 100644
--- a/Src/iPhone/Classes/InputMethodSelector.mm
+++ b/Src/iPhone/Classes/InputMethodSelector.mm
@@ -12,6 +12,7 @@
 #import "Common.h"
 #import "DasherAppDelegate.h"
 #import "CalibrationController.h"
+#import "ParametersController.h"
 
 typedef struct __FILTER_DESC__ {
 	NSString *title;
@@ -23,13 +24,13 @@ typedef struct __FILTER_DESC__ {
 SFilterDesc asTouchFilters[] = {
 	{@"Hybrid Mode", @"Tap or Hold", TOUCH_INPUT, "Stylus Control"},
   {@"Boxes", @"Tap box to select", TOUCH_INPUT, "Direct Mode"},
-  {@"Scanning", @"Tap screen when box highlighted", TOUCH_INPUT, "Menu Mode"},
-  {@"One Button Mode", @"Tap screen when cursor near", TOUCH_INPUT, "Static One Button Mode"},
 };
 
 SFilterDesc asDynamicFilters[] = {
-	{@"Dynamic 2B Mode", @"Tap Top or Bottom", TOUCH_INPUT, "Two Button Dynamic Mode"},
-  {@"Dynamic 1B Mode", @"Tap anywhere - twice", TOUCH_INPUT, "Two-push Dynamic Mode (New One Button)"},
+  {@"Scanning", @"Tap screen when box highlighted", TOUCH_INPUT, "Menu Mode"},
+  {@"One Button Mode", @"Tap screen when cursor near", TOUCH_INPUT, "Static One Button Mode"},
+	{@"Dynamic 1B Mode", @"Tap anywhere - twice", TOUCH_INPUT, "Two-push Dynamic Mode (New One Button)"},
+  {@"Dynamic 2B Mode", @"Tap Top or Bottom", TOUCH_INPUT, "Two Button Dynamic Mode"},
 };
 
 SFilterDesc asTiltFilters[] = {
@@ -51,20 +52,25 @@ typedef struct __SECTION_DESC__ {
 	
 SSectionDesc allMeths[] = {
 {@"Touch Control", asTouchFilters, sizeof(asTouchFilters) / sizeof(asTouchFilters[0])},
-{@"Dynamic Button Modes", asDynamicFilters, sizeof(asDynamicFilters) / sizeof(asDynamicFilters[0])},
+{@"Button Modes", asDynamicFilters, sizeof(asDynamicFilters) / sizeof(asDynamicFilters[0])},
 {@"Tilt Control", asTiltFilters, sizeof(asTiltFilters) / sizeof(asTiltFilters[0])},
 {@"Touch/tilt Combo", asMixedFilters, sizeof(asMixedFilters) / sizeof(asMixedFilters[0])},
 };
 
+ interface InputMethodSelector ()
+ property (retain) NSIndexPath *selectedPath;
+ end
+
 @implementation InputMethodSelector
 
-- (id)initWithNavCon:(UINavigationController *)_encNavCon {
-    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
-		encNavCon = _encNavCon;
+ synthesize selectedPath;
+
+- (id)init {
+  if (self = [super initWithStyle:UITableViewStyleGrouped]) {
 		self.tabBarItem.title = @"Control";
 		self.tabBarItem.image = [UIImage imageNamed:@"pen.png"];
-    }
-    return self;
+  }
+  return self;
 }
 
 /*
@@ -143,12 +149,17 @@ SSectionDesc allMeths[] = {
 	// Set up the cell...
 	SFilterDesc *filter = &allMeths[ [indexPath section] ].filters[ [indexPath row] ];
 	if (filter->deviceName == app.dasherInterface->GetStringParameter(SP_INPUT_DEVICE)
-		&& filter->filterName == app.dasherInterface->GetStringParameter(SP_INPUT_FILTER))
-	{
-		cell.accessoryType = UITableViewCellAccessoryCheckmark;
-		selectedPath = indexPath;
+		&& filter->filterName == app.dasherInterface->GetStringParameter(SP_INPUT_FILTER)
+    && (!selectedPath || [indexPath compare:selectedPath])) {
+      self.selectedPath = indexPath;
+      [self performSelectorOnMainThread:@selector(doSelect) withObject:nil waitUntilDone:NO];
 	}
-	else cell.accessoryType = UITableViewCellAccessoryNone;
+	
+  UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
+  cell.accessoryView = btn;
+  btn.tag = (int)filter;
+  [btn addTarget:self action:@selector(settings:) forControlEvents:UIControlEventTouchUpInside];
+  
 	cell.text = filter->title;
 	CGSize titleSize = [filter->title sizeWithFont:cell.font];
 	subText.frame = CGRectMake(titleSize.width + 30.0, 5.0, 245.0 - titleSize.width, 34.0);
@@ -158,6 +169,27 @@ SSectionDesc allMeths[] = {
     return cell;
 }
 
+- (void)moduleSettingsDone {
+  [self dismissModalViewControllerAnimated:YES];
+  [self doSelect];
+}
+
+- (void)doSelect {
+  [self.tableView selectRowAtIndexPath:selectedPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
+}
+
+- (void)settings:(id)button {
+  UIButton *btn = (UIButton *)button;
+  SFilterDesc *desc = (SFilterDesc *)btn.tag;
+  CDasherModule *mod = [DasherAppDelegate theApp].dasherInterface->GetModuleByName(desc->filterName);
+  SModuleSettings *settings=NULL; int count=0;
+  if (mod->GetSettings(&settings, &count)) {
+    ParametersController *params = [[[ParametersController alloc] initWithTitle:NSStringFromStdString(desc->filterName) Settings:settings Count:count] autorelease];
+    [params setTarget:self Selector:@selector(moduleSettingsDone)];
+    [self presentModalViewController:[[[UINavigationController alloc] initWithRootViewController:params] autorelease] animated:YES];
+  }
+}
+
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
     return allMeths[section].displayName;
 }
@@ -167,10 +199,8 @@ SSectionDesc allMeths[] = {
 }
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-	[tableView deselectRowAtIndexPath:indexPath animated:NO];
-	if (selectedPath)
-		[tableView cellForRowAtIndexPath:selectedPath].accessoryType = UITableViewCellAccessoryNone;
-	[tableView cellForRowAtIndexPath:(selectedPath = indexPath)].accessoryType = UITableViewCellAccessoryCheckmark;
+	//[tableView deselectRowAtIndexPath:indexPath animated:NO];
+	self.selectedPath = indexPath;
 	DasherAppDelegate *app = [DasherAppDelegate theApp];
 	SFilterDesc *filter = &allMeths[ [indexPath section] ].filters[ [indexPath row] ];
 	app.dasherInterface->SetStringParameter(SP_INPUT_DEVICE, filter->deviceName);
diff --git a/Src/iPhone/Classes/MiscSettings.h b/Src/iPhone/Classes/MiscSettings.h
index fb938ec..ab8ba6c 100644
--- a/Src/iPhone/Classes/MiscSettings.h
+++ b/Src/iPhone/Classes/MiscSettings.h
@@ -7,10 +7,9 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "ParametersController.h"
 
-
- interface MiscSettings : UIViewController {
-	UILabel *speedLbl, *budgetLbl, *marginLbl;
+ interface MiscSettings : ParametersController {
 }
-
+-(id)init;
 @end
diff --git a/Src/iPhone/Classes/MiscSettings.mm b/Src/iPhone/Classes/MiscSettings.mm
index 4c2ca6e..ecc7344 100644
--- a/Src/iPhone/Classes/MiscSettings.mm
+++ b/Src/iPhone/Classes/MiscSettings.mm
@@ -11,129 +11,23 @@
 #import "CDasherInterfaceBridge.h"
 #import "Parameters.h"
 
-//private methods...
- interface MiscSettings ()
-- (void)budgetSlid:(id)sender;
-- (void)speedSlid:(id)sender;
-- (void)marginSlid:(id)sender;
- end
+static SModuleSettings _settings[] = { //note iStep and string description are ignored
+  {LP_NODE_BUDGET, T_LONG, 400, 10000, 1, 0, ""}, //hopefully appropriate for an iPhone 3GS?
+  {LP_MAX_BITRATE, T_LONG, 10, 1200, 100, 0, ""}, //unfortunately appears as "MaxBitrateTimes100"...
+  {LP_MARGIN_WIDTH, T_LONG, 100, 900, 1, 0, ""},
+  {BP_AUTO_SPEEDCONTROL, T_BOOL, -1, -1, -1, -1, ""},
+  {BP_NONLINEAR_Y, T_BOOL, -1, -1, -1, -1, ""},
+  {BP_DOUBLE_X, T_BOOL, -1, -1, -1, -1, ""},
+};
+static int _count = sizeof(_settings) / sizeof(_settings[0]);
 
 @implementation MiscSettings
 
-- (id)init {
-	if (self = [super init]) {
-		self.title = @"Misc";
+- (id)init {  
+	if (self = [super initWithTitle:@"Misc" Settings:_settings Count:_count]) {
 		self.tabBarItem.image = [UIImage imageNamed:@"misc.png"];
 	}
 	return self;
 }
 
-// Implement loadView to create a view hierarchy programmatically, without using a nib.
-- (void)loadView {
-	CDasherInterfaceBridge *intf = [DasherAppDelegate theApp].dasherInterface;
-	UIView *view = [[[UIView alloc] init] autorelease];
-	view.backgroundColor = [UIColor whiteColor];
-	
-	budgetLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 30.0, 300.0, 20.0)] autorelease];
-	UISlider *budget = [[[UISlider alloc] initWithFrame:CGRectMake(10.0, 50.0, 300.0, 20.0)] autorelease];
-	budget.minimumValue = 100; budget.maximumValue = 4000; budget.value = intf->GetLongParameter(LP_NODE_BUDGET);
-	[budget addTarget:self action:@selector(budgetSlid:) forControlEvents:UIControlEventValueChanged];
-	[self budgetSlid:budget];
-	[view addSubview:budgetLbl]; [view addSubview:budget];
-	
-	speedLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 100.0, 300.0, 20.0)] autorelease];
-	UISlider *speed = [[[UISlider alloc] initWithFrame:CGRectMake(10.0, 120.0, 300.0, 20.0)] autorelease];
-	speed.minimumValue = 0.1; speed.maximumValue = 12.0; speed.value = intf->GetLongParameter(LP_MAX_BITRATE)/100.0;
-	[speed addTarget:self action:@selector(speedSlid:) forControlEvents:UIControlEventValueChanged];
-	[self speedSlid:speed];
-	[view addSubview:speedLbl]; [view addSubview:speed];
-
-	marginLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 170.0, 300.0, 20.0)] autorelease];
-  UISlider *margin = [[[UISlider alloc] initWithFrame:CGRectMake(10.0, 190.0, 300.0, 20.0)] autorelease];
-  margin.minimumValue = 100.0; margin.maximumValue = 900.0; margin.value = intf->GetLongParameter(LP_MARGIN_WIDTH);
-  [margin addTarget:self action:@selector(marginSlid:) forControlEvents:UIControlEventValueChanged];
-  [self marginSlid:margin];
-  [view addSubview:marginLbl]; [view addSubview:margin];
-  
-	UILabel *ascLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 232.0, 190.0, 20.0)] autorelease];
-	ascLbl.text = @"Auto Speed Control";
-	UISwitch *asc = [[[UISwitch alloc] initWithFrame:CGRectMake(210.0, 232.0, 100.0, 20.0)] autorelease];
-	[view addSubview:ascLbl]; [view addSubview:asc];
-	asc.on = intf->GetBoolParameter(BP_AUTO_SPEEDCONTROL);
-	[asc addTarget:self action:@selector(autoSpeedCon:) forControlEvents:UIControlEventValueChanged];
-  
-  UILabel *nonLinLbl = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 274.0, 190.0, 20.0)] autorelease];
-  nonLinLbl.text = @"Compress top/bottom";
-  UISwitch *nonLin = [[[UISwitch alloc] initWithFrame:CGRectMake(210.0, 274.0, 100.0, 20.0)] autorelease];
-  [view addSubview:nonLinLbl]; [view addSubview:nonLin];
-  nonLin.on = intf->GetBoolParameter(BP_NONLINEAR_Y);
-  [nonLin addTarget:self action:@selector(nonLinear:) forControlEvents:UIControlEventValueChanged];
-
-  UILabel *dblLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 316.0, 190.0, 20.0)] autorelease];
-  dblLabel.text = @"Touch on left half";
-  UISwitch *dbl = [[[UISwitch alloc] initWithFrame:CGRectMake(210.0, 316.0, 100.0, 20.0)] autorelease];
-  [view addSubview:dblLabel]; [view addSubview:dbl];
-  dbl.on = intf->GetBoolParameter(BP_DOUBLE_X);
-  [dbl addTarget:self action:@selector(doubleX:) forControlEvents:UIControlEventValueChanged];
-  
-  self.view = view;
-}
-
-- (void)autoSpeedCon:(id)sender {
-  [DasherAppDelegate theApp].dasherInterface->SetBoolParameter(BP_AUTO_SPEEDCONTROL, ((UISwitch *)sender).on);
-}
-
-- (void)nonLinear:(id)sender {
-  [DasherAppDelegate theApp].dasherInterface->SetBoolParameter(BP_NONLINEAR_Y, ((UISwitch *)sender).on);
-}
-
-- (void)doubleX:(id)sender {
-  [DasherAppDelegate theApp].dasherInterface->SetBoolParameter(BP_DOUBLE_X, ((UISwitch *)sender).on);
-}
-
-- (void)budgetSlid:(id)sender {
-	int v = ((UISlider *)sender).value;
-	[DasherAppDelegate theApp].dasherInterface->SetLongParameter(LP_NODE_BUDGET, v);
-	budgetLbl.text = [NSString stringWithFormat:@"Display detail: %i", v];
-}
-
-- (void)speedSlid:(id)sender {
-	float v = ((UISlider *)sender).value;
-	[DasherAppDelegate theApp].dasherInterface->SetLongParameter(LP_MAX_BITRATE, 100*v);
-	speedLbl.text = [NSString stringWithFormat:@"Max Bitrate: %1.2f", v];
-}
-
-- (void)marginSlid:(id)sender {
-  int v = ((UISlider *)sender).value;
-  [DasherAppDelegate theApp].dasherInterface->SetLongParameter(LP_MARGIN_WIDTH, v);
-  marginLbl.text = [NSString stringWithFormat:@"Margin Width: %i", v];
-}
-
-
-/*
-// Override to allow orientations other than the default portrait orientation.
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
-    // Return YES for supported orientations
-    return (interfaceOrientation == UIInterfaceOrientationPortrait);
-}
-*/
-
-- (void)didReceiveMemoryWarning {
-	// Releases the view if it doesn't have a superview.
-    [super didReceiveMemoryWarning];
-	
-	// Release any cached data, images, etc that aren't in use.
-}
-
-- (void)viewDidUnload {
-	// Release any retained subviews of the main view.
-	// e.g. self.myOutlet = nil;
-}
-
-
-- (void)dealloc {
-    [super dealloc];
-}
-
-
 @end
diff --git a/Src/iPhone/Classes/ParametersController.h b/Src/iPhone/Classes/ParametersController.h
new file mode 100644
index 0000000..c8921a0
--- /dev/null
+++ b/Src/iPhone/Classes/ParametersController.h
@@ -0,0 +1,22 @@
+//
+//  ParametersController.h
+//  Dasher
+//
+//  Created by Alan Lawrence on 10/02/2010.
+//  Copyright 2010 Cavendish Laboratory. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "ModuleSettings.h"
+
+ interface ParametersController : UIViewController {
+  SModuleSettings *settings;
+  int count;
+  id targetOnDone;
+  SEL selector;
+}
+
+-(id)initWithTitle:(NSString *)title Settings:(SModuleSettings *)settings Count:(int)count;
+-(void)setTarget:(id)target Selector:(SEL)selector;
+
+ end
diff --git a/Src/iPhone/Classes/ParametersController.mm b/Src/iPhone/Classes/ParametersController.mm
new file mode 100644
index 0000000..52a2ac3
--- /dev/null
+++ b/Src/iPhone/Classes/ParametersController.mm
@@ -0,0 +1,128 @@
+//
+//  ParametersController.mm
+//  Dasher
+//
+//  Created by Alan Lawrence on 10/02/2010.
+//  Copyright 2010 Cavendish Laboratory. All rights reserved.
+//
+
+#import "ParametersController.h"
+#import "DasherAppDelegate.h"
+#import "DasherUtil.h"
+
+using namespace Dasher;
+
+//private methods
+ interface ParametersController ()
+-(void)boolParamChanged:(id)uiswitch;
+-(void)longParamChanged:(id)uislider;
+ end
+
+ implementation ParametersController
+
+-(id)initWithTitle:(NSString *)title Settings:(SModuleSettings *)_settings Count:(int)_count {
+  if (self = [super init]) {
+    self.title=title;
+    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
+    settings = _settings;
+    count = _count;
+  }
+  return self;
+}
+
+-(void)setTarget:(id)_target Selector:(SEL)_selector {
+  UIBarButtonItem *item = (UIBarButtonItem *)self.navigationItem.leftBarButtonItem;
+  item.target = _target;
+  item.action = _selector;
+}
+
+- (void)loadView {
+  CDasherInterfaceBridge *intf = [DasherAppDelegate theApp].dasherInterface;
+  
+  UIScrollView *view = [[[UIScrollView alloc] init] autorelease];
+  self.view = view;
+  view.backgroundColor = [UIColor whiteColor];
+    
+  int y=15;
+  for (int i=0; i<count; i++) {
+    if (settings[i].iType == T_BOOL) {
+      UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, y, 190.0, 20.0)] autorelease];
+      label.text = NSStringFromStdString(intf->GetParamName(settings[i].iParameter));
+      UISwitch *sw = [[[UISwitch alloc] initWithFrame:CGRectMake(210.0, y, 100.0, 20.0)] autorelease];
+      [view addSubview:label];
+      [view addSubview:sw];
+      sw.on = intf->GetBoolParameter(sw.tag = settings[i].iParameter);
+      [sw addTarget:self action:@selector(boolParamChanged:) forControlEvents:UIControlEventValueChanged];
+      y += 50;
+    } else if (settings[i].iType == T_LONG) {
+      UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, y, 300.0, 20.0)] autorelease];
+      UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(10.0, y+20, 300.0, 20.0)] autorelease];
+      slider.tag = (int)label; label.tag=i;
+      slider.minimumValue = settings[i].iMin; slider.maximumValue = settings[i].iMax;
+      slider.value = intf->GetLongParameter(settings[i].iParameter);
+      [slider addTarget:self action:@selector(longParamChanged:) forControlEvents:UIControlEventValueChanged];
+      [self longParamChanged:slider];
+      [view addSubview:label]; [view addSubview:slider];
+      y += 70;
+    }
+  }
+  [view setContentSize:CGSizeMake(320.0,y-15)];
+}
+
+-(void)boolParamChanged:(id)uiswitch {
+  UISwitch *sw = (UISwitch *)uiswitch;
+  [DasherAppDelegate theApp].dasherInterface->SetBoolParameter(sw.tag, sw.on);
+}
+
+-(void)longParamChanged:(id)uislider {
+  CDasherInterfaceBridge *intf = [DasherAppDelegate theApp].dasherInterface;
+  UISlider *slider = (UISlider *)uislider;
+  UILabel *label = (UILabel *)slider.tag;
+  SModuleSettings *setting = &settings[label.tag];
+  long val = slider.value;
+  if (!label.text || val != intf->GetLongParameter(setting->iParameter)) {
+    intf->SetLongParameter(setting->iParameter, val);
+    int iPlaces=0, iDivisor(setting->iDivisor);
+    while (iDivisor > 1) {
+      iPlaces++;
+      iDivisor/=10;
+    }
+    NSString *format =[@"%@: %." stringByAppendingFormat:@"%df",iPlaces];  
+    label.text = [NSString stringWithFormat:format,NSStringFromStdString(intf->GetParamName(setting->iParameter)),(val / (float)setting->iDivisor)];
+  }
+}
+
+/*
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad {
+    [super viewDidLoad];
+}
+*/
+
+/*
+// Override to allow orientations other than the default portrait orientation.
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+    // Return YES for supported orientations
+    return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+*/
+
+- (void)didReceiveMemoryWarning {
+	// Releases the view if it doesn't have a superview.
+    [super didReceiveMemoryWarning];
+	
+	// Release any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+	// Release any retained subviews of the main view.
+	// e.g. self.myOutlet = nil;
+}
+
+
+- (void)dealloc {
+    [super dealloc];
+}
+
+
+ end
diff --git a/Src/iPhone/Dasher.xcodeproj/project.pbxproj b/Src/iPhone/Dasher.xcodeproj/project.pbxproj
index 09cf60e..9b8eb7c 100755
--- a/Src/iPhone/Dasher.xcodeproj/project.pbxproj
+++ b/Src/iPhone/Dasher.xcodeproj/project.pbxproj
@@ -148,6 +148,7 @@
 		3344FE650F71717C00506EAA /* UserLogTrial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3344FE0F0F71717C00506EAA /* UserLogTrial.cpp */; };
 		3344FE660F71717C00506EAA /* XMLUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3344FE130F71717C00506EAA /* XMLUtil.cpp */; };
 		334AC9B8102AE19400CE6871 /* Locked.png in Resources */ = {isa = PBXBuildFile; fileRef = 334AC9B7102AE19400CE6871 /* Locked.png */; };
+		334B1BF111232A8E007A6DFF /* ParametersController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 334B1BF011232A8E007A6DFF /* ParametersController.mm */; };
 		33627FBA0F7A82CF000C8818 /* training_albanian_SQ.txt in Resources */ = {isa = PBXBuildFile; fileRef = 33627F9A0F7A82CE000C8818 /* training_albanian_SQ.txt */; };
 		33627FBD0F7A82CF000C8818 /* training_bengali_BD.txt in Resources */ = {isa = PBXBuildFile; fileRef = 33627F9D0F7A82CE000C8818 /* training_bengali_BD.txt */; };
 		33627FBF0F7A82CF000C8818 /* training_canna_JP.txt in Resources */ = {isa = PBXBuildFile; fileRef = 33627F9F0F7A82CE000C8818 /* training_canna_JP.txt */; };
@@ -459,6 +460,9 @@
 		3344FE140F71717C00506EAA /* XMLUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLUtil.h; sourceTree = "<group>"; };
 		3344FE740F71718B00506EAA /* I18n.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = I18n.h; sourceTree = "<group>"; };
 		334AC9B7102AE19400CE6871 /* Locked.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Locked.png; sourceTree = "<group>"; };
+		334B1BEF11232A8E007A6DFF /* ParametersController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParametersController.h; sourceTree = "<group>"; };
+		334B1BF011232A8E007A6DFF /* ParametersController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ParametersController.mm; sourceTree = "<group>"; };
+		334B1C2011233B8B007A6DFF /* ModuleSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleSettings.h; sourceTree = "<group>"; };
 		33627F9A0F7A82CE000C8818 /* training_albanian_SQ.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_albanian_SQ.txt; sourceTree = "<group>"; };
 		33627F9D0F7A82CE000C8818 /* training_bengali_BD.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_bengali_BD.txt; sourceTree = "<group>"; };
 		33627F9F0F7A82CE000C8818 /* training_canna_JP.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_canna_JP.txt; sourceTree = "<group>"; };
@@ -552,6 +556,8 @@
 		080E96DDFE201D6D7F000001 /* IPhone Classes */ = {
 			isa = PBXGroup;
 			children = (
+				334B1BEF11232A8E007A6DFF /* ParametersController.h */,
+				334B1BF011232A8E007A6DFF /* ParametersController.mm */,
 				332F34B7103D91E5008448D7 /* LanguagesController.h */,
 				332F34B8103D91E5008448D7 /* LanguagesController.mm */,
 				3334D4DD1014745F0077948A /* MiscSettings.h */,
@@ -944,6 +950,7 @@
 		3344FE670F71718B00506EAA /* Common */ = {
 			isa = PBXGroup;
 			children = (
+				334B1C2011233B8B007A6DFF /* ModuleSettings.h */,
 				332387350F7838AC00DD75C5 /* Platform.h */,
 				332387300F78388200DD75C5 /* Common.h */,
 				332387310F78388200DD75C5 /* myassert.h */,
@@ -1242,6 +1249,7 @@
 				3334D4DF1014745F0077948A /* MiscSettings.mm in Sources */,
 				332F34B9103D91E5008448D7 /* LanguagesController.mm in Sources */,
 				337ECC1B10DD5E0700D0C6A5 /* ExpansionPolicy.cpp in Sources */,
+				334B1BF111232A8E007A6DFF /* ParametersController.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]