|
|
@@ -665,6 +665,23 @@ long timespec2millis(struct timespec *a)
|
|
|
return a->tv_sec*1000 + a->tv_nsec/1000000;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 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))
|
|
|
+ {
|
|
|
+ Game::getInstance()->touchEvent(touchEvent, x, y, 0);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int Platform::enterMessagePump()
|
|
|
{
|
|
|
int rc;
|
|
|
@@ -710,7 +727,7 @@ int Platform::enterMessagePump()
|
|
|
if (!__multiTouch)
|
|
|
{
|
|
|
screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_POSITION, position);
|
|
|
- Game::getInstance()->touchEvent(Touch::TOUCH_PRESS, position[0], position[1], 0);
|
|
|
+ Game::getInstance()->touchEvent(Touch::TOUCH_PRESS, position[0], position[1], 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -725,7 +742,7 @@ int Platform::enterMessagePump()
|
|
|
if (!__multiTouch)
|
|
|
{
|
|
|
screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_POSITION, position);
|
|
|
- Game::getInstance()->touchEvent(Touch::TOUCH_RELEASE, position[0], position[1], 0);
|
|
|
+ Game::getInstance()->touchEvent(Touch::TOUCH_RELEASE, position[0], position[1], 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -751,6 +768,92 @@ int Platform::enterMessagePump()
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ case SCREEN_EVENT_POINTER:
|
|
|
+ {
|
|
|
+ static int mouse_pressed = 0;
|
|
|
+ int buttons;
|
|
|
+ int wheel;
|
|
|
+ // A move event will be fired unless a button state changed.
|
|
|
+ bool move = true;
|
|
|
+ bool left_move = false;
|
|
|
+ //This is a mouse move event, it is applicable to a device with a usb mouse or simulator
|
|
|
+ screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
|
|
|
+ screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position);
|
|
|
+ screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel);
|
|
|
+
|
|
|
+ // Handle left mouse. Interpret as touch if the left mouse event is not consumed.
|
|
|
+ if (buttons & SCREEN_LEFT_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ left_move = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON;
|
|
|
+ mouseOrTouchEvent(Mouse::MOUSE_LEFT_BUTTON_PRESS, Touch::TOUCH_PRESS, position[0], position[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON;
|
|
|
+ mouseOrTouchEvent(Mouse::MOUSE_LEFT_BUTTON_RELEASE, Touch::TOUCH_RELEASE, position[0], position[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle right mouse
|
|
|
+ if (buttons & SCREEN_RIGHT_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON == 0)
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON;
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_RIGHT_BUTTON_PRESS, position[0], position[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON;
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_RIGHT_BUTTON_RELEASE, position[0], position[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle middle mouse
|
|
|
+ if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON == 0)
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON;
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_MIDDLE_BUTTON_PRESS, position[0], position[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON)
|
|
|
+ {
|
|
|
+ move = false;
|
|
|
+ mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON;
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_MIDDLE_BUTTON_RELEASE, position[0], position[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle mouse wheel events
|
|
|
+ if (wheel)
|
|
|
+ {
|
|
|
+ Game::getInstance()->mouseWheelEvent(position[0], position[1], -wheel);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
case SCREEN_EVENT_KEYBOARD:
|
|
|
{
|
|
|
screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags);
|