From 3729e986a4e1f93b0a5209d61ede1dfe59019664 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 13 Mar 2016 20:05:53 +1000 Subject: Different way of dealing with object popups, run a timer, check for mouse inactivity. --- src/extantz/extantz.c | 8 +++++ src/extantz/extantz.h | 7 +++++ src/extantz/scenri.c | 82 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index b5f272e..d20edb5 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -226,6 +226,7 @@ static void _on_resize(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA { globals *ourGlobals = data; GLData *gld = &ourGlobals->gld; + Scene_Data *scene = ourGlobals->scene; Evas_Coord h; efl_gfx_size_get(ourGlobals->win, &ourGlobals->win_w, &ourGlobals->win_h); @@ -237,6 +238,13 @@ static void _on_resize(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA efl_gfx_size_set(ourGlobals->win, ourGlobals->win_w, h); // Stop internal windows going under the toolbar. evas_object_resize(ourGlobals->mainWindow->layout, ourGlobals->win_w, h); + + if (scene) + { + evas_object_geometry_get(scene->image_e, &scene->x, &scene->y, &scene->w, &scene->h); + evas_canvas3d_scene_size_get(scene->scene, &scene->scene_w, &scene->scene_h); + } + #if USE_EPHYSICS if (ourGlobals->world) ephysics_world_render_geometry_set(ourGlobals->world, 0, 0, -50, ourGlobals->win_w, ourGlobals->win_h, 100); diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index ea22879..2930642 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -139,6 +139,13 @@ typedef struct _Scene_Data { Evas *evas; Evas_Object *image, *image_e; // Our Elm image, and it's Evas image. + + Evas_Coord x, y, w, h; // Position and size of our render image. + int scene_w, scene_h; // Size of the scene. + + int tick; // For tracking mouse movements for tooltips. + Evas_Coord mouse_x, mouse_y; + Eo *scene; Eo *root_node; Eo *camera_node; diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index a487d47..7662a96 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c @@ -136,46 +136,69 @@ Eina_Bool animateScene(globals *ourGlobals) return EINA_TRUE; } -static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) +static Eina_Bool _tourGuide(void *data) { Scene_Data *scene = data; - Evas_Event_Mouse_Move *ev = einfo; - Evas_Coord x, y, w, h; - Evas_Coord obj_x, obj_y; - int scene_w, scene_h; - Evas_Real scene_x, scene_y; - Evas_Real s, t; - Eo *n; - Eo *m; - Eina_Bool pick; - char *name = NULL; - evas_object_geometry_get(o, &x, &y, &w, &h); + if (0 < scene->tick) // Mouse has moved since last time we checked. + scene->tick = 0; + else if (0 == scene->tick) // Mouse has not moved since last time we checked. + { + Evas_Coord obj_x, obj_y; + Evas_Real scene_x, scene_y; + Evas_Real s, t; + Eo *n; + Eo *m; + Eina_Bool pick; + char *name = NULL; + + scene->tick--; // Only do this once. + + // Subtract image position from mouse coords. Cancel any offset. + obj_x = scene->mouse_x - scene->x; + obj_y = scene->mouse_y - scene->y; + + // Multiply the adjusted mouse coords by the ratio of widths. + scene_x = obj_x * scene->scene_w / (Evas_Real)scene->w; + scene_y = obj_y * scene->scene_h / (Evas_Real)scene->h; + + // Figure out what that points to. + pick = evas_canvas3d_scene_pick(scene->scene, scene_x, scene_y, &n, &m, &s, &t); + if (pick) + name = evas_object_data_get(n, "Name"); + // This is a raw Evas callback, on the Elm image internal Evas_Object. + // So we need to get the Elm Image back from the raw Evas_Object. + // Which is why we stuffed it in the scene structure. + if (name) + { + elm_object_tooltip_text_set(scene->image, name); + elm_object_tooltip_show(scene->image); + } + else + { + elm_object_tooltip_text_set(scene->image, ""); + elm_object_tooltip_hide(scene->image); + } + } - obj_x = ev->cur.canvas.x - x; - obj_y = ev->cur.canvas.y - y; + return ECORE_CALLBACK_RENEW; +} - eo_do(scene->scene, evas_canvas3d_scene_size_get(&scene_w, &scene_h)); +static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) +{ + Scene_Data *scene = data; + Evas_Event_Mouse_Move *ev = einfo; - scene_x = obj_x * scene_w / (Evas_Real)w; - scene_y = obj_y * scene_h / (Evas_Real)h; + scene->mouse_x = ev->cur.canvas.x; + scene->mouse_y = ev->cur.canvas.y; - eo_do(scene->scene, pick = evas_canvas3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t)); - if (pick) - name = evas_object_data_get(n, "Name"); - // This is a raw Evas callback, on the Elm image internal Evas_Object. - // So we need to get the Elm Image back from the raw Evas_Object. - // Which is why we stuffed it in the scene structure. - if (name) - { - elm_object_tooltip_text_set(scene->image, name); - elm_object_tooltip_show(scene->image); - } - else + if (0 == scene->tick) // First move. { elm_object_tooltip_text_set(scene->image, ""); elm_object_tooltip_hide(scene->image); } + // Mark mouse as having moved. + scene->tick++; } static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) @@ -456,6 +479,7 @@ Scene_Data *scenriAdd(Evas_Object *win) // Action? elm_object_tooltip_text_set(scene->image, ""); elm_object_tooltip_hide(scene->image); + ecore_timer_add(0.2, _tourGuide, scene); #if USE_ELM_IMG evas_obj_image_scene_set(scene->image_e, scene->scene); -- cgit v1.1