1 #include <Elementary.h>
3 # include "elementary_config.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);
177 po->dx = p->x - po->bx;
178 po->dy = p->y - po->by;
179 /* Give it a "lift" effect right from the start */
180 po->base_zoom = BASE_ZOOM * LIFT_FACTOR;
181 po->zoom = po->base_zoom;
182 po->shadow_zoom = 1.7;
185 return EVAS_EVENT_FLAG_NONE;
188 static Evas_Event_Flags
189 zoom_move(void *_po, void *event_info)
191 Photo_Object *po = (Photo_Object *) _po;
192 Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
193 printf("zoom move <%d,%d> <%f>\n", p->x, p->y, p->zoom);
194 po->zoom = po->base_zoom * p->zoom;
195 po->bx = p->x - po->dx;
196 po->by = p->y - po->dy;
198 return EVAS_EVENT_FLAG_NONE;
201 static Evas_Event_Flags
202 zoom_end(void *_po, void *event_info)
204 Photo_Object *po = (Photo_Object *) _po;
205 Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
206 printf("zoom end/abort <%d,%d> <%f>\n", p->x, p->y, p->zoom);
208 /* Make sure middle is in the screen, if not, fix it. */
210 /* FIXME: Use actual window sizes instead of the hardcoded
213 mx = po->bx + (po->bw / 2);
214 my = po->by + (po->bh / 2);
216 po->bx = 0 - (po->bw / 2);
218 po->bx = 480 - (po->bw / 2);
221 po->by = 0 - (po->bw / 2);
223 po->by = 800 - (po->bh / 2);
226 /* Apply the zoom out animator */
227 po->shadow_zoom = 1.3;
228 po->base_zoom = po->zoom;
229 po->zoom_out = elm_transit_add();
230 elm_transit_duration_set(po->zoom_out, zoom_out_animation_duration);
231 elm_transit_effect_add(po->zoom_out, zoom_out_animation_operation, po, zoom_out_animation_end);
232 elm_transit_go(po->zoom_out);
233 return EVAS_EVENT_FLAG_NONE;
237 _win_del_req(void *data, Evas_Object *obj __UNUSED__,
238 void *event_info __UNUSED__)
240 Photo_Object **photo_array = (Photo_Object **) data;
245 /* The content of the photo object is automatically deleted when the win
247 for ( ; *photo_array ; photo_array++)
255 photo_object_add(Evas_Object *parent, Evas_Object *ic, const char *icon, Evas_Coord x,
256 Evas_Coord y, Evas_Coord w, Evas_Coord h, int angle)
260 po = calloc(1, sizeof(*po));
261 po->base_zoom = po->zoom = BASE_ZOOM;
269 po->ic = elm_icon_add(parent);
270 elm_icon_file_set(po->ic, icon, NULL);
280 po->shadow = elm_icon_add(po->ic);
281 snprintf(buf, sizeof(buf), "%s/images/pol_shadow.png", elm_app_data_dir_get());
282 elm_icon_file_set(po->shadow, buf, NULL);
283 evas_object_resize(po->shadow, SHADOW_W, SHADOW_H);
284 evas_object_show(po->shadow);
287 po->hit = evas_object_polygon_add(evas_object_evas_get(parent));
288 evas_object_precise_is_inside_set(po->hit, EINA_TRUE);
289 evas_object_repeat_events_set(po->hit, EINA_TRUE);
290 evas_object_color_set(po->hit, 0, 0, 0, 0);
292 evas_object_resize(po->ic, po->bw, po->bh);
293 evas_object_show(po->ic);
295 evas_object_show(po->hit);
297 po->gl = elm_gesture_layer_add(po->ic);
298 elm_gesture_layer_hold_events_set(po->gl, EINA_TRUE);
299 elm_gesture_layer_attach(po->gl, po->hit);
301 /* FIXME: Add a po->rotate start so we take the first angle!!!! */
302 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE, rotate_move, po);
303 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END, rotate_end, po);
304 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT, rotate_end, po);
305 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START, zoom_start, po);
306 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE, zoom_move, po);
307 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END, zoom_end, po);
308 elm_gesture_layer_cb_set(po->gl, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT, zoom_end, po);
310 po->rotate = po->base_rotate = angle;
311 po->shadow_zoom = 1.3;
318 test_gesture_layer(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
319 void *event_info __UNUSED__)
322 Evas_Object *win, *bg;
325 Photo_Object **photo_array;
326 photo_array = calloc(sizeof(*photo_array), 4);
331 win = elm_win_add(NULL, "gesture-layer", ELM_WIN_BASIC);
332 elm_win_title_set(win, "Gesture Layer");
333 elm_win_autodel_set(win, EINA_TRUE);
334 evas_object_resize(win, w, h);
336 bg = elm_bg_add(win);
337 snprintf(buf, sizeof(buf), "%s/images/wood_01.jpg", elm_app_data_dir_get());
338 elm_bg_file_set(bg, buf, NULL);
339 elm_win_resize_object_add(win, bg);
340 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
341 evas_object_show(bg);
343 snprintf(buf, sizeof(buf), "%s/images/pol_sky.png", elm_app_data_dir_get());
344 photo_array[ind++] = photo_object_add(win, NULL, buf, 200, 200, 365, 400, 0);
345 snprintf(buf, sizeof(buf), "%s/images/pol_twofish.png", elm_app_data_dir_get());
346 photo_array[ind++] = photo_object_add(win, NULL, buf, 40, 300, 365, 400, 45);
348 Evas_Object *en = elm_entry_add(win);
349 elm_entry_entry_set(en, "You can use whatever object you want, "
350 "even entries like this.");
351 elm_entry_line_wrap_set(en, ELM_WRAP_MIXED);
353 Evas_Object *postit = elm_layout_add(win);
354 snprintf(buf, sizeof(buf), "%s/objects/postit_ent.edj", elm_app_data_dir_get());
355 elm_layout_file_set(postit, buf, "main");
356 elm_object_content_part_set(postit, "ent", en);
358 photo_array[ind++] = photo_object_add(win, postit, NULL, 50, 50, 382, 400, 355);
360 photo_array[ind] = NULL;
361 evas_object_smart_callback_add(win, "delete,request", _win_del_req,
363 evas_object_show(win);