2 # include "elementary_config.h"
5 #include <Elementary.h>
8 #include "elm_widget_photocam.h"
9 #include "elm_interface_scrollable.h"
11 #define MY_PAN_CLASS ELM_OBJ_PHOTOCAM_PAN_CLASS
13 #define MY_PAN_CLASS_NAME "Elm_Photocam_Pan"
14 #define MY_PAN_CLASS_NAME_LEGACY "elm_photocam_pan"
16 #define MY_CLASS ELM_OBJ_PHOTOCAM_CLASS
18 #define MY_CLASS_NAME "Elm_Photocam"
19 #define MY_CLASS_NAME_LEGACY "elm_photocam"
22 * TODO (maybe - optional future stuff):
24 * 1. wrap photo in theme edje so u can have styling around photo (like white
27 * 3. rotation flags in exif handling (nasty! should have rot in evas)
30 static const char SIG_CLICKED[] = "clicked";
31 static const char SIG_PRESS[] = "press";
32 static const char SIG_LONGPRESSED[] = "longpressed";
33 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
34 static const char SIG_LOAD[] = "load";
35 static const char SIG_LOADED[] = "loaded";
36 static const char SIG_LOAD_DETAIL[] = "load,detail";
37 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
38 static const char SIG_ZOOM_START[] = "zoom,start";
39 static const char SIG_ZOOM_STOP[] = "zoom,stop";
40 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
41 static const char SIG_SCROLL[] = "scroll";
42 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
43 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
44 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
45 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
46 static const char SIG_DOWNLOAD_START[] = "download,start";
47 static const char SIG_DOWNLOAD_PROGRESS[] = "download,progress";
48 static const char SIG_DOWNLOAD_DONE[] = "download,done";
49 static const char SIG_DOWNLOAD_ERROR[] = "download,error";
50 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
53 {SIG_LONGPRESSED, ""},
54 {SIG_CLICKED_DOUBLE, ""},
57 {SIG_LOAD_DETAIL, ""},
58 {SIG_LOADED_DETAIL, ""},
61 {SIG_ZOOM_CHANGE, ""},
63 {SIG_SCROLL_ANIM_START, ""},
64 {SIG_SCROLL_ANIM_STOP, ""},
65 {SIG_SCROLL_DRAG_START, ""},
66 {SIG_SCROLL_DRAG_STOP, ""},
67 {SIG_DOWNLOAD_START, ""},
68 {SIG_DOWNLOAD_PROGRESS, ""},
69 {SIG_DOWNLOAD_DONE, ""},
70 {SIG_DOWNLOAD_ERROR, ""},
71 {SIG_WIDGET_FOCUSED, ""}, /**< handled by elm_widget */
72 {SIG_WIDGET_UNFOCUSED, ""}, /**< handled by elm_widget */
77 _photocam_image_file_set(Evas_Object *obj, Elm_Photocam_Data *sd)
80 evas_object_image_mmap_set(obj, sd->f, NULL);
82 evas_object_image_file_set(obj, sd->file, NULL);
86 _sizing_eval(Evas_Object *obj)
88 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
89 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
91 evas_object_size_hint_max_get
92 (wd->resize_obj, &maxw, &maxh);
93 evas_object_size_hint_min_set(obj, minw, minh);
94 evas_object_size_hint_max_set(obj, maxw, maxh);
98 _calc_job_cb(void *data)
100 Evas_Object *obj = data;
101 ELM_PHOTOCAM_DATA_GET(obj, sd);
102 Evas_Coord minw, minh;
108 sd->resized = EINA_FALSE;
109 if (sd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
111 double tz = sd->zoom;
113 elm_photocam_zoom_set(obj, tz);
116 if ((minw != sd->minw) || (minh != sd->minh))
121 evas_object_smart_callback_call(sd->pan_obj, "changed", NULL);
125 evas_object_smart_changed(sd->pan_obj);
129 _elm_photocam_pan_evas_smart_move(Eo *obj EINA_UNUSED, Elm_Photocam_Pan_Data *psd, Evas_Coord x EINA_UNUSED, Evas_Coord y EINA_UNUSED)
131 ecore_job_del(psd->wsd->calc_job);
132 psd->wsd->calc_job = ecore_job_add(_calc_job_cb, psd->wobj);
136 _elm_photocam_pan_evas_smart_resize(Eo *obj, Elm_Photocam_Pan_Data *psd, Evas_Coord w, Evas_Coord h)
140 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
141 if ((ow == w) && (oh == h)) return;
143 psd->wsd->resized = EINA_TRUE;
144 ecore_job_del(psd->wsd->calc_job);
145 psd->wsd->calc_job = ecore_job_add(_calc_job_cb, psd->wobj);
149 _image_place(Evas_Object *obj,
157 Evas_Coord ax, ay, gw, gh;
159 ELM_PHOTOCAM_DATA_GET(obj, sd);
165 if (!sd->zoom_g_layer)
167 if (ow > gw) ax = (ow - gw) / 2;
168 if (oh > gh) ay = (oh - gh) / 2;
170 evas_object_move(sd->img, ox + 0 - px + ax, oy + 0 - py + ay);
171 evas_object_resize(sd->img, gw, gh);
175 sd->show.show = EINA_FALSE;
176 eo_do(obj, elm_interface_scrollable_content_region_show
177 (sd->show.x, sd->show.y, sd->show.w, sd->show.h));
182 _grid_load(Evas_Object *obj,
186 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
188 ELM_PHOTOCAM_DATA_GET(obj, sd);
189 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
191 evas_object_geometry_get(sd->pan_obj, &ox, &oy, &ow, &oh);
192 evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
196 for (y = 0; y < g->gh; y++)
198 for (x = 0; x < g->gw; x++)
200 int tn, xx, yy, ww, hh;
201 Eina_Bool visible = EINA_FALSE;
203 tn = (y * g->gw) + x;
204 xx = g->grid[tn].out.x;
205 yy = g->grid[tn].out.y;
206 ww = g->grid[tn].out.w;
207 hh = g->grid[tn].out.h;
208 if ((gw != g->w) && (g->w > 0))
211 xx = (gw * xx) / g->w;
212 ww = ((gw * (tx + ww)) / g->w) - xx;
214 if ((gh != g->h) && (g->h > 0))
217 yy = (gh * yy) / g->h;
218 hh = ((gh * (ty + hh)) / g->h) - yy;
220 if (ELM_RECTS_INTERSECT(xx - sd->pan_x + ox,
222 ww, hh, cvx, cvy, cvw, cvh))
224 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
226 g->grid[tn].want = 1;
227 evas_object_hide(g->grid[tn].img);
228 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
229 evas_object_image_load_scale_down_set
230 (g->grid[tn].img, g->zoom);
231 evas_object_image_load_region_set
232 (g->grid[tn].img, g->grid[tn].src.x, g->grid[tn].src.y,
233 g->grid[tn].src.w, g->grid[tn].src.h);
234 _photocam_image_file_set(g->grid[tn].img, sd);
235 evas_object_image_preload(g->grid[tn].img, 0);
237 if (sd->preload_num == 1)
239 edje_object_signal_emit
241 "elm,state,busy,start", "elm");
242 evas_object_smart_callback_call
243 (obj, SIG_LOAD_DETAIL, NULL);
246 else if ((g->grid[tn].want) && (!visible))
249 if (!sd->preload_num)
251 edje_object_signal_emit
253 "elm,state,busy,stop", "elm");
254 evas_object_smart_callback_call
255 (obj, SIG_LOADED_DETAIL, NULL);
257 g->grid[tn].want = 0;
258 evas_object_hide(g->grid[tn].img);
259 evas_object_image_preload(g->grid[tn].img, 1);
260 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
262 else if ((g->grid[tn].have) && (!visible))
264 g->grid[tn].have = 0;
265 evas_object_hide(g->grid[tn].img);
266 evas_object_image_preload(g->grid[tn].img, 1);
267 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
274 _grid_place(Evas_Object *obj,
283 Evas_Coord ax, ay, gw, gh, tx, ty;
286 ELM_PHOTOCAM_DATA_GET(obj, sd);
292 if (!sd->zoom_g_layer)
294 if (ow > gw) ax = (ow - gw) / 2;
295 if (oh > gh) ay = (oh - gh) / 2;
297 for (y = 0; y < g->gh; y++)
299 for (x = 0; x < g->gw; x++)
301 int tn, xx, yy, ww, hh;
303 tn = (y * g->gw) + x;
304 xx = g->grid[tn].out.x;
305 yy = g->grid[tn].out.y;
306 ww = g->grid[tn].out.w;
307 hh = g->grid[tn].out.h;
308 if ((gw != g->w) && (g->w > 0))
311 xx = (gw * xx) / g->w;
312 ww = ((gw * (tx + ww)) / g->w) - xx;
314 if ((gh != g->h) && (g->h > 0))
317 yy = (gh * yy) / g->h;
318 hh = ((gh * (ty + hh)) / g->h) - yy;
320 evas_object_move(g->grid[tn].img,
323 evas_object_resize(g->grid[tn].img, ww, hh);
329 _elm_photocam_pan_evas_smart_calculate(Eo *obj, Elm_Photocam_Pan_Data *psd)
333 Evas_Coord ox, oy, ow, oh;
335 ELM_WIDGET_DATA_GET_OR_RETURN(psd->wobj, wd);
337 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
339 wd->obj, psd->wsd->pan_x, psd->wsd->pan_y,
340 ox - psd->wsd->g_layer_zoom.imx, oy - psd->wsd->g_layer_zoom.imy, ow,
343 EINA_LIST_FOREACH(psd->wsd->grids, l, g)
345 _grid_load(wd->obj, g);
347 wd->obj, g, psd->wsd->pan_x,
348 psd->wsd->pan_y, ox - psd->wsd->g_layer_zoom.imx,
349 oy - psd->wsd->g_layer_zoom.imy, ow, oh);
354 _elm_photocam_pan_elm_pan_pos_set(Eo *obj, Elm_Photocam_Pan_Data *psd, Evas_Coord x, Evas_Coord y)
356 if ((x == psd->wsd->pan_x) && (y == psd->wsd->pan_y)) return;
359 evas_object_smart_changed(obj);
363 _elm_photocam_pan_elm_pan_pos_get(Eo *obj EINA_UNUSED, Elm_Photocam_Pan_Data *psd, Evas_Coord *x, Evas_Coord *y)
365 if (x) *x = psd->wsd->pan_x;
366 if (y) *y = psd->wsd->pan_y;
370 _elm_photocam_pan_elm_pan_pos_max_get(Eo *obj, Elm_Photocam_Pan_Data *psd, Evas_Coord *x, Evas_Coord *y)
374 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
375 ow = psd->wsd->minw - ow;
377 oh = psd->wsd->minh - oh;
384 _elm_photocam_pan_elm_pan_pos_min_get(Eo *obj EINA_UNUSED, Elm_Photocam_Pan_Data *_pd EINA_UNUSED, Evas_Coord *x, Evas_Coord *y)
391 _elm_photocam_pan_elm_pan_content_size_get(Eo *obj EINA_UNUSED, Elm_Photocam_Pan_Data *psd, Evas_Coord *w, Evas_Coord *h)
393 if (w) *w = psd->wsd->minw;
394 if (h) *h = psd->wsd->minh;
398 _elm_photocam_pan_eo_base_destructor(Eo *obj, Elm_Photocam_Pan_Data *psd)
400 eo_data_unref(psd->wobj, psd->wsd);
401 eo_do_super(obj, MY_PAN_CLASS, eo_destructor());
405 _elm_photocam_pan_class_constructor(Eo_Class *klass)
407 evas_smart_legacy_type_register(MY_PAN_CLASS_NAME_LEGACY, klass);
410 #include "elm_photocam_pan.eo.c"
413 _nearest_pow2_get(int num)
415 unsigned int n = num - 1;
427 _grid_clear(Evas_Object *obj,
432 ELM_PHOTOCAM_DATA_GET(obj, sd);
433 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
435 if (!g->grid) return;
436 for (y = 0; y < g->gh; y++)
438 for (x = 0; x < g->gw; x++)
442 tn = (y * g->gw) + x;
443 evas_object_del(g->grid[tn].img);
444 if (g->grid[tn].want)
447 if (!sd->preload_num)
449 edje_object_signal_emit
451 "elm,state,busy,stop", "elm");
452 evas_object_smart_callback_call
453 (obj, SIG_LOAD_DETAIL, NULL);
459 ELM_SAFE_FREE(g->grid, free);
465 _tile_preloaded_cb(void *data,
467 Evas_Object *o EINA_UNUSED,
468 void *event_info EINA_UNUSED)
470 Elm_Photocam_Grid_Item *git = data;
471 ELM_PHOTOCAM_DATA_GET(git->obj, sd);
472 ELM_WIDGET_DATA_GET_OR_RETURN(git->obj, wd);
477 evas_object_show(git->img);
480 if (!sd->preload_num)
482 edje_object_signal_emit
483 (wd->resize_obj, "elm,state,busy,stop",
485 evas_object_smart_callback_call
486 (wd->obj, SIG_LOADED_DETAIL, NULL);
492 _grid_zoom_calc(double zoom)
497 return _nearest_pow2_get(z);
500 static Elm_Phocam_Grid *
501 _grid_create(Evas_Object *obj)
506 ELM_PHOTOCAM_DATA_GET(obj, sd);
508 g = calloc(1, sizeof(Elm_Phocam_Grid));
511 g->zoom = _grid_zoom_calc(sd->zoom);
512 g->tsize = sd->tsize;
513 g->iw = sd->size.imw;
514 g->ih = sd->size.imh;
516 g->w = g->iw / g->zoom;
517 g->h = g->ih / g->zoom;
526 g->gw = (g->w + g->tsize - 1) / g->tsize;
527 g->gh = (g->h + g->tsize - 1) / g->tsize;
535 g->grid = calloc(1, sizeof(Elm_Photocam_Grid_Item) * g->gw * g->gh);
544 for (y = 0; y < g->gh; y++)
546 for (x = 0; x < g->gw; x++)
550 tn = (y * g->gw) + x;
551 g->grid[tn].src.x = x * g->tsize;
552 if (x == (g->gw - 1))
553 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
555 g->grid[tn].src.w = g->tsize;
556 g->grid[tn].src.y = y * g->tsize;
557 if (y == (g->gh - 1))
558 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
560 g->grid[tn].src.h = g->tsize;
562 g->grid[tn].out.x = g->grid[tn].src.x;
563 g->grid[tn].out.y = g->grid[tn].src.y;
564 g->grid[tn].out.w = g->grid[tn].src.w;
565 g->grid[tn].out.h = g->grid[tn].src.h;
567 g->grid[tn].obj = obj;
569 evas_object_image_add(evas_object_evas_get(obj));
570 evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE);
571 evas_object_image_scale_hint_set
572 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
573 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
575 /* XXX: check this */
576 evas_object_smart_member_add(g->grid[tn].img, sd->pan_obj);
577 elm_widget_sub_object_add(obj, g->grid[tn].img);
578 evas_object_image_filled_set(g->grid[tn].img, 1);
579 evas_object_event_callback_add
580 (g->grid[tn].img, EVAS_CALLBACK_IMAGE_PRELOADED,
581 _tile_preloaded_cb, &(g->grid[tn]));
589 _grid_clear_all(Evas_Object *obj)
593 ELM_PHOTOCAM_DATA_GET(obj, sd);
595 EINA_LIST_FREE(sd->grids, g)
603 _smooth_update(Evas_Object *obj)
609 ELM_PHOTOCAM_DATA_GET(obj, sd);
611 EINA_LIST_FOREACH(sd->grids, l, g)
613 for (y = 0; y < g->gh; y++)
615 for (x = 0; x < g->gw; x++)
619 tn = (y * g->gw) + x;
620 evas_object_image_smooth_scale_set
621 (g->grid[tn].img, (!sd->no_smooth));
626 evas_object_image_smooth_scale_set(sd->img, (!sd->no_smooth));
630 _grid_raise(Elm_Phocam_Grid *g)
634 for (y = 0; y < g->gh; y++)
636 for (x = 0; x < g->gw; x++)
640 tn = (y * g->gw) + x;
641 evas_object_raise(g->grid[tn].img);
647 _scroll_timeout_cb(void *data)
649 ELM_PHOTOCAM_DATA_GET(data, sd);
652 if (!sd->no_smooth) _smooth_update(data);
654 sd->scr_timer = NULL;
656 return ECORE_CALLBACK_CANCEL;
660 _main_img_preloaded_cb(void *data,
662 Evas_Object *o EINA_UNUSED,
663 void *event_info EINA_UNUSED)
665 Evas_Object *obj = data;
668 ELM_PHOTOCAM_DATA_GET(data, sd);
669 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
671 evas_object_show(sd->img);
672 sd->main_load_pending = 0;
673 g = _grid_create(obj);
676 sd->grids = eina_list_prepend(sd->grids, g);
679 ecore_job_del(sd->calc_job);
680 sd->calc_job = ecore_job_add(_calc_job_cb, data);
681 evas_object_smart_callback_call(data, SIG_LOADED, NULL);
683 if (!sd->preload_num)
685 edje_object_signal_emit
686 (wd->resize_obj, "elm,state,busy,stop", "elm");
687 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
692 _zoom_do(Evas_Object *obj,
695 Evas_Coord xx, yy, ow = 0, oh = 0;
697 ELM_PHOTOCAM_DATA_GET(obj, sd);
699 sd->size.w = (sd->size.ow * (1.0 - t)) + (sd->size.nw * t);
700 sd->size.h = (sd->size.oh * (1.0 - t)) + (sd->size.nh * t);
701 eo_do(obj, elm_interface_scrollable_content_viewport_size_get(&ow, &oh));
702 xx = (sd->size.spos.x * sd->size.w) - (ow / 2);
703 yy = (sd->size.spos.y * sd->size.h) - (oh / 2);
705 else if (xx > (sd->size.w - ow))
706 xx = sd->size.w - ow;
708 else if (yy > (sd->size.h - oh))
709 yy = sd->size.h - oh;
711 sd->show.show = EINA_TRUE;
717 ecore_job_del(sd->calc_job);
718 sd->calc_job = ecore_job_add(_calc_job_cb, obj);
721 Eina_List *l, *l_next;
724 EINA_LIST_FOREACH_SAFE(sd->grids, l, l_next, g)
728 sd->grids = eina_list_remove_list(sd->grids, l);
740 _zoom_anim_cb(void *data)
744 Evas_Object *obj = data;
746 ELM_PHOTOCAM_DATA_GET(obj, sd);
748 t = ecore_loop_time_get();
751 else if (sd->t_end > sd->t_start)
752 t = (t - sd->t_start) / (sd->t_end - sd->t_start);
757 go = _zoom_do(obj, t);
761 if (!sd->no_smooth) _smooth_update(data);
762 sd->zoom_animator = NULL;
763 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
770 _long_press_cb(void *data)
772 ELM_PHOTOCAM_DATA_GET(data, sd);
774 sd->long_timer = NULL;
775 sd->longpressed = EINA_TRUE;
776 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
778 return ECORE_CALLBACK_CANCEL;
782 _mouse_down_cb(void *data,
783 Evas *evas EINA_UNUSED,
784 Evas_Object *obj EINA_UNUSED,
787 Evas_Event_Mouse_Down *ev = event_info;
789 ELM_PHOTOCAM_DATA_GET(data, sd);
791 if (ev->button != 1) return;
792 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->on_hold = EINA_TRUE;
793 else sd->on_hold = EINA_FALSE;
794 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
795 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
797 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
798 sd->longpressed = EINA_FALSE;
799 ecore_timer_del(sd->long_timer);
800 sd->long_timer = ecore_timer_add
801 (_elm_config->longpress_timeout, _long_press_cb, data);
805 _mouse_up_cb(void *data,
806 Evas *evas EINA_UNUSED,
807 Evas_Object *obj EINA_UNUSED,
810 Evas_Event_Mouse_Up *ev = event_info;
812 ELM_PHOTOCAM_DATA_GET(data, sd);
814 if (ev->button != 1) return;
815 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->on_hold = EINA_TRUE;
816 else sd->on_hold = EINA_FALSE;
817 ELM_SAFE_FREE(sd->long_timer, ecore_timer_del);
819 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
820 sd->on_hold = EINA_FALSE;
823 EOLIAN static Eina_Bool
824 _elm_photocam_elm_widget_on_focus(Eo *obj, Elm_Photocam_Data *_pd EINA_UNUSED)
826 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
827 Eina_Bool int_ret = EINA_FALSE;
829 eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_on_focus());
830 if (!int_ret) return EINA_FALSE;
832 if (elm_widget_focus_get(obj))
834 edje_object_signal_emit
835 (wd->resize_obj, "elm,action,focus", "elm");
836 evas_object_focus_set(wd->resize_obj, EINA_TRUE);
840 edje_object_signal_emit
841 (wd->resize_obj, "elm,action,unfocus", "elm");
842 evas_object_focus_set(wd->resize_obj, EINA_FALSE);
848 EOLIAN static Eina_Bool
849 _elm_photocam_elm_widget_theme_apply(Eo *obj, Elm_Photocam_Data *sd EINA_UNUSED)
851 Eina_Bool int_ret = EINA_FALSE;
852 eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
853 if (!int_ret) return EINA_FALSE;
861 _scroll_animate_start_cb(Evas_Object *obj,
862 void *data EINA_UNUSED)
864 evas_object_smart_callback_call(obj, SIG_SCROLL_ANIM_START, NULL);
868 _scroll_animate_stop_cb(Evas_Object *obj,
869 void *data EINA_UNUSED)
871 evas_object_smart_callback_call(obj, SIG_SCROLL_ANIM_STOP, NULL);
875 _scroll_drag_start_cb(Evas_Object *obj,
876 void *data EINA_UNUSED)
878 evas_object_smart_callback_call(obj, SIG_SCROLL_DRAG_START, NULL);
882 _scroll_drag_stop_cb(Evas_Object *obj,
883 void *data EINA_UNUSED)
885 evas_object_smart_callback_call(obj, SIG_SCROLL_DRAG_STOP, NULL);
889 _scroll_cb(Evas_Object *obj,
890 void *data EINA_UNUSED)
892 ELM_PHOTOCAM_DATA_GET(obj, sd);
897 if (sd->no_smooth == 1) _smooth_update(obj);
900 ecore_timer_del(sd->scr_timer);
901 sd->scr_timer = ecore_timer_add(0.5, _scroll_timeout_cb, obj);
903 evas_object_smart_callback_call(obj, SIG_SCROLL, NULL);
906 EOLIAN static Eina_Bool
907 _elm_photocam_elm_widget_event(Eo *obj, Elm_Photocam_Data *_pd EINA_UNUSED, Evas_Object *src, Evas_Callback_Type type, void *event_info)
910 Evas_Event_Key_Down *ev = event_info;
917 Evas_Coord step_x = 0;
918 Evas_Coord step_y = 0;
919 Evas_Coord page_x = 0;
920 Evas_Coord page_y = 0;
922 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
923 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
924 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
927 elm_interface_scrollable_content_pos_get(&x, &y),
928 elm_interface_scrollable_step_size_get(&step_x, &step_y),
929 elm_interface_scrollable_page_size_get(&page_x, &page_y),
930 elm_interface_scrollable_content_viewport_size_get(&v_w, &v_h));
932 if ((!strcmp(ev->key, "Left")) ||
933 ((!strcmp(ev->key, "KP_Left")) && (!ev->string)))
937 else if ((!strcmp(ev->key, "Right")) ||
938 ((!strcmp(ev->key, "KP_Right")) && (!ev->string)))
942 else if ((!strcmp(ev->key, "Up")) ||
943 ((!strcmp(ev->key, "KP_Up")) && (!ev->string)))
947 else if ((!strcmp(ev->key, "Down")) ||
948 ((!strcmp(ev->key, "KP_Down")) && (!ev->string)))
952 else if ((!strcmp(ev->key, "Prior")) ||
953 ((!strcmp(ev->key, "KP_Prior")) && (!ev->string)))
956 y -= -(page_y * v_h) / 100;
960 else if ((!strcmp(ev->key, "Next")) ||
961 ((!strcmp(ev->key, "KP_Next")) && (!ev->string)))
964 y += -(page_y * v_h) / 100;
968 else if ((!strcmp(ev->key, "KP_Add")))
970 zoom = elm_photocam_zoom_get(obj);
972 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
973 elm_photocam_zoom_set(obj, zoom);
976 else if ((!strcmp(ev->key, "KP_Subtract")))
978 zoom = elm_photocam_zoom_get(obj);
980 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
981 elm_photocam_zoom_set(obj, zoom);
984 else return EINA_FALSE;
986 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
987 eo_do(obj, elm_interface_scrollable_content_pos_set(x, y, EINA_TRUE));
993 _bounce_eval(void *data)
995 Evas_Object *obj = data;
996 ELM_PHOTOCAM_DATA_GET(obj, sd);
999 if ((sd->g_layer_zoom.imx == sd->g_layer_zoom.bounce.x_end) &&
1000 (sd->g_layer_zoom.imy == sd->g_layer_zoom.bounce.y_end))
1002 sd->g_layer_zoom.imx = 0;
1003 sd->g_layer_zoom.imy = 0;
1004 sd->zoom_g_layer = EINA_FALSE;
1005 sd->g_layer_zoom.bounce.animator = NULL;
1007 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1009 return ECORE_CALLBACK_CANCEL;
1012 t = ecore_loop_time_get();
1013 tt = (t - sd->g_layer_zoom.bounce.t_start) /
1014 (sd->g_layer_zoom.bounce.t_end -
1015 sd->g_layer_zoom.bounce.t_start);
1017 tt = 1.0 - (tt * tt);
1019 if (t > sd->g_layer_zoom.bounce.t_end)
1021 sd->g_layer_zoom.imx = 0;
1022 sd->g_layer_zoom.imy = 0;
1023 sd->zoom_g_layer = EINA_FALSE;
1025 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1028 sd->g_layer_zoom.bounce.animator = NULL;
1029 return ECORE_CALLBACK_CANCEL;
1032 if (sd->g_layer_zoom.imx != sd->g_layer_zoom.bounce.x_end)
1033 sd->g_layer_zoom.imx =
1034 sd->g_layer_zoom.bounce.x_start * (1.0 - tt) +
1035 sd->g_layer_zoom.bounce.x_end * tt;
1037 if (sd->g_layer_zoom.imy != sd->g_layer_zoom.bounce.y_end)
1038 sd->g_layer_zoom.imy =
1039 sd->g_layer_zoom.bounce.y_start * (1.0 - tt) +
1040 sd->g_layer_zoom.bounce.y_end * tt;
1042 _zoom_do(obj, 1.0 - (1.0 - tt));
1044 return ECORE_CALLBACK_RENEW;
1048 _g_layer_zoom_do(Evas_Object *obj,
1051 Elm_Gesture_Zoom_Info *g_layer)
1053 int regx, regy, regw, regh, ix, iy, iw, ih;
1054 Evas_Coord rx, ry, rw = 0, rh = 0;
1057 ELM_PHOTOCAM_DATA_GET(obj, sd);
1058 sd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1059 sd->zoom = sd->g_layer_start / g_layer->zoom;
1060 sd->size.ow = sd->size.w;
1061 sd->size.oh = sd->size.h;
1062 eo_do(obj, elm_interface_scrollable_content_pos_get(&rx, &ry));
1063 eo_do(obj, elm_interface_scrollable_content_viewport_size_get(&rw, &rh));
1064 if ((rw <= 0) || (rh <= 0)) return;
1066 sd->size.nw = (double)sd->size.imw / sd->zoom;
1067 sd->size.nh = (double)sd->size.imh / sd->zoom;
1069 elm_photocam_image_region_get(obj, ®x, ®y, ®w, ®h);
1070 evas_object_geometry_get(sd->img, &ix, &iy, &iw, &ih);
1072 sd->pvx = g_layer->x;
1073 sd->pvy = g_layer->y;
1075 xx = (px / sd->zoom) - sd->pvx;
1076 yy = (py / sd->zoom) - sd->pvy;
1077 sd->g_layer_zoom.imx = 0;
1078 sd->g_layer_zoom.imy = 0;
1080 if ((xx < 0) || (rw > sd->size.nw))
1082 sd->g_layer_zoom.imx = xx;
1085 else if ((xx + rw) > sd->size.nw)
1087 sd->g_layer_zoom.imx = xx + rw - sd->size.nw;
1088 xx = sd->size.nw - rw;
1091 if ((yy < 0) || (rh > sd->size.nh))
1093 sd->g_layer_zoom.imy = yy;
1096 else if ((yy + rh) > sd->size.nh)
1098 sd->g_layer_zoom.imy = yy + rh - sd->size.nh;
1099 yy = sd->size.nh - rh;
1102 sd->size.spos.x = (double)(xx + (rw / 2)) / (double)(sd->size.nw);
1103 sd->size.spos.y = (double)(yy + (rh / 2)) / (double)(sd->size.nh);
1108 static Evas_Event_Flags
1109 _g_layer_zoom_start_cb(void *data,
1112 Evas_Object *obj = data;
1113 Elm_Gesture_Zoom_Info *p = event_info;
1114 ELM_PHOTOCAM_DATA_GET(obj, sd);
1115 double marginx = 0, marginy = 0;
1116 Evas_Coord rw = 0, rh = 0;
1119 ELM_SAFE_FREE(sd->g_layer_zoom.bounce.animator, ecore_animator_del);
1120 sd->zoom_g_layer = EINA_TRUE;
1122 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_TRUE));
1124 elm_photocam_image_region_get(obj, &x, &y, &w, &h);
1125 eo_do(obj, elm_interface_scrollable_content_viewport_size_get(&rw, &rh));
1127 if (rw > sd->size.nw)
1128 marginx = (rw - sd->size.nw) / 2;
1129 if (rh > sd->size.nh)
1130 marginy = (rh - sd->size.nh) / 2;
1132 sd->g_layer_start = sd->zoom;
1134 sd->zoom_point_x = x + ((p->x - marginx) * sd->zoom) +
1135 sd->g_layer_zoom.imx;
1136 sd->zoom_point_y = y + ((p->y - marginy) * sd->zoom) +
1137 sd->g_layer_zoom.imy;
1139 return EVAS_EVENT_FLAG_NONE;
1142 static Evas_Event_Flags
1143 _g_layer_zoom_move_cb(void *data,
1146 Elm_Photocam_Data *sd = eo_data_scope_get(data, MY_CLASS);
1147 Elm_Gesture_Zoom_Info *p = event_info;
1149 _g_layer_zoom_do(data, sd->zoom_point_x, sd->zoom_point_y, p);
1151 return EVAS_EVENT_FLAG_NONE;
1154 static Evas_Event_Flags
1155 _g_layer_zoom_end_cb(void *data,
1156 void *event_info EINA_UNUSED)
1158 Evas_Object *obj = data;
1159 ELM_PHOTOCAM_DATA_GET(obj, sd);
1162 eo_do(obj, elm_interface_scrollable_content_viewport_size_get(&rw, &rh));
1163 sd->g_layer_start = 1.0;
1165 if (sd->g_layer_zoom.imx || sd->g_layer_zoom.imy)
1169 t = ecore_loop_time_get();
1170 sd->g_layer_zoom.bounce.x_start = sd->g_layer_zoom.imx;
1171 sd->g_layer_zoom.bounce.y_start = sd->g_layer_zoom.imy;
1172 sd->g_layer_zoom.bounce.x_end = 0;
1173 sd->g_layer_zoom.bounce.y_end = 0;
1175 if (rw > sd->size.nw &&
1181 if ((sd->size.imw < rw) && (sd->size.imh < rh))
1184 sd->size.nw = sd->size.imw;
1185 sd->size.nh = sd->size.imh;
1189 ph = (sd->size.imh * rw) / sd->size.imw;
1192 pw = (sd->size.imw * rh) / sd->size.imh;
1199 if (sd->size.imw > sd->size.imh)
1200 z = (double)sd->size.imw / pw;
1202 z = (double)sd->size.imh / ph;
1208 sd->g_layer_zoom.bounce.x_end = (sd->size.nw - rw) / 2;
1209 sd->g_layer_zoom.bounce.y_end = (sd->size.nh - rh) / 2;
1215 xx = (sd->zoom_point_x / sd->zoom) - sd->pvx;
1216 yy = (sd->zoom_point_y / sd->zoom) - sd->pvy;
1221 if (rw > sd->size.nw)
1222 sd->g_layer_zoom.bounce.x_end = (sd->size.nw - rw) / 2;
1223 if ((xx + rw) > sd->size.nw)
1224 xx = sd->size.nw - rw;
1226 if (rh > sd->size.nh)
1227 sd->g_layer_zoom.bounce.y_end = (sd->size.nh - rh) / 2;
1228 if ((yy + rh) > sd->size.nh)
1229 yy = sd->size.nh - rh;
1231 sd->size.spos.x = (double)(xx + (rw / 2)) / (double)(sd->size.nw);
1232 sd->size.spos.y = (double)(yy + (rh / 2)) / (double)(sd->size.nh);
1235 sd->g_layer_zoom.bounce.t_start = t;
1236 sd->g_layer_zoom.bounce.t_end = t +
1237 _elm_config->page_scroll_friction;
1239 sd->g_layer_zoom.bounce.animator =
1240 ecore_animator_add(_bounce_eval, obj);
1244 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1245 sd->zoom_g_layer = EINA_FALSE;
1248 return EVAS_EVENT_FLAG_NONE;
1252 _elm_photocam_evas_smart_add(Eo *obj, Elm_Photocam_Data *priv)
1254 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1255 Elm_Photocam_Pan_Data *pan_data;
1257 Evas_Coord minw, minh;
1259 elm_widget_sub_object_parent_add(obj);
1261 edje = edje_object_add(evas_object_evas_get(obj));
1262 elm_widget_resize_object_set(obj, edje, EINA_TRUE);
1264 eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
1266 elm_widget_theme_object_set
1267 (obj, edje, "photocam", "base", elm_widget_style_get(obj));
1269 priv->hit_rect = evas_object_rectangle_add(evas_object_evas_get(obj));
1270 evas_object_smart_member_add(priv->hit_rect, obj);
1271 elm_widget_sub_object_add(obj, priv->hit_rect);
1273 /* common scroller hit rectangle setup */
1274 evas_object_color_set(priv->hit_rect, 0, 0, 0, 0);
1275 evas_object_show(priv->hit_rect);
1276 evas_object_repeat_events_set(priv->hit_rect, EINA_TRUE);
1278 elm_widget_can_focus_set(obj, EINA_TRUE);
1280 eo_do(obj, elm_interface_scrollable_objects_set(edje, priv->hit_rect));
1283 elm_interface_scrollable_animate_start_cb_set(_scroll_animate_start_cb),
1284 elm_interface_scrollable_animate_stop_cb_set(_scroll_animate_stop_cb),
1285 elm_interface_scrollable_drag_start_cb_set(_scroll_drag_start_cb),
1286 elm_interface_scrollable_drag_stop_cb_set(_scroll_drag_stop_cb),
1287 elm_interface_scrollable_scroll_cb_set(_scroll_cb));
1289 eo_do(obj, elm_interface_scrollable_bounce_allow_set(bounce, bounce));
1291 priv->pan_obj = eo_add(MY_PAN_CLASS, evas_object_evas_get(obj));
1292 pan_data = eo_data_scope_get(priv->pan_obj, MY_PAN_CLASS);
1293 eo_data_ref(obj, NULL);
1294 pan_data->wobj = obj;
1295 pan_data->wsd = priv;
1297 eo_do(obj, elm_interface_scrollable_extern_pan_set(priv->pan_obj));
1299 priv->g_layer_start = 1.0;
1301 priv->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1304 priv->img = evas_object_image_add(evas_object_evas_get(obj));
1305 evas_object_image_load_orientation_set(priv->img, EINA_TRUE);
1306 evas_object_image_scale_hint_set(priv->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1307 evas_object_event_callback_add
1308 (priv->img, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, obj);
1309 evas_object_event_callback_add
1310 (priv->img, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, obj);
1311 evas_object_image_scale_hint_set(priv->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1314 evas_object_smart_member_add(priv->img, priv->pan_obj);
1316 elm_widget_sub_object_add(obj, priv->img);
1317 evas_object_image_filled_set(priv->img, EINA_TRUE);
1318 evas_object_event_callback_add
1319 (priv->img, EVAS_CALLBACK_IMAGE_PRELOADED, _main_img_preloaded_cb, obj);
1321 edje_object_size_min_calc(edje, &minw, &minh);
1322 evas_object_size_hint_min_set(obj, minw, minh);
1329 _elm_photocam_evas_smart_del(Eo *obj, Elm_Photocam_Data *sd)
1333 EINA_LIST_FREE(sd->grids, g)
1338 eo_unref(sd->pan_obj);
1339 ELM_SAFE_FREE(sd->pan_obj, evas_object_del);
1341 if (sd->f) eina_file_close(sd->f);
1342 free(sd->remote_data);
1343 if (sd->remote) _elm_url_cancel(sd->remote);
1344 eina_stringshare_del(sd->file);
1345 ecore_job_del(sd->calc_job);
1346 ecore_timer_del(sd->scr_timer);
1347 ecore_timer_del(sd->long_timer);
1348 ecore_animator_del(sd->zoom_animator);
1349 ecore_animator_del(sd->g_layer_zoom.bounce.animator);
1351 eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
1355 _elm_photocam_evas_smart_move(Eo *obj, Elm_Photocam_Data *sd, Evas_Coord x, Evas_Coord y)
1357 eo_do_super(obj, MY_CLASS, evas_obj_smart_move(x, y));
1359 evas_object_move(sd->hit_rect, x, y);
1363 _elm_photocam_evas_smart_resize(Eo *obj, Elm_Photocam_Data *sd, Evas_Coord w, Evas_Coord h)
1365 eo_do_super(obj, MY_CLASS, evas_obj_smart_resize(w, h));
1367 evas_object_resize(sd->hit_rect, w, h);
1371 _elm_photocam_evas_smart_member_add(Eo *obj, Elm_Photocam_Data *sd, Evas_Object *member)
1374 eo_do_super(obj, MY_CLASS, evas_obj_smart_member_add(member));
1377 evas_object_raise(sd->hit_rect);
1381 elm_photocam_add(Evas_Object *parent)
1383 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1384 Evas_Object *obj = eo_add(MY_CLASS, parent);
1390 _elm_photocam_eo_base_constructor(Eo *obj, Elm_Photocam_Data *_pd EINA_UNUSED)
1392 eo_do_super(obj, MY_CLASS, eo_constructor());
1394 evas_obj_type_set(MY_CLASS_NAME_LEGACY),
1395 evas_obj_smart_callbacks_descriptions_set(_smart_callbacks));
1399 _internal_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file, Eina_File *f, Evas_Load_Error *ret)
1401 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1402 Evas_Load_Error err;
1406 if (!eina_stringshare_replace(&sd->file, file)) return;
1407 sd->f = eina_file_dup(f);
1409 evas_object_image_smooth_scale_set(sd->img, (sd->no_smooth == 0));
1410 evas_object_image_file_set(sd->img, NULL, NULL);
1411 evas_object_image_load_scale_down_set(sd->img, 0);
1412 _photocam_image_file_set(sd->img, sd);
1413 err = evas_object_image_load_error_get(sd->img);
1414 if (err != EVAS_LOAD_ERROR_NONE)
1416 ERR("Things are going bad for '%s' (%p) : %i", file, sd->img, err);
1417 if (ret) *ret = err;
1420 evas_object_image_size_get(sd->img, &w, &h);
1422 sd->do_region = evas_object_image_region_support_get(sd->img);
1425 sd->size.w = sd->size.imw / sd->zoom;
1426 sd->size.h = sd->size.imh / sd->zoom;
1427 evas_object_image_file_set(sd->img, NULL, NULL);
1428 evas_object_image_load_scale_down_set(sd->img, 8);
1429 _photocam_image_file_set(sd->img, sd);
1430 err = evas_object_image_load_error_get(sd->img);
1431 if (err != EVAS_LOAD_ERROR_NONE)
1433 ERR("Things are going bad for '%s' (%p)", file, sd->img);
1434 if (ret) *ret = err;
1438 evas_object_image_preload(sd->img, 0);
1439 sd->main_load_pending = EINA_TRUE;
1441 sd->calc_job = ecore_job_add(_calc_job_cb, obj);
1442 evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1444 if (sd->preload_num == 1)
1446 edje_object_signal_emit
1447 (wd->resize_obj, "elm,state,busy,start", "elm");
1448 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1453 elm_photocam_zoom_set(obj, tz);
1455 if (ret) *ret = evas_object_image_load_error_get(sd->img);
1459 _elm_photocam_download_done(void *data, Elm_Url *url EINA_UNUSED, Eina_Binbuf *download)
1462 Elm_Photocam_Data *sd = eo_data_scope_get(obj, MY_CLASS);
1465 Evas_Load_Error ret = EVAS_LOAD_ERROR_NONE;
1467 free(sd->remote_data);
1468 length = eina_binbuf_length_get(download);
1469 sd->remote_data = eina_binbuf_string_steal(download);
1470 f = eina_file_virtualize(_elm_url_get(url),
1471 sd->remote_data, length,
1473 _internal_file_set(obj, sd, _elm_url_get(url), f, &ret);
1476 if (ret != EVAS_LOAD_ERROR_NONE)
1478 Elm_Photocam_Error err = { 0, EINA_TRUE };
1480 free(sd->remote_data);
1481 sd->remote_data = NULL;
1482 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &err);
1486 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_DONE, NULL);
1493 _elm_photocam_download_cancel(void *data, Elm_Url *url EINA_UNUSED, int error)
1496 Elm_Photocam_Data *sd = eo_data_scope_get(obj, MY_CLASS);
1497 Elm_Photocam_Error err = { error, EINA_FALSE };
1499 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &err);
1505 _elm_photocam_download_progress(void *data, Elm_Url *url EINA_UNUSED, double now, double total)
1508 Elm_Photocam_Progress progress;
1511 progress.total = total;
1512 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_PROGRESS, &progress);
1515 static const char *remote_uri[] = {
1516 "http://", "https://", "ftp://"
1519 EOLIAN static Evas_Load_Error
1520 _elm_photocam_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file)
1522 Evas_Load_Error ret = EVAS_LOAD_ERROR_NONE;
1525 _grid_clear_all(obj);
1526 ELM_SAFE_FREE(sd->g_layer_zoom.bounce.animator, ecore_animator_del);
1527 if (sd->zoom_animator)
1530 if (sd->no_smooth == 0) _smooth_update(obj);
1531 ecore_animator_del(sd->zoom_animator);
1532 sd->zoom_animator = NULL;
1534 ecore_job_del(sd->calc_job);
1535 evas_object_hide(sd->img);
1536 if (sd->f) eina_file_close(sd->f);
1539 free(sd->remote_data);
1540 if (sd->remote) _elm_url_cancel(sd->remote);
1543 for (i = 0; i < sizeof (remote_uri) / sizeof (remote_uri[0]); ++i)
1544 if (!strncmp(remote_uri[i], file, strlen(remote_uri[i])))
1546 // Found a remote target !
1547 sd->remote = _elm_url_download(file,
1548 _elm_photocam_download_done,
1549 _elm_photocam_download_cancel,
1550 _elm_photocam_download_progress,
1554 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_START, NULL);
1560 _internal_file_set(obj, sd, file, NULL, &ret);
1565 EOLIAN static const char*
1566 _elm_photocam_file_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
1572 _elm_photocam_zoom_set(Eo *obj, Elm_Photocam_Data *sd, double zoom)
1577 Elm_Phocam_Grid *g, *g_zoom = NULL;
1578 Evas_Coord pw, ph, rx, ry, rw, rh;
1579 int zoom_changed = 0, started = 0;
1581 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1582 if (zoom == sd->zoom) return;
1585 sd->size.ow = sd->size.w;
1586 sd->size.oh = sd->size.h;
1587 eo_do(obj, elm_interface_scrollable_content_pos_get(&rx, &ry));
1588 eo_do(obj, elm_interface_scrollable_content_viewport_size_get(&rw, &rh));
1589 if ((rw <= 0) || (rh <= 0)) return;
1591 if (sd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1593 sd->size.nw = (double)sd->size.imw / sd->zoom;
1594 sd->size.nh = (double)sd->size.imh / sd->zoom;
1596 else if (sd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1598 if ((sd->size.imw < 1) || (sd->size.imh < 1))
1605 ph = (sd->size.imh * rw) / sd->size.imw;
1608 pw = (sd->size.imw * rh) / sd->size.imh;
1615 if (sd->size.imw > sd->size.imh)
1616 z = (double)sd->size.imw / pw;
1618 z = (double)sd->size.imh / ph;
1626 else if (sd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1628 if ((sd->size.imw < 1) || (sd->size.imh < 1))
1635 ph = (sd->size.imh * rw) / sd->size.imw;
1638 pw = (sd->size.imw * rh) / sd->size.imh;
1645 if (sd->size.imw > sd->size.imh)
1646 z = (double)sd->size.imw / pw;
1648 z = (double)sd->size.imh / ph;
1656 else if (sd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN)
1658 if ((sd->size.imw < 1) || (sd->size.imh < 1))
1663 else if ((sd->size.imw < rw) && (sd->size.imh < rh))
1665 if (1 != sd->zoom) zoom_changed = 1;
1667 sd->size.nw = sd->size.imw;
1668 sd->size.nh = sd->size.imh;
1672 ph = (sd->size.imh * rw) / sd->size.imw;
1675 pw = (sd->size.imw * rh) / sd->size.imh;
1680 if (sd->size.imw > sd->size.imh)
1681 z = (double)sd->size.imw / pw;
1683 z = (double)sd->size.imh / ph;
1692 if (sd->main_load_pending)
1694 sd->size.w = sd->size.nw;
1695 sd->size.h = sd->size.nh;
1700 EINA_LIST_FOREACH(sd->grids, l, g)
1702 if (g->zoom == _grid_zoom_calc(sd->zoom))
1704 sd->grids = eina_list_remove(sd->grids, g);
1705 sd->grids = eina_list_prepend(sd->grids, g);
1711 g = _grid_create(obj);
1714 if (eina_list_count(sd->grids) > 1)
1716 g_zoom = eina_list_last(sd->grids)->data;
1717 sd->grids = eina_list_remove(sd->grids, g_zoom);
1718 _grid_clear(obj, g_zoom);
1720 EINA_LIST_FOREACH(sd->grids, l, g_zoom)
1725 sd->grids = eina_list_prepend(sd->grids, g);
1729 EINA_LIST_FREE(sd->grids, g)
1731 _grid_clear(obj, g);
1737 sd->t_start = ecore_loop_time_get();
1738 sd->t_end = sd->t_start + _elm_config->zoom_friction;
1739 if ((sd->size.w > 0) && (sd->size.h > 0))
1741 sd->size.spos.x = (double)(rx + (rw / 2)) / (double)sd->size.w;
1742 sd->size.spos.y = (double)(ry + (rh / 2)) / (double)sd->size.h;
1746 sd->size.spos.x = 0.5;
1747 sd->size.spos.y = 0.5;
1749 if (rw > sd->size.w) sd->size.spos.x = 0.5;
1750 if (rh > sd->size.h) sd->size.spos.y = 0.5;
1751 if (sd->size.spos.x > 1.0) sd->size.spos.x = 1.0;
1752 if (sd->size.spos.y > 1.0) sd->size.spos.y = 1.0;
1760 if (!sd->zoom_animator)
1762 sd->zoom_animator = ecore_animator_add(_zoom_anim_cb, obj);
1764 if (sd->no_smooth == 1) _smooth_update(obj);
1769 an = sd->zoom_animator;
1772 if (!_zoom_anim_cb(obj))
1774 ecore_animator_del(an);
1779 ecore_job_del(sd->calc_job);
1780 sd->calc_job = ecore_job_add(_calc_job_cb, obj);
1784 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1786 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1789 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1792 EOLIAN static double
1793 _elm_photocam_zoom_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
1799 _elm_photocam_zoom_mode_set(Eo *obj, Elm_Photocam_Data *sd, Elm_Photocam_Zoom_Mode mode)
1803 if (sd->mode == mode) return;
1808 elm_photocam_zoom_set(obj, tz);
1811 EOLIAN static Elm_Photocam_Zoom_Mode
1812 _elm_photocam_zoom_mode_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
1818 _elm_photocam_image_size_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd, int *w, int *h)
1820 if (w) *w = sd->size.imw;
1821 if (h) *h = sd->size.imh;
1825 _elm_photocam_image_region_get(Eo *obj, Elm_Photocam_Data *sd, int *x, int *y, int *w, int *h)
1827 Evas_Coord sx, sy, sw, sh;
1829 eo_do((Eo *)obj, elm_interface_scrollable_content_pos_get(&sx, &sy));
1830 eo_do((Eo *)obj, elm_interface_scrollable_content_viewport_size_get(&sw, &sh));
1835 *x = (sd->size.imw * sx) / sd->size.w;
1836 if (*x > sd->size.imw) *x = sd->size.imw;
1840 *w = (sd->size.imw * sw) / sd->size.w;
1841 if (*w > sd->size.imw) *w = sd->size.imw;
1856 *y = (sd->size.imh * sy) / sd->size.h;
1857 if (*y > sd->size.imh) *y = sd->size.imh;
1861 *h = (sd->size.imh * sh) / sd->size.h;
1862 if (*h > sd->size.imh) *h = sd->size.imh;
1875 _elm_photocam_image_region_show(Eo *obj, Elm_Photocam_Data *sd, int x, int y, int w, int h)
1879 if ((sd->size.imw < 1) || (sd->size.imh < 1)) return;
1880 rx = (x * sd->size.w) / sd->size.imw;
1881 ry = (y * sd->size.h) / sd->size.imh;
1882 rw = (w * sd->size.w) / sd->size.imw;
1883 rh = (h * sd->size.h) / sd->size.imh;
1886 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw;
1887 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh;
1888 if (sd->g_layer_zoom.bounce.animator)
1890 ecore_animator_del(sd->g_layer_zoom.bounce.animator);
1891 sd->g_layer_zoom.bounce.animator = NULL;
1894 if (sd->zoom_animator)
1897 ecore_animator_del(sd->zoom_animator);
1898 sd->zoom_animator = NULL;
1900 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1902 eo_do(obj, elm_interface_scrollable_content_region_show(rx, ry, rw, rh));
1906 elm_photocam_image_region_bring_in(Evas_Object *obj,
1912 ELM_PHOTOCAM_CHECK(obj);
1913 eo_do(obj, elm_interface_scrollable_region_bring_in(x, y, w, h));
1917 _elm_photocam_elm_interface_scrollable_region_bring_in(Eo *obj, Elm_Photocam_Data *sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1921 if ((sd->size.imw < 1) || (sd->size.imh < 1)) return;
1922 rx = (x * sd->size.w) / sd->size.imw;
1923 ry = (y * sd->size.h) / sd->size.imh;
1924 rw = (w * sd->size.w) / sd->size.imw;
1925 rh = (h * sd->size.h) / sd->size.imh;
1928 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw;
1929 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh;
1930 if (sd->g_layer_zoom.bounce.animator)
1932 ecore_animator_del(sd->g_layer_zoom.bounce.animator);
1933 sd->g_layer_zoom.bounce.animator = NULL;
1936 if (sd->zoom_animator)
1939 if (!sd->no_smooth) _smooth_update(obj);
1940 ecore_animator_del(sd->zoom_animator);
1941 sd->zoom_animator = NULL;
1943 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1945 eo_do_super(obj, MY_CLASS, elm_interface_scrollable_region_bring_in(rx, ry, rw, rh));
1949 _elm_photocam_paused_set(Eo *obj, Elm_Photocam_Data *sd, Eina_Bool paused)
1953 if (sd->paused == paused) return;
1954 sd->paused = paused;
1955 if (!sd->paused) return;
1957 if (sd->g_layer_zoom.bounce.animator)
1959 ecore_animator_del(sd->g_layer_zoom.bounce.animator);
1960 sd->g_layer_zoom.bounce.animator = NULL;
1963 if (sd->zoom_animator)
1965 ecore_animator_del(sd->zoom_animator);
1966 sd->zoom_animator = NULL;
1968 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1972 EOLIAN static Eina_Bool
1973 _elm_photocam_paused_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
1978 EOLIAN static Evas_Object*
1979 _elm_photocam_internal_image_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
1985 elm_photocam_bounce_set(Evas_Object *obj,
1989 ELM_PHOTOCAM_CHECK(obj);
1991 eo_do(obj, elm_interface_scrollable_bounce_allow_set(h_bounce, v_bounce));
1995 elm_photocam_bounce_get(const Evas_Object *obj,
1996 Eina_Bool *h_bounce,
1997 Eina_Bool *v_bounce)
1999 ELM_PHOTOCAM_CHECK(obj);
2001 eo_do((Eo *)obj, elm_interface_scrollable_bounce_allow_get(h_bounce, v_bounce));
2005 _elm_photocam_gesture_enabled_set(Eo *obj, Elm_Photocam_Data *sd, Eina_Bool gesture)
2007 gesture = !!gesture;
2009 if (sd->do_gesture == gesture) return;
2011 sd->do_gesture = gesture;
2013 ELM_SAFE_FREE(sd->g_layer, evas_object_del);
2015 if (!gesture) return;
2017 sd->g_layer = elm_gesture_layer_add(obj);
2018 if (!sd->g_layer) return;
2020 elm_gesture_layer_attach(sd->g_layer, obj);
2021 elm_gesture_layer_cb_set
2022 (sd->g_layer, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
2023 _g_layer_zoom_start_cb, obj);
2024 elm_gesture_layer_cb_set
2025 (sd->g_layer, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
2026 _g_layer_zoom_move_cb, obj);
2027 elm_gesture_layer_cb_set
2028 (sd->g_layer, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END,
2029 _g_layer_zoom_end_cb, obj);
2030 elm_gesture_layer_cb_set
2031 (sd->g_layer, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT,
2032 _g_layer_zoom_end_cb, obj);
2035 EOLIAN static Eina_Bool
2036 _elm_photocam_gesture_enabled_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd)
2038 return sd->do_gesture;
2042 _elm_photocam_class_constructor(Eo_Class *klass)
2044 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
2047 #include "elm_photocam.eo.c"