IOS7: Add input accessory view to virtual keyboard

This adds buttons for some keys that are not present on the iOS
keyboard, such as the function and arrow keys, as well as a GMM
key.
This commit is contained in:
Thierry Crozat 2019-06-23 21:46:47 +01:00
parent d6a1248a16
commit 3ba9245138
5 changed files with 158 additions and 5 deletions

View file

@ -40,7 +40,8 @@ enum InputEvent {
kInputApplicationSuspended, kInputApplicationSuspended,
kInputApplicationResumed, kInputApplicationResumed,
kInputSwipe, kInputSwipe,
kInputTap kInputTap,
kInputMainMenu
}; };
enum ScreenOrientation { enum ScreenOrientation {

View file

@ -35,6 +35,7 @@
- (UITextView *)inputView; - (UITextView *)inputView;
- (void)setInputDelegate:(id)delegate; - (void)setInputDelegate:(id)delegate;
- (void)handleKeyPress:(unichar)c; - (void)handleKeyPress:(unichar)c;
- (void)handleMainMenuKey;
- (void)showKeyboard; - (void)showKeyboard;
- (void)hideKeyboard; - (void)hideKeyboard;

View file

@ -21,6 +21,7 @@
*/ */
#include "backends/platform/ios7/ios7_keyboard.h" #include "backends/platform/ios7/ios7_keyboard.h"
#include "common/keyboard.h"
@interface UITextInputTraits @interface UITextInputTraits
- (void)setAutocorrectionType:(int)type; - (void)setAutocorrectionType:(int)type;
@ -50,6 +51,66 @@
//item.leadingBarButtonGroups = @[]; //item.leadingBarButtonGroups = @[];
//item.trailingBarButtonGroups = @[]; //item.trailingBarButtonGroups = @[];
UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)] autorelease];
toolbar.barTintColor = keyboard.backgroundColor;
toolbar.tintColor = keyboard.tintColor;
toolbar.translucent = NO;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
toolbar.items = @[
// GMM button
[[[UIBarButtonItem alloc] initWithTitle:@"\u2630" style:UIBarButtonItemStylePlain target:self action:@selector(mainMenuKey)] autorelease],
// Escape key
[[[UIBarButtonItem alloc] initWithTitle:@"Esc" style:UIBarButtonItemStylePlain target:self action:@selector(escapeKey)] autorelease],
// Return key
[[[UIBarButtonItem alloc] initWithTitle:@"\u23ce" style:UIBarButtonItemStylePlain target:self action:@selector(returnKey)] autorelease],
// Function keys
[[[UIBarButtonItem alloc] initWithTitle:@"F1" style:UIBarButtonItemStylePlain target:self action:@selector(fn1Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F2" style:UIBarButtonItemStylePlain target:self action:@selector(fn2Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F3" style:UIBarButtonItemStylePlain target:self action:@selector(fn3Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F4" style:UIBarButtonItemStylePlain target:self action:@selector(fn4Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F5" style:UIBarButtonItemStylePlain target:self action:@selector(fn5Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F6" style:UIBarButtonItemStylePlain target:self action:@selector(fn6Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F7" style:UIBarButtonItemStylePlain target:self action:@selector(fn7Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F8" style:UIBarButtonItemStylePlain target:self action:@selector(fn8Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F9" style:UIBarButtonItemStylePlain target:self action:@selector(fn9Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F10" style:UIBarButtonItemStylePlain target:self action:@selector(fn10Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F11" style:UIBarButtonItemStylePlain target:self action:@selector(fn11Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F12" style:UIBarButtonItemStylePlain target:self action:@selector(fn12Key)] autorelease],
// Arrow keys
[[[UIBarButtonItem alloc] initWithTitle:@"\u2190" style:UIBarButtonItemStylePlain target:self action:@selector(leftArrowKey)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"\u2191" style:UIBarButtonItemStylePlain target:self action:@selector(upArrowKey)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"\u2192" style:UIBarButtonItemStylePlain target:self action:@selector(rightArrowKey)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"\u2193" style:UIBarButtonItemStylePlain target:self action:@selector(downArrowKey)] autorelease],
// Spacer at the end
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
];
} else {
// There is less space, so only add buttons for keys for which we do not have getsures
toolbar.items = @[
// Return key
[[[UIBarButtonItem alloc] initWithTitle:@"\u23ce" style:UIBarButtonItemStylePlain target:self action:@selector(returnKey)] autorelease],
// Function keys
[[[UIBarButtonItem alloc] initWithTitle:@"F1" style:UIBarButtonItemStylePlain target:self action:@selector(fn1Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F2" style:UIBarButtonItemStylePlain target:self action:@selector(fn2Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F3" style:UIBarButtonItemStylePlain target:self action:@selector(fn3Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F4" style:UIBarButtonItemStylePlain target:self action:@selector(fn4Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F5" style:UIBarButtonItemStylePlain target:self action:@selector(fn5Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F6" style:UIBarButtonItemStylePlain target:self action:@selector(fn6Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F7" style:UIBarButtonItemStylePlain target:self action:@selector(fn7Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F8" style:UIBarButtonItemStylePlain target:self action:@selector(fn8Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F9" style:UIBarButtonItemStylePlain target:self action:@selector(fn9Key)] autorelease],
[[[UIBarButtonItem alloc] initWithTitle:@"F10" style:UIBarButtonItemStylePlain target:self action:@selector(fn10Key)] autorelease],
// [[[UIBarButtonItem alloc] initWithTitle:@"F11" style:UIBarButtonItemStylePlain target:self action:@selector(fn11Key)] autorelease],
// [[[UIBarButtonItem alloc] initWithTitle:@"F12" style:UIBarButtonItemStylePlain target:self action:@selector(fn12Key)] autorelease],
// Spacer at the end
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
];
}
self.inputAccessoryView = toolbar;
[toolbar sizeToFit];
return self; return self;
} }
@ -62,19 +123,95 @@
} }
- (void) upArrow: (UIKeyCommand *) keyCommand { - (void) upArrow: (UIKeyCommand *) keyCommand {
[softKeyboard handleKeyPress:273]; [softKeyboard handleKeyPress:Common::KEYCODE_UP];
} }
- (void) downArrow: (UIKeyCommand *) keyCommand { - (void) downArrow: (UIKeyCommand *) keyCommand {
[softKeyboard handleKeyPress:274]; [softKeyboard handleKeyPress:Common::KEYCODE_DOWN];
} }
- (void) leftArrow: (UIKeyCommand *) keyCommand { - (void) leftArrow: (UIKeyCommand *) keyCommand {
[softKeyboard handleKeyPress:276]; [softKeyboard handleKeyPress:Common::KEYCODE_LEFT];
} }
- (void) rightArrow: (UIKeyCommand *) keyCommand { - (void) rightArrow: (UIKeyCommand *) keyCommand {
[softKeyboard handleKeyPress:275]; [softKeyboard handleKeyPress:Common::KEYCODE_RIGHT];
}
- (void) mainMenuKey {
[softKeyboard handleMainMenuKey];
}
- (void) escapeKey {
[softKeyboard handleKeyPress:Common::KEYCODE_ESCAPE];
}
- (void) fn1Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F1];
}
- (void) fn2Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F2];
}
- (void) fn3Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F3];
}
- (void) fn4Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F4];
}
- (void) fn5Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F5];
}
- (void) fn6Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F6];
}
- (void) fn7Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F7];
}
- (void) fn8Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F8];
}
- (void) fn9Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F9];
}
- (void) fn10Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F10];
}
- (void) fn11Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F11];
}
- (void) fn12Key {
[softKeyboard handleKeyPress:Common::KEYCODE_F12];
}
- (void) leftArrowKey {
[softKeyboard handleKeyPress:Common::KEYCODE_LEFT];
}
- (void) upArrowKey {
[softKeyboard handleKeyPress:Common::KEYCODE_UP];
}
- (void) rightArrowKey {
[softKeyboard handleKeyPress:Common::KEYCODE_RIGHT];
}
- (void) downArrowKey {
[softKeyboard handleKeyPress:Common::KEYCODE_DOWN];
}
- (void) returnKey {
[softKeyboard handleKeyPress:Common::KEYCODE_RETURN];
} }
@end @end
@ -114,6 +251,10 @@
[inputDelegate handleKeyPress:c]; [inputDelegate handleKeyPress:c];
} }
- (void)handleMainMenuKey {
[inputDelegate handleMainMenuKey];
}
- (void)showKeyboard { - (void)showKeyboard {
[inputView becomeFirstResponder]; [inputView becomeFirstResponder];
} }

View file

@ -106,6 +106,12 @@ bool OSystem_iOS7::pollEvent(Common::Event &event) {
return false; return false;
break; break;
case kInputMainMenu:
event.type = Common::EVENT_MAINMENU;
_queuedInputEvent.type = Common::EVENT_INVALID;
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
break;
default: default:
break; break;
} }

View file

@ -1066,6 +1066,10 @@ uint getSizeNextPOT(uint size) {
} }
} }
- (void)handleMainMenuKey {
[self addEvent:InternalEvent(kInputMainMenu, 0, 0)];
}
- (void)applicationSuspend { - (void)applicationSuspend {
[self addEvent:InternalEvent(kInputApplicationSuspended, 0, 0)]; [self addEvent:InternalEvent(kInputApplicationSuspended, 0, 0)];
} }