1 #include "e_mod_main.h"
2 
3 //////////////////////////////////////////////////////////////////////////////
4 // globals
5 static Evas_Object *o_img, *o_rend, *win2, *o_events, *o_scroll;
6 static Evas_Object *o_col1, *o_col2;
7 static int img_w, img_h,  edit_w, edit_h;
8 
9 static int window_pad = 64;
10 
11 typedef enum
12 {
13    TOOL_NONE,
14    TOOL_CROP,
15    TOOL_MODIFY,
16    TOOL_DELETE,
17    TOOL_BOX,
18    TOOL_LINE
19 } Tool_Mode;
20 
21 typedef struct
22 {
23    int r, g, b, a;
24 } Tool_Color;
25 
26 static Tool_Mode tool_mode = TOOL_NONE;
27 static int color_sel = 0;
28 Tool_Color color[2] =
29 {
30    { 255, 255, 255, 255 },
31    {   0,   0,   0, 255 }
32 };
33 
34 //
35 //////////////////////////////////////////////////////////////////////////////
36 
37 static inline double
to_rad(double deg)38 to_rad(double deg)
39 {
40    return (deg * M_PI * 2.0) / 360.0;
41 }
42 
43 static inline double
to_deg(double rad)44 to_deg(double rad)
45 {
46    return (rad * 360.0) / (M_PI * 2.0);
47 }
48 
49 static inline int
premul(int v,int a)50 premul(int v, int a)
51 {
52    return (v * a) / 255;
53 }
54 
55 //////////////////////////////////////////////////////////////////////////////
56 // draw/modify handling objects
57 
58 typedef enum
59 {
60    MODIFY_NONE,
61    MODIFY_LINE,
62    MODIFY_BOX
63 } Modify_Mode;
64 
65 typedef enum
66 {
67    MODIFY_BOX_NONE,
68    MODIFY_BOX_MOVE,
69    MODIFY_BOX_RESIZE_TL,
70    MODIFY_BOX_RESIZE_TR,
71    MODIFY_BOX_RESIZE_BL,
72    MODIFY_BOX_RESIZE_BR,
73    MODIFY_BOX_ROTATE_TL,
74    MODIFY_BOX_ROTATE_TR,
75    MODIFY_BOX_ROTATE_BL,
76    MODIFY_BOX_ROTATE_BR
77 } Modify_Box_Mode;
78 
79 static Eina_List   *draw_objects = NULL;
80 static Evas_Object *o_draw_handles[2] = { NULL, NULL };
81 static Eina_Bool    modify_down = EINA_FALSE;
82 static int          modify_down_x = 0;
83 static int          modify_down_y = 0;
84 static int          modify_x = 0;
85 static int          modify_y = 0;
86 static int          modify_line_x1 = 0;
87 static int          modify_line_y1 = 0;
88 static int          modify_line_x2 = 0;
89 static int          modify_line_y2 = 0;
90 static int          modify_box_x1 = 0;
91 static int          modify_box_y1 = 0;
92 static int          modify_box_x2 = 0;
93 static int          modify_box_y2 = 0;
94 static double       modify_box_angle = 0.0;
95 static int          modify_handle_offx = 0;
96 static int          modify_handle_offy = 0;
97 static Modify_Mode  modify_mode = MODIFY_NONE;
98 
99 static Eina_Bool       modify_box_rotate = EINA_FALSE;
100 static Modify_Box_Mode modify_box_mode = MODIFY_BOX_NONE;
101 
102 static void colorsel_set(void);
103 static void draw_selectable_set(Eina_Bool sel);
104 static void line_clear(void);
105 static void line_modify_begin(Evas_Object *o, int x1, int y1, int x2, int y2, int inset);
106 static void line_modify_coord_set(int x1, int y1, int x2, int y2);
107 static void line_modify_coord_get(int *x1, int *y1, int *x2, int *y2);
108 static void line_eval(void);
109 static void box_clear(void);
110 static void box_modify_begin(Evas_Object *o, int x1, int y1, int x2, int y2, double ang);
111 static void box_modify_coord_set(int x1, int y1, int x2, int y2, double ang);
112 static void box_modify_coord_get(int *x1, int *y1, int *x2, int *y2, double *ang);
113 static Evas_Object *box_obj_get(void);
114 static void box_eval(void);
115 
116 static void
draw_handle_line_update(void)117 draw_handle_line_update(void)
118 {
119    int x1, y1, x2, y2;
120 
121    line_modify_coord_get(&x1, &y1, &x2, &y2);
122    evas_object_move(o_draw_handles[0],
123                     x1 + modify_handle_offx, y1 + modify_handle_offy);
124    evas_object_move(o_draw_handles[1],
125                     x2 + modify_handle_offx, y2 + modify_handle_offy);
126 }
127 
128 static void
draw_handle_box_update(void)129 draw_handle_box_update(void)
130 {
131    Evas_Object *o = box_obj_get();
132    Evas_Coord x, y, w, h;
133    const Evas_Map *m0;
134    Evas_Map *m;
135 
136    evas_object_geometry_get(o, &x, &y, &w, &h);
137    evas_object_geometry_set(o_draw_handles[0], x, y, w, h);
138    m0 = evas_object_map_get(o);
139    if (m0)
140      {
141         m = evas_map_dup(m0);
142         evas_object_map_set(o_draw_handles[0], m);
143         evas_map_free(m);
144         evas_object_map_enable_set(o_draw_handles[0], EINA_TRUE);
145         evas_object_show(o_draw_handles[0]);
146      }
147 }
148 
149 static void
_cb_modify_mouse_down(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)150 _cb_modify_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
151 {
152    Evas_Event_Mouse_Down *ev = info;
153 
154    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
155    if (ev->button == 1)
156      {
157         modify_down = EINA_TRUE;
158         evas_pointer_canvas_xy_get(evas_object_evas_get(win2), &modify_x, &modify_y);
159         modify_down_x = modify_x;
160         modify_down_y = modify_y;
161         if (modify_mode == MODIFY_LINE)
162           {
163              line_modify_coord_get(&modify_line_x1, &modify_line_y1,
164                                    &modify_line_x2, &modify_line_y2);
165           }
166         else if (modify_mode == MODIFY_BOX)
167           {
168              box_modify_coord_get(&modify_box_x1, &modify_box_y1,
169                                   &modify_box_x2, &modify_box_y2,
170                                   &modify_box_angle);
171           }
172         elm_object_scroll_hold_push(o_scroll);
173         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
174      }
175 }
176 
177 static void
_cb_modify_mouse_up(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)178 _cb_modify_mouse_up(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
179 {
180    Evas_Event_Mouse_Up *ev = info;
181 
182    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
183    if (ev->button == 1)
184      {
185         int dx, dy;
186 
187         if (!modify_down) return;
188         modify_down = EINA_FALSE;
189         elm_object_scroll_hold_pop(o_scroll);
190         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
191         dx = modify_x - modify_down_x;
192         dy = modify_y - modify_down_y;
193         if ((modify_box_mode == MODIFY_BOX_MOVE) &&
194             (((dx * dx) + (dy * dy)) < (5 * 5)))
195           {
196              modify_box_rotate = !modify_box_rotate;
197              if (modify_box_rotate)
198                elm_layout_signal_emit(o_draw_handles[0], "e,state,resize", "e");
199              else
200                elm_layout_signal_emit(o_draw_handles[0], "e,state,move", "e");
201           }
202      }
203 }
204 
205 static void
rot_point(int * x,int * y,int cx,int cy,double ang)206 rot_point(int *x, int *y, int cx, int cy, double ang)
207 {
208    int dx = *x - cx;
209    int dy = *y - cy;
210    double len = sqrt((dx * dx) + (dy * dy));
211    double a = atan2(dy, dx);
212    *x = cx + (cos(a + to_rad(ang)) * len);
213    *y = cy + (sin(a + to_rad(ang)) * len);
214 }
215 
216 static double
angle_get(int x1,int y1,int x2,int y2,int px,int py,double ang,int nx,int ny)217 angle_get(int x1, int y1, int x2, int y2, int px, int py, double ang, int nx, int ny)
218 {
219    int cx = (x1 + x2) / 2;
220    int cy = (y1 + y2) / 2;
221    double ang_pt = 360.0 + to_deg(atan2(py - cy, px - cx)) + ang;
222    double ang_new = 360.0 + to_deg(atan2(ny - cy, nx - cx));
223    return fmod(360.0 + ang_new - ang_pt, 360.0);
224 }
225 
226 static void
_cb_modify_mouse_move(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj,void * info)227 _cb_modify_mouse_move(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info)
228 {
229    Evas_Event_Mouse_Move *ev = info;
230    int mx, my;
231 
232    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
233    if (!modify_down) return;
234    evas_pointer_canvas_xy_get(evas_object_evas_get(win2), &modify_x, &modify_y);
235    mx = modify_x - modify_down_x;
236    my = modify_y - modify_down_y;
237    if (modify_mode == MODIFY_LINE)
238      {
239         if (obj == o_draw_handles[0])
240           line_modify_coord_set(modify_line_x1 + mx,
241                                 modify_line_y1 + my,
242                                 modify_line_x2, modify_line_y2);
243         else if (obj == o_draw_handles[1])
244           line_modify_coord_set(modify_line_x1, modify_line_y1,
245                                 modify_line_x2 + mx,
246                                 modify_line_y2 + my);
247         draw_handle_line_update();
248         line_eval();
249      }
250    else if (modify_mode == MODIFY_BOX)
251      {
252         if (modify_box_mode == MODIFY_BOX_MOVE)
253           {
254              box_modify_coord_set(modify_box_x1 + mx,
255                                   modify_box_y1 + my,
256                                   modify_box_x2 + mx,
257                                   modify_box_y2 + my,
258                                   modify_box_angle);
259           }
260         else if (modify_box_mode == MODIFY_BOX_RESIZE_TL)
261           {
262              if (modify_box_rotate)
263                {
264                   double rot_by =
265                     angle_get(modify_box_x1, modify_box_y1,
266                               modify_box_x2, modify_box_y2,
267                               modify_box_x1, modify_box_y1,
268                               modify_box_angle,
269                               modify_x, modify_y);
270                   box_modify_coord_set(modify_box_x1, modify_box_y1,
271                                        modify_box_x2, modify_box_y2,
272                                        modify_box_angle + rot_by);
273                }
274              else
275                {
276                   rot_point(&mx, &my, 0, 0, -modify_box_angle);
277                   box_modify_coord_set(modify_box_x1 + mx,
278                                        modify_box_y1 + my,
279                                        modify_box_x2 - mx,
280                                        modify_box_y2 - my,
281                                        modify_box_angle);
282                }
283           }
284         else if (modify_box_mode == MODIFY_BOX_RESIZE_TR)
285           {
286              if (modify_box_rotate)
287                {
288                   double rot_by =
289                     angle_get(modify_box_x1, modify_box_y1,
290                               modify_box_x2, modify_box_y2,
291                               modify_box_x2, modify_box_y1,
292                               modify_box_angle,
293                               modify_x, modify_y);
294                   box_modify_coord_set(modify_box_x1, modify_box_y1,
295                                        modify_box_x2, modify_box_y2,
296                                        modify_box_angle + rot_by);
297                }
298              else
299                {
300                   rot_point(&mx, &my, 0, 0, -modify_box_angle);
301                   box_modify_coord_set(modify_box_x1 - mx,
302                                        modify_box_y1 + my,
303                                        modify_box_x2 + mx,
304                                        modify_box_y2 - my,
305                                        modify_box_angle);
306                }
307           }
308         else if (modify_box_mode == MODIFY_BOX_RESIZE_BL)
309           {
310              if (modify_box_rotate)
311                {
312                   double rot_by =
313                     angle_get(modify_box_x1, modify_box_y1,
314                               modify_box_x2, modify_box_y2,
315                               modify_box_x1, modify_box_y2,
316                               modify_box_angle,
317                               modify_x, modify_y);
318                   box_modify_coord_set(modify_box_x1, modify_box_y1,
319                                        modify_box_x2, modify_box_y2,
320                                        modify_box_angle + rot_by);
321                }
322              else
323                {
324                   rot_point(&mx, &my, 0, 0, -modify_box_angle);
325                   box_modify_coord_set(modify_box_x1 + mx,
326                                        modify_box_y1 - my,
327                                        modify_box_x2 - mx,
328                                        modify_box_y2 + my,
329                                        modify_box_angle);
330                }
331           }
332         else if (modify_box_mode == MODIFY_BOX_RESIZE_BR)
333           {
334              if (modify_box_rotate)
335                {
336                   double rot_by =
337                     angle_get(modify_box_x1, modify_box_y1,
338                               modify_box_x2, modify_box_y2,
339                               modify_box_x2, modify_box_y2,
340                               modify_box_angle,
341                               modify_x, modify_y);
342                   box_modify_coord_set(modify_box_x1, modify_box_y1,
343                                        modify_box_x2, modify_box_y2,
344                                        modify_box_angle + rot_by);
345                }
346              else
347                {
348                   rot_point(&mx, &my, 0, 0, -modify_box_angle);
349                   box_modify_coord_set(modify_box_x1 - mx,
350                                        modify_box_y1 - my,
351                                        modify_box_x2 + mx,
352                                        modify_box_y2 + my,
353                                        modify_box_angle);
354                }
355           }
356         box_eval();
357         draw_handle_box_update();
358      }
359    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
360 }
361 
362 static void
_cb_mod_move(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)363 _cb_mod_move(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
364 {
365    modify_box_mode = MODIFY_BOX_MOVE;
366 }
367 
368 static void
_cb_mod_resize_tl(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)369 _cb_mod_resize_tl(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
370 {
371    modify_box_mode = MODIFY_BOX_RESIZE_TL;
372 }
373 
374 static void
_cb_mod_resize_tr(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)375 _cb_mod_resize_tr(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
376 {
377    modify_box_mode = MODIFY_BOX_RESIZE_TR;
378 }
379 
380 static void
_cb_mod_resize_bl(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)381 _cb_mod_resize_bl(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
382 {
383    modify_box_mode = MODIFY_BOX_RESIZE_BL;
384 }
385 
386 static void
_cb_mod_resize_br(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)387 _cb_mod_resize_br(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
388 {
389    modify_box_mode = MODIFY_BOX_RESIZE_BR;
390 }
391 
392 static void
draw_modify_clear(void)393 draw_modify_clear(void)
394 {
395    int i;
396 
397    modify_mode = MODIFY_NONE;
398    modify_box_mode = MODIFY_BOX_NONE;
399    modify_box_rotate = EINA_FALSE;
400    for (i = 0; i < 2; i++)
401      {
402         if (!o_draw_handles[i]) continue;
403         evas_object_del(o_draw_handles[i]);
404         o_draw_handles[i] = NULL;
405      }
406    line_clear();
407    box_clear();
408 }
409 
410 static Evas_Object *
draw_handle_add(Evas_Object * parent,const char * group)411 draw_handle_add(Evas_Object *parent, const char *group)
412 {
413    Evas_Object *o;
414    Evas_Coord minw, minh;
415    char path[PATH_MAX];
416    char buf[1024];
417 
418    o = elm_layout_add(parent);
419    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
420    snprintf(buf, sizeof(buf), "e/modules/shot/%s", group);
421    elm_layout_file_set(o, path, buf);
422    edje_object_size_min_calc(elm_layout_edje_get(o), &minw, &minh);
423    evas_object_resize(o, minw, minh);
424    modify_handle_offx = -(minw / 2);
425    modify_handle_offy = -(minh / 2);
426    evas_object_show(o);
427    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
428                                   _cb_modify_mouse_down, NULL);
429    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP,
430                                   _cb_modify_mouse_up, NULL);
431    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE,
432                                   _cb_modify_mouse_move, NULL);
433    return o;
434 }
435 
436 static Evas_Object *
draw_boxhandle_add(Evas_Object * parent,const char * group)437 draw_boxhandle_add(Evas_Object *parent, const char *group)
438 {
439    Evas_Object *o;
440    char path[PATH_MAX];
441    char buf[1024];
442 
443    o = elm_layout_add(parent);
444    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
445    snprintf(buf, sizeof(buf), "e/modules/shot/%s", group);
446    elm_layout_file_set(o, path, buf);
447    evas_object_repeat_events_set(o, EINA_TRUE);
448    evas_object_show(o);
449    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
450                                   _cb_modify_mouse_down, NULL);
451    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP,
452                                   _cb_modify_mouse_up, NULL);
453    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE,
454                                   _cb_modify_mouse_move, NULL);
455    return o;
456 }
457 
458 static void
draw_color_rects_update(void)459 draw_color_rects_update(void)
460 {
461    evas_object_color_set(o_col1,
462                          premul(color[0].r, color[0].a),
463                          premul(color[0].g, color[0].a),
464                          premul(color[0].b, color[0].a),
465                          color[0].a);
466    evas_object_color_set(o_col2,
467                          premul(color[1].r, color[1].a),
468                          premul(color[1].g, color[1].a),
469                          premul(color[1].b, color[1].a),
470                          color[1].a);
471 }
472 
473 static void
draw_modify_begin(Evas_Object * o)474 draw_modify_begin(Evas_Object *o)
475 {
476    if (evas_object_data_get(o, "line"))
477      {
478         modify_mode = MODIFY_LINE;
479         int x1 = (int)(uintptr_t)evas_object_data_get(o, "x1");
480         int y1 = (int)(uintptr_t)evas_object_data_get(o, "y1");
481         int x2 = (int)(uintptr_t)evas_object_data_get(o, "x2");
482         int y2 = (int)(uintptr_t)evas_object_data_get(o, "y2");
483         int inset = (int)(uintptr_t)evas_object_data_get(o, "inset");
484         modify_line_x1 = x1; modify_line_y1 = y1;
485         modify_line_x2 = x2; modify_line_y2 = y2;
486         line_modify_begin(o, x1, y1, x2, y2, inset);
487         evas_object_raise(o);
488         evas_object_stack_below(evas_object_data_get(o, "shadow"), o);
489         edje_object_color_class_get(elm_layout_edje_get(o), "color",
490                                     &color[0].r, &color[0].g, &color[0].b, &color[0].a,
491                                     NULL, NULL, NULL, NULL,
492                                     NULL, NULL, NULL, NULL);
493         edje_object_color_class_get(elm_layout_edje_get(o), "color2",
494                                     &color[1].r, &color[1].g, &color[1].b, &color[1].a,
495                                     NULL, NULL, NULL, NULL,
496                                     NULL, NULL, NULL, NULL);
497         colorsel_set();
498         o_draw_handles[0] = draw_handle_add(win2, "tool/line/handle");
499         o_draw_handles[1] = draw_handle_add(win2, "tool/line/handle");
500         draw_handle_line_update();
501      }
502    else if (evas_object_data_get(o, "box"))
503      {
504         modify_mode = MODIFY_BOX;
505         modify_box_mode = MODIFY_BOX_NONE;
506         modify_box_rotate = EINA_FALSE;
507         int x1 = (int)(uintptr_t)evas_object_data_get(o, "x1");
508         int y1 = (int)(uintptr_t)evas_object_data_get(o, "y1");
509         int x2 = (int)(uintptr_t)evas_object_data_get(o, "x2");
510         int y2 = (int)(uintptr_t)evas_object_data_get(o, "y2");
511         double ang = (double)(uintptr_t)evas_object_data_get(o, "angle") / 1000000.0;
512         modify_box_x1 = x1; modify_box_y1 = y1;
513         modify_box_x2 = x2; modify_box_y2 = y2;
514         box_modify_begin(o, x1, y1, x2, y2, ang);
515         evas_object_raise(o);
516         evas_object_stack_below(evas_object_data_get(o, "shadow"), o);
517         edje_object_color_class_get(elm_layout_edje_get(o), "color",
518                                     &color[0].r, &color[0].g, &color[0].b, &color[0].a,
519                                     NULL, NULL, NULL, NULL,
520                                     NULL, NULL, NULL, NULL);
521         edje_object_color_class_get(elm_layout_edje_get(o), "color2",
522                                     &color[1].r, &color[1].g, &color[1].b, &color[1].a,
523                                     NULL, NULL, NULL, NULL,
524                                     NULL, NULL, NULL, NULL);
525         colorsel_set();
526         o_draw_handles[0] = draw_boxhandle_add(win2, "tool/box/handle");
527         elm_layout_signal_callback_add(o_draw_handles[0],
528                                        "action,move,begin", "e",
529                                        _cb_mod_move, NULL);
530         elm_layout_signal_callback_add(o_draw_handles[0],
531                                        "action,resize,tl,begin", "e",
532                                        _cb_mod_resize_tl, NULL);
533         elm_layout_signal_callback_add(o_draw_handles[0],
534                                        "action,resize,tr,begin", "e",
535                                        _cb_mod_resize_tr, NULL);
536         elm_layout_signal_callback_add(o_draw_handles[0],
537                                        "action,resize,bl,begin", "e",
538                                        _cb_mod_resize_bl, NULL);
539         elm_layout_signal_callback_add(o_draw_handles[0],
540                                        "action,resize,br,begin", "e",
541                                        _cb_mod_resize_br, NULL);
542         if (evas_object_data_get(o, "entry"))
543           elm_layout_signal_emit(o_draw_handles[0], "e,state,moveall,off", "e");
544         draw_handle_box_update();
545      }
546    draw_color_rects_update();
547 }
548 
549 static void
_cb_draw_none_mouse_down(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)550 _cb_draw_none_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
551 {
552    Evas_Event_Mouse_Down *ev = info;
553 
554    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
555    if (ev->button == 1)
556      {
557         Evas_Object *o = box_obj_get();
558 
559         if (o)
560           {
561              o = evas_object_data_get(o, "entry");
562              if (o) elm_object_focus_set(o, EINA_FALSE);
563           }
564         draw_modify_clear();
565      }
566 }
567 
568 static void
_cb_draw_mouse_down(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj,void * info)569 _cb_draw_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info)
570 {
571    Evas_Event_Mouse_Down *ev = info;
572 
573    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
574    if (ev->button == 1)
575      {
576         if (tool_mode == TOOL_MODIFY)
577           {
578              Evas_Object *o;
579 
580              draw_modify_clear();
581              draw_modify_begin(obj);
582              o = evas_object_data_get(obj, "entry");
583              if (o)
584                {
585                   elm_object_focus_move_policy_automatic_set(o_scroll, EINA_FALSE);
586                   elm_object_focus_move_policy_automatic_set(o, EINA_FALSE);
587                   elm_object_focus_allow_set(o_scroll, EINA_FALSE);
588                   elm_object_focus_set(o_rend, EINA_TRUE);
589                   elm_object_focus_set(o, EINA_TRUE);
590                }
591           }
592         else if (tool_mode == TOOL_DELETE)
593           {
594              Evas_Object *o;
595 
596              draw_objects = eina_list_remove(draw_objects, obj);
597              o = evas_object_data_get(obj, "shadow");
598              if (o) evas_object_del(o);
599              evas_object_del(obj);
600           }
601      }
602 }
603 
604 static void
draw_selectable_set(Eina_Bool sel)605 draw_selectable_set(Eina_Bool sel)
606 {
607    Eina_List *l;
608    Evas_Object *o;
609 
610    EINA_LIST_FOREACH(draw_objects, l, o)
611      {
612         evas_object_pass_events_set(o, !sel);
613      }
614 }
615 //
616 //////////////////////////////////////////////////////////////////////////////
617 
618 //////////////////////////////////////////////////////////////////////////////
619 //
620 //
621 //////////////////////////////////////////////////////////////////////////////
622 
623 //////////////////////////////////////////////////////////////////////////////
624 // line tool handling
625 static Eina_Bool    line_mouse_pressed = EINA_FALSE;
626 static const char  *line_style = NULL;
627 static Evas_Object *o_line = NULL;
628 static Evas_Object *o_line_shadow = NULL;
629 static int          line_x1 = 0;
630 static int          line_y1 = 0;
631 static int          line_x2 = 0;
632 static int          line_y2 = 0;
633 static int          line_point_inset = 0;
634 static int          line_shadow_point_inset = 0;
635 static int          line_shadow_off_x = 0;
636 static int          line_shadow_off_y = 0;
637 
638 static void
line_clear(void)639 line_clear(void)
640 {
641    o_line = NULL;
642 }
643 
644 static void
line_modify_coord_set(int x1,int y1,int x2,int y2)645 line_modify_coord_set(int x1, int y1, int x2, int y2)
646 {
647    line_x1 = x1; line_y1 = y1;
648    line_x2 = x2; line_y2 = y2;
649 }
650 
651 static void
line_modify_coord_get(int * x1,int * y1,int * x2,int * y2)652 line_modify_coord_get(int *x1, int *y1, int *x2, int *y2)
653 {
654    *x1 = line_x1; *y1 = line_y1;
655    *x2 = line_x2; *y2 = line_y2;
656 }
657 
658 static void
line_shadow_off_get(void)659 line_shadow_off_get(void)
660 {
661    const char *s;
662 
663    s = edje_object_data_get(o_line_shadow, "offset_x");
664    if (s) line_shadow_off_x = atoi(s);
665    else line_shadow_off_x = 0;
666    s = edje_object_data_get(o_line_shadow, "offset_y");
667    if (s) line_shadow_off_y = atoi(s);
668    else line_shadow_off_y = 0;
669    line_shadow_off_x = ELM_SCALE_SIZE(line_shadow_off_x);
670    line_shadow_off_y = ELM_SCALE_SIZE(line_shadow_off_y);
671 }
672 
673 static void
line_modify_begin(Evas_Object * o,int x1,int y1,int x2,int y2,int inset)674 line_modify_begin(Evas_Object *o, int x1, int y1, int x2, int y2, int inset)
675 {
676    o_line = o;
677    o_line_shadow = evas_object_data_get(o_line, "shadow");
678    line_modify_coord_set(x1, y1, x2, y2);
679    line_point_inset = inset;
680    line_shadow_point_inset =
681      (int)(uintptr_t)evas_object_data_get(o_line_shadow, "inset");
682    line_shadow_off_get();
683 }
684 
685 static void
line_map_apply(Evas_Object * o,int x1,int y1,int x2,int y2,int offx,int offy,int inset)686 line_map_apply(Evas_Object *o, int x1, int y1, int x2, int y2, int offx, int offy, int inset)
687 {
688    Evas_Map *m;
689    int dx = x2 - x1;
690    int dy = y2 - y1;
691    int x, y, w, h;
692    int len = sqrt((dx * dx) + (dy * dy));
693    double len2;
694    // angle from horiz axis + angle == y2 > y1
695    double angle = fmod(360.0 + to_deg(atan2(dy, dx)), 360.0);
696 
697    // 0                     1
698    //  +--------------------+
699    //  |\ x1 y1       x2,y2/|
700    //  | +----------------+ |
701    //  |/ <--- len ------> \<- len2
702    //  +--------------------+
703    // 3                     2
704    len2 = sqrt((inset * inset) + (inset * inset));
705    w = len + (inset * 2);
706    h = inset * 2;
707    evas_object_resize(o, w, h);
708    m = evas_map_new(4);
709    evas_map_alpha_set(m, EINA_TRUE);
710    evas_map_smooth_set(m, EINA_TRUE);
711    evas_map_util_points_color_set(m, 255, 255, 255, 255);
712    evas_map_util_points_populate_from_object(m ,o);
713    x = cos(to_rad(angle - 135.0)) * len2;
714    y = sin(to_rad(angle - 135.0)) * len2;
715    evas_map_point_coord_set(m, 0, x1 + x + offx, y1 + y + offy, 0);
716    x = cos(to_rad(angle - 45.0)) * len2;
717    y = sin(to_rad(angle - 45.0)) * len2;
718    evas_map_point_coord_set(m, 1, x2 + x + offx, y2 + y + offy, 0);
719    x = cos(to_rad(angle + 45.0)) * len2;
720    y = sin(to_rad(angle + 45.0)) * len2;
721    evas_map_point_coord_set(m, 2, x2 + x + offx, y2 + y + offy, 0);
722    x = cos(to_rad(angle + 135.0)) * len2;
723    y = sin(to_rad(angle + 135.0)) * len2;
724    evas_map_point_coord_set(m, 3, x1 + x + offx, y1 + y + offy, 0);
725    evas_object_map_set(o, m);
726    evas_map_free(m);
727    evas_object_map_enable_set(o, EINA_TRUE);
728    evas_object_show(o);
729 }
730 
731 static void
line_eval(void)732 line_eval(void)
733 {
734    line_map_apply(o_line, line_x1, line_y1, line_x2, line_y2,
735                   0, 0, line_point_inset);
736    evas_object_data_set(o_line, "x1", (void *)(uintptr_t)line_x1);
737    evas_object_data_set(o_line, "y1", (void *)(uintptr_t)line_y1);
738    evas_object_data_set(o_line, "x2", (void *)(uintptr_t)line_x2);
739    evas_object_data_set(o_line, "y2", (void *)(uintptr_t)line_y2);
740    line_map_apply(o_line_shadow, line_x1, line_y1, line_x2, line_y2,
741                   line_shadow_off_x, line_shadow_off_y,
742                   line_shadow_point_inset);
743 }
744 
745 static void
line_color_set(void)746 line_color_set(void)
747 {
748    if (!o_line) return;
749    edje_object_color_class_set
750      (elm_layout_edje_get(o_line),
751       "color", color[0].r, color[0].g, color[0].b, color[0].a,
752       0, 0, 0, 0, 0, 0, 0, 0);
753    edje_object_color_class_set
754      (elm_layout_edje_get(evas_object_data_get(o_line, "shadow")),
755       "color", color[0].r, color[0].g, color[0].b, color[0].a,
756       0, 0, 0, 0, 0, 0, 0, 0);
757    edje_object_color_class_set
758      (elm_layout_edje_get(o_line),
759       "color2", color[1].r, color[1].g, color[1].b, color[1].a,
760       0, 0, 0, 0, 0, 0, 0, 0);
761    edje_object_color_class_set
762      (elm_layout_edje_get(evas_object_data_get(o_line, "shadow")),
763       "color2", color[1].r, color[1].g, color[1].b, color[1].a,
764        0, 0, 0, 0, 0, 0, 0, 0);
765 }
766 
767 static Evas_Object *
line_obj_add(Evas_Object * parent,const char * style,const char * append,int * inset)768 line_obj_add(Evas_Object *parent, const char *style, const char *append, int *inset)
769 {
770    Evas_Object *o;
771    Evas_Coord minw, minh;
772    char path[PATH_MAX];
773    char buf[1024];
774 
775    o = elm_layout_add(parent);
776    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
777    snprintf(buf, sizeof(buf), "e/modules/shot/item/line/%s%s", style, append);
778    elm_layout_file_set(o, path, buf);
779    evas_object_pass_events_set(o, EINA_TRUE);
780    edje_object_size_min_calc(elm_layout_edje_get(o), &minw, &minh);
781    *inset = minh / 2;
782    evas_object_data_set(o, "line", o);
783    evas_object_data_set(o, "inset", (void *)(uintptr_t)(*inset));
784    return o;
785 }
786 
787 static void
line_down(int x,int y)788 line_down(int x, int y)
789 {
790    line_mouse_pressed = EINA_TRUE;
791    line_modify_coord_set(x, y, x, y);
792 
793    o_line = line_obj_add(win2, line_style, "", &line_point_inset);
794    draw_objects = eina_list_append(draw_objects, o_line);
795    evas_object_event_callback_add(o_line, EVAS_CALLBACK_MOUSE_DOWN,
796                                   _cb_draw_mouse_down, NULL);
797 
798    o_line_shadow = line_obj_add(win2, line_style, "/shadow",
799                                 &line_shadow_point_inset);
800    line_shadow_off_get();
801 
802    evas_object_stack_below(o_line_shadow, o_line);
803    evas_object_data_set(o_line, "shadow", o_line_shadow);
804 
805    line_color_set();
806    line_eval();
807 }
808 
809 static void
line_up(int x EINA_UNUSED,int y EINA_UNUSED)810 line_up(int x EINA_UNUSED, int y EINA_UNUSED)
811 {
812    line_mouse_pressed = EINA_FALSE;
813    o_line = NULL;
814 }
815 
816 static void
line_move(int x,int y)817 line_move(int x, int y)
818 {
819    line_x2 = x; line_y2 = y;
820    line_eval();
821 }
822 //
823 //////////////////////////////////////////////////////////////////////////////
824 
825 //////////////////////////////////////////////////////////////////////////////
826 // box tool handling
827 static Eina_Bool    box_mouse_pressed = EINA_FALSE;
828 static const char  *box_style = NULL;
829 static Evas_Object *o_box = NULL;
830 static Evas_Object *o_box_shadow = NULL;
831 static int          box_x1 = 0;
832 static int          box_y1 = 0;
833 static int          box_x2 = 0;
834 static int          box_y2 = 0;
835 static double       box_angle = 0.0;
836 static int          box_minw = 0;
837 static int          box_minh = 0;
838 static int          box_shadow_off_x = 0;
839 static int          box_shadow_off_y = 0;
840 static int          box_shadow_minw = 0;
841 static int          box_shadow_minh = 0;
842 
843 static void
box_clear(void)844 box_clear(void)
845 {
846    o_box = NULL;
847 }
848 
849 static void
box_modify_coord_set(int x1,int y1,int x2,int y2,double ang)850 box_modify_coord_set(int x1, int y1, int x2, int y2, double ang)
851 {
852    double a;
853    static const double stops[] = { 0, 45, 90, 135, 180, 225, 270, 315, 360 };
854    static const double hyst = 2.0;
855    int i;
856 
857    box_x1 = x1; box_y1 = y1;
858    box_x2 = x2; box_y2 = y2;
859    a = fmod(360.0 + ang, 360.0);
860    for (i = 0; i < (int)(sizeof(stops) / sizeof(stops[0])); i++)
861      {
862         if ((a >= (stops[i] - hyst)) && (a <= (stops[i] + hyst)))
863           {
864              a = stops[i];
865              break;
866           }
867      }
868    box_angle = a;
869 }
870 
871 static void
box_modify_coord_get(int * x1,int * y1,int * x2,int * y2,double * ang)872 box_modify_coord_get(int *x1, int *y1, int *x2, int *y2, double *ang)
873 {
874    *x1 = box_x1; *y1 = box_y1;
875    *x2 = box_x2; *y2 = box_y2;
876    *ang = box_angle;
877 }
878 
879 static Evas_Object *
box_obj_get(void)880 box_obj_get(void)
881 {
882    return o_box;
883 }
884 
885 static void
box_shadow_off_get(void)886 box_shadow_off_get(void)
887 {
888    const char *s;
889 
890    s = edje_object_data_get(o_box_shadow, "offset_x");
891    if (s) box_shadow_off_x = atoi(s);
892    else box_shadow_off_x = 0;
893    s = edje_object_data_get(o_box_shadow, "offset_y");
894    if (s) box_shadow_off_y = atoi(s);
895    else box_shadow_off_y = 0;
896    box_shadow_off_x = ELM_SCALE_SIZE(box_shadow_off_x);
897    box_shadow_off_y = ELM_SCALE_SIZE(box_shadow_off_y);
898    box_shadow_minw = (int)(uintptr_t)evas_object_data_get(o_box_shadow, "minw");
899    box_shadow_minh = (int)(uintptr_t)evas_object_data_get(o_box_shadow, "minh");
900 }
901 
902 static void
box_color_set(void)903 box_color_set(void)
904 {
905    Evas_Object *o;
906 
907    if (!o_box) return;
908    edje_object_color_class_set
909      (elm_layout_edje_get(o_box),
910       "color", color[0].r, color[0].g, color[0].b, color[0].a, 0, 0, 0, 0, 0, 0, 0, 0);
911    edje_object_color_class_set
912      (elm_layout_edje_get(evas_object_data_get(o_box, "shadow")),
913       "color", color[0].r, color[0].g, color[0].b, color[0].a, 0, 0, 0, 0, 0, 0, 0, 0);
914    edje_object_color_class_set
915      (elm_layout_edje_get(o_box),
916       "color2", color[1].r, color[1].g, color[1].b, color[1].a, 0, 0, 0, 0, 0, 0, 0, 0);
917    edje_object_color_class_set
918      (elm_layout_edje_get(evas_object_data_get(o_box, "shadow")),
919       "color2", color[1].r, color[1].g, color[1].b, color[1].a, 0, 0, 0, 0, 0, 0, 0, 0);
920    o = evas_object_data_get(o_box, "entry");
921    if (o)
922      {
923         const char *s;
924         char buf[256];
925 
926         s = edje_object_data_get(elm_layout_edje_get(o_box), "entry_style");
927         if (s)
928           {
929              int l = strlen(s);
930 
931              if (l > 0)
932                {
933                   char *tmp = malloc(l + 1 + 8 + 8);
934 
935                   if (tmp)
936                     {
937                        strcpy(tmp, s);
938                        if (tmp[l - 1] == '\'')
939                          {
940                             tmp[l - 1] = 0;
941                             snprintf(buf, sizeof(buf),
942                                      " color=#%02x%02x%02x%02x'",
943                                      color[1].r, color[1].g, color[1].b, color[1].a);
944                             strcpy(tmp + l - 1, buf);
945                             elm_entry_text_style_user_pop(o);
946                             elm_entry_text_style_user_push(o, tmp);
947                          }
948                        free(tmp);
949                     }
950                }
951           }
952      }
953 }
954 
955 static void
box_modify_begin(Evas_Object * o,int x1,int y1,int x2,int y2,double ang)956 box_modify_begin(Evas_Object *o, int x1, int y1, int x2, int y2, double ang)
957 {
958    o_box = o;
959    o_box_shadow = evas_object_data_get(o_box, "shadow");
960    box_modify_coord_set(x1, y1, x2, y2, ang);
961    box_minw = (int)(uintptr_t)evas_object_data_get(o_box, "minw");
962    box_minh = (int)(uintptr_t)evas_object_data_get(o_box, "minh");
963    box_angle = (double)(uintptr_t)evas_object_data_get(o_box, "angle") / 1000000.0;
964    box_shadow_off_get();
965 }
966 
967 static void
box_map_apply(Evas_Object * o,int x1,int y1,int x2,int y2,int minw,int minh,int offx,int offy,double ang)968 box_map_apply(Evas_Object *o, int x1, int y1, int x2, int y2, int minw, int minh, int offx, int offy, double ang)
969 {
970    Evas_Map *m;
971    int x, y, w, h, cx, cy;
972 
973    if (x2 >= x1)
974      {
975         x = x1;
976         w = x2 - x1;
977      }
978    else
979      {
980         x = x2;
981         w = x1 - x2;
982      }
983    if (y2 >= y1)
984      {
985         y = y1;
986         h = y2 - y1;
987      }
988    else
989      {
990         y = y2;
991         h = y1 - y2;
992      }
993    x -= minw / 2;
994    y -= minh / 2;
995    w += minw;
996    h += minh;
997    cx = (x1 + x2 + offx) / 2;
998    cy = (y1 + y2 + offy) / 2;
999    evas_object_geometry_set(o, x + offx, y + offy, w, h);
1000    m = evas_map_new(4);
1001    evas_map_alpha_set(m, EINA_TRUE);
1002    evas_map_smooth_set(m, EINA_TRUE);
1003    evas_map_util_points_color_set(m, 255, 255, 255, 255);
1004    evas_map_util_points_populate_from_object(m ,o);
1005    evas_map_util_rotate(m, ang, cx, cy);
1006    evas_object_map_set(o, m);
1007    evas_map_free(m);
1008    evas_object_map_enable_set(o, EINA_TRUE);
1009    evas_object_show(o);
1010 }
1011 
1012 static Evas_Object *
box_obj_add(Evas_Object * parent,const char * style,const char * append,int * minw,int * minh)1013 box_obj_add(Evas_Object *parent, const char *style, const char *append, int *minw, int *minh)
1014 {
1015    Evas_Object *o, *o2;
1016    char path[PATH_MAX];
1017    char buf[1024];
1018 
1019    o = elm_layout_add(parent);
1020    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
1021    snprintf(buf, sizeof(buf), "e/modules/shot/item/box/%s%s", style, append);
1022    elm_layout_file_set(o, path, buf);
1023    if (edje_object_part_exists(elm_layout_edje_get(o), "e.swallow.entry"))
1024      {
1025         const char *s;
1026 
1027         o2 = elm_entry_add(parent);
1028         s = edje_object_data_get(elm_layout_edje_get(o), "entry_style");
1029         if (s) elm_entry_text_style_user_push(o2, s);
1030         elm_object_text_set(o2, "Sample Text");
1031         elm_object_part_content_set(o, "e.swallow.entry", o2);
1032         evas_object_data_set(o, "entry", o2);
1033      }
1034    evas_object_pass_events_set(o, EINA_TRUE);
1035    evas_object_data_set(o, "box", o);
1036    edje_object_size_min_calc(elm_layout_edje_get(o), minw, minh);
1037    evas_object_data_set(o, "minw", (void *)(uintptr_t)*minw);
1038    evas_object_data_set(o, "minh", (void *)(uintptr_t)*minh);
1039    return o;
1040 }
1041 
1042 static void
box_eval(void)1043 box_eval(void)
1044 {
1045    box_map_apply(o_box, box_x1, box_y1, box_x2, box_y2,
1046                  box_minw, box_minh, 0, 0, box_angle);
1047    evas_object_data_set(o_box, "x1", (void *)(uintptr_t)box_x1);
1048    evas_object_data_set(o_box, "y1", (void *)(uintptr_t)box_y1);
1049    evas_object_data_set(o_box, "x2", (void *)(uintptr_t)box_x2);
1050    evas_object_data_set(o_box, "y2", (void *)(uintptr_t)box_y2);
1051    evas_object_data_set(o_box, "angle", (void *)(uintptr_t)(box_angle * 1000000.0));
1052    box_map_apply(o_box_shadow, box_x1, box_y1, box_x2, box_y2,
1053                  box_shadow_minw, box_shadow_minh,
1054                  box_shadow_off_x, box_shadow_off_y,
1055                  box_angle);
1056 }
1057 
1058 static void
box_down(int x,int y)1059 box_down(int x, int y)
1060 {
1061    box_mouse_pressed = EINA_TRUE;
1062    box_modify_coord_set(x, y, x, y, 0.0);
1063    o_box = box_obj_add(win2, box_style, "", &box_minw, &box_minh);
1064    draw_objects = eina_list_append(draw_objects, o_box);
1065    evas_object_event_callback_add(o_box, EVAS_CALLBACK_MOUSE_DOWN,
1066                                   _cb_draw_mouse_down, NULL);
1067    o_box_shadow = box_obj_add(win2, box_style, "/shadow",
1068                               &box_shadow_minw, &box_shadow_minh);
1069    box_shadow_off_get();
1070    evas_object_stack_below(o_box_shadow, o_box);
1071    evas_object_data_set(o_box, "shadow", o_box_shadow);
1072    box_color_set();
1073    box_eval();
1074 }
1075 
1076 static void
box_up(int x EINA_UNUSED,int y EINA_UNUSED)1077 box_up(int x EINA_UNUSED, int y EINA_UNUSED)
1078 {
1079    box_mouse_pressed = EINA_FALSE;
1080    o_box = NULL;
1081 }
1082 
1083 static void
box_move(int x,int y)1084 box_move(int x, int y)
1085 {
1086    box_x2 = x; box_y2 = y;
1087    box_eval();
1088 }
1089 //
1090 //////////////////////////////////////////////////////////////////////////////
1091 
1092 //////////////////////////////////////////////////////////////////////////////
1093 // crop handling
1094 typedef enum
1095 {
1096    CROP_NONE,
1097    CROP_SCREEN,
1098    CROP_WINDOW_PAD,
1099    CROP_WINDOW,
1100    CROP_AREA
1101 } Crop_Mode;
1102 
1103 typedef enum
1104 {
1105    CROP_ADJUST_NONE,
1106    CROP_ADJUST_TL,
1107    CROP_ADJUST_TR,
1108    CROP_ADJUST_BL,
1109    CROP_ADJUST_BR
1110 } Crop_Adjust;
1111 
1112 typedef struct
1113 {
1114    int x, y, w, h;
1115 } Crop_Area;
1116 
1117 static Crop_Mode    crop_mode = CROP_NONE;
1118 static Crop_Adjust  crop_adjust = CROP_ADJUST_NONE;
1119 static Crop_Area   *crop_screen_areas = NULL;
1120 static Crop_Area   *crop_window_areas = NULL;
1121 static Crop_Area    crop_area = { 0, 0, 0, 0 };
1122 static int          crop_down_x = 0;
1123 static int          crop_down_y = 0;
1124 static int          crop_adjust_x = 0;
1125 static int          crop_adjust_y = 0;
1126 static Eina_Bool    crop_area_changed = EINA_FALSE;
1127 static Eina_Bool    crop_mouse_pressed = EINA_FALSE;
1128 static Evas_Object *o_crop = NULL;
1129 
1130 static void crop_down(int x, int y);
1131 
1132 static void
crop_resize_begin(void)1133 crop_resize_begin(void)
1134 {
1135    Evas_Coord x, y;
1136 
1137    evas_pointer_canvas_xy_get(evas_object_evas_get(o_crop), &x, &y);
1138    elm_object_scroll_hold_push(o_scroll);
1139    crop_down(x, y);
1140 }
1141 
1142 static void
_cb_crop_resize_tl(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)1143 _cb_crop_resize_tl(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
1144 {
1145    Evas_Coord x, y;
1146 
1147    if (tool_mode != TOOL_CROP) return;
1148    crop_adjust = CROP_ADJUST_TL;
1149    evas_pointer_canvas_xy_get(evas_object_evas_get(o_crop), &x, &y);
1150    crop_adjust_x = crop_area.x - x;
1151    crop_adjust_y = crop_area.y - y;
1152    crop_resize_begin();
1153 }
1154 
1155 static void
_cb_crop_resize_tr(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)1156 _cb_crop_resize_tr(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
1157 {
1158    Evas_Coord x, y;
1159 
1160    if (tool_mode != TOOL_CROP) return;
1161    crop_adjust = CROP_ADJUST_TR;
1162    evas_pointer_canvas_xy_get(evas_object_evas_get(o_crop), &x, &y);
1163    crop_adjust_x = crop_area.x + crop_area.w - 1 - x;
1164    crop_adjust_y = crop_area.y - y;
1165    crop_resize_begin();
1166 }
1167 
1168 static void
_cb_crop_resize_bl(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)1169 _cb_crop_resize_bl(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
1170 {
1171    Evas_Coord x, y;
1172 
1173    if (tool_mode != TOOL_CROP) return;
1174    crop_adjust = CROP_ADJUST_BL;
1175    evas_pointer_canvas_xy_get(evas_object_evas_get(o_crop), &x, &y);
1176    crop_adjust_x = crop_area.x - x;
1177    crop_adjust_y = crop_area.y + crop_area.h - 1 - y;
1178    crop_resize_begin();
1179 }
1180 
1181 static void
_cb_crop_resize_br(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)1182 _cb_crop_resize_br(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
1183 {
1184    Evas_Coord x, y;
1185 
1186    if (tool_mode != TOOL_CROP) return;
1187    crop_adjust = CROP_ADJUST_BR;
1188    evas_pointer_canvas_xy_get(evas_object_evas_get(o_crop), &x, &y);
1189    crop_adjust_x = crop_area.x + crop_area.w - 1 - x;
1190    crop_adjust_y = crop_area.y + crop_area.h - 1 - y;
1191    crop_resize_begin();
1192 }
1193 
1194 static void
crop_create(void)1195 crop_create(void)
1196 {
1197    if (!o_crop)
1198      {
1199         Evas_Object *o;
1200         char path[PATH_MAX];
1201 
1202         o_crop = o = elm_layout_add(win2);
1203         snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
1204         elm_layout_file_set(o, path, "e/modules/shot/tool/crop");
1205         evas_object_repeat_events_set(o, EINA_TRUE);
1206         elm_layout_signal_callback_add(o, "action,resize,tl,begin", "e",
1207                                        _cb_crop_resize_tl, NULL);
1208         elm_layout_signal_callback_add(o, "action,resize,tr,begin", "e",
1209                                        _cb_crop_resize_tr, NULL);
1210         elm_layout_signal_callback_add(o, "action,resize,bl,begin", "e",
1211                                        _cb_crop_resize_bl, NULL);
1212         elm_layout_signal_callback_add(o, "action,resize,br,begin", "e",
1213                                        _cb_crop_resize_br, NULL);
1214         evas_object_layer_set(o, 100);
1215         evas_object_resize(o, img_w, img_h);
1216         evas_object_show(o);
1217      }
1218 }
1219 
1220 static void
crop_position(void)1221 crop_position(void)
1222 {
1223    if (o_crop)
1224      {
1225         Evas_Object *o = elm_layout_edje_get(o_crop);
1226         edje_object_part_drag_value_set
1227           (o, "e/drag/rel1",
1228            crop_area.x,
1229            crop_area.y);
1230         edje_object_part_drag_value_set
1231           (o, "e/drag/rel2",
1232            crop_area.x + crop_area.w,
1233            crop_area.y + crop_area.h);
1234      }
1235 }
1236 
1237 static void
crop_export(void)1238 crop_export(void)
1239 {
1240    crop.x = crop_area.x;
1241    crop.y = crop_area.y;
1242    crop.w = crop_area.w;
1243    crop.h = crop_area.h;
1244 }
1245 
1246 static void
crop_clear(void)1247 crop_clear(void)
1248 {
1249    crop_area.x = crop_area.y = crop_area.w = crop_area.h = 0;
1250    crop_export();
1251    if (o_crop)
1252      {
1253         evas_object_del(o_crop);
1254         o_crop = NULL;
1255      }
1256 }
1257 
1258 static void
crop_update(void)1259 crop_update(void)
1260 {
1261    if ((crop_area.w > 5) || (crop_area.h > 5)) crop_create();
1262    if (o_crop)
1263      {
1264         crop_mode = CROP_AREA;
1265         crop_position();
1266      }
1267 }
1268 
1269 static void
crop_eval(int x1,int y1,int x2,int y2)1270 crop_eval(int x1, int y1, int x2, int y2)
1271 {
1272    if (x1 < x2)
1273      {
1274         crop_area.x = x1;
1275         crop_area.w = x2 - x1 + 1;
1276      }
1277    else
1278      {
1279         crop_area.x = x2;
1280         crop_area.w = x1 - x2 + 1;
1281      }
1282    if (y1 < y2)
1283      {
1284         crop_area.y = y1;
1285         crop_area.h = y2 - y1 + 1;
1286      }
1287    else
1288      {
1289         crop_area.y = y2;
1290         crop_area.h = y1 - y2 + 1;
1291      }
1292    E_RECTS_CLIP_TO_RECT(crop_area.x, crop_area.y,
1293                         crop_area.w, crop_area.h,
1294                         0, 0, img_w, img_h);
1295    if (crop_area.w < 1) crop_area.w = 1;
1296    if (crop_area.h < 1) crop_area.h = 1;
1297    if (crop_area.x >= img_w) crop_area.x = img_w - 1;
1298    if (crop_area.y >= img_h) crop_area.y = img_h - 1;
1299    crop_export();
1300    crop_update();
1301 }
1302 
1303 static void
crop_down(int x,int y)1304 crop_down(int x, int y)
1305 {
1306    crop_down_x = x;
1307    crop_down_y = y;
1308    crop_area_changed = EINA_FALSE;
1309    crop_mouse_pressed = EINA_TRUE;
1310    if (crop_mode == CROP_NONE)
1311      {
1312         crop_clear();
1313         if (crop_adjust == CROP_ADJUST_NONE)
1314           crop_eval(crop_down_x, crop_down_y, x, y);
1315      }
1316 }
1317 
1318 static Eina_Bool
point_in_area(int x,int y,Crop_Area area)1319 point_in_area(int x, int y, Crop_Area area)
1320 {
1321    if ((x >= area.x) && (y >= area.y) &&
1322        (x < (area.x + area.w)) && (y < (area.y + area.h)))
1323      return EINA_TRUE;
1324    return EINA_FALSE;
1325 }
1326 
1327 static void
crop_up(int x,int y)1328 crop_up(int x, int y)
1329 {
1330    Eina_Bool found = EINA_FALSE;
1331    int i;
1332 
1333    if (!crop_mouse_pressed) return;
1334    crop_mouse_pressed = EINA_FALSE;
1335    if (crop_mode == CROP_NONE)
1336      { // pick a screen to crop
1337         if (crop_screen_areas)
1338           {
1339              for (i = 0; crop_screen_areas[i].w; i++);
1340              // only have one screen - no point trying to crop the screen
1341              if (i < 2) goto try_win;
1342              for (i = 0; crop_screen_areas[i].w; i++)
1343                {
1344                   if (point_in_area(x, y, crop_screen_areas[i]))
1345                     {
1346                        crop_area = crop_screen_areas[i];
1347                        crop_create();
1348                        crop_export();
1349                        crop_position();
1350                        found = EINA_TRUE;
1351                        crop_mode = CROP_SCREEN;
1352                        break;
1353                     }
1354                }
1355           }
1356         else goto try_win;
1357      }
1358    else if (crop_mode == CROP_SCREEN)
1359      { // pick a window plus padding
1360 try_win:
1361         if (crop_window_areas)
1362           {
1363              for (i = 0; crop_window_areas[i].w; i++)
1364                {
1365                   if (point_in_area(x, y, crop_window_areas[i]))
1366                     {
1367                        crop_area = crop_window_areas[i];
1368                        crop_area.x -= ELM_SCALE_SIZE(window_pad);
1369                        crop_area.y -= ELM_SCALE_SIZE(window_pad);
1370                        crop_area.w += ELM_SCALE_SIZE(window_pad) * 2;
1371                        crop_area.h += ELM_SCALE_SIZE(window_pad) * 2;
1372                        E_RECTS_CLIP_TO_RECT(crop_area.x, crop_area.y,
1373                                             crop_area.w, crop_area.h,
1374                                             0, 0, img_w, img_h);
1375                        crop_create();
1376                        crop_export();
1377                        crop_position();
1378                        found = EINA_TRUE;
1379                        crop_mode = CROP_WINDOW_PAD;
1380                        break;
1381                     }
1382                }
1383           }
1384         if (!found) crop_mode = CROP_NONE;
1385      }
1386    else if (crop_mode == CROP_WINDOW_PAD)
1387      { // pick a window
1388         if (crop_window_areas)
1389           {
1390              for (i = 0; crop_window_areas[i].w; i++)
1391                {
1392                   if (point_in_area(x, y, crop_window_areas[i]))
1393                     {
1394                        crop_area = crop_window_areas[i];
1395                        E_RECTS_CLIP_TO_RECT(crop_area.x, crop_area.y,
1396                                             crop_area.w, crop_area.h,
1397                                             0, 0, img_w, img_h);
1398                        crop_create();
1399                        crop_export();
1400                        crop_position();
1401                        found = EINA_TRUE;
1402                        crop_mode = CROP_WINDOW;
1403                        break;
1404                     }
1405                }
1406           }
1407         if (!found) crop_mode = CROP_NONE;
1408      }
1409    else if (crop_mode == CROP_WINDOW)
1410      { // got back to none
1411         crop_mode = CROP_NONE;
1412      }
1413    else if (crop_mode == CROP_AREA)
1414      {
1415         if (crop_area_changed) found = EINA_TRUE;
1416         else crop_mode = CROP_NONE;
1417      }
1418    if (!found)
1419      {
1420         crop_clear();
1421      }
1422 }
1423 
1424 static void
crop_move(int x,int y)1425 crop_move(int x, int y)
1426 {
1427    if (!crop_mouse_pressed) return;
1428    if (crop_adjust == CROP_ADJUST_NONE)
1429      {
1430         crop_eval(crop_down_x, crop_down_y, x, y);
1431         if ((crop_area.w > 5) || (crop_area.h > 5))
1432           crop_area_changed = EINA_TRUE;
1433      }
1434    else
1435      {
1436         x += crop_adjust_x;
1437         y += crop_adjust_y;
1438         if (crop_adjust == CROP_ADJUST_TL)
1439           crop_eval(x, y, crop_area.x + crop_area.w - 1, crop_area.y + crop_area.h - 1);
1440         else if (crop_adjust == CROP_ADJUST_TR)
1441           crop_eval(crop_area.x, y, x, crop_area.y + crop_area.h - 1);
1442         else if (crop_adjust == CROP_ADJUST_BL)
1443           crop_eval(x, crop_area.y, crop_area.x + crop_area.w - 1, y);
1444         else if (crop_adjust == CROP_ADJUST_BR)
1445           crop_eval(crop_area.x, crop_area.y, x, y);
1446         crop_area_changed = EINA_TRUE;
1447      }
1448 }
1449 //
1450 //////////////////////////////////////////////////////////////////////////////
1451 
1452 //////////////////////////////////////////////////////////////////////////////
1453 // zoom handling
1454 #define ZOOM_COUNT 16
1455 #define ZOOM_NONE 8
1456 #define ZOOM_DEFAULT 4
1457 static int zoom = ZOOM_DEFAULT;
1458 static int zooms[] = { 125, 143, 167, 200, 250, 333, 500, 750,
1459                        1000,
1460                        2000, 3000, 4000, 5000, 6000, 7000, 8000 };
1461 
1462 static void
zoom_set(int slot)1463 zoom_set(int slot)
1464 {
1465    zoom = slot;
1466    if (zoom < 0) zoom = 0;
1467    else if (zoom >= ZOOM_COUNT) zoom = ZOOM_COUNT - 1;
1468    edit_w = (img_w * zooms[zoom]) / 1000;
1469    edit_h = (img_h * zooms[zoom]) / 1000;
1470    if (zooms[zoom] >= 1000) evas_object_image_smooth_scale_set(o_rend, EINA_FALSE);
1471    else evas_object_image_smooth_scale_set(o_rend, EINA_TRUE);
1472    evas_object_size_hint_min_set(o_rend, edit_w, edit_h);
1473    evas_object_resize(o_rend, edit_w, edit_h);
1474 }
1475 
1476 static void
_cb_tool_zoom_plus(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info EINA_UNUSED)1477 _cb_tool_zoom_plus(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info EINA_UNUSED)
1478 {
1479    elm_scroller_gravity_set(o_scroll, 0.5, 0.5);
1480    zoom_set(zoom + 1);
1481 }
1482 
1483 static void
_cb_tool_zoom_reset(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info EINA_UNUSED)1484 _cb_tool_zoom_reset(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info EINA_UNUSED)
1485 {
1486    elm_scroller_gravity_set(o_scroll, 0.5, 0.5);
1487    zoom_set(ZOOM_NONE);
1488 }
1489 
1490 static void
_cb_tool_zoom_minus(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info EINA_UNUSED)1491 _cb_tool_zoom_minus(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info EINA_UNUSED)
1492 {
1493    elm_scroller_gravity_set(o_scroll, 0.5, 0.5);
1494    zoom_set(zoom - 1);
1495 }
1496 
1497 static void
_cb_edit_wheel(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)1498 _cb_edit_wheel(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
1499 {
1500    Evas_Event_Mouse_Wheel *ev = info;
1501 
1502    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1503    if ((evas_key_modifier_is_set(ev->modifiers, "Control")) &&
1504        (ev->direction == 0))
1505      {
1506         Evas_Coord x, y, w, h, px, py;
1507         double gx, gy;
1508 
1509         evas_pointer_canvas_xy_get(evas_object_evas_get(win), &px, &py);
1510         evas_object_geometry_get(o_rend, &x, &y, &w, &h);
1511         if (px < x) px = x;
1512         if (py < y) py = y;
1513         if (px >= (x + w)) px = x + w - 1;
1514         if (py >= (y + h)) py = y + h - 1;
1515         if ((w > 0) && (h > 0))
1516           {
1517              gx = (double)(px - x) / (double)w;
1518              gy = (double)(py - y) / (double)h;
1519              elm_scroller_gravity_set(o_scroll, gx, gy);
1520           }
1521         zoom_set(zoom - ev->z);
1522         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1523      }
1524 }
1525 
1526 static void
_cb_edit_mouse_down(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)1527 _cb_edit_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
1528 {
1529    Evas_Event_Mouse_Down *ev = info;
1530 
1531    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1532    if (ev->button == 1)
1533      {
1534         if (tool_mode == TOOL_CROP)
1535           {
1536              crop_adjust = CROP_ADJUST_NONE;
1537              elm_object_scroll_hold_push(o_scroll);
1538              crop_down(ev->canvas.x, ev->canvas.y);
1539              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1540           }
1541         else if (tool_mode == TOOL_BOX)
1542           {
1543              elm_object_scroll_hold_push(o_scroll);
1544              box_down(ev->canvas.x, ev->canvas.y);
1545              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1546           }
1547         else if (tool_mode == TOOL_LINE)
1548           {
1549              elm_object_scroll_hold_push(o_scroll);
1550              line_down(ev->canvas.x, ev->canvas.y);
1551              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1552           }
1553      }
1554 }
1555 
1556 static void
_cb_edit_mouse_up(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)1557 _cb_edit_mouse_up(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
1558 {
1559    Evas_Event_Mouse_Up *ev = info;
1560 
1561    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1562    if (ev->button == 1)
1563      {
1564         if (tool_mode == TOOL_CROP)
1565           {
1566              elm_object_scroll_hold_pop(o_scroll);
1567              crop_up(ev->canvas.x, ev->canvas.y);
1568              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1569           }
1570         else if (tool_mode == TOOL_BOX)
1571           {
1572              elm_object_scroll_hold_pop(o_scroll);
1573              box_up(ev->canvas.x, ev->canvas.y);
1574              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1575           }
1576         else if (tool_mode == TOOL_LINE)
1577           {
1578              elm_object_scroll_hold_pop(o_scroll);
1579              line_up(ev->canvas.x, ev->canvas.y);
1580              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1581           }
1582      }
1583 }
1584 
1585 static void
_cb_edit_mouse_move(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info)1586 _cb_edit_mouse_move(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info)
1587 {
1588    Evas_Event_Mouse_Move *ev = info;
1589 
1590    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1591    if (tool_mode == TOOL_CROP)
1592      {
1593         if (crop_mouse_pressed)
1594           {
1595              crop_move(ev->cur.canvas.x, ev->cur.canvas.y);
1596              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1597           }
1598      }
1599    else if (tool_mode == TOOL_BOX)
1600      {
1601         if (box_mouse_pressed)
1602           {
1603              box_move(ev->cur.canvas.x, ev->cur.canvas.y);
1604              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1605           }
1606      }
1607    else if (tool_mode == TOOL_LINE)
1608      {
1609         if (line_mouse_pressed)
1610           {
1611              line_move(ev->cur.canvas.x, ev->cur.canvas.y);
1612              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1613           }
1614      }
1615 }
1616 //
1617 //////////////////////////////////////////////////////////////////////////////
1618 
1619 //////////////////////////////////////////////////////////////////////////////
1620 // tool type
1621 typedef struct
1622 {
1623    Tool_Mode mode;
1624    const char *style;
1625 } Tool_Info;
1626 
1627 static int       _tool_info_count = 0;
1628 static Tool_Info tool_info[100] =  { { 0 } };
1629 
1630 static void
_cb_tool_changed(void * data EINA_UNUSED,Evas_Object * obj,void * info EINA_UNUSED)1631 _cb_tool_changed(void *data EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
1632 {
1633    int val = elm_radio_value_get(obj);
1634 
1635    o_box = o_line = NULL;
1636    if (tool_info[val].mode != TOOL_CROP)
1637      draw_modify_clear();
1638    if ((tool_info[val].mode == TOOL_MODIFY) ||
1639        (tool_info[val].mode == TOOL_DELETE))
1640      draw_selectable_set(EINA_TRUE);
1641    else
1642      draw_selectable_set(EINA_FALSE);
1643    tool_mode = tool_info[val].mode;
1644    line_style = box_style = tool_info[val].style;
1645 }
1646 
1647 static void
_cb_color_change(void * data EINA_UNUSED,Evas_Object * obj,void * info EINA_UNUSED)1648 _cb_color_change(void *data EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
1649 {
1650    Evas_Object *o;
1651 
1652    if (color_sel == 0) o = o_col1;
1653    else o = o_col2;
1654    elm_colorselector_color_get(obj,
1655                                &color[color_sel].r, &color[color_sel].g,
1656                                &color[color_sel].b, &color[color_sel].a);
1657    evas_object_color_set(o,
1658                          premul(color[color_sel].r, color[color_sel].a),
1659                          premul(color[color_sel].g, color[color_sel].a),
1660                          premul(color[color_sel].b, color[color_sel].a),
1661                          color[color_sel].a);
1662    line_color_set();
1663    box_color_set();
1664 }
1665 //
1666 //////////////////////////////////////////////////////////////////////////////
1667 
1668 //////////////////////////////////////////////////////////////////////////////
1669 // xxx
1670 //
1671 //////////////////////////////////////////////////////////////////////////////
1672 
1673 //////////////////////////////////////////////////////////////////////////////
1674 // colorsel stuff
1675 static Evas_Object *o_colorsel = NULL;
1676 static void
colorsel_set(void)1677 colorsel_set(void)
1678 {
1679    elm_colorselector_color_set(o_colorsel,
1680                                color[color_sel].r, color[color_sel].g,
1681                                color[color_sel].b, color[color_sel].a);
1682 }
1683 //
1684 //////////////////////////////////////////////////////////////////////////////
1685 
1686 //////////////////////////////////////////////////////////////////////////////
1687 // ui setup
1688 static void
_cb_win_del(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * info EINA_UNUSED)1689 _cb_win_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *info EINA_UNUSED)
1690 {
1691    line_mouse_pressed = EINA_FALSE;
1692    box_mouse_pressed = EINA_FALSE;
1693    draw_objects = eina_list_free(draw_objects);
1694    o_draw_handles[0] = NULL;
1695    o_draw_handles[1] = NULL;
1696    o_box = NULL;
1697    o_line = NULL;
1698    color_sel = 0;
1699    crop_mode = CROP_NONE;
1700    crop_adjust = CROP_ADJUST_NONE;
1701    free(crop_screen_areas);
1702    crop_screen_areas = NULL;
1703    free(crop_window_areas);
1704    crop_window_areas = NULL;
1705    crop_area.x = crop_area.y = crop_area.w = crop_area.h = 0;
1706    crop_area_changed = EINA_FALSE;
1707    crop_mouse_pressed = EINA_FALSE;
1708    zoom = ZOOM_DEFAULT;
1709    modify_down = EINA_FALSE;
1710    win = NULL;
1711 }
1712 
1713 static void
_focfix(void * data)1714 _focfix(void *data)
1715 {
1716    Evas_Object *obj = data;
1717 
1718    elm_object_focus_set(o_rend, EINA_TRUE);
1719    elm_object_focus_set(obj, EINA_TRUE);
1720    evas_object_unref(obj);
1721 }
1722 
1723 static void
_cb_col_changed(void * data EINA_UNUSED,Evas_Object * obj,void * info EINA_UNUSED)1724 _cb_col_changed(void *data EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
1725 {
1726    color_sel = elm_radio_value_get(obj);
1727    elm_colorselector_color_set(o_colorsel,
1728                                color[color_sel].r, color[color_sel].g,
1729                                color[color_sel].b, color[color_sel].a);
1730 }
1731 
1732 static void
_cb_win_focus(void * data EINA_UNUSED,Evas_Object * obj,void * info EINA_UNUSED)1733 _cb_win_focus(void *data EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
1734 {
1735    if ((tool_mode == TOOL_MODIFY) &&
1736        (o_box) && (evas_object_data_get(o_box, "entry")))
1737      {
1738         // XXXX: this is a hack - hook to window focus....
1739         evas_object_ref(obj);
1740         ecore_job_add(_focfix, obj);
1741      }
1742 }
1743 
1744 static Evas_Object *
ui_tool_add(Evas_Object * parent,Evas_Object * tb,Evas_Object * radg,int x,int y,const char * icon,const char * tooltip,int size,const char * style,Tool_Mode mode)1745 ui_tool_add(Evas_Object *parent, Evas_Object *tb, Evas_Object *radg, int x, int y, const char *icon, const char *tooltip, int size, const char *style, Tool_Mode mode)
1746 {
1747    Evas_Object *o, *rad;
1748    int val = _tool_info_count;
1749    char path[PATH_MAX];
1750    char buf[256];
1751 
1752    tool_info[val].mode = mode;
1753    tool_info[val].style = style;
1754    _tool_info_count++;
1755 
1756    o = evas_object_rectangle_add(evas_object_evas_get(parent));
1757    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1758    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1759    evas_object_color_set(o, 0, 0, 0, 0);
1760    evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(size), ELM_SCALE_SIZE(size));
1761    elm_table_pack(tb, o, x, y, 1, 1);
1762 
1763    rad = o = elm_radio_add(parent);
1764    elm_object_tooltip_text_set(o, tooltip);
1765    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1766    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1767    elm_radio_state_value_set(o, val);
1768    elm_object_style_set(o, "icon");
1769    if (radg) elm_radio_group_add(o, radg);
1770    evas_object_smart_callback_add(o, "changed", _cb_tool_changed, NULL);
1771    elm_table_pack(tb, o, x, y, 1, 1);
1772    evas_object_show(o);
1773 
1774    o = elm_icon_add(parent);
1775    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
1776    snprintf(buf, sizeof(buf), "e/modules/shot/tool/icon/%s", icon);
1777    elm_layout_file_set(o, path, buf);
1778    elm_object_content_set(rad, o);
1779    evas_object_show(o);
1780    return rad;
1781 }
1782 
1783 static Evas_Object *
ui_icon_button_add(Evas_Object * parent,const char * icon)1784 ui_icon_button_add(Evas_Object *parent, const char *icon)
1785 {
1786    Evas_Object *o, *ic;
1787    char path[PATH_MAX];
1788    char buf[256];
1789 
1790    ic = o = elm_icon_add(parent);
1791    snprintf(path, sizeof(path), "%s/shotedit.edj", e_module_dir_get(shot_module));
1792    snprintf(buf, sizeof(buf), "e/modules/shot/icon/%s", icon);
1793    elm_layout_file_set(o, path, buf);
1794 
1795    o = elm_button_add(parent);
1796    elm_object_content_set(o, ic);
1797    evas_object_show(ic);
1798    evas_object_show(o);
1799    return o;
1800 }
1801 
1802 Evas_Object *
ui_edit(Evas_Object * window,Evas_Object * o_bg,E_Zone * zone,E_Client * ec,void * dst,int sx,int sy,int sw,int sh,Evas_Object ** o_img_ret)1803 ui_edit(Evas_Object *window, Evas_Object *o_bg, E_Zone *zone,
1804         E_Client *ec, void *dst, int sx, int sy, int sw, int sh,
1805         Evas_Object **o_img_ret)
1806 {
1807    Evas *evas, *evas2;
1808    Evas_Object *o, *tb, *tb2, *sc, *fr, *bx, *radg, *rad, *bx_ret;
1809    int w, h;
1810 
1811    o = win = window;
1812    evas_object_smart_callback_add(o, "focused", _cb_win_focus, NULL);
1813 
1814    evas = evas_object_evas_get(win);
1815    evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cb_win_del, NULL);
1816 
1817    if ((!zone) && (ec)) zone = ec->zone;
1818    if (zone)
1819      {
1820         int i;
1821 
1822         for (i = ZOOM_NONE; i >= 0; i--)
1823           {
1824              w = (sw * zooms[i]) / 1000;
1825              if (w <= (zone->w / 2))
1826                {
1827                   zoom = i;
1828                   break;
1829                }
1830           }
1831      }
1832    w = (sw * zooms[zoom]) / 1000;
1833    if (w < ELM_SCALE_SIZE(400)) w = 400;
1834    h = (w * sh) / sw;
1835    if ((zone) && (h > (zone->h / 2))) h = zone->h / 2;
1836 
1837    if (!ec)
1838      {
1839         const Eina_List *l;
1840         E_Zone *z;
1841         int i, count;
1842 
1843         count = eina_list_count(e_comp->zones);
1844         if (count > 0)
1845           {
1846              crop_screen_areas = calloc(count + 1, sizeof(Crop_Area));
1847              if (crop_screen_areas)
1848                {
1849                   i = 0;
1850                   EINA_LIST_FOREACH(e_comp->zones, l, z)
1851                     {
1852                        crop_screen_areas[i].x = z->x;
1853                        crop_screen_areas[i].y = z->y;
1854                        crop_screen_areas[i].w = z->w;
1855                        crop_screen_areas[i].h = z->h;
1856                        i++;
1857                     }
1858                }
1859           }
1860         count = eina_list_count(e_comp->clients);
1861         if (count > 0)
1862           {
1863              crop_window_areas = calloc(count + 1, sizeof(Crop_Area));
1864              if (crop_window_areas)
1865                {
1866                   i = 0;
1867                   // top to bottom...
1868                   E_CLIENT_REVERSE_FOREACH(ec)
1869                     {
1870                        if ((ec->iconic) || (ec->hidden)) continue;
1871                        crop_window_areas[i].x = ec->x;
1872                        crop_window_areas[i].y = ec->y;
1873                        crop_window_areas[i].w = ec->w;
1874                        crop_window_areas[i].h = ec->h;
1875                        i++;
1876                     }
1877                }
1878           }
1879      }
1880    else
1881      {
1882         crop_window_areas = calloc(2, sizeof(Crop_Area));
1883         crop_window_areas[0].x = ec->x - sx;
1884         crop_window_areas[0].y = ec->y - sy;
1885         crop_window_areas[0].w = ec->w;
1886         crop_window_areas[0].h = ec->h;
1887      }
1888 
1889    o_crop = NULL;
1890    crop_mouse_pressed = EINA_FALSE;
1891    crop_area.x = 0;
1892    crop_area.y = 0;
1893    crop_area.w = 0;
1894    crop_area.h = 0;
1895 
1896    tb = o = elm_table_add(win);
1897    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1898    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1899    elm_object_part_content_set(o_bg, "e.swallow.content", o);
1900    evas_object_show(o);
1901 
1902    o = evas_object_rectangle_add(evas);
1903    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1904    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1905    evas_object_size_hint_min_set(o, w, h);
1906    evas_object_pass_events_set(o, EINA_TRUE);
1907    elm_table_pack(tb, o, 0, 0, 10, 10);
1908 
1909    sc = o = elm_scroller_add(win);
1910    elm_scroller_gravity_set(o, 0.5, 0.5);
1911    elm_object_focus_next_object_set(o, o, ELM_FOCUS_PREVIOUS);
1912    elm_object_focus_next_object_set(o, o, ELM_FOCUS_NEXT);
1913    elm_object_focus_next_object_set(o, o, ELM_FOCUS_UP);
1914    elm_object_focus_next_object_set(o, o, ELM_FOCUS_DOWN);
1915    elm_object_focus_next_object_set(o, o, ELM_FOCUS_RIGHT);
1916    elm_object_focus_next_object_set(o, o, ELM_FOCUS_LEFT);
1917    o_scroll = sc;
1918    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1919    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1920    elm_table_pack(tb, o, 0, 0, 10, 10);
1921    evas_object_show(o);
1922 
1923    bx_ret = bx = o = elm_box_add(win);
1924    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
1925    evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
1926    elm_table_pack(tb, o, 10, 0, 1, 10);
1927    evas_object_show(o);
1928 
1929    fr = o = elm_frame_add(win);
1930    elm_frame_autocollapse_set(o, EINA_TRUE);
1931    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1932    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
1933    elm_object_text_set(o, _("Tools"));
1934    elm_box_pack_end(bx, o);
1935    evas_object_show(o);
1936 
1937    tb2 = o = elm_table_add(win);
1938    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1939    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
1940    elm_object_content_set(fr, o);
1941    evas_object_show(o);
1942 
1943    _tool_info_count = 0;
1944    radg
1945      = ui_tool_add(win, tb2, NULL, 0, 0, "crop",               _("Select crop area"),      40, NULL,             TOOL_CROP);
1946    o = ui_tool_add(win, tb2, radg, 1, 0, "modify",             _("Modify objects"),        40, NULL,             TOOL_MODIFY);
1947    o = ui_tool_add(win, tb2, radg, 2, 0, "delete",             _("Delete objects"),        40, NULL,             TOOL_DELETE);
1948 
1949    o = elm_separator_add(win);
1950    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1951    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
1952    elm_separator_horizontal_set(o, EINA_TRUE);
1953    elm_table_pack(tb2, o, 0, 1, 4, 1);
1954    evas_object_show(o);
1955 
1956    o = ui_tool_add(win, tb2, radg, 0, 2, "line-arrow",         _("Single arrow line"),     40, "arrow",          TOOL_LINE);
1957    o = ui_tool_add(win, tb2, radg, 1, 2, "line-arrow2",        _("Double arrow line"),     40, "arrow2",         TOOL_LINE);
1958    o = ui_tool_add(win, tb2, radg, 2, 2, "line-arrow0",        _("Plain line"),            40, "arrow0",         TOOL_LINE);
1959    o = ui_tool_add(win, tb2, radg, 3, 2, "box-solid",          _("Solid box"),             40, "solid",          TOOL_BOX);
1960 
1961    o = ui_tool_add(win, tb2, radg, 0, 3, "box-malloc",         _("Malloc"),                40, "malloc",         TOOL_BOX);
1962    o = ui_tool_add(win, tb2, radg, 1, 3, "box-demalloc",       _("Malloc (evil)"),         40, "demalloc",       TOOL_BOX);
1963    o = ui_tool_add(win, tb2, radg, 2, 3, "box-finger",         _("Pointing finger"),       40, "finger",         TOOL_BOX);
1964    o = ui_tool_add(win, tb2, radg, 3, 3, "box-logo",           _("Enlightenment logo"),    40, "logo",           TOOL_BOX);
1965 
1966    o = ui_tool_add(win, tb2, radg, 0, 4, "box-foot",           _("Foot"),                  40, "foot",           TOOL_BOX);
1967    o = ui_tool_add(win, tb2, radg, 1, 4, "box-walk",           _("Silly walk"),            40, "walk",           TOOL_BOX);
1968    o = ui_tool_add(win, tb2, radg, 2, 4, "box-outline-box",    _("Box outline"),           40, "outline-box",    TOOL_BOX);
1969    o = ui_tool_add(win, tb2, radg, 3, 4, "box-outline-circle", _("Circle outline"),        40, "outline-circle", TOOL_BOX);
1970 
1971    o = ui_tool_add(win, tb2, radg, 0, 5, "box-text-empty",     _("Plain text"),            40, "text/empty",     TOOL_BOX);
1972    o = ui_tool_add(win, tb2, radg, 1, 5, "box-text-plain",     _("Text box"),              40, "text/plain",     TOOL_BOX);
1973    o = ui_tool_add(win, tb2, radg, 2, 5, "box-text-cloud",     _("Text thought bubble"),   40, "text/cloud",     TOOL_BOX);
1974    o = ui_tool_add(win, tb2, radg, 3, 5, "box-text-cloud2",    _("Text thought bubble 2"), 40, "text/cloud2",    TOOL_BOX);
1975 
1976    o = ui_tool_add(win, tb2, radg, 0, 6, "box-text-speech",    _("Speech bubble"),         40, "text/speech",    TOOL_BOX);
1977    o = ui_tool_add(win, tb2, radg, 1, 6, "box-text-speech2",   _("Speech bubble 2"),       40, "text/speech2",   TOOL_BOX);
1978    o = ui_tool_add(win, tb2, radg, 2, 6, "box-text-kaboom",    _("Kaboom splat"),          40, "text/kaboom",    TOOL_BOX);
1979    o = ui_tool_add(win, tb2, radg, 3, 6, "box-text-kapow",     _("Pow explode"),           40, "text/kapow",     TOOL_BOX);
1980 
1981    _cb_tool_changed(NULL, radg, NULL);
1982 
1983    fr = o = elm_frame_add(win);
1984    elm_frame_autocollapse_set(o, EINA_TRUE);
1985    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1986    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
1987    elm_object_text_set(o, _("Color"));
1988    elm_box_pack_end(bx, o);
1989    evas_object_show(o);
1990 
1991    tb2 = o = elm_table_add(win);
1992    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1993    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
1994    elm_object_content_set(fr, tb2);
1995    evas_object_show(o);
1996 
1997    bx = o = elm_box_add(win);
1998    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
1999    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2000    elm_box_horizontal_set(o, EINA_TRUE);
2001    elm_table_pack(tb2, o, 0, 0, 1, 1);
2002    evas_object_show(o);
2003 
2004    rad = o = elm_radio_add(win);
2005    radg = rad;
2006    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
2007    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2008    elm_radio_state_value_set(o, 0);
2009    elm_object_style_set(o, "icon");
2010    evas_object_smart_callback_add(o, "changed", _cb_col_changed, NULL);
2011    o_col1 = o = evas_object_rectangle_add(evas);
2012    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2013    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2014    evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(24), ELM_SCALE_SIZE(24));
2015    elm_object_content_set(rad, o);
2016    elm_box_pack_end(bx, rad);
2017    evas_object_show(rad);
2018 
2019    rad = o = elm_radio_add(win);
2020    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
2021    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2022    elm_radio_state_value_set(o, 1);
2023    elm_object_style_set(o, "icon");
2024    evas_object_smart_callback_add(o, "changed", _cb_col_changed, NULL);
2025    elm_radio_group_add(o, radg);
2026    o_col2 = o = evas_object_rectangle_add(evas);
2027    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2028    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2029    evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(24), ELM_SCALE_SIZE(24));
2030    elm_object_content_set(rad, o);
2031    elm_box_pack_end(bx, rad);
2032    evas_object_show(rad);
2033 
2034    draw_color_rects_update();
2035 
2036    o = o_colorsel = elm_colorselector_add(win);
2037    evas_object_resize(o, ELM_SCALE_SIZE(160), ELM_SCALE_SIZE(160));
2038    elm_colorselector_palette_clear(o);
2039    elm_colorselector_palette_color_add(o, 255, 255, 255, 255);
2040    elm_colorselector_palette_color_add(o, 224, 224, 224, 255);
2041    elm_colorselector_palette_color_add(o, 192, 192, 192, 255);
2042    elm_colorselector_palette_color_add(o, 160, 160, 160, 255);
2043    elm_colorselector_palette_color_add(o, 128, 128, 128, 255);
2044    elm_colorselector_palette_color_add(o,  96,  96,  96, 255);
2045    elm_colorselector_palette_color_add(o,  64,  64,  64, 255);
2046    elm_colorselector_palette_color_add(o,  32,  32,  32, 255);
2047    elm_colorselector_palette_color_add(o,   0,   0,   0, 255);
2048    elm_colorselector_palette_color_add(o,  51, 153, 255, 255);
2049    elm_colorselector_palette_color_add(o, 255, 153,  51, 255);
2050    elm_colorselector_palette_color_add(o, 255,  51, 153, 255);
2051    elm_colorselector_palette_color_add(o, 255,   0,   0, 255);
2052    elm_colorselector_palette_color_add(o, 255, 128,   0, 255);
2053    elm_colorselector_palette_color_add(o, 255, 255,   0, 255);
2054    elm_colorselector_palette_color_add(o, 128, 255,   0, 255);
2055    elm_colorselector_palette_color_add(o,   0, 255,   0, 255);
2056    elm_colorselector_palette_color_add(o,   0, 255, 128, 255);
2057    elm_colorselector_palette_color_add(o,   0, 255, 255, 255);
2058    elm_colorselector_palette_color_add(o,   0, 128, 255, 255);
2059    elm_colorselector_palette_color_add(o,   0,   0, 255, 255);
2060    elm_colorselector_palette_color_add(o, 128,   0, 255, 255);
2061    elm_colorselector_palette_color_add(o, 255,   0, 255, 255);
2062    elm_colorselector_palette_color_add(o, 255,   0, 128, 255);
2063    elm_colorselector_color_set(o, 255, 255, 255, 255);
2064    elm_table_pack(tb2, o, 0, 1, 1, 1);
2065    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
2066    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
2067    evas_object_show(o);
2068    evas_object_smart_callback_add(o, "changed", _cb_color_change, NULL);
2069 
2070    o = elm_frame_add(win);
2071    elm_object_style_set(o, "pad_large");
2072    elm_table_pack(tb, o, 9, 0, 1, 1);
2073 
2074    o = ui_icon_button_add(win, "zoom-in");
2075    elm_table_pack(tb, o, 8, 1, 1, 1);
2076    evas_object_smart_callback_add(o, "clicked", _cb_tool_zoom_plus, NULL);
2077 
2078    o = ui_icon_button_add(win, "zoom");
2079    elm_table_pack(tb, o, 8, 2, 1, 1);
2080    evas_object_smart_callback_add(o, "clicked", _cb_tool_zoom_reset, NULL);
2081 
2082    o = ui_icon_button_add(win, "zoom-out");
2083    elm_table_pack(tb, o, 8, 3, 1, 1);
2084    evas_object_smart_callback_add(o, "clicked", _cb_tool_zoom_minus, NULL);
2085    evas_object_show(o);
2086 
2087    img_w = edit_w = sw;
2088    img_h = edit_h = sh;
2089 
2090    win2 = o = elm_win_add(win, "inlined", ELM_WIN_INLINED_IMAGE);
2091    evas_object_resize(win2, edit_w, edit_h);
2092    evas_object_show(o);
2093    evas2 = evas_object_evas_get(win2);
2094    evas_font_path_append(evas2, e_module_dir_get(shot_module));
2095 
2096    tb2 = o = elm_table_add(win);
2097    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2098    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
2099    elm_object_content_set(sc, o);
2100    evas_object_show(o);
2101 
2102    o_rend = o = elm_win_inlined_image_object_get(win2);
2103    *o_img_ret = o;
2104    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2105    evas_object_size_hint_align_set(o, 0.5, 0.5);
2106    evas_object_size_hint_min_set(o, edit_w, edit_h);
2107    elm_table_pack(tb2, o, 0, 0, 1, 1);
2108    evas_object_show(o);
2109 
2110    o_img = o = evas_object_image_filled_add(evas2);
2111    evas_object_image_smooth_scale_set(o_img, EINA_FALSE);
2112    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
2113                                   _cb_draw_none_mouse_down, NULL);
2114    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2115    evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888);
2116    evas_object_image_alpha_set(o, EINA_FALSE);
2117    evas_object_image_size_set(o, sw, sh);
2118    evas_object_image_data_copy_set(o, dst);
2119    evas_object_image_data_update_add(o, 0, 0, sw, sh);
2120    evas_object_size_hint_min_set(o, img_w, img_h);
2121    evas_object_size_hint_max_set(o, img_w, img_h);
2122    elm_win_resize_object_add(win2, o);
2123    evas_object_show(o);
2124 
2125    zoom_set(zoom);
2126 
2127    o_events = o = evas_object_rectangle_add(evas2);
2128    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2129    evas_object_color_set(o, 0, 0, 0, 0);
2130    evas_object_repeat_events_set(o, EINA_TRUE);
2131    elm_win_resize_object_add(win2, o);
2132    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _cb_edit_wheel, NULL);
2133    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _cb_edit_mouse_down, NULL);
2134    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _cb_edit_mouse_up, NULL);
2135    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _cb_edit_mouse_move, NULL);
2136    evas_object_show(o);
2137 
2138    return bx_ret;
2139 }
2140 
2141 void
ui_edit_prepare(void)2142 ui_edit_prepare(void)
2143 {
2144    if (o_draw_handles[0]) evas_object_hide(o_draw_handles[0]);
2145    if (o_draw_handles[1]) evas_object_hide(o_draw_handles[1]);
2146    evas_object_hide(o_crop);
2147    elm_win_norender_push(win2);
2148    elm_win_render(win2);
2149 }
2150 
2151 void
ui_edit_crop_screen_set(int x,int y,int w,int h)2152 ui_edit_crop_screen_set(int x, int y, int w, int h)
2153 {
2154    crop_area.x = x;
2155    crop_area.y = y;
2156    crop_area.w = w;
2157    crop_area.h = h;
2158    E_RECTS_CLIP_TO_RECT(crop_area.x, crop_area.y,
2159                         crop_area.w, crop_area.h,
2160                         0, 0, img_w, img_h);
2161    crop_create();
2162    crop_export();
2163    crop_position();
2164    crop_mode = CROP_SCREEN;
2165 }
2166 
2167 //
2168 //////////////////////////////////////////////////////////////////////////////
2169