From 8982ca01141f87d3744dd3b5866b05b0117889c6 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 11 May 2014 05:00:01 +1000 Subject: Add internal window title bar, and dragging them around. Plus some related clean ups. --- build.lua | 1 + src/GuiLua/GuiLua.c | 4 +- src/extantz/ephysics_demo.c | 2 +- src/extantz/woMan.c | 2 +- src/libraries/winFang.c | 104 +++++++++++++++++++++++++++++++++++++++----- src/libraries/winFang.h | 3 ++ src/purkle/purkle.c | 2 +- 7 files changed, 103 insertions(+), 15 deletions(-) diff --git a/build.lua b/build.lua index 359dbe8..1128d71 100755 --- a/build.lua +++ b/build.lua @@ -95,5 +95,6 @@ if 'nil' == type(args) then buildSub('libraries', 'src/libraries') buildSub('LuaSL', 'src/LuaSL') buildSub('GuiLua', 'src/GuiLua') + buildSub('purkle', 'src/purkle') buildSub('extantz', 'src/extantz') end diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 494be84..09c3fe9 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -196,6 +196,8 @@ static int widget(lua_State *L) ); evas_object_smart_callback_add(wid->obj, "clicked", _on_click, wid); + evas_object_show(win->box); + lua_pushlightuserdata(L, (void *) wid); return 1; } @@ -259,7 +261,7 @@ static int window(lua_State *L) world = gl->world; } - win = winFangAdd(parent, 25, 25, w, h, title, name, world); + win = winFangAdd(parent, 25, 55, w, h, title, name, world); if (gl) { // If there's no parent, we become the parent. diff --git a/src/extantz/ephysics_demo.c b/src/extantz/ephysics_demo.c index 4655dbb..6ace8a0 100644 --- a/src/extantz/ephysics_demo.c +++ b/src/extantz/ephysics_demo.c @@ -44,7 +44,7 @@ EPhysics_World *ephysicsAdd(globals *ourGlobals) ephysics_body_evas_object_set(box_body1, box1, EINA_TRUE); ephysics_body_restitution_set(box_body1, 0.7); ephysics_body_friction_set(box_body1, 0); - ephysics_body_linear_velocity_set(box_body1, -1500, 2000, 0); + ephysics_body_linear_velocity_set(box_body1, -150, 20, 0); ephysics_body_angular_velocity_set(box_body1, 0, 0, 36); ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); eo_unref(box1); diff --git a/src/extantz/woMan.c b/src/extantz/woMan.c index 2911686..52b3a30 100644 --- a/src/extantz/woMan.c +++ b/src/extantz/woMan.c @@ -159,7 +159,7 @@ winFang *woMan_add(globals *ourGlobals) char buf[PATH_MAX]; int i; - me = winFangAdd(ourGlobals->mainWindow, 30, 150, ourGlobals->win_w / 3, ourGlobals->win_h / 3, "virtual world manager", "woMan", ourGlobals->world); + me = winFangAdd(ourGlobals->mainWindow, 30, 200, ourGlobals->win_w / 3, ourGlobals->win_h / 3, "virtual world manager", "woMan", ourGlobals->world); // A tab thingy. tb = elm_toolbar_add(me->win); diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index 205cedb..bcf99ce 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -49,6 +49,55 @@ static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_ evas_map_free(p); } +static void _onBgMove(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Move *ev = event_info; + winFang *win = data; + Evas_Coord x, y, w, h; + Evas_Object *img = elm_win_inlined_image_object_get(win->win), *test; + Eina_List *objs, *this; + int padding = 1, i = 0, overs[4][2]; + + if (obj != img) return; + if (1 != ev->buttons) return; + + // Looks like ePhysics wont cooperate about coords and other things, so plan B. + + evas_object_geometry_get(img, &x, &y, &w, &h); + x += ev->cur.canvas.x - ev->prev.output.x; + y += ev->cur.canvas.y - ev->prev.output.y; + overs[0][0] = x - padding; overs[0][1] = y - padding; + overs[1][0] = x + padding + w; overs[1][1] = y - padding; + overs[2][0] = x + padding + w; overs[2][1] = y + padding + h; + overs[3][0] = x - padding; overs[3][1] = y + padding + h; + + // If we are over two or more windows, stop. + objs = evas_objects_in_rectangle_get(win->e, overs[0][0], overs[0][1], w + (padding * 2), h + (padding * 2), EINA_TRUE, EINA_FALSE); + EINA_LIST_FOREACH(objs, this, test) + { + const char * name = evas_object_name_get(test); + if (name && (strcmp("winFang", name) == 0)) + i++; + } + if (2 <= i) + { + return; + } + + // Check if we are outside the parent window. + evas_object_geometry_get(win->parent->win, NULL, NULL, &w, &h); + if ((overs[0][0] < 0) || (overs[0][1] < 0)) + { + return; + } + if ((overs[2][0] > w) || (overs[2][1] > h)) + { + return; + } + + evas_object_move(img, x, y); +} + static void _on_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { elm_exit(); @@ -75,7 +124,8 @@ void winFangShow(winFang *win) winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world) { winFang *result; - Evas_Object *obj, *obj2; + Evas_Object *obj, *obj1; + Evas *obj2; char buf[PATH_MAX]; int i; @@ -84,6 +134,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch eina_clist_init(&result->winFangs); if (parent) result->internal = EINA_TRUE; + result->parent = parent; result->x = x; result->y = y; @@ -98,9 +149,11 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch result->win = elm_win_add(parent->win, name, ELM_WIN_INLINED_IMAGE); eina_clist_add_head(&parent->winFangs, &result->node); obj = elm_win_inlined_image_object_get(result->win); + evas_object_name_set(obj, "winFang"); // On mouse down we try to shift focus to the backing image, this seems to be the correct thing to force focus onto it's widgets. // According to the Elm inlined image window example, this is what's needed to. evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL); + evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _onBgMove, result); elm_win_alpha_set(result->win, EINA_TRUE); // image object for win is unlinked to its pos/size - so manual control @@ -110,6 +163,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch evas_object_resize(obj, result->w, result->h); obj2 = evas_object_evas_get(obj); + result->e = obj2; // Create corner handles. snprintf(buf, sizeof(buf), "%s/pt.png", elm_app_data_dir_get()); for (i = 0; i < 4; i++) @@ -143,16 +197,6 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch eo_unref(result->hand[i]); #endif } - if (world) - { - result->body = ephysics_body_box_add(world); - ephysics_body_evas_object_set(result->body, obj, EINA_TRUE); - ephysics_body_restitution_set(result->body, 0.7); - ephysics_body_friction_set(result->body, 0); - ephysics_body_linear_velocity_set(result->body, 80, -60, 0); - ephysics_body_angular_velocity_set(result->body, 0, 0, 360); - ephysics_body_sleeping_threshold_set(result->body, 0.1, 0.1); - } } else { @@ -182,6 +226,44 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch ); elm_win_resize_object_add(result->win, result->box); + if (result->internal) + { + result->title = eo_add(ELM_OBJ_LABEL_CLASS, result->win, + evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), + evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0.0), + evas_obj_visibility_set(EINA_TRUE) + ); + elm_object_style_set(result->title, "slide_bounce"); + snprintf(buf, PATH_MAX, "%s", title); + elm_object_text_set(result->title, buf); + elm_box_pack_end(result->box, result->title); + eo_unref(result->title); + +#if 0 + // EPysics enable the window. + if (world) + { + result->body = ephysics_body_box_add(world); + ephysics_body_evas_object_set(result->body, obj, EINA_TRUE); + ephysics_body_mass_set(result->body, 0); +// ephysics_body_restitution_set(result->body, 0.7); +// ephysics_body_friction_set(result->body, 0); +// ephysics_body_linear_velocity_set(result->body, 0, 0, 0); +// ephysics_body_angular_velocity_set(result->body, 0, 0, 0); + ephysics_body_sleeping_threshold_set(result->body, 0.1, 0.1); + } +#endif + + obj1 = eo_add(ELM_OBJ_SEPARATOR_CLASS, result->win, + evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), + evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0.0), + elm_obj_separator_horizontal_set(EINA_TRUE), + evas_obj_visibility_set(EINA_TRUE) + ); + elm_box_pack_end(result->box, obj1); + eo_unref(obj1); + } + evas_object_resize(result->win, result->w, result->h); evas_object_show(result->win); diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index a84c8de..f3b4e45 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -18,7 +18,10 @@ typedef struct _winFang { + Evas *e; + struct _winFang *parent; Evas_Object *win; + Evas_Object *title; Evas_Object *bg; Evas_Object *box; EPhysics_Body *body; diff --git a/src/purkle/purkle.c b/src/purkle/purkle.c index 8ea012c..ef0bbf2 100644 --- a/src/purkle/purkle.c +++ b/src/purkle/purkle.c @@ -19,7 +19,7 @@ static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) Widget *wid; Evas_Object *en; - me = winFangAdd(parent, 30, 520, w, h, "chatter box", "purkle", world); + me = winFangAdd(parent, 30, 590, w, h, "chatter box", "purkle", world); en = eo_add(ELM_OBJ_ENTRY_CLASS, me->win, elm_obj_entry_scrollable_set(EINA_TRUE), -- cgit v1.1