summaryrefslogtreecommitdiff
path: root/common/src/ivug-mouse-event.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/ivug-mouse-event.c')
-rwxr-xr-xcommon/src/ivug-mouse-event.c300
1 files changed, 268 insertions, 32 deletions
diff --git a/common/src/ivug-mouse-event.c b/common/src/ivug-mouse-event.c
index db3e52c..e58240a 100755
--- a/common/src/ivug-mouse-event.c
+++ b/common/src/ivug-mouse-event.c
@@ -1,19 +1,18 @@
-/*
- * Copyright 2012 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.tizenopensource.org/license
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include <Elementary.h>
#include <stdbool.h>
@@ -32,12 +31,16 @@ typedef enum {
MOUSE_DOWN_UNKNWON,
MOUSE_DOWN_NONE,
MOUSE_DOWN_1,
- MOUSE_DOWN_ERROR, // Error
+ MOUSE_DOWN_2,
+ MOUSE_DOWN_3,
+ MOUSE_DOWN_4, // Invalid state.
} MouseState;
+
#define INVALID_DEVICE_ID (-1)
-#define NUM_MAX_BUTTON (1)
+#define MULTI_INDEX (9)
+#define NUM_MAX_BUTTON (3)
typedef struct _mouse_data_t{
void *pClientData;
@@ -56,8 +59,12 @@ typedef struct _mouse_data_t{
unsigned int prev_dist;
- MouseEvent center;
+ int multi_min_idx; // multi min index is different in each target. Temp solution
+ bool bSendPinchStart;
+
+ MouseEvent center;
+ int pinch_dist;
// For debugging purpose, later will be removed.
char alias[100]; //
} mouse_data_t;
@@ -67,6 +74,15 @@ typedef struct _mouse_data_t{
#define __UNUSED__ __attribute__((unused))
#endif
+static unsigned int _get_distance(int prevX, int prevY, int X, int Y)
+{
+#include <math.h>
+ int dx = prevX - X;
+ int dy = prevY - Y;
+
+ return sqrt(dx*dx + dy*dy);
+}
+
static void _on_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
{
if ( data == NULL )
@@ -116,6 +132,55 @@ static void _on_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj,
MSG_MOUSE_MED("Func:%s Device=%d XY(%d,%d)", "_on_mouse_down", pressed, ev->x , ev->y );
}
+ else if ( pData->m_state == MOUSE_DOWN_2 )
+ {
+ MouseEvent *other = NULL;
+
+ if ( pData->bDown[ (pressed + 1) % NUM_MAX_BUTTON] == true )
+ {
+ other = &pData->event[(pressed + 1) % NUM_MAX_BUTTON];
+ }
+
+ if ( pData->bDown[(pressed + 2) % NUM_MAX_BUTTON] == true )
+ {
+ if ( other != NULL )
+ {
+ MSG_MOUSE_ERROR("Error!!!");
+ }
+ other = &pData->event[(pressed + 2) % NUM_MAX_BUTTON];
+ }
+
+ if ( other == NULL )
+ {
+ MSG_MOUSE_ERROR("[%s] Error! Pressed(%d,%d,%d)", pData->alias,
+ pData->bDown[0],
+ pData->bDown[1],
+ pData->bDown[2]);
+
+ return ; // Fix for B/S
+ }
+
+ int centerX = ( other->x + ev->x ) / 2;
+ int centerY = ( other->y + ev->y ) / 2;
+
+ int dist = _get_distance(other->x, other->y, ev->x, ev->y);
+
+ MSG_MOUSE_HIGH("[%s] Callback PinchStart : Dev=%d OtherDev=%d Center(%d,%d) Dist=%d", pData->alias, ev->device, other->device, centerX, centerY, dist);
+
+ if ( pData->cb.onPinchStart )
+ {
+ pData->center.x = centerX;
+ pData->center.y = centerY;
+ pData->center.timestamp = ev->timestamp;
+ pData->pinch_dist = dist;
+
+ (pData->cb.onPinchStart)(pData->obj, &pData->center, dist, pData->pClientData);
+ }
+
+ pData->prev_dist = dist;
+
+ MSG_MOUSE_HIGH("[%s] Two fingure is clicked. Distance=%d", pData->alias, pData->prev_dist);
+ }
else
{
MSG_MOUSE_WARN("[%s] Ignore third finger! State=%d Dev=%d bPressed(%d,%d,%d)", pData->alias, pData->m_state, ev->device,
@@ -189,7 +254,17 @@ static void _on_mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj, vo
pData->bDown[pressed] = false;
- if ( pData->m_state == MOUSE_DOWN_NONE )
+ if ( pData->m_state == MOUSE_DOWN_1 )
+ {
+ MSG_MOUSE_HIGH("[%s] Callback Pinch End", pData->alias);
+
+ if ( pData->cb.onPinchEnd )
+ {
+ pData->bSendPinchStart = false;
+ (pData->cb.onPinchEnd)(pData->obj, ev, pData->pClientData);
+ }
+ }
+ else if ( pData->m_state == MOUSE_DOWN_NONE )
{
MSG_MOUSE_HIGH("[%s] Callback Mouse Up : Dev=%d (%d,%d)", pData->alias, ev->device, ev->x, ev->y);
@@ -248,25 +323,83 @@ static void _on_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj,
switch ( pData->m_state )
{
- case MOUSE_DOWN_1:
+ case MOUSE_DOWN_3:
+ // Ignore Mouse Event when all 3 buttons is pressed.
+ return ;
+ case MOUSE_DOWN_2:
+ {
+ MouseEvent *other = NULL;
+
+ if ( pData->bDown[ (pressed + 1) % NUM_MAX_BUTTON] == true )
{
- MSG_MOUSE_MED("Func:%s. Device=%d Old(%d,%d) Cur(%d,%d)", __FUNCTION__, pressed,
- pData->event[pressed].x, pData->event[pressed].y,
- ev->x , ev->y);
+ other = &pData->event[(pressed + 1) % NUM_MAX_BUTTON];
+ }
- if ( pData->cb.onMouseMove )
+ if ( pData->bDown[(pressed + 2) % NUM_MAX_BUTTON] == true )
+ {
+ if ( other != NULL )
{
- MSG_MOUSE_MED("[%s] Callback Mouse Move : (%d,%d)", pData->alias, ev->x, ev->y);
- (pData->cb.onMouseMove)(pData->obj, &pData->event[pressed], ev, pData->pClientData);
+ MSG_MOUSE_ERROR("Debug me!!!");
}
+ other = &pData->event[(pressed + 2) % NUM_MAX_BUTTON];
+ }
+
+ if ( other == NULL )
+ {
+ MSG_MOUSE_ERROR("[%s] Error! Pressed(%d,%d,%d)", pData->alias,
+ pData->bDown[0],
+ pData->bDown[1],
+ pData->bDown[2]);
+
+ // TODO : Recover.
+ return;
+ }
- pData->event[pressed] = *ev;
+ int centerX = ( other->x + ev->x ) / 2;
+ int centerY = ( other->y + ev->y ) / 2;
- break;
+ int dist = _get_distance(other->x, other->y, ev->x, ev->y);
+
+ if ( pData->cb.onPinchMove )
+ {
+ MSG_MOUSE_MED("Callback Pinch : (%d,%d) dDistance=%d", centerX, centerY, dist - pData->prev_dist);
+
+ pData->center.x = centerX;
+ pData->center.y = centerY;
+ pData->center.timestamp = ev->timestamp;
+ pData->pinch_dist = dist;
+
+ (pData->cb.onPinchMove)(pData->obj, &pData->center, pData->pinch_dist , pData->pClientData);
+ }
+
+ pData->prev_dist = dist;
+
+ MSG_MOUSE_LOW("Pinch zoom. Pos1(%d,%d) Pos2(%d,%d) Delta=%d", other->x, other->y, ev->x, ev->y, pData->prev_dist);
+
+ pData->event[pressed] = *ev;
+
+ return ;
+ }
+ break;
+ case MOUSE_DOWN_1:
+ {
+ MSG_MOUSE_MED("Func:%s. Device=%d Old(%d,%d) Cur(%d,%d)", __FUNCTION__, pressed,
+ pData->event[pressed].x, pData->event[pressed].y,
+ ev->x , ev->y);
+
+ if ( pData->cb.onMouseMove )
+ {
+ MSG_MOUSE_MED("[%s] Callback Mouse Move : (%d,%d)", pData->alias, ev->x, ev->y);
+ (pData->cb.onMouseMove)(pData->obj, &pData->event[pressed], ev, pData->pClientData);
}
- default:
- MSG_MOUSE_ERROR("[%s] Something wrong. state=%d", pData->alias, pData->m_state);
- break;
+
+ pData->event[pressed] = *ev;
+
+ break;
+ }
+ default:
+ MSG_MOUSE_ERROR("[%s] Something wrong. state=%d", pData->alias, pData->m_state);
+ break;
}
@@ -333,6 +466,102 @@ static void _proxy_on_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object
}
+static void _proxy_on_mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
+{
+ Evas_Event_Multi_Down *ev = event_info;
+ mouse_data_t *pData = data;
+
+ MouseEvent event;
+
+ if ( pData->multi_min_idx == INVALID_DEVICE_ID)
+ {
+ MSG_MOUSE_HIGH("[%s] Min Device Index=%d", pData->alias, ev->device);
+ pData->multi_min_idx = ev->device -1; // Index start from 0. so -1 is needed
+ }
+
+ event.device = ev->device - pData->multi_min_idx; // ev->device is 10(for second), 11(3rd), 12(4th) finger
+ event.timestamp = ev->timestamp;
+ event.x = ev->canvas.x;
+ event.y = ev->canvas.y;
+ event.button_flags = 0;
+ event.event_flags = ev->event_flags;
+
+
+ if(event.device >= NUM_MAX_BUTTON)
+ {
+ MSG_MOUSE_FATAL("[%s] Invalid Device. Dev=%d Min=%d", pData->alias, event.device, pData->multi_min_idx);
+ return;
+ }
+
+ MSG_MOUSE_MED("%s Dev=%d", __func__, ev->device);
+
+ _on_mouse_down(data, NULL, obj, (void *)&event);
+}
+
+static void _proxy_on_mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
+{
+ Evas_Event_Multi_Up *ev = event_info;
+ mouse_data_t *pData = data;
+
+ MouseEvent event;
+
+ if ( pData->multi_min_idx == INVALID_DEVICE_ID)
+ {
+ // Sometimes Multi up came ealry
+ MSG_MOUSE_HIGH("[%s] Min Device Index=%d", pData->alias, ev->device);
+ pData->multi_min_idx = ev->device -1; // Index start from 0. so -1 is needed
+ }
+
+ event.device = ev->device - pData->multi_min_idx;
+ event.timestamp = ev->timestamp;
+ event.x = ev->canvas.x;
+ event.y = ev->canvas.y;
+ event.button_flags = 0;
+ event.event_flags = ev->event_flags;
+
+ if(event.device >= NUM_MAX_BUTTON)
+ {
+ MSG_MOUSE_FATAL("[%s] Invalid Device. Dev=%d Min=%d", pData->alias, event.device, pData->multi_min_idx);
+ return;
+ }
+
+ MSG_MOUSE_MED("%s Dev=%d", __func__, ev->device);
+
+ _on_mouse_up(data, NULL, obj, (void *)&event);
+
+}
+
+static void _proxy_on_mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
+{
+ Evas_Event_Multi_Move *ev = event_info;
+ mouse_data_t *pData = data;
+
+ MouseEvent event;
+
+ if ( pData->multi_min_idx == INVALID_DEVICE_ID)
+ {
+ // Mouse Move come faster than Mouse down
+ MSG_MOUSE_HIGH("[%s] Min Device Index=%d", pData->alias, ev->device);
+ pData->multi_min_idx = ev->device -1;
+ }
+
+ event.device = ev->device - pData->multi_min_idx;
+ event.timestamp = ev->timestamp;
+ event.x = ev->cur.canvas.x;
+ event.y = ev->cur.canvas.y;
+ event.button_flags = 0;
+ event.event_flags = ev->event_flags;
+
+ if(event.device >= NUM_MAX_BUTTON)
+ {
+ MSG_MOUSE_FATAL("[%s] Invalid Device. Dev=%d Min=%d", pData->alias, event.device, pData->multi_min_idx);
+ return;
+ }
+
+ MSG_MOUSE_MED("%s Dev=%d", __func__, ev->device);
+
+ _on_mouse_move(data, NULL, obj, (void *)&event);
+}
Ivug_Event_Handle
ivug_mouse_event_add(Evas_Object *obj, mouse_callback_t *pCallback, void *client_data, const char *alias)
@@ -345,6 +574,7 @@ ivug_mouse_event_add(Evas_Object *obj, mouse_callback_t *pCallback, void *client
pData->obj = obj;
pData->pClientData = client_data;
pData->m_state = MOUSE_DOWN_NONE;
+ pData->multi_min_idx = INVALID_DEVICE_ID;
strncpy(pData->alias, alias, sizeof(pData->alias));
memcpy(&pData->cb, pCallback, sizeof(mouse_callback_t));
@@ -352,6 +582,9 @@ ivug_mouse_event_add(Evas_Object *obj, mouse_callback_t *pCallback, void *client
evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MOUSE_DOWN, _proxy_on_mouse_down, pData);
evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MOUSE_UP, _proxy_on_mouse_up, pData);
evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MOUSE_MOVE, _proxy_on_mouse_move, pData);
+ evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MULTI_DOWN, _proxy_on_mouse_multi_down, pData);
+ evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MULTI_UP, _proxy_on_mouse_multi_up, pData);
+ evas_object_event_callback_add(pData->obj, EVAS_CALLBACK_MULTI_MOVE, _proxy_on_mouse_multi_move, pData);
MSG_MOUSE_HIGH("Mouse Event Handler Add : Alias(%s) 0x%08x for Object(0x%08x)", alias, pData, obj);
@@ -366,6 +599,9 @@ void ivug_mouse_event_del(Ivug_Event_Handle handle)
evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MOUSE_DOWN, _proxy_on_mouse_down);
evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MOUSE_UP, _proxy_on_mouse_up);
evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MOUSE_MOVE, _proxy_on_mouse_move);
+ evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MULTI_DOWN, _proxy_on_mouse_multi_down);
+ evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MULTI_UP, _proxy_on_mouse_multi_up);
+ evas_object_event_callback_del(pData->obj, EVAS_CALLBACK_MULTI_MOVE, _proxy_on_mouse_multi_move);
MSG_MOUSE_HIGH("Mouse Event Handler Remove : 0x%08x", pData);