Skip to content

Commit

Permalink
IOS: Implement kFeatureVirtualKeyboard to show/hide the keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
criezy committed Feb 16, 2019
1 parent 63a6a3c commit 4795f2b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
6 changes: 6 additions & 0 deletions backends/platform/ios7/ios7_osys_main.cpp
Expand Up @@ -171,6 +171,7 @@ bool OSystem_iOS7::hasFeature(Feature f) {
switch (f) {
case kFeatureCursorPalette:
case kFeatureFilteringMode:
case kFeatureVirtualKeyboard:
return true;

default:
Expand All @@ -193,6 +194,9 @@ void OSystem_iOS7::setFeatureState(Feature f, bool enable) {
case kFeatureAspectRatioCorrection:
_videoContext->asprectRatioCorrection = enable;
break;
case kFeatureVirtualKeyboard:
setShowKeyboard(enable);
break;

default:
break;
Expand All @@ -207,6 +211,8 @@ bool OSystem_iOS7::getFeatureState(Feature f) {
return _videoContext->filtering;
case kFeatureAspectRatioCorrection:
return _videoContext->asprectRatioCorrection;
case kFeatureVirtualKeyboard:
return isKeyboardShown();

default:
return false;
Expand Down
2 changes: 2 additions & 0 deletions backends/platform/ios7/ios7_osys_main.h
Expand Up @@ -209,6 +209,8 @@ class OSystem_iOS7 : public EventsBaseBackend, public PaletteManager {
protected:
void initVideoContext();
void updateOutputSurface();
void setShowKeyboard(bool);
bool isKeyboardShown() const;

void internUpdateScreen();
void dirtyFullScreen();
Expand Down
20 changes: 20 additions & 0 deletions backends/platform/ios7/ios7_osys_video.mm
Expand Up @@ -583,3 +583,23 @@ static inline void execute_on_main_thread(void (^block)(void)) {
[[iOS7AppDelegate iPhoneView] updateMouseCursor];
});
}

void OSystem_iOS7::setShowKeyboard(bool show) {
if (show) {
execute_on_main_thread(^ {
[[iOS7AppDelegate iPhoneView] showKeyboard];
});
} else {
// Do not hide the keyboard in portrait mode as it is shown automatically and not
// just when asked with the kFeatureVirtualKeyboard.
if (_screenOrientation == kScreenOrientationLandscape || _screenOrientation == kScreenOrientationFlippedLandscape) {
execute_on_main_thread(^ {
[[iOS7AppDelegate iPhoneView] hideKeyboard];
});
}
}
}

bool OSystem_iOS7::isKeyboardShown() const {
return [[iOS7AppDelegate iPhoneView] isKeyboardShown];
}
5 changes: 5 additions & 0 deletions backends/platform/ios7/ios7_video.h
Expand Up @@ -48,6 +48,7 @@ typedef struct {
Common::List<InternalEvent> _events;
NSLock *_eventLock;
SoftKeyboard *_keyboardView;
BOOL _keyboardVisible;

EAGLContext *_context;
GLuint _viewRenderbuffer;
Expand Down Expand Up @@ -120,6 +121,10 @@ typedef struct {

- (void)deviceOrientationChanged:(UIDeviceOrientation)orientation;

- (void)showKeyboard;
- (void)hideKeyboard;
- (BOOL)isKeyboardShown;

- (void)applicationSuspend;

- (void)applicationResume;
Expand Down
21 changes: 18 additions & 3 deletions backends/platform/ios7/ios7_video.mm
Expand Up @@ -413,6 +413,7 @@ - (id)initWithFrame:(struct CGRect)frame {
#endif

_keyboardView = nil;
_keyboardVisible = NO;
_screenTexture = 0;
_overlayTexture = 0;
_mouseCursorTexture = 0;
Expand Down Expand Up @@ -725,7 +726,7 @@ - (void)initSurface {
[_keyboardView setInputDelegate:self];
[self addSubview:[_keyboardView inputView]];
[self addSubview: _keyboardView];
[_keyboardView showKeyboard];
[self showKeyboard];
}

glBindRenderbuffer(GL_RENDERBUFFER, _viewRenderbuffer); printOpenGLError();
Expand Down Expand Up @@ -907,12 +908,26 @@ - (void)deviceOrientationChanged:(UIDeviceOrientation)orientation {

BOOL isLandscape = (self.bounds.size.width > self.bounds.size.height);
if (isLandscape) {
[_keyboardView hideKeyboard];
[self hideKeyboard];
} else {
[_keyboardView showKeyboard];
[self showKeyboard];
}
}

- (void)showKeyboard {
[_keyboardView showKeyboard];
_keyboardVisible = YES;
}

- (void)hideKeyboard {
[_keyboardView hideKeyboard];
_keyboardVisible = NO;
}

- (BOOL)isKeyboardShown {
return _keyboardVisible;
}

- (UITouch *)secondTouchOtherTouchThan:(UITouch *)touch in:(NSSet *)set {
NSArray *all = [set allObjects];
for (UITouch *t in all) {
Expand Down

0 comments on commit 4795f2b

Please sign in to comment.