summaryrefslogtreecommitdiff
path: root/platform/iphone
diff options
context:
space:
mode:
authorRuslan Mustakov <r.mustakov@gmail.com>2017-10-04 15:39:31 +0700
committerRuslan Mustakov <r.mustakov@gmail.com>2017-10-04 17:21:05 +0700
commit275e537058ed870c4d37002f2110b7866d2ed1ae (patch)
tree150656cd97e9bae45098829d34d3fd34f1beadb0 /platform/iphone
parent6dc1025e6313d711939269e1578fff5ffc0cd30a (diff)
Allow to obtain virtual keyboard height
On mobile platforms virtual keyboards take up significant amount of screen space and UI containing a text box may need to be adjusted after the keyboard appears to keep the text box visible to user. This commit adds a way to obtain virtual keyabord height so that controls are aware of how much they need to move.
Diffstat (limited to 'platform/iphone')
-rw-r--r--platform/iphone/gl_view.h2
-rw-r--r--platform/iphone/gl_view.mm40
-rw-r--r--platform/iphone/os_iphone.cpp9
-rw-r--r--platform/iphone/os_iphone.h4
4 files changed, 55 insertions, 0 deletions
diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h
index a9fd8d5711..f7309396c6 100644
--- a/platform/iphone/gl_view.h
+++ b/platform/iphone/gl_view.h
@@ -100,6 +100,8 @@
- (void)destroyFramebuffer;
- (void)audioRouteChangeListenerCallback:(NSNotification *)notification;
+- (void)keyboardOnScreen:(NSNotification *)notification;
+- (void)keyboardHidden:(NSNotification *)notification;
@property NSTimeInterval animationInterval;
@property(nonatomic, assign) BOOL useCADisplayLink;
diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm
index 3e206c3a2c..02da706cc5 100644
--- a/platform/iphone/gl_view.mm
+++ b/platform/iphone/gl_view.mm
@@ -63,6 +63,7 @@ void _pause_video();
void _focus_out_video();
void _unpause_video();
void _stop_video();
+CGFloat _points_to_pixels(CGFloat);
void _show_keyboard(String p_existing) {
keyboard_text = p_existing;
@@ -174,6 +175,19 @@ void _stop_video() {
video_playing = false;
}
+CGFloat _points_to_pixels(CGFloat points) {
+ float pixelPerInch;
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ pixelPerInch = 132;
+ } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+ pixelPerInch = 163;
+ } else {
+ pixelPerInch = 160;
+ }
+ CGFloat pointsPerInch = 72.0;
+ return (points / pointsPerInch * pixelPerInch);
+}
+
@implementation GLView
@synthesize animationInterval;
@@ -537,6 +551,20 @@ static void clear_touches() {
[self resignFirstResponder];
};
+- (void)keyboardOnScreen:(NSNotification *)notification {
+ NSDictionary *info = notification.userInfo;
+ NSValue *value = info[UIKeyboardFrameEndUserInfoKey];
+
+ CGRect rawFrame = [value CGRectValue];
+ CGRect keyboardFrame = [self convertRect:rawFrame fromView:nil];
+
+ OSIPhone::get_singleton()->set_virtual_keyboard_height(_points_to_pixels(keyboardFrame.size.height));
+}
+
+- (void)keyboardHidden:(NSNotification *)notification {
+ OSIPhone::get_singleton()->set_virtual_keyboard_height(0);
+}
+
- (void)deleteBackward {
if (keyboard_text.length())
keyboard_text.erase(keyboard_text.length() - 1, 1);
@@ -606,6 +634,18 @@ static void clear_touches() {
name:AVAudioSessionRouteChangeNotification
object:nil];
+ printf("******** adding observer for keyboard show/hide\n");
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardOnScreen:)
+ name:UIKeyboardDidShowNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardHidden:)
+ name:UIKeyboardDidHideNotification
+ object:nil];
+
//self.autoresizesSubviews = YES;
//[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 5009f7d8ae..219e93facf 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -463,6 +463,14 @@ void OSIPhone::hide_virtual_keyboard() {
_hide_keyboard();
};
+void OSIPhone::set_virtual_keyboard_height(int p_height) {
+ virtual_keyboard_height = p_height;
+}
+
+int OSIPhone::get_virtual_keyboard_height() const {
+ return virtual_keyboard_height;
+}
+
Error OSIPhone::shell_open(String p_uri) {
return _shell_open(p_uri);
};
@@ -576,6 +584,7 @@ OSIPhone::OSIPhone(int width, int height) {
vm.resizable = false;
set_video_mode(vm);
event_count = 0;
+ virtual_keyboard_height = 0;
_set_logger(memnew(SyslogLogger));
};
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 11f4eed5e7..cf2396e87b 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -124,6 +124,8 @@ private:
InputDefault *input;
+ int virtual_keyboard_height;
+
public:
bool iterate();
@@ -133,6 +135,7 @@ public:
void mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, bool p_use_as_mouse);
void touches_cancelled();
void key(uint32_t p_key, bool p_pressed);
+ void set_virtual_keyboard_height(int p_height);
int set_base_framebuffer(int p_fb);
@@ -168,6 +171,7 @@ public:
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
virtual void hide_virtual_keyboard();
+ virtual int get_virtual_keyboard_height() const;
virtual void set_cursor_shape(CursorShape p_shape);