diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-10-01 04:43:09 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-10-01 04:43:09 +0000 |
| commit | 99049558d148696e3a12c67943bc2fa2fce5a7ec (patch) | |
| tree | f8f52f5291db69a2faf08edbad24cdca991ad583 | |
| parent | MacOS app: using Command+f or Command+Enter to toggle fullscreen mode instead... (diff) | |
| download | DiligentEngine-99049558d148696e3a12c67943bc2fa2fce5a7ec.tar.gz DiligentEngine-99049558d148696e3a12c67943bc2fa2fce5a7ec.zip | |
Updated MacOS application
| -rw-r--r-- | Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm | 106 | ||||
| -rw-r--r-- | Common/NativeApp/include/MacOS/MacOSAppBase.h | 7 |
2 files changed, 24 insertions, 89 deletions
diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm index 6af9c4c..c8f9228 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm +++ b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm @@ -26,112 +26,58 @@ @implementation ViewController - -- (void)mouseMove:(NSEvent *)theEvent { - NSPoint curPoint = [self.view convertPoint:[theEvent locationInWindow] fromView:nil]; - - NSRect viewRectPoints = [self.view bounds]; - NSRect viewRectPixels = [self.view convertRectToBacking:viewRectPoints]; - curPoint = [self.view convertPointToBacking:curPoint]; - +- (void)handleEvent : (NSEvent *)theEvent { auto* view = (ViewBase*)self.view; auto* theApp = [view lockApp]; - if(theApp) - theApp->OnMouseMove(curPoint.x, viewRectPixels.size.height-1 - curPoint.y); + if(theApp){ + theApp->HandleOSXEvent(theEvent, view); + } [view unlockApp]; } +- (void)mouseMove:(NSEvent *)theEvent { + [self handleEvent:theEvent]; +} + - (void)mouseDown:(NSEvent *)theEvent { - [self mouseMove: theEvent]; - - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - theApp->OnMouseDown(1); - [view unlockApp]; - } + [self handleEvent:theEvent]; } - (void)mouseUp:(NSEvent *)theEvent { - [self mouseMove: theEvent]; - - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - theApp->OnMouseUp(1); - [view unlockApp]; - } + [self handleEvent:theEvent]; } - (void)rightMouseDown:(NSEvent *)theEvent { - [self mouseMove: theEvent]; - - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - theApp->OnMouseDown(3); - [view unlockApp]; - } + [self handleEvent:theEvent]; } - (void)rightMouseUp:(NSEvent *)theEvent { - [self mouseMove: theEvent]; - - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - theApp->OnMouseUp(3); - [view unlockApp]; - } + [self handleEvent:theEvent]; } - (void)mouseMoved:(NSEvent *)theEvent { - [self mouseMove: theEvent]; + [self handleEvent:theEvent]; } - (void)mouseDragged:(NSEvent *)theEvent { - [self mouseMove: theEvent]; + [self handleEvent:theEvent]; } - (void)keyEvent:(NSEvent *)theEvent isKeyPressed:(bool)keyPressed { - unichar c = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; - int key = 0; - switch(c){ - case NSLeftArrowFunctionKey: key = 260; break; - case NSRightArrowFunctionKey: key = 262; break; - case 0x7F: key = '\b'; break; - default: key = c; - } - - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - { - if (keyPressed) - theApp->OnKeyPressed(key); - else - theApp->OnKeyReleased(key); - } - [view unlockApp]; - } + [self handleEvent:theEvent]; } - (void)keyDown:(NSEvent *)theEvent { - [self keyEvent:theEvent isKeyPressed:true]; + [self handleEvent:theEvent]; [super keyDown:theEvent]; } - (void)keyUp:(NSEvent *)theEvent { - [self keyEvent:theEvent isKeyPressed:false]; + [self handleEvent:theEvent]; [super keyUp:theEvent]; } @@ -140,22 +86,16 @@ // modifier key (Shift, Control, and so on) - (void)flagsChanged:(NSEvent *)event { - auto modifierFlags = [event modifierFlags]; - { - auto* view = (ViewBase*)self.view; - auto* theApp = [view lockApp]; - if(theApp) - { - theApp->OnFlagsChanged(modifierFlags & NSEventModifierFlagShift, - modifierFlags & NSEventModifierFlagControl, - modifierFlags & NSEventModifierFlagOption); - } - [view unlockApp]; - } + [self handleEvent:event]; [super flagsChanged:event]; } +- (void)scrollWheel:(NSEvent *)event +{ + [self handleEvent:event]; +} + - (BOOL)acceptsFirstResponder { return YES; } diff --git a/Common/NativeApp/include/MacOS/MacOSAppBase.h b/Common/NativeApp/include/MacOS/MacOSAppBase.h index a242b8e..923fcec 100644 --- a/Common/NativeApp/include/MacOS/MacOSAppBase.h +++ b/Common/NativeApp/include/MacOS/MacOSAppBase.h @@ -35,12 +35,7 @@ public: using AppBase::Update; void Update(); virtual void Initialize(void* view) = 0; - virtual void OnMouseDown(int button){} - virtual void OnMouseUp(int button){} - virtual void OnMouseMove(int x, int y){} - virtual void OnKeyPressed(int key){} - virtual void OnKeyReleased(int key){} - virtual void OnFlagsChanged(bool ShiftPressed, bool ControlPressed, bool AltPressed){} + virtual void HandleOSXEvent(void* event, void* view){}; protected: Timer timer; |
