|
|
@@ -45,7 +45,9 @@ static bool __multiTouch = false;
|
|
|
static float __pitch;
|
|
|
static float __roll;
|
|
|
static const char* __glExtensions;
|
|
|
-static struct gestures_set * __gesturesSet;
|
|
|
+static struct gestures_set * __gestureSet;
|
|
|
+static bool __gestureEventsProcessed;
|
|
|
+static bool __gestureEvents[5];
|
|
|
PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray = NULL;
|
|
|
PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays = NULL;
|
|
|
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays = NULL;
|
|
|
@@ -448,38 +450,56 @@ void gesture_callback(gesture_base_t* gesture, mtouch_event_t* event, void* para
|
|
|
{
|
|
|
case GESTURE_SWIPE:
|
|
|
{
|
|
|
- gesture_swipe_t* swipe = (gesture_swipe_t*)gesture;
|
|
|
- Game::getInstance()->gestureSwipeEvent(swipe->coords.x, swipe->coords.y, swipe->direction);
|
|
|
- break;
|
|
|
+ if (__gestureEvents[(unsigned int) Gesture::GESTURE_SWIPE])
|
|
|
+ {
|
|
|
+ gesture_swipe_t* swipe = (gesture_swipe_t*)gesture;
|
|
|
+ Game::getInstance()->gestureSwipeEvent(swipe->coords.x, swipe->coords.y, swipe->direction);
|
|
|
+ }
|
|
|
}
|
|
|
+ break;
|
|
|
|
|
|
case GESTURE_PINCH:
|
|
|
{
|
|
|
- gesture_pinch_t* pinch = (gesture_pinch_t*)gesture;
|
|
|
- float scale = 1.0f; // todo: try to map this the same across ios and android.
|
|
|
- Game::getInstance()->gesturePinchEvent(pinch->centroid.x, pinch->centroid.y, scale);
|
|
|
- break;
|
|
|
+ if (__gestureEvents[(unsigned int) Gesture::GESTURE_PINCH])
|
|
|
+ {
|
|
|
+ gesture_pinch_t* pinch = (gesture_pinch_t*)gesture;
|
|
|
+ float dist_x = (float)pinch->last_distance.x - (float)pinch->distance.x;
|
|
|
+ float dist_y = (float)pinch->last_distance.y - (float)pinch->distance.y;
|
|
|
+ float scale = sqrt( (dist_x * dist_x) + (dist_y * dist_y) );
|
|
|
+ Game::getInstance()->gesturePinchEvent(pinch->centroid.x, pinch->centroid.y, scale);
|
|
|
+ }
|
|
|
}
|
|
|
+ break;
|
|
|
|
|
|
case GESTURE_ROTATE:
|
|
|
{
|
|
|
- gesture_rotate_t* rotate = (gesture_rotate_t*)gesture;
|
|
|
- Game::getInstance()->gestureRotateEvent(rotate->centroid.x, rotate->centroid.y, rotate->angle);
|
|
|
- break;
|
|
|
+ if (__gestureEvents[(unsigned int) Gesture::GESTURE_ROTATE])
|
|
|
+ {
|
|
|
+ gesture_rotate_t* rotate = (gesture_rotate_t*)gesture;
|
|
|
+ Game::getInstance()->gestureRotateEvent(rotate->centroid.x, rotate->centroid.y, rotate->angle);
|
|
|
+ }
|
|
|
}
|
|
|
+ break;
|
|
|
+
|
|
|
case GESTURE_TAP:
|
|
|
{
|
|
|
- gesture_tap_t* tap = (gesture_tap_t*)gesture;
|
|
|
- Game::getInstance()->gestureTapEvent(tap->touch_coords.x, tap->touch_coords.y);
|
|
|
- break;
|
|
|
+ if (__gestureEvents[(unsigned int) Gesture::GESTURE_TAP])
|
|
|
+ {
|
|
|
+ gesture_tap_t* tap = (gesture_tap_t*)gesture;
|
|
|
+ Game::getInstance()->gestureTapEvent(tap->touch_coords.x, tap->touch_coords.y);
|
|
|
+ }
|
|
|
}
|
|
|
+ break;
|
|
|
|
|
|
case GESTURE_DOUBLE_TAP:
|
|
|
{
|
|
|
- gesture_tap_t* double_tap = (gesture_tap_t*)gesture;
|
|
|
- Game::getInstance()->gestureTapDoubleEvent(double_tap->touch_coords.x,double_tap->touch_coords.y);
|
|
|
- break;
|
|
|
+ if (__gestureEvents[(unsigned int) Gesture::GESTURE_TAP_DOUBLE])
|
|
|
+ {
|
|
|
+ gesture_tap_t* double_tap = (gesture_tap_t*)gesture;
|
|
|
+ Game::getInstance()->gestureTapDoubleEvent(double_tap->touch_coords.x, double_tap->touch_coords.y);
|
|
|
+ }
|
|
|
}
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -537,6 +557,13 @@ Platform* Platform::create(Game* game, void* attachToWindow)
|
|
|
FileSystem::setResourcePath("./app/native/");
|
|
|
Platform* platform = new Platform(game);
|
|
|
|
|
|
+ __gestureSet = gestures_set_alloc();
|
|
|
+ swipe_gesture_alloc(NULL, gesture_callback, __gestureSet);
|
|
|
+ pinch_gesture_alloc(NULL, gesture_callback, __gestureSet);
|
|
|
+ rotate_gesture_alloc(NULL, gesture_callback, __gestureSet);
|
|
|
+ tap_gesture_alloc(NULL, gesture_callback, __gestureSet);
|
|
|
+ double_tap_gesture_alloc(NULL, gesture_callback, __gestureSet);
|
|
|
+
|
|
|
bps_initialize();
|
|
|
|
|
|
// Initialize navigator and orientation
|
|
|
@@ -873,7 +900,10 @@ int Platform::enterMessagePump()
|
|
|
case SCREEN_EVENT_MTOUCH_TOUCH:
|
|
|
{
|
|
|
screen_get_mtouch_event(__screenEvent, &touchEvent, 0);
|
|
|
- if (__multiTouch || touchEvent.contact_id == 0)
|
|
|
+ if (__gestureEventsProcessed)
|
|
|
+ rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL);
|
|
|
+
|
|
|
+ if ( !rc && (__multiTouch || touchEvent.contact_id == 0))
|
|
|
{
|
|
|
gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, touchEvent.x, touchEvent.y, touchEvent.contact_id);
|
|
|
}
|
|
|
@@ -883,7 +913,10 @@ int Platform::enterMessagePump()
|
|
|
case SCREEN_EVENT_MTOUCH_RELEASE:
|
|
|
{
|
|
|
screen_get_mtouch_event(__screenEvent, &touchEvent, 0);
|
|
|
- if (__multiTouch || touchEvent.contact_id == 0)
|
|
|
+ if (__gestureEventsProcessed)
|
|
|
+ rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL);
|
|
|
+
|
|
|
+ if (!rc && (__multiTouch || touchEvent.contact_id == 0))
|
|
|
{
|
|
|
gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, touchEvent.x, touchEvent.y, touchEvent.contact_id);
|
|
|
}
|
|
|
@@ -893,7 +926,10 @@ int Platform::enterMessagePump()
|
|
|
case SCREEN_EVENT_MTOUCH_MOVE:
|
|
|
{
|
|
|
screen_get_mtouch_event(__screenEvent, &touchEvent, 0);
|
|
|
- if (__multiTouch ||touchEvent.contact_id == 0)
|
|
|
+ if (__gestureEventsProcessed)
|
|
|
+ rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL);
|
|
|
+
|
|
|
+ if (!rc && (__multiTouch || touchEvent.contact_id == 0))
|
|
|
{
|
|
|
gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, touchEvent.x, touchEvent.y, touchEvent.contact_id);
|
|
|
}
|
|
|
@@ -1257,52 +1293,37 @@ bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheel
|
|
|
|
|
|
void Platform::recognizeGesture(Gesture::GestureEvent evt)
|
|
|
{
|
|
|
- if (evt != Gesture::GESTURE_NONE && __gesturesSet == NULL)
|
|
|
- {
|
|
|
- __gesturesSet = gestures_set_alloc();
|
|
|
- }
|
|
|
-
|
|
|
switch(evt)
|
|
|
{
|
|
|
case Gesture::GESTURE_NONE:
|
|
|
- {
|
|
|
- if (__gesturesSet)
|
|
|
- {
|
|
|
- gestures_set_free(__gesturesSet);
|
|
|
- __gesturesSet = NULL;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
+ __gestureEventsProcessed = false;
|
|
|
+ memset( __gestureEvents, 0, sizeof(__gestureEvents));
|
|
|
+ break;
|
|
|
|
|
|
case Gesture::GESTURE_SWIPE:
|
|
|
- {
|
|
|
- swipe_gesture_alloc(NULL, gesture_callback, __gesturesSet);
|
|
|
- break;
|
|
|
- }
|
|
|
+ __gestureEventsProcessed = true;
|
|
|
+ __gestureEvents[(unsigned int) Gesture::GESTURE_SWIPE] = true;
|
|
|
+ break;
|
|
|
|
|
|
case Gesture::GESTURE_PINCH:
|
|
|
- {
|
|
|
- pinch_gesture_alloc(NULL, gesture_callback, __gesturesSet);
|
|
|
+ __gestureEventsProcessed = true;
|
|
|
+ __gestureEvents[(unsigned int) Gesture::GESTURE_PINCH] = true;
|
|
|
break;
|
|
|
- }
|
|
|
|
|
|
case Gesture::GESTURE_ROTATE:
|
|
|
- {
|
|
|
- rotate_gesture_alloc(NULL, gesture_callback, __gesturesSet);
|
|
|
- break;
|
|
|
- }
|
|
|
+ __gestureEventsProcessed = true;
|
|
|
+ __gestureEvents[(unsigned int) Gesture::GESTURE_ROTATE] = true;
|
|
|
+ break;
|
|
|
|
|
|
case Gesture::GESTURE_TAP:
|
|
|
- {
|
|
|
- tap_gesture_alloc(NULL, gesture_callback, __gesturesSet);
|
|
|
- break;
|
|
|
- }
|
|
|
+ __gestureEventsProcessed = true;
|
|
|
+ __gestureEvents[(unsigned int) Gesture::GESTURE_TAP] = true;
|
|
|
+ break;
|
|
|
|
|
|
case Gesture::GESTURE_TAP_DOUBLE:
|
|
|
- {
|
|
|
- double_tap_gesture_alloc(NULL, gesture_callback, __gesturesSet);
|
|
|
- break;
|
|
|
- }
|
|
|
+ __gestureEventsProcessed = true;
|
|
|
+ __gestureEvents[(unsigned int) Gesture::GESTURE_TAP_DOUBLE] = true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|