mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-31 22:05:10 +02:00
Merge pull request #1493 from kambala-decapitator/ios-spacebar
[iOS] use pinch gesture as Spacebar hotkey instead of Tab
This commit is contained in:
commit
7e78e0abdc
@ -10,11 +10,13 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#include <SDL_events.h>
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface GameChatKeyboardHandler : NSObject
|
@interface GameChatKeyboardHandler : NSObject
|
||||||
|
|
||||||
- (void)triggerInput;
|
+ (void)sendKeyEventWithKeyCode:(SDL_KeyCode)keyCode;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -10,20 +10,8 @@
|
|||||||
|
|
||||||
#import "GameChatKeyboardHandler.h"
|
#import "GameChatKeyboardHandler.h"
|
||||||
|
|
||||||
#include <SDL_events.h>
|
|
||||||
|
|
||||||
static int watchReturnKey(void * userdata, SDL_Event * event);
|
static int watchReturnKey(void * userdata, SDL_Event * event);
|
||||||
|
|
||||||
static void sendKeyEvent(SDL_KeyCode keyCode)
|
|
||||||
{
|
|
||||||
SDL_Event keyEvent;
|
|
||||||
keyEvent.key = (SDL_KeyboardEvent){
|
|
||||||
.type = SDL_KEYDOWN,
|
|
||||||
.keysym.sym = keyCode,
|
|
||||||
};
|
|
||||||
SDL_PushEvent(&keyEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@interface GameChatKeyboardHandler ()
|
@interface GameChatKeyboardHandler ()
|
||||||
@property (nonatomic) BOOL wasChatMessageSent;
|
@property (nonatomic) BOOL wasChatMessageSent;
|
||||||
@ -31,28 +19,40 @@ static void sendKeyEvent(SDL_KeyCode keyCode)
|
|||||||
|
|
||||||
@implementation GameChatKeyboardHandler
|
@implementation GameChatKeyboardHandler
|
||||||
|
|
||||||
- (void)triggerInput {
|
+ (void)sendKeyEventWithKeyCode:(SDL_KeyCode)keyCode
|
||||||
|
{
|
||||||
|
SDL_Event keyEvent;
|
||||||
|
keyEvent.key = (SDL_KeyboardEvent){
|
||||||
|
.type = SDL_KEYDOWN,
|
||||||
|
.state = SDL_PRESSED,
|
||||||
|
.keysym.sym = keyCode,
|
||||||
|
};
|
||||||
|
SDL_PushEvent(&keyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
__auto_type notificationCenter = NSNotificationCenter.defaultCenter;
|
__auto_type notificationCenter = NSNotificationCenter.defaultCenter;
|
||||||
[notificationCenter addObserver:self selector:@selector(textDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
|
[notificationCenter addObserver:self selector:@selector(textDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
|
||||||
[notificationCenter addObserver:self selector:@selector(textDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil];
|
[notificationCenter addObserver:self selector:@selector(textDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil];
|
||||||
|
|
||||||
self.wasChatMessageSent = NO;
|
return self;
|
||||||
sendKeyEvent(SDLK_TAB);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Notifications
|
#pragma mark - Notifications
|
||||||
|
|
||||||
- (void)textDidBeginEditing:(NSNotification *)n {
|
- (void)textDidBeginEditing:(NSNotification *)n {
|
||||||
|
self.wasChatMessageSent = NO;
|
||||||
|
|
||||||
// watch for pressing Return to ignore sending Escape key after keyboard is closed
|
// watch for pressing Return to ignore sending Escape key after keyboard is closed
|
||||||
SDL_AddEventWatch(watchReturnKey, (__bridge void *)self);
|
SDL_AddEventWatch(watchReturnKey, (__bridge void *)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)textDidEndEditing:(NSNotification *)n {
|
- (void)textDidEndEditing:(NSNotification *)n {
|
||||||
[NSNotificationCenter.defaultCenter removeObserver:self];
|
|
||||||
|
|
||||||
// discard chat message
|
// discard chat message
|
||||||
if(!self.wasChatMessageSent)
|
if(!self.wasChatMessageSent)
|
||||||
sendKeyEvent(SDLK_ESCAPE);
|
[[self class] sendKeyEventWithKeyCode:SDLK_ESCAPE];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
- (void)handlePinch:(UIGestureRecognizer *)gesture {
|
- (void)handlePinch:(UIGestureRecognizer *)gesture {
|
||||||
if(gesture.state != UIGestureRecognizerStateBegan || CSH->state != EClientState::GAMEPLAY)
|
if(gesture.state != UIGestureRecognizerStateBegan || CSH->state != EClientState::GAMEPLAY)
|
||||||
return;
|
return;
|
||||||
[self.gameChatHandler triggerInput];
|
[GameChatKeyboardHandler sendKeyEventWithKeyCode:SDLK_SPACE];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - UIGestureRecognizerDelegate
|
#pragma mark - UIGestureRecognizerDelegate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user