[dasher: 5/5] iPhone updates: - Adjust interface (removing toolbar) when iPhone is held in landscape position - Ad



commit 2e238a9972ea48fb2f3c29d10f17e7ee4d5322cc
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Thu Jan 7 14:18:25 2010 +0000

    iPhone updates:
    - Adjust interface (removing toolbar) when iPhone is held in landscape position
    - Add 1px border between text and canvas in both portrait & landscape

 ChangeLog                               |   12 +++++
 Src/iPhone/Classes/DasherAppDelegate.h  |    6 +-
 Src/iPhone/Classes/DasherAppDelegate.mm |   81 ++++++++++++++++++++++++-------
 Src/iPhone/Classes/EAGLView.mm          |    9 ++-
 Src/iPhone/Classes/TextView.h           |    5 +-
 Src/iPhone/Classes/TextView.mm          |   19 +++++++
 6 files changed, 106 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3f38f21..20bbb2d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-01-07  Alan Lawrence <acl33 inf phy cam ac uk>
+
+	* Remove GetSymbols in favour of SymbolStream which converts 
+	  one UTF-8 character at a time avoiding huge vector<symbol>
+	* Robustness improvements to ExpansionPolicy code for 
+	  finding-next-smallest double
+	* iPhone updates:
+	  - ExpansionPolicy, factory removal, DEBUG, private methods
+	  - Adjust interface (removing toolbar) when iPhone is held
+	    in landscape position
+	  - Add 1px border between text and canvas in both portrait & landscape
+
 2009-12-20  Patrick Welche <prlw1 cam ac uk>
 
 	* Import newer gconf-2.m4
diff --git a/Src/iPhone/Classes/DasherAppDelegate.h b/Src/iPhone/Classes/DasherAppDelegate.h
index 2b65ad6..a297b75 100644
--- a/Src/iPhone/Classes/DasherAppDelegate.h
+++ b/Src/iPhone/Classes/DasherAppDelegate.h
@@ -9,14 +9,14 @@
 #import <UIKit/UIKit.h>
 #import "CDasherInterfaceBridge.h"
 #import "CDasherScreenBridge.h"
+#import "TextView.h"
 
 @class EAGLView;
 
- interface DasherAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate, UITextViewDelegate> {
+ interface DasherAppDelegate : UIViewController <UIApplicationDelegate, UIActionSheetDelegate, UITextViewDelegate> {
     UIWindow *window;
-	UIViewController *controller;
     EAGLView *glView;
-	UITextView *text;
+	TextView *text;
 	NSRange selectedText;
 	CDasherInterfaceBridge* _dasherInterface;
 	UIButton *speedBtn;
diff --git a/Src/iPhone/Classes/DasherAppDelegate.mm b/Src/iPhone/Classes/DasherAppDelegate.mm
index 90ed0d2..ae8e5ae 100644
--- a/Src/iPhone/Classes/DasherAppDelegate.mm
+++ b/Src/iPhone/Classes/DasherAppDelegate.mm
@@ -22,6 +22,7 @@
 - (void)initDasherInterface;
 - (void)finishStartup;
 - (void)doSpeedBtnImage:(NSString *)msg;
+- (CGRect)doLayout;
 @property (retain) UILabel *screenLockLabel;
 @end
 
@@ -29,31 +30,75 @@
 
 @synthesize screenLockLabel;
 
+-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+  if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
+    return NO;
+  return YES;
+}
+
+-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+  [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+  CGRect appFrame = [UIScreen mainScreen].applicationFrame;
+  window.frame=appFrame;
+  self.view.frame = CGRectMake(0.0, 0.0, appFrame.size.width, appFrame.size.height);
+  if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
+    [self.view addSubview:tools];
+  else
+    [tools removeFromSuperview];
+  [self doLayout];
+}
+
+/// Sets sizes of toolbar and textview according to current orientation
+/// Also computes and returns desired size of glView, and sets said _iff_ glView is non-nil
+-(CGRect)doLayout {
+  CGSize mainSize = self.view.bounds.size;
+  CGRect dashRect;
+  switch (self.interfaceOrientation) {
+    case UIInterfaceOrientationPortrait: {
+      dashRect = CGRectMake(0.0, 0.0, mainSize.width, mainSize.height - 100.0);
+      /*CGRect textRect =*/text.frame = CGRectMake(0.0, dashRect.size.height, mainSize.width, 70.0);
+      text.bLandscape = NO;
+      tools.frame = CGRectMake(0.0, mainSize.height - 30.0, mainSize.width, 30.0);
+      break;
+    }
+    case UIInterfaceOrientationLandscapeRight:
+    case UIInterfaceOrientationLandscapeLeft: {
+      CGRect textRect = CGRectMake(0.0, 0.0, 100.0, mainSize.height);//-30.0);
+      text.frame = textRect;
+      text.bLandscape = YES;
+      dashRect = CGRectMake(textRect.size.width, 0.0, mainSize.width-textRect.size.width, mainSize.height);//-30.0);
+      break;
+    }
+    default:
+      NSAssert(false, @"Unexpected interface orientation");
+  }
+  if (glView) glView.frame=dashRect;
+  return dashRect;
+}
+
 -(CDasherInterfaceBridge *)dasherInterface {return _dasherInterface;}
 
 - (void)applicationDidFinishLaunching:(UIApplication *)application {
 	CGSize mainSize = [UIScreen mainScreen].applicationFrame.size;
 	window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
-	controller = [[UIViewController alloc] init];
-	controller.view = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, mainSize.width, mainSize.height)] autorelease];
+	self.view = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, mainSize.width, mainSize.height)] autorelease];
 
-	[window addSubview:controller.view];
+	[window addSubview:self.view];
 
   //start training in a separate thread.
-  [controller doAsyncLocked:@"Initializing..." target:self selector:@selector(initDasherInterface) param:nil];
+  [self doAsyncLocked:@"Initializing..." target:self selector:@selector(initDasherInterface) param:nil];
 
-	CGRect dashRect = CGRectMake(0.0, 0.0, mainSize.width, mainSize.height - 100.0);
-	CGRect textRect = CGRectMake(0.0, dashRect.size.height, mainSize.width, 70.0);
-	CGRect toolRect = CGRectMake(0.0, mainSize.height - 30.0, mainSize.width, 30.0);
-	glView = [[[EAGLView alloc] initWithFrame:dashRect Delegate:self] autorelease];
+  //create GUI components...
+	text = [[[TextView alloc] init] autorelease];
+	tools = [[UIToolbar alloc] init]; //retain a reference (until dealloc) because of rotation
+	glView = [[[EAGLView alloc] initWithFrame:[self doLayout] Delegate:self] autorelease];
 	
-	text = [[[TextView alloc] initWithFrame:textRect] autorelease];
 	text.text=@"";
 	text.editable = NO;
 	text.delegate = self;
 	selectedText.location = selectedText.length = 0;
-	
-	tools = [[[UIToolbar alloc] initWithFrame:toolRect] autorelease];
+
+  //...and lay them out
 	UIBarButtonItem *settings = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cog.png"] style:UIBarButtonItemStylePlain target:self action:@selector(settings)] autorelease];
 	speedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 	[speedBtn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 2.0, 0.0, 2.0)];
@@ -72,9 +117,9 @@
 				mail,
 				nil]];
 	
-	[controller.view addSubview:glView];
-	[controller.view addSubview:text];
-	[controller.view addSubview:tools];
+	[self.view addSubview:glView];
+	[self.view addSubview:text];
+	[self.view addSubview:tools];
 	[window makeKeyAndVisible];
   //exit this routine; initDasherInterface (in separate thread) will cause this (main) thread
   // to execute finishStartup, and finally unlock the display, when it's done with training etc.
@@ -147,11 +192,11 @@
                 [[[StringParamController alloc] initWithTitle:@"Colour" image:[UIImage imageNamed:@"palette.png"] settingParam:SP_COLOUR_ID] autorelease],
 						    [[[MiscSettings alloc] init] autorelease],
 						    nil];
-  [controller presentModalViewController:settings animated:YES];
+  [self presentModalViewController:settings animated:YES];
 }
 
 - (void)settingsDone {
-	[controller dismissModalViewControllerAnimated:YES];
+	[self dismissModalViewControllerAnimated:YES];
 	[glView startAnimation];
 }
 
@@ -235,8 +280,8 @@
 }
 
 - (void)dealloc {
-	[controller release];
 	[window release];
+  [tools release];
 	[super dealloc];
 }
 
@@ -335,4 +380,4 @@
   [pool release];
 }
 
- end
\ No newline at end of file
+ end
diff --git a/Src/iPhone/Classes/EAGLView.mm b/Src/iPhone/Classes/EAGLView.mm
index 72de06b..1137bec 100644
--- a/Src/iPhone/Classes/EAGLView.mm
+++ b/Src/iPhone/Classes/EAGLView.mm
@@ -105,11 +105,14 @@
 
 
 - (void)layoutSubviews {
-	doneLayout = YES;
-    [EAGLContext setCurrentContext:context];
+	  [EAGLContext setCurrentContext:context];
     [self destroyFramebuffer];
     [self createFramebuffer];
-    [self drawView];
+  if (doneLayout)
+    dasherApp.dasherInterface->ChangeScreen(new CDasherScreenBridge(self));
+  else //first time, DasherAppDelegate will create screen as part of startup
+    doneLayout = YES;
+  [self drawView];
 }
 
 
diff --git a/Src/iPhone/Classes/TextView.h b/Src/iPhone/Classes/TextView.h
index 8284002..f96245b 100644
--- a/Src/iPhone/Classes/TextView.h
+++ b/Src/iPhone/Classes/TextView.h
@@ -8,9 +8,10 @@
 
 #import <UIKit/UIKit.h>
 
-
 @interface TextView : UITextView {
-
+  BOOL bLandscape;
 }
 
+/// TRUE => draw border along right edge; FALSE => draw border along top edge
+ property (nonatomic) BOOL bLandscape;
 @end
diff --git a/Src/iPhone/Classes/TextView.mm b/Src/iPhone/Classes/TextView.mm
index e6ca698..3bb5487 100644
--- a/Src/iPhone/Classes/TextView.mm
+++ b/Src/iPhone/Classes/TextView.mm
@@ -11,6 +11,7 @@
 
 @implementation TextView
 
+ synthesize bLandscape;
 
 - (id)initWithFrame:(CGRect)frame {
     if (self = [super initWithFrame:frame]) {
@@ -29,4 +30,22 @@
   if (!bEditable) [super setEditable:NO];
 }
 
+-(void)drawRect:(CGRect) rect {
+  [super drawRect:rect];
+  //add one-pixel border along appropriate edge, to separate from Dasher "canvas"
+  CGContextRef currentContext = UIGraphicsGetCurrentContext();
+  CGContextSetLineWidth(currentContext, 1.0); //or whatever width you want
+  CGContextSetRGBStrokeColor(currentContext, 0.0, 0.0, 0.0, 1.0);
+  CGContextBeginPath(currentContext);
+  CGSize sz = self.frame.size;
+  if (bLandscape) {
+    CGContextMoveToPoint(currentContext,sz.width,0.0);
+    CGContextAddLineToPoint(currentContext, sz.width, sz.height);
+  } else {
+    CGContextMoveToPoint(currentContext,0.0,0.0);
+    CGContextAddLineToPoint(currentContext, sz.width, 0.0);
+  }
+  CGContextStrokePath(currentContext);
+}
+
 @end



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