Skip to content

Commit

Permalink
Build for mac platform #777
Browse files Browse the repository at this point in the history
  • Loading branch information
timi-liuliang committed Oct 11, 2020
1 parent 61c5be4 commit 6d50523
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/mac/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[Renderer initWindowSize];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification
Expand Down
46 changes: 46 additions & 0 deletions app/mac/GameViewController.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <engine/core/input/input.h>
#import "GameViewController.h"
#import "Renderer.h"

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/mac/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-(nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)view;

// init window size
+(nonnull instancetype)initWindowSize;
-(nonnull instancetype)initWindowSize;

@end

4 changes: 3 additions & 1 deletion app/mac/Renderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6d50523

Please # to comment.