1 #include <Elementary.h>
3 #include "els_scroller.h"
6 * TODO (maybe - optional future stuff):
8 * 1. wrap photo in theme edje so u can have styling around photo (like white
11 * 3. rotation flags in exif handling (nasty! should have rot in evas)
14 typedef struct _Widget_Data Widget_Data;
15 typedef struct _Pan Pan;
16 typedef struct _Grid Grid;
17 typedef struct _Grid_Item Grid_Item;
33 int tsize; // size of tile (tsize x tsize pixels)
34 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
35 int iw, ih; // size of image in pixels
36 int w, h; // size of grid image in pixels (represented by grid)
37 int gw, gh; // size of grid in tiles
38 Grid_Item *grid; // the grid (gw * gh items)
39 Eina_Bool dead : 1; // old grid. will die as soon as anim is over
46 Evas_Object *pan_smart;
48 Evas_Coord pan_x, pan_y, minw, minh;
51 Elm_Photocam_Zoom_Mode mode;
55 Ecore_Timer *scr_timer;
56 Ecore_Timer *long_timer;
57 Ecore_Animator *zoom_animator;
58 double t_start, t_end;
72 Evas_Coord x, y ,w ,h;
75 Evas_Object *img; // low res version of image (scale down == 8)
79 Eina_Bool main_load_pending : 1;
80 Eina_Bool resized : 1;
81 Eina_Bool longpressed : 1;
82 Eina_Bool on_hold : 1;
88 Evas_Object_Smart_Clipped_Data __clipped_data;
92 static const char *widtype = NULL;
93 static void _del_hook(Evas_Object *obj);
94 static void _theme_hook(Evas_Object *obj);
95 static void _on_focus_hook(void *data, Evas_Object *obj);
96 //static void _show_region_hook(void *data, Evas_Object *obj);
97 static void _sizing_eval(Evas_Object *obj);
98 static void _calc_job(void *data);
99 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
100 Evas_Callback_Type type, void *event_info);
101 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
102 static void grid_clear(Evas_Object *obj, Grid *g);
103 static Grid *grid_create(Evas_Object *obj);
104 static void grid_load(Evas_Object *obj, Grid *g);
106 static const char SIG_CLICKED[] = "clicked";
107 static const char SIG_PRESS[] = "press";
108 static const char SIG_LONGPRESSED[] = "longpressed";
109 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
110 static const char SIG_LOAD[] = "load";
111 static const char SIG_LOADED[] = "loaded";
112 static const char SIG_LOAD_DETAIL[] = "load,detail";
113 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
114 static const char SIG_ZOOM_START[] = "zoom,start";
115 static const char SIG_ZOOM_STOP[] = "zoom,stop";
116 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
117 static const char SIG_SCROLL[] = "scroll";
118 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
119 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
120 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
121 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
123 static const Evas_Smart_Cb_Description _signals[] = {
126 {SIG_LONGPRESSED, ""},
127 {SIG_CLICKED_DOUBLE, ""},
130 {SIG_LOAD_DETAIL, ""},
131 {SIG_LOADED_DETAIL, ""},
132 {SIG_ZOOM_START, ""},
134 {SIG_ZOOM_CHANGE, ""},
136 {SIG_SCROLL_ANIM_START, ""},
137 {SIG_SCROLL_ANIM_STOP, ""},
138 {SIG_SCROLL_DRAG_START, ""},
139 {SIG_SCROLL_DRAG_STOP, ""},
145 nearest_pow2(int num)
147 unsigned int n = num - 1;
157 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
159 Widget_Data *wd = elm_widget_data_get(obj);
160 Evas_Coord ax, ay, gw, gh;
166 if (ow > gw) ax = (ow - gw) / 2;
167 if (oh > gh) ay = (oh - gh) / 2;
168 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
169 evas_object_resize(wd->img, gw, gh);
173 wd->show.show = EINA_FALSE;
174 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
179 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
181 Widget_Data *wd = elm_widget_data_get(obj);
182 Evas_Coord ax, ay, gw, gh, tx, ty;
189 if (ow > gw) ax = (ow - gw) / 2;
190 if (oh > gh) ay = (oh - gh) / 2;
191 for (y = 0; y < g->gh; y++)
193 for (x = 0; x < g->gw; x++)
195 int tn, xx, yy, ww, hh;
197 tn = (y * g->gw) + x;
198 xx = g->grid[tn].out.x;
199 yy = g->grid[tn].out.y;
200 ww = g->grid[tn].out.w;
201 hh = g->grid[tn].out.h;
202 if ((gw != g->w) && (g->w > 0))
205 xx = (gw * xx) / g->w;
206 ww = ((gw * (tx + ww)) / g->w) - xx;
208 if ((gh != g->h) && (g->h > 0))
211 yy = (gh * yy) / g->h;
212 hh = ((gh * (ty + hh)) / g->h) - yy;
214 evas_object_move(g->grid[tn].img,
217 evas_object_resize(g->grid[tn].img, ww, hh);
223 grid_clear(Evas_Object *obj, Grid *g)
225 Widget_Data *wd = elm_widget_data_get(obj);
228 if (!g->grid) return;
229 for (y = 0; y < g->gh; y++)
231 for (x = 0; x < g->gw; x++)
235 tn = (y * g->gw) + x;
236 evas_object_del(g->grid[tn].img);
237 if (g->grid[tn].want)
240 if (!wd->preload_num)
242 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
243 "elm,state,busy,stop", "elm");
244 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
256 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
258 Grid_Item *git = data;
263 evas_object_show(git->img);
265 git->wd->preload_num--;
266 if (!git->wd->preload_num)
268 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
269 "elm,state,busy,stop", "elm");
270 evas_object_smart_callback_call(git->wd->obj, SIG_LOADED_DETAIL, NULL);
276 grid_zoom_calc(double zoom)
280 return nearest_pow2(z);
284 grid_create(Evas_Object *obj)
286 Widget_Data *wd = elm_widget_data_get(obj);
290 if (!wd) return NULL;
291 g = calloc(1, sizeof(Grid));
293 g->zoom = grid_zoom_calc(wd->zoom);
294 g->tsize = wd->tsize;
295 g->iw = wd->size.imw;
296 g->ih = wd->size.imh;
298 g->w = g->iw / g->zoom;
299 g->h = g->ih / g->zoom;
300 if (g->zoom >= 8) return NULL;
301 g->gw = (g->w + g->tsize - 1) / g->tsize;
302 g->gh = (g->h + g->tsize - 1) / g->tsize;
303 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
310 for (y = 0; y < g->gh; y++)
312 for (x = 0; x < g->gw; x++)
316 tn = (y * g->gw) + x;
317 g->grid[tn].src.x = x * g->tsize;
318 if (x == (g->gw - 1))
319 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
321 g->grid[tn].src.w = g->tsize;
322 g->grid[tn].src.y = y * g->tsize;
323 if (y == (g->gh - 1))
324 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
326 g->grid[tn].src.h = g->tsize;
328 g->grid[tn].out.x = g->grid[tn].src.x;
329 g->grid[tn].out.y = g->grid[tn].src.y;
330 g->grid[tn].out.w = g->grid[tn].src.w;
331 g->grid[tn].out.h = g->grid[tn].src.h;
335 evas_object_image_add(evas_object_evas_get(obj));
336 evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE);
337 evas_object_image_scale_hint_set
338 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
339 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
340 evas_object_smart_member_add(g->grid[tn].img,
342 elm_widget_sub_object_add(obj, g->grid[tn].img);
343 evas_object_image_filled_set(g->grid[tn].img, 1);
344 evas_object_event_callback_add(g->grid[tn].img,
345 EVAS_CALLBACK_IMAGE_PRELOADED,
354 grid_load(Evas_Object *obj, Grid *g)
356 Widget_Data *wd = elm_widget_data_get(obj);
358 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
360 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
361 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
364 for (y = 0; y < g->gh; y++)
366 for (x = 0; x < g->gw; x++)
368 int tn, xx, yy, ww, hh;
369 Eina_Bool visible = EINA_FALSE;
371 tn = (y * g->gw) + x;
372 xx = g->grid[tn].out.x;
373 yy = g->grid[tn].out.y;
374 ww = g->grid[tn].out.w;
375 hh = g->grid[tn].out.h;
376 if ((gw != g->w) && (g->w > 0))
379 xx = (gw * xx) / g->w;
380 ww = ((gw * (tx + ww)) / g->w) - xx;
382 if ((gh != g->h) && (g->h > 0))
385 yy = (gh * yy) / g->h;
386 hh = ((gh * (ty + hh)) / g->h) - yy;
388 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
393 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
395 g->grid[tn].want = 1;
396 evas_object_hide(g->grid[tn].img);
397 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
398 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
399 evas_object_image_load_region_set(g->grid[tn].img,
404 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
405 evas_object_image_preload(g->grid[tn].img, 0);
407 if (wd->preload_num == 1)
409 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
410 "elm,state,busy,start", "elm");
411 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
414 else if ((g->grid[tn].want) && (!visible))
417 if (!wd->preload_num)
419 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
420 "elm,state,busy,stop", "elm");
421 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
423 g->grid[tn].want = 0;
424 evas_object_hide(g->grid[tn].img);
425 evas_object_image_preload(g->grid[tn].img, 1);
426 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
428 else if ((g->grid[tn].have) && (!visible))
430 g->grid[tn].have = 0;
431 evas_object_hide(g->grid[tn].img);
432 evas_object_image_preload(g->grid[tn].img, 1);
433 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
440 grid_clearall(Evas_Object *obj)
442 Widget_Data *wd = elm_widget_data_get(obj);
445 EINA_LIST_FREE(wd->grids, g)
453 _smooth_update(Evas_Object *obj)
455 Widget_Data *wd = elm_widget_data_get(obj);
460 EINA_LIST_FOREACH(wd->grids, l, g)
462 for (y = 0; y < g->gh; y++)
464 for (x = 0; x < g->gw; x++)
468 tn = (y * g->gw) + x;
469 evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
473 evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
481 for (y = 0; y < g->gh; y++)
483 for (x = 0; x < g->gw; x++)
487 tn = (y * g->gw) + x;
488 evas_object_raise(g->grid[tn].img);
494 _scr_timeout(void *data)
496 Widget_Data *wd = elm_widget_data_get(data);
497 if (!wd) return ECORE_CALLBACK_CANCEL;
499 if (!wd->nosmooth) _smooth_update(data);
500 wd->scr_timer = NULL;
501 return ECORE_CALLBACK_CANCEL;
505 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
507 Widget_Data *wd = elm_widget_data_get(data);
512 if (wd->nosmooth == 1) _smooth_update(data);
514 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
515 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
519 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
521 Evas_Object *obj = data;
522 Widget_Data *wd = elm_widget_data_get(obj);
525 evas_object_show(wd->img);
526 wd->main_load_pending = 0;
527 g = grid_create(obj);
530 wd->grids = eina_list_prepend(wd->grids, g);
531 grid_load(wd->obj, g);
533 if (wd->calc_job) ecore_job_del(wd->calc_job);
534 wd->calc_job = ecore_job_add(_calc_job, wd);
535 evas_object_smart_callback_call(data, SIG_LOADED, NULL);
537 if (!wd->preload_num)
539 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
540 "elm,state,busy,stop", "elm");
541 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
546 zoom_do(Evas_Object *obj, double t)
548 Widget_Data *wd = elm_widget_data_get(obj);
549 Evas_Coord xx, yy, ow, oh;
550 if (!wd) return ECORE_CALLBACK_CANCEL;
551 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
552 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
553 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
554 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
555 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
557 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
559 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
561 wd->show.show = EINA_TRUE;
567 if (wd->calc_job) ecore_job_del(wd->calc_job);
568 wd->calc_job = ecore_job_add(_calc_job, wd);
571 Eina_List *l, *l_next;
574 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
578 wd->grids = eina_list_remove_list(wd->grids, l);
583 return ECORE_CALLBACK_CANCEL;
585 return ECORE_CALLBACK_RENEW;
590 _zoom_anim(void *data)
592 Evas_Object *obj = data;
593 Widget_Data *wd = elm_widget_data_get(obj);
596 if (!wd) return ECORE_CALLBACK_CANCEL;
597 t = ecore_loop_time_get();
600 else if (wd->t_end > wd->t_start)
601 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
606 go = zoom_do(obj, t);
610 if (!wd->nosmooth) _smooth_update(data);
611 wd->zoom_animator = NULL;
612 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
618 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
620 Widget_Data *wd = elm_widget_data_get(data);
621 // Evas_Event_Mouse_Move *ev = event_info;
626 _long_press(void *data)
628 Widget_Data *wd = elm_widget_data_get(data);
629 if (!wd) return ECORE_CALLBACK_CANCEL;
630 wd->long_timer = NULL;
631 wd->longpressed = EINA_TRUE;
632 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
633 return ECORE_CALLBACK_CANCEL;
637 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
639 Widget_Data *wd = elm_widget_data_get(data);
640 Evas_Event_Mouse_Down *ev = event_info;
642 if (ev->button != 1) return;
643 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
644 else wd->on_hold = EINA_FALSE;
645 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
646 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
648 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
649 wd->longpressed = EINA_FALSE;
650 if (wd->long_timer) ecore_timer_del(wd->long_timer);
651 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
655 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
657 Widget_Data *wd = elm_widget_data_get(data);
658 Evas_Event_Mouse_Up *ev = event_info;
660 if (ev->button != 1) return;
661 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
662 else wd->on_hold = EINA_FALSE;
665 ecore_timer_del(wd->long_timer);
666 wd->long_timer = NULL;
669 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
670 wd->on_hold = EINA_FALSE;
673 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
676 _del_hook(Evas_Object *obj)
678 Widget_Data *wd = elm_widget_data_get(obj);
681 EINA_LIST_FREE(wd->grids, g)
683 if (g->grid) free(g->grid);
686 evas_object_del(wd->pan_smart);
687 wd->pan_smart = NULL;
688 if (wd->file) eina_stringshare_del(wd->file);
689 if (wd->calc_job) ecore_job_del(wd->calc_job);
690 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
691 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
692 if (wd->long_timer) ecore_timer_del(wd->long_timer);
697 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
699 Widget_Data *wd = elm_widget_data_get(obj);
701 if (elm_widget_focus_get(obj))
703 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
704 evas_object_focus_set(wd->obj, EINA_TRUE);
708 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
709 evas_object_focus_set(wd->obj, EINA_FALSE);
714 _theme_hook(Evas_Object *obj)
716 Widget_Data *wd = elm_widget_data_get(obj);
718 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
719 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
725 _show_region_hook(void *data, Evas_Object *obj)
727 Widget_Data *wd = elm_widget_data_get(data);
728 Evas_Coord x, y, w, h;
730 elm_widget_show_region_get(obj, &x, &y, &w, &h);
731 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
736 _sizing_eval(Evas_Object *obj)
738 Widget_Data *wd = elm_widget_data_get(obj);
739 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
741 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
742 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
745 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
746 evas_object_size_hint_min_set(obj, minw, minh);
747 evas_object_size_hint_max_set(obj, maxw, maxh);
751 _calc_job(void *data)
753 Widget_Data *wd = data;
754 Evas_Coord minw, minh;
761 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
763 double tz = wd->zoom;
765 elm_photocam_zoom_set(wd->obj, tz);
768 if ((minw != wd->minw) || (minh != wd->minh))
772 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
773 _sizing_eval(wd->obj);
776 evas_object_smart_changed(wd->pan_smart);
780 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
782 Pan *sd = evas_object_smart_data_get(obj);
784 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
787 evas_object_smart_changed(obj);
791 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
793 Pan *sd = evas_object_smart_data_get(obj);
795 if (x) *x = sd->wd->pan_x;
796 if (y) *y = sd->wd->pan_y;
800 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
802 Pan *sd = evas_object_smart_data_get(obj);
805 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
806 ow = sd->wd->minw - ow;
808 oh = sd->wd->minh - oh;
815 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
822 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
824 Pan *sd = evas_object_smart_data_get(obj);
826 if (w) *w = sd->wd->minw;
827 if (h) *h = sd->wd->minh;
831 _pan_add(Evas_Object *obj)
834 Evas_Object_Smart_Clipped_Data *cd;
836 cd = evas_object_smart_data_get(obj);
838 sd = calloc(1, sizeof(Pan));
840 sd->__clipped_data = *cd;
842 evas_object_smart_data_set(obj, sd);
846 _pan_del(Evas_Object *obj)
848 Pan *sd = evas_object_smart_data_get(obj);
854 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
856 Pan *sd = evas_object_smart_data_get(obj);
859 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
860 if ((ow == w) && (oh == h)) return;
862 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
863 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
867 _pan_calculate(Evas_Object *obj)
869 Pan *sd = evas_object_smart_data_get(obj);
870 Evas_Coord ox, oy, ow, oh;
874 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
875 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
876 EINA_LIST_FOREACH(sd->wd->grids, l, g)
878 grid_load(sd->wd->obj, g);
879 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
884 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
886 Pan *sd = evas_object_smart_data_get(obj);
888 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
889 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
893 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
895 Widget_Data *wd = elm_widget_data_get(obj);
897 elm_smart_scroller_hold_set(wd->scr, 1);
901 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
903 Widget_Data *wd = elm_widget_data_get(obj);
905 elm_smart_scroller_hold_set(wd->scr, 0);
909 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
911 Widget_Data *wd = elm_widget_data_get(obj);
913 elm_smart_scroller_freeze_set(wd->scr, 1);
917 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
919 Widget_Data *wd = elm_widget_data_get(obj);
921 elm_smart_scroller_freeze_set(wd->scr, 0);
925 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
927 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
931 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
933 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
937 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
939 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
943 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
945 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
949 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
951 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
955 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
956 Evas_Callback_Type type, void *event_info)
959 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
960 Evas_Event_Key_Down *ev = event_info;
961 Widget_Data *wd = elm_widget_data_get(obj);
962 if (!wd) return EINA_FALSE;
963 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
967 Evas_Coord step_x = 0;
968 Evas_Coord step_y = 0;
971 Evas_Coord page_x = 0;
972 Evas_Coord page_y = 0;
974 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
975 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
976 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
977 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
979 if ((!strcmp(ev->keyname, "Left")) ||
980 (!strcmp(ev->keyname, "KP_Left")))
984 else if ((!strcmp(ev->keyname, "Right")) ||
985 (!strcmp(ev->keyname, "KP_Right")))
989 else if ((!strcmp(ev->keyname, "Up")) ||
990 (!strcmp(ev->keyname, "KP_Up")))
994 else if ((!strcmp(ev->keyname, "Down")) ||
995 (!strcmp(ev->keyname, "KP_Down")))
999 else if ((!strcmp(ev->keyname, "Prior")) ||
1000 (!strcmp(ev->keyname, "KP_Prior")))
1003 y -= -(page_y * v_h) / 100;
1007 else if ((!strcmp(ev->keyname, "Next")) ||
1008 (!strcmp(ev->keyname, "KP_Next")))
1011 y += -(page_y * v_h) / 100;
1015 else if ((!strcmp(ev->keyname, "KP_Add")))
1017 zoom = elm_photocam_zoom_get(obj);
1019 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1020 elm_photocam_zoom_set(obj, zoom);
1023 else if ((!strcmp(ev->keyname, "KP_Subtract")))
1025 zoom = elm_photocam_zoom_get(obj);
1027 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1028 elm_photocam_zoom_set(obj, zoom);
1031 else return EINA_FALSE;
1033 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1034 elm_smart_scroller_child_pos_set(wd->scr, x, y);
1040 elm_photocam_add(Evas_Object *parent)
1045 Evas_Coord minw, minh;
1046 static Evas_Smart *smart = NULL;
1047 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1049 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1051 ELM_SET_WIDTYPE(widtype, "photocam");
1052 elm_widget_type_set(obj, "photocam");
1053 elm_widget_sub_object_add(parent, obj);
1054 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1055 elm_widget_data_set(obj, wd);
1056 elm_widget_del_hook_set(obj, _del_hook);
1057 elm_widget_theme_hook_set(obj, _theme_hook);
1058 elm_widget_can_focus_set(obj, EINA_TRUE);
1059 elm_widget_event_hook_set(obj, _event_hook);
1061 wd->scr = elm_smart_scroller_add(e);
1062 elm_smart_scroller_widget_set(wd->scr, obj);
1063 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
1064 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
1065 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
1066 elm_widget_resize_object_set(obj, wd->scr);
1068 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1069 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1070 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1071 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1072 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1074 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1078 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1079 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1080 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1081 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1085 static Evas_Smart_Class sc;
1087 evas_object_smart_clipped_smart_set(&_pan_sc);
1089 sc.name = "elm_photocam_pan";
1090 sc.version = EVAS_SMART_CLASS_VERSION;
1093 sc.resize = _pan_resize;
1094 sc.move = _pan_move;
1095 sc.calculate = _pan_calculate;
1096 smart = evas_smart_class_new(&sc);
1100 wd->pan_smart = evas_object_smart_add(e, smart);
1101 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1105 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1106 _pan_set, _pan_get, _pan_max_get,
1107 _pan_min_get, _pan_child_size_get);
1110 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1114 wd->img = evas_object_image_add(e);
1115 evas_object_image_load_orientation_set(wd->img, EINA_TRUE);
1116 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1117 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1119 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1121 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1123 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1124 evas_object_smart_member_add(wd->img, wd->pan_smart);
1125 elm_widget_sub_object_add(obj, wd->img);
1126 evas_object_image_filled_set(wd->img, 1);
1127 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1128 _main_preloaded, obj);
1130 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1132 evas_object_size_hint_min_set(obj, minw, minh);
1134 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1140 EAPI Evas_Load_Error
1141 elm_photocam_file_set(Evas_Object *obj, const char *file)
1143 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1144 Widget_Data *wd = elm_widget_data_get(obj);
1146 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1147 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1150 evas_object_hide(wd->img);
1151 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1152 evas_object_image_file_set(wd->img, NULL, NULL);
1153 evas_object_image_load_scale_down_set(wd->img, 0);
1154 evas_object_image_file_set(wd->img, wd->file, NULL);
1155 evas_object_image_size_get(wd->img, &w, &h);
1158 wd->size.w = wd->size.imw / wd->zoom;
1159 wd->size.h = wd->size.imh / wd->zoom;
1160 if (wd->zoom_animator)
1163 if (wd->nosmooth == 0) _smooth_update(obj);
1164 ecore_animator_del(wd->zoom_animator);
1165 wd->zoom_animator = NULL;
1167 evas_object_image_file_set(wd->img, NULL, NULL);
1168 evas_object_image_load_scale_down_set(wd->img, 8);
1169 evas_object_image_file_set(wd->img, wd->file, NULL);
1170 evas_object_image_preload(wd->img, 0);
1171 wd->main_load_pending = 1;
1172 if (wd->calc_job) ecore_job_del(wd->calc_job);
1173 wd->calc_job = ecore_job_add(_calc_job, wd);
1174 evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1176 if (wd->preload_num == 1)
1178 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1179 "elm,state,busy,start", "elm");
1180 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1183 double tz = wd->zoom;
1185 elm_photocam_zoom_set(wd->obj, tz);
1187 return evas_object_image_load_error_get(wd->img);
1191 elm_photocam_file_get(const Evas_Object *obj)
1193 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1194 Widget_Data *wd = elm_widget_data_get(obj);
1195 if (!wd) return NULL;
1200 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1202 ELM_CHECK_WIDTYPE(obj, widtype);
1203 Widget_Data *wd = elm_widget_data_get(obj);
1205 Grid *g, *g_zoom = NULL;
1206 Evas_Coord pw, ph, rx, ry, rw, rh;
1208 int zoom_changed = 0, started = 0;
1211 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1212 if (zoom == wd->zoom) return;
1214 wd->size.ow = wd->size.w;
1215 wd->size.oh = wd->size.h;
1216 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1217 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1218 if ((rw <= 0) || (rh <= 0)) return;
1220 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1222 wd->size.nw = (double)wd->size.imw / wd->zoom;
1223 wd->size.nh = (double)wd->size.imh / wd->zoom;
1225 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1227 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1234 ph = (wd->size.imh * rw) / wd->size.imw;
1237 pw = (wd->size.imw * rh) / wd->size.imh;
1244 if (wd->size.imw > wd->size.imh)
1245 z = wd->size.imw / pw;
1247 z = wd->size.imh / ph;
1249 else if (z >= 4) z = 4;
1250 else if (z >= 2) z = 2;
1252 if (z != wd->zoom) zoom_changed = 1;
1258 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1260 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1267 ph = (wd->size.imh * rw) / wd->size.imw;
1270 pw = (wd->size.imw * rh) / wd->size.imh;
1277 if (wd->size.imw > wd->size.imh)
1278 z = wd->size.imw / pw;
1280 z = wd->size.imh / ph;
1282 else if (z >= 4) z = 4;
1283 else if (z >= 2) z = 2;
1285 if (z != wd->zoom) zoom_changed = 1;
1291 if (wd->main_load_pending)
1293 wd->size.w = wd->size.nw;
1294 wd->size.h = wd->size.nh;
1297 EINA_LIST_FOREACH(wd->grids, l, g)
1299 if (g->zoom == grid_zoom_calc(wd->zoom))
1301 wd->grids = eina_list_remove(wd->grids, g);
1302 wd->grids = eina_list_prepend(wd->grids, g);
1307 g = grid_create(obj);
1310 if (eina_list_count(wd->grids) > 1)
1312 g_zoom = eina_list_last(wd->grids)->data;
1313 wd->grids = eina_list_remove(wd->grids, g_zoom);
1314 grid_clear(obj, g_zoom);
1316 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1321 wd->grids = eina_list_prepend(wd->grids, g);
1325 EINA_LIST_FREE(wd->grids, g)
1332 wd->t_start = ecore_loop_time_get();
1333 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1334 if ((wd->size.w > 0) && (wd->size.h > 0))
1336 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1337 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1341 wd->size.spos.x = 0.5;
1342 wd->size.spos.y = 0.5;
1344 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1345 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1346 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1347 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1354 if (!wd->zoom_animator)
1356 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1358 if (wd->nosmooth == 1) _smooth_update(obj);
1362 an = wd->zoom_animator;
1365 if (!_zoom_anim(obj))
1367 ecore_animator_del(an);
1371 if (wd->calc_job) ecore_job_del(wd->calc_job);
1372 wd->calc_job = ecore_job_add(_calc_job, wd);
1376 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1378 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1381 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1385 elm_photocam_zoom_get(const Evas_Object *obj)
1387 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1388 Widget_Data *wd = elm_widget_data_get(obj);
1389 if (!wd) return 1.0;
1394 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1396 ELM_CHECK_WIDTYPE(obj, widtype);
1397 Widget_Data *wd = elm_widget_data_get(obj);
1399 if (wd->mode == mode) return;
1402 double tz = wd->zoom;
1404 elm_photocam_zoom_set(wd->obj, tz);
1408 EAPI Elm_Photocam_Zoom_Mode
1409 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1411 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1412 Widget_Data *wd = elm_widget_data_get(obj);
1413 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1418 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1420 ELM_CHECK_WIDTYPE(obj, widtype);
1421 Widget_Data *wd = elm_widget_data_get(obj);
1423 if (w) *w = wd->size.imw;
1424 if (h) *h = wd->size.imh;
1428 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1430 ELM_CHECK_WIDTYPE(obj, widtype);
1431 Widget_Data *wd = elm_widget_data_get(obj);
1432 Evas_Coord sx, sy, sw, sh;
1434 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1435 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1440 *x = (wd->size.imw * sx) / wd->size.w;
1441 if (*x > wd->size.imw) *x = wd->size.imw;
1442 else if (*x < 0) *x = 0;
1446 *w = (wd->size.imw * sw) / wd->size.w;
1447 if (*w > wd->size.imw) *w = wd->size.imw;
1448 else if (*w < 0) *w = 0;
1461 *y = (wd->size.imh * sy) / wd->size.h;
1462 if (*y > wd->size.imh) *y = wd->size.imh;
1463 else if (*y < 0) *y = 0;
1467 *h = (wd->size.imh * sh) / wd->size.h;
1468 if (*h > wd->size.imh) *h = wd->size.imh;
1469 else if (*h < 0) *h = 0;
1480 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1482 ELM_CHECK_WIDTYPE(obj, widtype);
1483 Widget_Data *wd = elm_widget_data_get(obj);
1486 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1487 rx = (x * wd->size.w) / wd->size.imw;
1488 ry = (y * wd->size.h) / wd->size.imh;
1489 rw = (w * wd->size.w) / wd->size.imw;
1490 rh = (h * wd->size.h) / wd->size.imh;
1493 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1494 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1495 if (wd->zoom_animator)
1498 ecore_animator_del(wd->zoom_animator);
1499 wd->zoom_animator = NULL;
1501 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1503 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1507 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1509 ELM_CHECK_WIDTYPE(obj, widtype);
1510 Widget_Data *wd = elm_widget_data_get(obj);
1513 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1514 rx = (x * wd->size.w) / wd->size.imw;
1515 ry = (y * wd->size.h) / wd->size.imh;
1516 rw = (w * wd->size.w) / wd->size.imw;
1517 rh = (h * wd->size.h) / wd->size.imh;
1520 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1521 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1522 if (wd->zoom_animator)
1525 if (!wd->nosmooth) _smooth_update(obj);
1526 ecore_animator_del(wd->zoom_animator);
1527 wd->zoom_animator = NULL;
1529 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1531 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1535 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1537 ELM_CHECK_WIDTYPE(obj, widtype);
1538 Widget_Data *wd = elm_widget_data_get(obj);
1540 if (wd->paused == !!paused) return;
1541 wd->paused = paused;
1544 if (wd->zoom_animator)
1546 ecore_animator_del(wd->zoom_animator);
1547 wd->zoom_animator = NULL;
1549 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1555 elm_photocam_paused_get(const Evas_Object *obj)
1557 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1558 Widget_Data *wd = elm_widget_data_get(obj);
1559 if (!wd) return EINA_FALSE;
1564 elm_photocam_internal_image_get(const Evas_Object *obj)
1566 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1567 Widget_Data *wd = elm_widget_data_get(obj);
1568 if (!wd) return NULL;
1573 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1575 ELM_CHECK_WIDTYPE(obj, widtype);
1576 Widget_Data *wd = elm_widget_data_get(obj);
1578 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1582 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1584 ELM_CHECK_WIDTYPE(obj, widtype);
1585 Widget_Data *wd = elm_widget_data_get(obj);
1587 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);