diff --git a/PanoPainter/AppDelegate.m b/PanoPainter/AppDelegate.m index 58061ca..73aac62 100644 --- a/PanoPainter/AppDelegate.m +++ b/PanoPainter/AppDelegate.m @@ -7,9 +7,12 @@ // #import "AppDelegate.h" +#import "GameViewController.h" #include "app.h" -@interface AppDelegate () +@interface AppDelegate () { + GameViewController* view; +} @end @@ -18,17 +21,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. + view = (GameViewController*)self.window.rootViewController; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + App::I.redraw = true; + [view reset_touch]; } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + App::I.redraw = true; } - (void)applicationWillEnterForeground:(UIApplication *)application { @@ -43,6 +50,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + App::I.redraw = true; } @end diff --git a/PanoPainter/GameViewController.h b/PanoPainter/GameViewController.h index c8cfd3c..8b11eca 100644 --- a/PanoPainter/GameViewController.h +++ b/PanoPainter/GameViewController.h @@ -11,4 +11,6 @@ @interface GameViewController : GLKViewController +- (void)reset_touch; + @end diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 1e5f101..fff09b9 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -21,6 +21,7 @@ //std::map< int t_count = 0; +glm::vec2 t_pos; @implementation GameViewController @@ -49,11 +50,27 @@ int t_count = 0; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; - + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillBeShown:) + name:UIKeyboardDidShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWasHidden:) + name:UIKeyboardDidHideNotification object:nil]; +} + +- (void)keyboardWillBeShown:(NSNotification*)aNotification +{ + App::I.redraw = true; + App::I.animate = true; +} +- (void)keyboardWasHidden:(NSNotification*)aNotification +{ + App::I.redraw = true; + App::I.animate = false; } // Called when the UIKeyboardDidShowNotification is sent. @@ -66,8 +83,10 @@ int t_count = 0; CGRect frame = view.frame; frame.size.height -= kbSize.height; view.frame = frame; + App::I.resize(frame.size.width * view.contentScaleFactor, frame.size.height * view.contentScaleFactor); + App::I.animate = false; } // Called when the UIKeyboardWillHideNotification is sent @@ -77,6 +96,16 @@ int t_count = 0; self.view.frame = frame; App::I.resize(frame.size.width * self.view.contentScaleFactor, frame.size.height * self.view.contentScaleFactor); + App::I.animate = true; +} + +- (void)reset_touch +{ + if (t_count == 2) + App::I.gesture_end(); + else + App::I.mouse_cancel(0); + t_count = 0; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event @@ -88,6 +117,7 @@ int t_count = 0; App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force); t_count = 1; + t_pos = {touchLocation.x * scale, touchLocation.y * scale}; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { @@ -135,6 +165,7 @@ int t_count = 0; App::I.mouse_move(touchLocation.x * scale, touchLocation.y * scale, force); } } + t_pos = {tl0.x * scale, tl0.y * scale}; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { @@ -147,6 +178,7 @@ int t_count = 0; else App::I.mouse_up(0, touchLocation.x * scale, touchLocation.y * scale); t_count = 0; + t_pos = {touchLocation.x * scale, touchLocation.y * scale}; } - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator @@ -236,7 +268,7 @@ int t_count = 0; - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { - if (!App::I.redraw) + if (!(App::I.redraw || App::I.animate)) return; App::I.clear(); App::I.update(0); diff --git a/data/layout.xml b/data/layout.xml index 3ea0189..503a9c4 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -173,10 +173,10 @@ - - - - + + + +