diff --git a/app/mac/AppDelegate.mm b/app/mac/AppDelegate.mm index 8676ed878..a6deca32d 100644 --- a/app/mac/AppDelegate.mm +++ b/app/mac/AppDelegate.mm @@ -9,7 +9,6 @@ @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - [Renderer initWindowSize]; } - (void)applicationWillTerminate:(NSNotification *)aNotification diff --git a/app/mac/GameViewController.mm b/app/mac/GameViewController.mm index 617851455..28d8c75ec 100644 --- a/app/mac/GameViewController.mm +++ b/app/mac/GameViewController.mm @@ -1,3 +1,4 @@ +#include #import "GameViewController.h" #import "Renderer.h" @@ -30,4 +31,49 @@ - (void)viewDidLoad _view.delegate = _renderer; } +- (void)mouseDown:(NSEvent *)event +{ + CGPoint windowPos = [event locationInWindow]; + Echo::Input::instance()->notifyMouseButtonDown(0, Echo::Vector2(windowPos.x, windowPos.y)); +} + +- (void)mouseUp:(NSEvent *)event +{ + CGPoint windowPos = [event locationInWindow]; + Echo::Input::instance()->notifyMouseButtonUp(0, Echo::Vector2(windowPos.x, windowPos.y)); +} + +- (void)rightMouseDown:(NSEvent *)event +{ + CGPoint windowPos = [event locationInWindow]; + Echo::Input::instance()->notifyMouseButtonDown(1, Echo::Vector2(windowPos.x, windowPos.y)); +} + +- (void)rightMouseUp:(NSEvent *)event +{ + CGPoint windowPos = [event locationInWindow]; + Echo::Input::instance()->notifyMouseButtonUp(1, Echo::Vector2(windowPos.x, windowPos.y)); +} + +- (void)mouseMoved:(NSEvent *)event +{ + CGPoint windowPos = [event locationInWindow]; + Echo::Input::instance()->notifyMouseMove(0, Echo::Vector2(windowPos.x, windowPos.y)); +} + +- (void)scrollWheel:(NSEvent *)event +{ + +} + +- (void)keyDown:(NSEvent *)event +{ + Echo::Input::instance()->notifyKeyDown(event.keyCode); +} + +- (void)keyUp:(NSEvent *)event +{ + Echo::Input::instance()->notifyKeyUp(event.keyCode); +} + @end diff --git a/app/mac/Renderer.h b/app/mac/Renderer.h index 628fd2fd5..bca28f91e 100644 --- a/app/mac/Renderer.h +++ b/app/mac/Renderer.h @@ -8,7 +8,7 @@ -(nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)view; // init window size -+(nonnull instancetype)initWindowSize; +-(nonnull instancetype)initWindowSize; @end diff --git a/app/mac/Renderer.mm b/app/mac/Renderer.mm index 9b95cd640..764c3b2ed 100644 --- a/app/mac/Renderer.mm +++ b/app/mac/Renderer.mm @@ -36,10 +36,12 @@ -(nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)view Echo::PathUtil::FormatPath(rootcfg.m_userPath); Echo::Engine::instance()->initialize(rootcfg); + [self initWindowSize]; + return self; } -+(nonnull instancetype)initWindowSize +-(nonnull instancetype)initWindowSize { // default window size Echo::GameSettings* settings = Echo::GameSettings::instance();