2 # include "elementary_config.h"
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
7 /* We zoom out to this value so we'll be able to use map and have a nice
8 * resolution when zooming in. */
10 /* The amount of zoom to do when "lifting" objects. */
11 #define LIFT_FACTOR 1.3
12 /* The base size of the shadow image. */
15 #define RAD2DEG(x) ((x) * 57.295779513)
17 static double zoom_out_animation_duration = 0.4;
19 struct _Photo_Object {
20 Evas_Object *ic, *shadow;
23 Elm_Transit *zoom_out;
24 /* bx, by - current wanted coordinates of the photo object.
25 * bw, bh - original size of the "ic" object.
26 * dx, dy - Used to indicate the distance between the center point
27 * where we put down our fingers (when started moving the item) to
28 * the coords of the object, so we'll be able to calculate movement
30 Evas_Coord bx, by, bw, bh, dx, dy;
31 /* Because gesture layer only knows the amount of rotation/zoom we do
32 * per gesture, we have to keep the current rotate/zoom factor and the
33 * one that was before we started the gesture. */
34 int base_rotate, rotate;
35 double base_zoom, zoom;
38 typedef struct _Photo_Object Photo_Object;
41 /* This function applies the information from the Photo_Object to the actual
42 * evas objects. Zoom/rotate factors and etc. */
44 apply_changes(Photo_Object *po)
48 map = evas_map_new(4);
49 evas_map_point_coord_set(map, 0, po->bx, po->by, 0);
50 evas_map_point_coord_set(map, 1, po->bx + po->bw, po->by, 0);
51 evas_map_point_coord_set(map, 2, po->bx + po->bw, po->by + po->bh, 0);
52 evas_map_point_coord_set(map, 3, po->bx, po->by + po->bh, 0);
53 evas_map_point_image_uv_set(map, 0, 0, 0);
54 evas_map_point_image_uv_set(map, 1, po->bw, 0);
55 evas_map_point_image_uv_set(map, 2, po->bw, po->bh);
56 evas_map_point_image_uv_set(map, 3, 0, po->bh);
57 evas_map_util_rotate(map, po->rotate,
58 po->bx + po->bw / 2, po->by + po->bh /2);
59 evas_map_util_zoom(map, po->zoom, po->zoom,
60 po->bx + po->bw / 2, po->by + po->bh /2);
61 evas_object_map_enable_set(po->ic, EINA_TRUE);
62 evas_object_map_set(po->ic, map);
65 Evas_Map *shadow_map = evas_map_new(4);
66 evas_map_point_coord_set(shadow_map, 0, po->bx, po->by, 0);
67 evas_map_point_coord_set(shadow_map, 1, po->bx + po->bw, po->by, 0);
68 evas_map_point_coord_set(shadow_map, 2, po->bx + po->bw, po->by + po->bh, 0);
69 evas_map_point_coord_set(shadow_map, 3, po->bx, po->by + po->bh, 0);
70 evas_map_point_image_uv_set(shadow_map, 0, 0, 0);
71 evas_map_point_image_uv_set(shadow_map, 1, SHADOW_W, 0);
72 evas_map_point_image_uv_set(shadow_map, 2, SHADOW_W, SHADOW_H);
73 evas_map_point_image_uv_set(shadow_map, 3, 0, SHADOW_H);
74 evas_map_util_rotate(shadow_map, po->rotate,
75 po->bx + po->bw / 2, po->by + po->bh /2);
76 evas_map_util_zoom(shadow_map, po->zoom * po->shadow_zoom,
77 po->zoom * po->shadow_zoom,
78 po->bx + (po->bw / 2), po->by + (po->bh / 2));
79 evas_object_map_enable_set(po->shadow, EINA_TRUE);
80 evas_object_map_set(po->shadow, shadow_map);
81 evas_map_free(shadow_map);
84 /* Update the position of the hit box */
86 Evas_Coord minx, miny, maxx, maxy;
88 evas_object_polygon_points_clear(po->hit);
89 evas_map_point_coord_get(map, 0, &minx, &miny, NULL);
92 evas_object_polygon_point_add(po->hit, minx, miny);
93 for (i = 1 ; i <= 3 ; i++)
96 evas_map_point_coord_get(map, i, &x, &y, NULL);
97 evas_object_polygon_point_add(po->hit, x, y);
110 evas_object_raise(po->shadow);
111 evas_object_raise(po->ic);
112 evas_object_raise(po->hit);
116 /* Zoom out animation */
118 zoom_out_animation_operation(void *_po, Elm_Transit *transit __UNUSED__,
121 Photo_Object *po = (Photo_Object *) _po;
122 po->zoom = BASE_ZOOM + ((po->base_zoom - BASE_ZOOM) * (1.0 - progress));
127 zoom_out_animation_end(void *_po, Elm_Transit *transit __UNUSED__)
129 Photo_Object *po = (Photo_Object *) _po;
131 po->base_zoom = po->zoom = BASE_ZOOM;
137 static Evas_Event_Flags
138 rotate_move(void *_po, void *event_info)
140 Photo_Object *po = (Photo_Object *) _po;
141 Elm_Gesture_Rotate_Info *p = (Elm_Gesture_Rotate_Info *) event_info;
142 printf("rotate move <%d,%d> base=<%f> <%f>\n", p->x, p->y, RAD2DEG(p->base_angle), RAD2DEG(p->angle));
143 po->rotate = po->base_rotate + (int) RAD2DEG(p->base_angle - p->angle);
147 return EVAS_EVENT_FLAG_NONE;
150 static Evas_Event_Flags
151 rotate_end(void *_po, void *event_info)
153 Photo_Object *po = (Photo_Object *) _po;
154 Elm_Gesture_Rotate_Info *p = (Elm_Gesture_Rotate_Info *) event_info;
155 printf("rotate end/abort <%d,%d> base=<%f> <%f>\n", p->x, p->y, RAD2DEG(p->base_angle), RAD2DEG(p->angle));
156 po->base_rotate += (int) RAD2DEG(p->base_angle - p->angle);
159 return EVAS_EVENT_FLAG_NONE;
162 static Evas_Event_Flags
163 zoom_start(void *_po, void *event_info)
165 Photo_Object *po = (Photo_Object *) _po;
166 Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
167 printf("zoom start <%d,%d> <%f>\n", p->x, p->y, p->zoom);
169 /* If there's an active animator, stop it */
172 elm_transit_del(po->zoom_out);
176 /* Give it a "lift" effect right from the start */
177 po->base_zoom = BASE_ZOOM * LIFT_FACTOR;
178 po->zoom = po->base_zoom;
179 po->shadow_zoom = 1.7;
182 return EVAS_EVENT_FLAG_NONE;
185 static Evas_Event_Flags
186 zoom_move(void *_po, void *event_info)
188 Photo_Object *po = (Photo_Object *) _po;
189 Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
190 printf("zoom move <%d,%d> <%f>\n", p->x, p->y, p->zoom);
191 po->zoom = po->base_zoom * p->zoom;
193 return EVAS_EVENT_FLAG_NONE;
196 static Evas_Event_Flags
197 zoom_end(void *_po, void *event_info)
199 Photo_Object *po = (Photo_Object *) _po;
200 Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
201 printf("zoom end/abort <%d,%d> <%f>\n", p->x, p->y, p->zoom);
203 /* Apply the zoom out animator */
204 po->shadow_zoom = 1.3;
205 po->base_zoom = po->zoom;
206 po->zoom_out = elm_transit_add();
207 elm_transit_duration_set(po->zoom_out, zoom_out_animation_duration);
208 elm_transit_effect_add(po->zoom_out, zoom_out_animation_operation, po, zoom_out_animation_end);
209 elm_transit_go(po->zoom_out);
210 return EVAS_EVENT_FLAG_NONE;
213 static Evas_Event_Flags
214 momentum_start(void *_po, void *event_info)
216 Photo_Object *po = (Photo_Object *) _po;
217 Elm_Gesture_Momentum_Info *p = (Elm_Gesture_Momentum_Info *) event_info;
218 printf("momentum_start <%d,%d>\n", p->x2, p->y2);
220 po->dx = p->x2 - po->bx;
221 po->dy = p->y2 - po->by;
224 return EVAS_EVENT_FLAG_NONE;
227 static Evas_Event_Flags
228 momentum_move(void *_po, void *event_info)
230 Photo_Object *po = (Photo_Object *) _po;
231 Elm_Gesture_Momentum_Info *p = (Elm_Gesture_Momentum_Info *) event_info;
232 printf("momentum move <%d,%d>\n", p->x2, p->y2);
234 po->bx = p->x2 - po->dx;
235 po->by = p->y2 - po->dy;
238 return EVAS_EVENT_FLAG_NONE;
241 static Evas_Event_Flags
242 momentum_end(void *_po, void *event_info)
244 Photo_Object *po = (Photo_Object *) _po;
245 Elm_Gesture_Momentum_Info *p = (Elm_Gesture_Momentum_Info *) event_info;
246 printf("momentum end/abort <%d,%d> <%d,%d>\n", p->x2, p->y2, p->mx, p->my);
249 /* Make sure middle is in the screen, if not, fix it. */
251 /* FIXME: Use actual window sizes instead of the hardcoded
254 mx = po->bx + (po->bw / 2);
255 my = po->by + (po->bh / 2);
257 po->bx = 0 - (po->bw / 2);
259 po->bx = 480 - (po->bw / 2);
262 po->by = 0 - (po->bw / 2);
264 po->by = 800 - (po->bh / 2);
268 return EVAS_EVENT_FLAG_NONE;
272 _win_del_req(void *data, Evas_Object *obj __UNUSED__,
273 void *event_info __UNUSED__)
275 Photo_Object **photo_array = (Photo_Object **) data;
280 /* The content of the photo object is automatically deleted when the win
282 for ( ; *photo_array ; photo_array++)
290 photo_object_add(Evas_Object *parent, Evas_Object *ic, const char *icon, Evas_Coord x,
291 Evas_Coord y, Evas_Coord w, Evas_Coord h, int angle)
295 po = calloc(1, sizeof(*po));
296 po->base_zoom = po->zoom = BASE_ZOOM;
304 po->ic = elm_icon_add(parent);
305 elm_icon_file_set(po->ic, icon, NULL);
315 po->shadow = elm_icon_add(po->ic);
316 snprintf(buf, sizeof(buf), "%s/images/pol_shadow.png", elm_app_data_dir_get());
317 elm_icon_file_set(po->shadow, buf, NULL);
318 evas_object_resize(po->shadow, SHADOW_W, SHADOW_H);
319 evas_object_show(po->shadow);
322 po->hit = evas_object_polygon_add(evas_object_evas_get(parent));
323 evas_object_precise_is_inside_set(po->hit, EINA_TRUE);
324 evas_object_repeat_events_set(po->hit, EINA_TRUE);
325 evas_object_color_set(po->hit, 0, 0, 0, 0);
327 evas_object_resize(po->ic, po->bw, po->bh);
328 evas_object_show(po->ic);
330 evas_object_show(po->hit);
332 po->gl = elm_gesture_layer_add(po->ic);
333 elm_gesture_layer_hold_events_set(po->gl, EINA_TRUE);
334 elm_gesture_layer_attach(po->gl, po->hit);
336 /* FIXME: Add a po->rotate start so we take the first angle!!!! */
337 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE, rotate_move, po);
338 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END, rotate_end, po);
339 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT, rotate_end, po);
340 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START, zoom_start, po);
341 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE, zoom_move, po);
342 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END, zoom_end, po);
343 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT, zoom_end, po);
344 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_START, momentum_start, po);
345 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_MOVE, momentum_move, po);
346 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_END, momentum_end, po);
347 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_ABORT, momentum_end, po);
349 po->rotate = po->base_rotate = angle;
350 po->shadow_zoom = 1.3;
357 test_gesture_layer(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
358 void *event_info __UNUSED__)
361 Evas_Object *win, *bg;
364 Photo_Object **photo_array;
365 photo_array = calloc(sizeof(*photo_array), 4);
370 win = elm_win_add(NULL, "gesture-layer", ELM_WIN_BASIC);
371 elm_win_title_set(win, "Gesture Layer");
372 elm_win_autodel_set(win, EINA_TRUE);
373 evas_object_resize(win, w, h);
375 bg = elm_bg_add(win);
376 snprintf(buf, sizeof(buf), "%s/images/wood_01.jpg", elm_app_data_dir_get());
377 elm_bg_file_set(bg, buf, NULL);
378 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
379 elm_win_resize_object_add(win, bg);
380 evas_object_show(bg);
382 snprintf(buf, sizeof(buf), "%s/images/pol_sky.png", elm_app_data_dir_get());
383 photo_array[ind++] = photo_object_add(win, NULL, buf, 200, 200, 365, 400, 0);
384 snprintf(buf, sizeof(buf), "%s/images/pol_twofish.png", elm_app_data_dir_get());
385 photo_array[ind++] = photo_object_add(win, NULL, buf, 40, 300, 365, 400, 45);
387 Evas_Object *en = elm_entry_add(win);
388 elm_object_text_set(en, "You can use whatever object you want, "
389 "even entries like this.");
390 elm_entry_line_wrap_set(en, ELM_WRAP_MIXED);
392 Evas_Object *postit = elm_layout_add(win);
393 snprintf(buf, sizeof(buf), "%s/objects/postit_ent.edj", elm_app_data_dir_get());
394 elm_layout_file_set(postit, buf, "main");
395 elm_object_part_content_set(postit, "ent", en);
397 photo_array[ind++] = photo_object_add(win, postit, NULL, 50, 50, 382, 400, 355);
399 photo_array[ind] = NULL;
400 evas_object_smart_callback_add(win, "delete,request", _win_del_req,
402 evas_object_show(win);