input boxes UI, keyboard animation

This commit is contained in:
2017-08-13 12:41:10 +01:00
parent 6d3c9380b2
commit 060e08a891
12 changed files with 132 additions and 41 deletions

View File

@@ -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

View File

@@ -11,4 +11,6 @@
@interface GameViewController : GLKViewController <UIKeyInput>
- (void)reset_touch;
@end

View File

@@ -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<UITouch *> *)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<UITouch *> *)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<UITouch *> *)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<UIViewControllerTransitionCoordinator>)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);