summaryrefslogtreecommitdiffstats
path: root/Common/NativeApp
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-05-17 06:07:02 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-05-17 06:07:02 +0000
commitce421eff9d5745a2227db4150304a8ea22096a3f (patch)
treebad10872cd8318558963b343bd7d8686543c6366 /Common/NativeApp
parentUpdated samples (fixed build error) (diff)
downloadDiligentEngine-ce421eff9d5745a2227db4150304a8ea22096a3f.tar.gz
DiligentEngine-ce421eff9d5745a2227db4150304a8ea22096a3f.zip
NativeApp: added key released event handling on MacOS
Diffstat (limited to 'Common/NativeApp')
-rw-r--r--Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm26
-rw-r--r--Common/NativeApp/include/MacOS/MacOSAppBase.h1
2 files changed, 23 insertions, 4 deletions
diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
index 9559284..0df734b 100644
--- a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
+++ b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm
@@ -97,7 +97,8 @@
[self mouseMove: theEvent];
}
-- (void)keyDown:(NSEvent *)theEvent {
+- (void)keyEvent:(NSEvent *)theEvent isKeyPressed:(bool)keyPressed
+{
unichar c = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
int key = 0;
switch(c){
@@ -106,18 +107,35 @@
case 0x7F: key = '\b'; break;
default: key = c;
}
-
+
{
auto* view = (ViewBase*)self.view;
auto* theApp = [view lockApp];
if(theApp)
- theApp->OnKeyPressed(key);
+ {
+ if (keyPressed)
+ theApp->OnKeyPressed(key);
+ else
+ theApp->OnKeyReleased(key);
+ }
[view unlockApp];
}
-
+}
+
+- (void)keyDown:(NSEvent *)theEvent
+{
+ [self keyEvent:theEvent isKeyPressed:true];
+
[super keyDown:theEvent];
}
+- (void)keyUp:(NSEvent *)theEvent
+{
+ [self keyEvent:theEvent isKeyPressed:false];
+
+ [super keyUp:theEvent];
+}
+
- (BOOL)acceptsFirstResponder {
return YES;
}
diff --git a/Common/NativeApp/include/MacOS/MacOSAppBase.h b/Common/NativeApp/include/MacOS/MacOSAppBase.h
index d8df9df..2922ac9 100644
--- a/Common/NativeApp/include/MacOS/MacOSAppBase.h
+++ b/Common/NativeApp/include/MacOS/MacOSAppBase.h
@@ -39,6 +39,7 @@ public:
virtual void OnMouseUp(int button){}
virtual void OnMouseMove(int x, int y){}
virtual void OnKeyPressed(int key){}
+ virtual void OnKeyReleased(int key){}
protected:
Timer timer;