diff options
Diffstat (limited to '')
-rw-r--r-- | src/libraries/winFang.c | 164 |
1 files changed, 97 insertions, 67 deletions
diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index 5f5b575..6b15a6d 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c | |||
@@ -5,67 +5,31 @@ | |||
5 | // Evas style event callback. | 5 | // Evas style event callback. |
6 | static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 6 | static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) |
7 | { | 7 | { |
8 | Evas_Event_Mouse_Down *ev = event_info; | 8 | winFang *win = data; |
9 | Evas_Event_Mouse_Down *ev = event_info; | ||
9 | 10 | ||
10 | if (1 == ev->button) | 11 | if (1 == ev->button) |
11 | elm_object_focus_set(obj, EINA_TRUE); | 12 | { |
12 | } | 13 | Evas_Object *objs = evas_object_top_at_pointer_get(win->e); |
13 | 14 | ||
14 | static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 15 | // TODO - This always returns the elm_win. So how the hell do you tell what got clicked on? |
15 | { | 16 | printf("%s %s\n", evas_object_type_get(objs), evas_object_name_get(objs)); |
16 | Evas_Event_Mouse_Move *ev = event_info; | 17 | |
17 | Evas_Object *orig = data; | 18 | elm_object_focus_set(obj, EINA_TRUE); |
18 | Evas_Coord x, y; | 19 | } |
19 | Evas_Map *p; | ||
20 | int i, w, h; | ||
21 | |||
22 | if (!ev->buttons) return; | ||
23 | evas_object_geometry_get(obj, &x, &y, NULL, NULL); | ||
24 | evas_object_move(obj, | ||
25 | x + (ev->cur.canvas.x - ev->prev.output.x), | ||
26 | y + (ev->cur.canvas.y - ev->prev.output.y)); | ||
27 | evas_object_image_size_get(orig, &w, &h); | ||
28 | p = evas_map_new(4); | ||
29 | evas_object_map_enable_set(orig, EINA_TRUE); | ||
30 | // evas_object_raise(orig); | ||
31 | for (i = 0; i < 4; i++) | ||
32 | { | ||
33 | Evas_Object *hand; | ||
34 | char key[32]; | ||
35 | |||
36 | snprintf(key, sizeof(key), "h-%i\n", i); | ||
37 | hand = evas_object_data_get(orig, key); | ||
38 | evas_object_raise(hand); | ||
39 | evas_object_geometry_get(hand, &x, &y, NULL, NULL); | ||
40 | x += 15; | ||
41 | y += 15; | ||
42 | evas_map_point_coord_set(p, i, x, y, 0); | ||
43 | if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0); | ||
44 | else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0); | ||
45 | else if (i == 2) evas_map_point_image_uv_set(p, i, w, h); | ||
46 | else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h); | ||
47 | } | ||
48 | evas_object_map_set(orig, p); | ||
49 | evas_map_free(p); | ||
50 | } | 20 | } |
51 | 21 | ||
52 | static void _onBgMove(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 22 | static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) |
53 | { | 23 | { |
54 | Evas_Event_Mouse_Move *ev = event_info; | ||
55 | winFang *win = data; | ||
56 | Evas_Coord x, y, w, h; | ||
57 | Evas_Object *img = elm_win_inlined_image_object_get(win->win), *test; | 24 | Evas_Object *img = elm_win_inlined_image_object_get(win->win), *test; |
58 | Eina_List *objs, *this; | 25 | Eina_List *objs, *this; |
26 | Evas_Coord mw, mh; | ||
59 | int padding = 1, i = 0, overs[4][2]; | 27 | int padding = 1, i = 0, overs[4][2]; |
60 | 28 | ||
61 | if (obj != img) return; | 29 | // Sanity check. |
62 | if (1 != ev->buttons) return; | 30 | if ((20 > w) || (20 > h)) |
63 | 31 | return; | |
64 | // Looks like ePhysics wont cooperate about coords and other things, so plan B. | ||
65 | 32 | ||
66 | evas_object_geometry_get(img, &x, &y, &w, &h); | ||
67 | x += ev->cur.canvas.x - ev->prev.output.x; | ||
68 | y += ev->cur.canvas.y - ev->prev.output.y; | ||
69 | overs[0][0] = x - padding; overs[0][1] = y - padding; | 33 | overs[0][0] = x - padding; overs[0][1] = y - padding; |
70 | overs[1][0] = x + padding + w; overs[1][1] = y - padding; | 34 | overs[1][0] = x + padding + w; overs[1][1] = y - padding; |
71 | overs[2][0] = x + padding + w; overs[2][1] = y + padding + h; | 35 | overs[2][0] = x + padding + w; overs[2][1] = y + padding + h; |
@@ -85,17 +49,94 @@ static void _onBgMove(void *data, Evas *evas, Evas_Object *obj, void *event_info | |||
85 | } | 49 | } |
86 | 50 | ||
87 | // Check if we are outside the parent window. | 51 | // Check if we are outside the parent window. |
88 | evas_object_geometry_get(win->parent->win, NULL, NULL, &w, &h); | 52 | evas_object_geometry_get(win->parent->win, NULL, NULL, &mw, &mh); |
89 | if ((overs[0][0] < 0) || (overs[0][1] < 0)) | 53 | if ((overs[0][0] < 0) || (overs[0][1] < 0)) |
90 | { | 54 | { |
91 | return; | 55 | return; |
92 | } | 56 | } |
93 | if ((overs[2][0] > w) || (overs[2][1] > h)) | 57 | if ((overs[2][0] > mw) || (overs[2][1] > mh)) |
94 | { | 58 | { |
95 | return; | 59 | return; |
96 | } | 60 | } |
97 | 61 | ||
98 | evas_object_move(img, x, y); | 62 | // All good, do it. |
63 | win->x = x; win->y = y; | ||
64 | win->w = w; win->h = h; | ||
65 | evas_object_geometry_set(img, x, y, w, h); | ||
66 | for (i = 0; i < 4; i++) | ||
67 | { | ||
68 | int cx = win->x, cy = win->y; | ||
69 | |||
70 | if (i == 1) cx += win->w; | ||
71 | else if (i == 2) {cx += win->w; cy += win->h;} | ||
72 | else if (i == 3) cy += win->h; | ||
73 | evas_object_move(win->hand[i], cx - 15, cy - 15); | ||
74 | } | ||
75 | // TODO - This just stretches everything, we don't really want that. | ||
76 | } | ||
77 | |||
78 | static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
79 | { | ||
80 | Evas_Event_Mouse_Move *ev = event_info; | ||
81 | winFang *win = data; | ||
82 | Evas_Coord x, y, w, h, dx = 0, dy = 0, dw = 0, dh = 0, mx, my; | ||
83 | Evas_Object *img = elm_win_inlined_image_object_get(win->win); | ||
84 | int i; | ||
85 | |||
86 | if (!ev->buttons) return; | ||
87 | |||
88 | mx = ev->cur.canvas.x - ev->prev.output.x; | ||
89 | my = ev->cur.canvas.y - ev->prev.output.y; | ||
90 | evas_object_geometry_get(img, &x, &y, &w, &h); | ||
91 | |||
92 | for (i = 0; i < 4; i++) | ||
93 | { | ||
94 | if (obj == win->hand[i]) | ||
95 | { | ||
96 | switch (i) | ||
97 | { | ||
98 | case 0 : | ||
99 | { | ||
100 | dw -= mx; dh -= my; dx += mx; dy += my; | ||
101 | break; | ||
102 | } | ||
103 | case 1 : | ||
104 | { | ||
105 | dw += mx; dh -= my; dy += my; | ||
106 | break; | ||
107 | } | ||
108 | case 2 : | ||
109 | { | ||
110 | dw += mx; dh += my; | ||
111 | break; | ||
112 | } | ||
113 | case 3 : | ||
114 | { | ||
115 | dw -= mx; dh += my; dx += mx; | ||
116 | break; | ||
117 | } | ||
118 | } | ||
119 | _checkWindowBounds(win, x + dx, y + dy, w + dw, h + dh); | ||
120 | return; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | static void _onBgMove(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
126 | { | ||
127 | Evas_Event_Mouse_Move *ev = event_info; | ||
128 | winFang *win = data; | ||
129 | Evas_Object *img = elm_win_inlined_image_object_get(win->win); | ||
130 | Evas_Coord x, y, w, h; | ||
131 | |||
132 | if (1 != ev->buttons) return; | ||
133 | |||
134 | // Looks like ePhysics wont cooperate about coords and other things, so plan B. | ||
135 | |||
136 | evas_object_geometry_get(img, &x, &y, &w, &h); | ||
137 | x += ev->cur.canvas.x - ev->prev.output.x; | ||
138 | y += ev->cur.canvas.y - ev->prev.output.y; | ||
139 | _checkWindowBounds(win, x, y, w, h); | ||
99 | } | 140 | } |
100 | 141 | ||
101 | static void _on_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | 142 | static void _on_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
@@ -152,7 +193,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch | |||
152 | evas_object_name_set(obj, "winFang"); | 193 | evas_object_name_set(obj, "winFang"); |
153 | // 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. | 194 | // 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. |
154 | // According to the Elm inlined image window example, this is what's needed to. | 195 | // According to the Elm inlined image window example, this is what's needed to. |
155 | evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL); | 196 | evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, result); |
156 | evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _onBgMove, result); | 197 | evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _onBgMove, result); |
157 | elm_win_alpha_set(result->win, EINA_TRUE); | 198 | elm_win_alpha_set(result->win, EINA_TRUE); |
158 | 199 | ||
@@ -175,16 +216,6 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch | |||
175 | else if (i == 2) {cx += result->w; cy += result->h;} | 216 | else if (i == 2) {cx += result->w; cy += result->h;} |
176 | else if (i == 3) cy += result->h; | 217 | else if (i == 3) cy += result->h; |
177 | snprintf(key, sizeof(key), "h-%i\n", i); | 218 | snprintf(key, sizeof(key), "h-%i\n", i); |
178 | #if 1 | ||
179 | result->hand[i] = evas_object_image_filled_add(obj2); | ||
180 | evas_object_image_file_set(result->hand[i], buf, NULL); | ||
181 | evas_object_resize(result->hand[i], 31, 31); | ||
182 | evas_object_move(result->hand[i], cx - 15, cy - 15); | ||
183 | evas_object_data_set(obj, key, result->hand[i]); | ||
184 | evas_object_show(result->hand[i]); | ||
185 | evas_object_event_callback_add(result->hand[i], EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj); | ||
186 | #else | ||
187 | // TODO - No idea why, but using this version makes the window vanish when you click on a handle. | ||
188 | result->hand[i] = eo_add(EVAS_OBJ_IMAGE_CLASS, obj2, | 219 | result->hand[i] = eo_add(EVAS_OBJ_IMAGE_CLASS, obj2, |
189 | evas_obj_image_filled_set(EINA_TRUE), | 220 | evas_obj_image_filled_set(EINA_TRUE), |
190 | evas_obj_image_file_set(buf, NULL), | 221 | evas_obj_image_file_set(buf, NULL), |
@@ -193,9 +224,8 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch | |||
193 | eo_key_data_set(key, result->hand[i], NULL), | 224 | eo_key_data_set(key, result->hand[i], NULL), |
194 | evas_obj_visibility_set(EINA_TRUE) | 225 | evas_obj_visibility_set(EINA_TRUE) |
195 | ); | 226 | ); |
196 | evas_object_event_callback_add(result->hand[i], EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj); | 227 | evas_object_event_callback_add(result->hand[i], EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, result); |
197 | eo_unref(result->hand[i]); | 228 | eo_unref(result->hand[i]); |
198 | #endif | ||
199 | } | 229 | } |
200 | } | 230 | } |
201 | else | 231 | else |