|
|
@@ -102,9 +102,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
|
|
|
- (id) initWithFrame: (NSRect) frame
|
|
|
{
|
|
|
- lock = [[NSRecursiveLock alloc] init];
|
|
|
- _game = Game::getInstance();
|
|
|
- __timeStart = getMachTimeInMilliseconds();
|
|
|
+
|
|
|
NSOpenGLPixelFormatAttribute attrs[] =
|
|
|
{
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
@@ -120,7 +118,12 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
if (!pf)
|
|
|
NSLog(@"OpenGL pixel format not supported.");
|
|
|
|
|
|
- self = [super initWithFrame:frame pixelFormat:[pf autorelease]];
|
|
|
+ if((self = [super initWithFrame:frame pixelFormat:[pf autorelease]]))
|
|
|
+ {
|
|
|
+ lock = [[NSRecursiveLock alloc] init];
|
|
|
+ _game = Game::getInstance();
|
|
|
+ __timeStart = getMachTimeInMilliseconds();
|
|
|
+ }
|
|
|
|
|
|
return self;
|
|
|
}
|
|
|
@@ -173,18 +176,87 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
[super dealloc];
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Fires a mouse event or a touch event on the game.
|
|
|
+ * If the mouse event is not consumed, a touch event is fired instead.
|
|
|
+ *
|
|
|
+ * @param mouseEvent The mouse event to fire.
|
|
|
+ * @param touchEvent The touch event to fire.
|
|
|
+ * @param x The x position of the touch in pixels.
|
|
|
+ * @param y The y position of the touch in pixels.
|
|
|
+ */
|
|
|
+void mouseOrTouchEvent(Mouse::MouseEvent mouseEvent, Touch::TouchEvent touchEvent, int x, int y)
|
|
|
+{
|
|
|
+ if (!Game::getInstance()->mouseEvent(mouseEvent, x, y, 0))
|
|
|
+ {
|
|
|
+ Game::getInstance()->touchEvent(touchEvent, x, y, 0);
|
|
|
+ }
|
|
|
+}
|
|
|
+- (void) mouse: (Mouse::MouseEvent) mouseEvent orTouchEvent: (Touch::TouchEvent) touchEvent atX: (int) x y: (int) y s: (int) s
|
|
|
+{
|
|
|
+ if (!Game::getInstance()->mouseEvent(mouseEvent, x, y, s))
|
|
|
+ {
|
|
|
+ Game::getInstance()->touchEvent(touchEvent, x, y, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ // Fire a move event if none of the buttons changed.
|
|
|
+ if (left_move)
|
|
|
+ {
|
|
|
+ mouseOrTouchEvent(Mouse::MOUSE_MOVE, Touch::TOUCH_MOVE, position[0], position[1]);
|
|
|
+ }
|
|
|
+ else if (move)
|
|
|
+ {
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_MOVE, position[0], position[1], 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle mouse wheel events
|
|
|
+ if (wheel)
|
|
|
+ {
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_WHEEL, position[0], position[1], -wheel);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
- (void) mouseDown: (NSEvent*) event
|
|
|
{
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
__leftMouseDown = true;
|
|
|
- _game->touchEvent(Touch::TOUCH_PRESS, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ [self mouse: Mouse::MOUSE_PRESS_LEFT_BUTTON orTouchEvent: Touch::TOUCH_PRESS atX: WINDOW_HEIGHT - point.x y: point.y s: 0];
|
|
|
+
|
|
|
+
|
|
|
+ //_game->mouseEvent(Mouse::MOUSE_PRESS_LEFT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ /*
|
|
|
+ MOUSE_PRESS_LEFT_BUTTON,
|
|
|
+ MOUSE_RELEASE_LEFT_BUTTON,
|
|
|
+ MOUSE_PRESS_MIDDLE_BUTTON,
|
|
|
+ MOUSE_RELEASE_MIDDLE_BUTTON,
|
|
|
+ MOUSE_PRESS_RIGHT_BUTTON,
|
|
|
+ MOUSE_RELEASE_RIGHT_BUTTON,
|
|
|
+ MOUSE_MOVE,
|
|
|
+ MOUSE_WHEEL
|
|
|
+*/
|
|
|
}
|
|
|
|
|
|
- (void) mouseUp: (NSEvent*) event
|
|
|
{
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
__leftMouseDown = false;
|
|
|
- _game->touchEvent(Touch::TOUCH_RELEASE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ [self mouse: Mouse::MOUSE_RELEASE_LEFT_BUTTON orTouchEvent: Touch::TOUCH_RELEASE atX: point.x y: WINDOW_HEIGHT - point.y s: 0];
|
|
|
+}
|
|
|
+- (void)mouseMoved:(NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+- (void)scrollWheel: (NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_WHEEL, point.x, WINDOW_HEIGHT - point.y, (int)([theEvent deltaY] * 10.0f));
|
|
|
}
|
|
|
|
|
|
- (void) mouseDragged: (NSEvent*) event
|
|
|
@@ -192,7 +264,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
if (__leftMouseDown)
|
|
|
{
|
|
|
- _game->touchEvent(Touch::TOUCH_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ [self mouse: Mouse::MOUSE_MOVE orTouchEvent: Touch::TOUCH_MOVE atX: point.x y: WINDOW_HEIGHT - point.y s: 0];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -201,12 +273,14 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
__rightMouseDown = true;
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
__lx = point.x;
|
|
|
- __ly = WINDOW_HEIGHT - point.y;
|
|
|
+ __ly = WINDOW_HEIGHT - point.y;
|
|
|
+ //_game->mouseEvent(Mouse::MOUSE_PRESS_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
}
|
|
|
|
|
|
- (void) rightMouseUp: (NSEvent*) event
|
|
|
{
|
|
|
__rightMouseDown = false;
|
|
|
+ //_game->mouseEvent(Mouse::MOUSE_RELEASE_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
}
|
|
|
|
|
|
- (void) rightMouseDragged: (NSEvent*) event
|
|
|
@@ -225,6 +299,25 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
// Update the last X/Y values.
|
|
|
__lx = point.x;
|
|
|
__ly = (WINDOW_HEIGHT - point.y);
|
|
|
+ //_game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ }
|
|
|
+}
|
|
|
+- (void)otherMouseDown: (NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_PRESS_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+- (void)otherMouseUp: (NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_RELEASE_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+- (void)otherMouseDragged: (NSEvent *) event
|
|
|
+{
|
|
|
+ if(__hasMouse)
|
|
|
+ {
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -544,6 +637,7 @@ int Platform::enterMessagePump()
|
|
|
backing:NSBackingStoreBuffered
|
|
|
defer:NO];
|
|
|
|
|
|
+ [window setAcceptsMouseMovedEvents:YES];
|
|
|
[window setContentView:__view];
|
|
|
[window setDelegate:__view];
|
|
|
[__view release];
|