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));
294 g->zoom = grid_zoom_calc(wd->zoom);
295 g->tsize = wd->tsize;
296 g->iw = wd->size.imw;
297 g->ih = wd->size.imh;
299 g->w = g->iw / g->zoom;
300 g->h = g->ih / g->zoom;
306 g->gw = (g->w + g->tsize - 1) / g->tsize;
307 g->gh = (g->h + g->tsize - 1) / g->tsize;
308 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
315 for (y = 0; y < g->gh; y++)
317 for (x = 0; x < g->gw; x++)
321 tn = (y * g->gw) + x;
322 g->grid[tn].src.x = x * g->tsize;
323 if (x == (g->gw - 1))
324 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
326 g->grid[tn].src.w = g->tsize;
327 g->grid[tn].src.y = y * g->tsize;
328 if (y == (g->gh - 1))
329 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
331 g->grid[tn].src.h = g->tsize;
333 g->grid[tn].out.x = g->grid[tn].src.x;
334 g->grid[tn].out.y = g->grid[tn].src.y;
335 g->grid[tn].out.w = g->grid[tn].src.w;
336 g->grid[tn].out.h = g->grid[tn].src.h;
340 evas_object_image_add(evas_object_evas_get(obj));
341 evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE);
342 evas_object_image_scale_hint_set
343 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
344 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
345 evas_object_smart_member_add(g->grid[tn].img,
347 elm_widget_sub_object_add(obj, g->grid[tn].img);
348 evas_object_image_filled_set(g->grid[tn].img, 1);
349 evas_object_event_callback_add(g->grid[tn].img,
350 EVAS_CALLBACK_IMAGE_PRELOADED,
359 grid_load(Evas_Object *obj, Grid *g)
361 Widget_Data *wd = elm_widget_data_get(obj);
363 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
365 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
366 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
369 for (y = 0; y < g->gh; y++)
371 for (x = 0; x < g->gw; x++)
373 int tn, xx, yy, ww, hh;
374 Eina_Bool visible = EINA_FALSE;
376 tn = (y * g->gw) + x;
377 xx = g->grid[tn].out.x;
378 yy = g->grid[tn].out.y;
379 ww = g->grid[tn].out.w;
380 hh = g->grid[tn].out.h;
381 if ((gw != g->w) && (g->w > 0))
384 xx = (gw * xx) / g->w;
385 ww = ((gw * (tx + ww)) / g->w) - xx;
387 if ((gh != g->h) && (g->h > 0))
390 yy = (gh * yy) / g->h;
391 hh = ((gh * (ty + hh)) / g->h) - yy;
393 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
398 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
400 g->grid[tn].want = 1;
401 evas_object_hide(g->grid[tn].img);
402 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
403 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
404 evas_object_image_load_region_set(g->grid[tn].img,
409 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
410 evas_object_image_preload(g->grid[tn].img, 0);
412 if (wd->preload_num == 1)
414 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
415 "elm,state,busy,start", "elm");
416 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
419 else if ((g->grid[tn].want) && (!visible))
422 if (!wd->preload_num)
424 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
425 "elm,state,busy,stop", "elm");
426 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
428 g->grid[tn].want = 0;
429 evas_object_hide(g->grid[tn].img);
430 evas_object_image_preload(g->grid[tn].img, 1);
431 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
433 else if ((g->grid[tn].have) && (!visible))
435 g->grid[tn].have = 0;
436 evas_object_hide(g->grid[tn].img);
437 evas_object_image_preload(g->grid[tn].img, 1);
438 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
445 grid_clearall(Evas_Object *obj)
447 Widget_Data *wd = elm_widget_data_get(obj);
450 EINA_LIST_FREE(wd->grids, g)
458 _smooth_update(Evas_Object *obj)
460 Widget_Data *wd = elm_widget_data_get(obj);
465 EINA_LIST_FOREACH(wd->grids, l, g)
467 for (y = 0; y < g->gh; y++)
469 for (x = 0; x < g->gw; x++)
473 tn = (y * g->gw) + x;
474 evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
478 evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
486 for (y = 0; y < g->gh; y++)
488 for (x = 0; x < g->gw; x++)
492 tn = (y * g->gw) + x;
493 evas_object_raise(g->grid[tn].img);
499 _scr_timeout(void *data)
501 Widget_Data *wd = elm_widget_data_get(data);
502 if (!wd) return ECORE_CALLBACK_CANCEL;
504 if (!wd->nosmooth) _smooth_update(data);
505 wd->scr_timer = NULL;
506 return ECORE_CALLBACK_CANCEL;
510 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
512 Widget_Data *wd = elm_widget_data_get(data);
517 if (wd->nosmooth == 1) _smooth_update(data);
519 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
520 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
524 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
526 Evas_Object *obj = data;
527 Widget_Data *wd = elm_widget_data_get(obj);
530 evas_object_show(wd->img);
531 wd->main_load_pending = 0;
532 g = grid_create(obj);
535 wd->grids = eina_list_prepend(wd->grids, g);
536 grid_load(wd->obj, g);
538 if (wd->calc_job) ecore_job_del(wd->calc_job);
539 wd->calc_job = ecore_job_add(_calc_job, wd);
540 evas_object_smart_callback_call(data, SIG_LOADED, NULL);
542 if (!wd->preload_num)
544 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
545 "elm,state,busy,stop", "elm");
546 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
551 zoom_do(Evas_Object *obj, double t)
553 Widget_Data *wd = elm_widget_data_get(obj);
554 Evas_Coord xx, yy, ow, oh;
555 if (!wd) return ECORE_CALLBACK_CANCEL;
556 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
557 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
558 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
559 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
560 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
562 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
564 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
566 wd->show.show = EINA_TRUE;
572 if (wd->calc_job) ecore_job_del(wd->calc_job);
573 wd->calc_job = ecore_job_add(_calc_job, wd);
576 Eina_List *l, *l_next;
579 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
583 wd->grids = eina_list_remove_list(wd->grids, l);
588 return ECORE_CALLBACK_CANCEL;
590 return ECORE_CALLBACK_RENEW;
595 _zoom_anim(void *data)
597 Evas_Object *obj = data;
598 Widget_Data *wd = elm_widget_data_get(obj);
601 if (!wd) return ECORE_CALLBACK_CANCEL;
602 t = ecore_loop_time_get();
605 else if (wd->t_end > wd->t_start)
606 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
611 go = zoom_do(obj, t);
615 if (!wd->nosmooth) _smooth_update(data);
616 wd->zoom_animator = NULL;
617 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
623 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
625 Widget_Data *wd = elm_widget_data_get(data);
626 // Evas_Event_Mouse_Move *ev = event_info;
631 _long_press(void *data)
633 Widget_Data *wd = elm_widget_data_get(data);
634 if (!wd) return ECORE_CALLBACK_CANCEL;
635 wd->long_timer = NULL;
636 wd->longpressed = EINA_TRUE;
637 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
638 return ECORE_CALLBACK_CANCEL;
642 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
644 Widget_Data *wd = elm_widget_data_get(data);
645 Evas_Event_Mouse_Down *ev = event_info;
647 if (ev->button != 1) return;
648 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
649 else wd->on_hold = EINA_FALSE;
650 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
651 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
653 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
654 wd->longpressed = EINA_FALSE;
655 if (wd->long_timer) ecore_timer_del(wd->long_timer);
656 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
660 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
662 Widget_Data *wd = elm_widget_data_get(data);
663 Evas_Event_Mouse_Up *ev = event_info;
665 if (ev->button != 1) return;
666 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
667 else wd->on_hold = EINA_FALSE;
670 ecore_timer_del(wd->long_timer);
671 wd->long_timer = NULL;
674 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
675 wd->on_hold = EINA_FALSE;
678 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
681 _del_hook(Evas_Object *obj)
683 Widget_Data *wd = elm_widget_data_get(obj);
686 EINA_LIST_FREE(wd->grids, g)
688 if (g->grid) free(g->grid);
691 evas_object_del(wd->pan_smart);
692 wd->pan_smart = NULL;
693 if (wd->file) eina_stringshare_del(wd->file);
694 if (wd->calc_job) ecore_job_del(wd->calc_job);
695 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
696 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
697 if (wd->long_timer) ecore_timer_del(wd->long_timer);
702 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
704 Widget_Data *wd = elm_widget_data_get(obj);
706 if (elm_widget_focus_get(obj))
708 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
709 evas_object_focus_set(wd->obj, EINA_TRUE);
713 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
714 evas_object_focus_set(wd->obj, EINA_FALSE);
719 _theme_hook(Evas_Object *obj)
721 Widget_Data *wd = elm_widget_data_get(obj);
723 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
724 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
730 _show_region_hook(void *data, Evas_Object *obj)
732 Widget_Data *wd = elm_widget_data_get(data);
733 Evas_Coord x, y, w, h;
735 elm_widget_show_region_get(obj, &x, &y, &w, &h);
736 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
741 _sizing_eval(Evas_Object *obj)
743 Widget_Data *wd = elm_widget_data_get(obj);
744 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
746 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
747 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
750 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
751 evas_object_size_hint_min_set(obj, minw, minh);
752 evas_object_size_hint_max_set(obj, maxw, maxh);
756 _calc_job(void *data)
758 Widget_Data *wd = data;
759 Evas_Coord minw, minh;
766 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
768 double tz = wd->zoom;
770 elm_photocam_zoom_set(wd->obj, tz);
773 if ((minw != wd->minw) || (minh != wd->minh))
777 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
778 _sizing_eval(wd->obj);
781 evas_object_smart_changed(wd->pan_smart);
785 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
787 Pan *sd = evas_object_smart_data_get(obj);
789 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
792 evas_object_smart_changed(obj);
796 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
798 Pan *sd = evas_object_smart_data_get(obj);
800 if (x) *x = sd->wd->pan_x;
801 if (y) *y = sd->wd->pan_y;
805 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
807 Pan *sd = evas_object_smart_data_get(obj);
810 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
811 ow = sd->wd->minw - ow;
813 oh = sd->wd->minh - oh;
820 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
827 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
829 Pan *sd = evas_object_smart_data_get(obj);
831 if (w) *w = sd->wd->minw;
832 if (h) *h = sd->wd->minh;
836 _pan_add(Evas_Object *obj)
839 Evas_Object_Smart_Clipped_Data *cd;
841 cd = evas_object_smart_data_get(obj);
843 sd = calloc(1, sizeof(Pan));
845 sd->__clipped_data = *cd;
847 evas_object_smart_data_set(obj, sd);
851 _pan_del(Evas_Object *obj)
853 Pan *sd = evas_object_smart_data_get(obj);
859 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
861 Pan *sd = evas_object_smart_data_get(obj);
864 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
865 if ((ow == w) && (oh == h)) return;
867 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
868 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
872 _pan_calculate(Evas_Object *obj)
874 Pan *sd = evas_object_smart_data_get(obj);
875 Evas_Coord ox, oy, ow, oh;
879 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
880 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
881 EINA_LIST_FOREACH(sd->wd->grids, l, g)
883 grid_load(sd->wd->obj, g);
884 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
889 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
891 Pan *sd = evas_object_smart_data_get(obj);
893 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
894 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
898 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
900 Widget_Data *wd = elm_widget_data_get(obj);
902 elm_smart_scroller_hold_set(wd->scr, 1);
906 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
908 Widget_Data *wd = elm_widget_data_get(obj);
910 elm_smart_scroller_hold_set(wd->scr, 0);
914 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
916 Widget_Data *wd = elm_widget_data_get(obj);
918 elm_smart_scroller_freeze_set(wd->scr, 1);
922 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
924 Widget_Data *wd = elm_widget_data_get(obj);
926 elm_smart_scroller_freeze_set(wd->scr, 0);
930 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
932 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
936 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
938 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
942 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
944 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
948 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
950 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
954 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
956 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
960 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
961 Evas_Callback_Type type, void *event_info)
964 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
965 Evas_Event_Key_Down *ev = event_info;
966 Widget_Data *wd = elm_widget_data_get(obj);
967 if (!wd) return EINA_FALSE;
968 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
972 Evas_Coord step_x = 0;
973 Evas_Coord step_y = 0;
976 Evas_Coord page_x = 0;
977 Evas_Coord page_y = 0;
979 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
980 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
981 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
982 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
984 if ((!strcmp(ev->keyname, "Left")) ||
985 (!strcmp(ev->keyname, "KP_Left")))
989 else if ((!strcmp(ev->keyname, "Right")) ||
990 (!strcmp(ev->keyname, "KP_Right")))
994 else if ((!strcmp(ev->keyname, "Up")) ||
995 (!strcmp(ev->keyname, "KP_Up")))
999 else if ((!strcmp(ev->keyname, "Down")) ||
1000 (!strcmp(ev->keyname, "KP_Down")))
1004 else if ((!strcmp(ev->keyname, "Prior")) ||
1005 (!strcmp(ev->keyname, "KP_Prior")))
1008 y -= -(page_y * v_h) / 100;
1012 else if ((!strcmp(ev->keyname, "Next")) ||
1013 (!strcmp(ev->keyname, "KP_Next")))
1016 y += -(page_y * v_h) / 100;
1020 else if ((!strcmp(ev->keyname, "KP_Add")))
1022 zoom = elm_photocam_zoom_get(obj);
1024 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1025 elm_photocam_zoom_set(obj, zoom);
1028 else if ((!strcmp(ev->keyname, "KP_Subtract")))
1030 zoom = elm_photocam_zoom_get(obj);
1032 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1033 elm_photocam_zoom_set(obj, zoom);
1036 else return EINA_FALSE;
1038 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1039 elm_smart_scroller_child_pos_set(wd->scr, x, y);
1045 elm_photocam_add(Evas_Object *parent)
1050 Evas_Coord minw, minh;
1051 static Evas_Smart *smart = NULL;
1052 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1054 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1056 ELM_SET_WIDTYPE(widtype, "photocam");
1057 elm_widget_type_set(obj, "photocam");
1058 elm_widget_sub_object_add(parent, obj);
1059 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1060 elm_widget_data_set(obj, wd);
1061 elm_widget_del_hook_set(obj, _del_hook);
1062 elm_widget_theme_hook_set(obj, _theme_hook);
1063 elm_widget_can_focus_set(obj, EINA_TRUE);
1064 elm_widget_event_hook_set(obj, _event_hook);
1066 wd->scr = elm_smart_scroller_add(e);
1067 elm_smart_scroller_widget_set(wd->scr, obj);
1068 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
1069 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
1070 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
1071 elm_widget_resize_object_set(obj, wd->scr);
1073 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1074 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1075 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1076 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1077 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1079 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1083 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1084 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1085 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1086 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1090 static Evas_Smart_Class sc;
1092 evas_object_smart_clipped_smart_set(&_pan_sc);
1094 sc.name = "elm_photocam_pan";
1095 sc.version = EVAS_SMART_CLASS_VERSION;
1098 sc.resize = _pan_resize;
1099 sc.move = _pan_move;
1100 sc.calculate = _pan_calculate;
1101 smart = evas_smart_class_new(&sc);
1105 wd->pan_smart = evas_object_smart_add(e, smart);
1106 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1110 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1111 _pan_set, _pan_get, _pan_max_get,
1112 _pan_min_get, _pan_child_size_get);
1115 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1119 wd->img = evas_object_image_add(e);
1120 evas_object_image_load_orientation_set(wd->img, EINA_TRUE);
1121 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1122 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1124 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1126 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1128 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1129 evas_object_smart_member_add(wd->img, wd->pan_smart);
1130 elm_widget_sub_object_add(obj, wd->img);
1131 evas_object_image_filled_set(wd->img, 1);
1132 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1133 _main_preloaded, obj);
1135 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1137 evas_object_size_hint_min_set(obj, minw, minh);
1139 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1145 EAPI Evas_Load_Error
1146 elm_photocam_file_set(Evas_Object *obj, const char *file)
1148 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1149 Widget_Data *wd = elm_widget_data_get(obj);
1151 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1152 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1155 evas_object_hide(wd->img);
1156 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1157 evas_object_image_file_set(wd->img, NULL, NULL);
1158 evas_object_image_load_scale_down_set(wd->img, 0);
1159 evas_object_image_file_set(wd->img, wd->file, NULL);
1160 evas_object_image_size_get(wd->img, &w, &h);
1163 wd->size.w = wd->size.imw / wd->zoom;
1164 wd->size.h = wd->size.imh / wd->zoom;
1165 if (wd->zoom_animator)
1168 if (wd->nosmooth == 0) _smooth_update(obj);
1169 ecore_animator_del(wd->zoom_animator);
1170 wd->zoom_animator = NULL;
1172 evas_object_image_file_set(wd->img, NULL, NULL);
1173 evas_object_image_load_scale_down_set(wd->img, 8);
1174 evas_object_image_file_set(wd->img, wd->file, NULL);
1175 evas_object_image_preload(wd->img, 0);
1176 wd->main_load_pending = 1;
1177 if (wd->calc_job) ecore_job_del(wd->calc_job);
1178 wd->calc_job = ecore_job_add(_calc_job, wd);
1179 evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1181 if (wd->preload_num == 1)
1183 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1184 "elm,state,busy,start", "elm");
1185 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1188 double tz = wd->zoom;
1190 elm_photocam_zoom_set(wd->obj, tz);
1192 return evas_object_image_load_error_get(wd->img);
1196 elm_photocam_file_get(const Evas_Object *obj)
1198 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1199 Widget_Data *wd = elm_widget_data_get(obj);
1200 if (!wd) return NULL;
1205 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1207 ELM_CHECK_WIDTYPE(obj, widtype);
1208 Widget_Data *wd = elm_widget_data_get(obj);
1210 Grid *g, *g_zoom = NULL;
1211 Evas_Coord pw, ph, rx, ry, rw, rh;
1213 int zoom_changed = 0, started = 0;
1216 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1217 if (zoom == wd->zoom) return;
1219 wd->size.ow = wd->size.w;
1220 wd->size.oh = wd->size.h;
1221 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1222 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1223 if ((rw <= 0) || (rh <= 0)) return;
1225 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1227 wd->size.nw = (double)wd->size.imw / wd->zoom;
1228 wd->size.nh = (double)wd->size.imh / wd->zoom;
1230 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1232 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1239 ph = (wd->size.imh * rw) / wd->size.imw;
1242 pw = (wd->size.imw * rh) / wd->size.imh;
1249 if (wd->size.imw > wd->size.imh)
1250 z = wd->size.imw / pw;
1252 z = wd->size.imh / ph;
1254 else if (z >= 4) z = 4;
1255 else if (z >= 2) z = 2;
1257 if (z != wd->zoom) zoom_changed = 1;
1263 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1265 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1272 ph = (wd->size.imh * rw) / wd->size.imw;
1275 pw = (wd->size.imw * rh) / wd->size.imh;
1282 if (wd->size.imw > wd->size.imh)
1283 z = wd->size.imw / pw;
1285 z = wd->size.imh / ph;
1287 else if (z >= 4) z = 4;
1288 else if (z >= 2) z = 2;
1290 if (z != wd->zoom) zoom_changed = 1;
1296 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN)
1298 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1303 else if ((wd->size.imw < rw) && (wd->size.imh < rh))
1305 if (1 != wd->zoom) zoom_changed = 1;
1307 wd->size.nw = wd->size.imw;
1308 wd->size.nh = wd->size.imh;
1312 ph = (wd->size.imh * rw) / wd->size.imw;
1315 pw = (wd->size.imw * rh) / wd->size.imh;
1320 if (wd->size.imw > wd->size.imh)
1321 z = wd->size.imw / pw;
1323 z = wd->size.imh / ph;
1324 if (z != wd->zoom) zoom_changed = 1;
1330 if (wd->main_load_pending)
1332 wd->size.w = wd->size.nw;
1333 wd->size.h = wd->size.nh;
1336 EINA_LIST_FOREACH(wd->grids, l, g)
1338 if (g->zoom == grid_zoom_calc(wd->zoom))
1340 wd->grids = eina_list_remove(wd->grids, g);
1341 wd->grids = eina_list_prepend(wd->grids, g);
1346 g = grid_create(obj);
1349 if (eina_list_count(wd->grids) > 1)
1351 g_zoom = eina_list_last(wd->grids)->data;
1352 wd->grids = eina_list_remove(wd->grids, g_zoom);
1353 grid_clear(obj, g_zoom);
1355 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1360 wd->grids = eina_list_prepend(wd->grids, g);
1364 EINA_LIST_FREE(wd->grids, g)
1371 wd->t_start = ecore_loop_time_get();
1372 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1373 if ((wd->size.w > 0) && (wd->size.h > 0))
1375 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1376 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1380 wd->size.spos.x = 0.5;
1381 wd->size.spos.y = 0.5;
1383 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1384 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1385 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1386 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1393 if (!wd->zoom_animator)
1395 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1397 if (wd->nosmooth == 1) _smooth_update(obj);
1401 an = wd->zoom_animator;
1404 if (!_zoom_anim(obj))
1406 ecore_animator_del(an);
1410 if (wd->calc_job) ecore_job_del(wd->calc_job);
1411 wd->calc_job = ecore_job_add(_calc_job, wd);
1415 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1417 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1420 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1424 elm_photocam_zoom_get(const Evas_Object *obj)
1426 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1427 Widget_Data *wd = elm_widget_data_get(obj);
1428 if (!wd) return 1.0;
1433 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1435 ELM_CHECK_WIDTYPE(obj, widtype);
1436 Widget_Data *wd = elm_widget_data_get(obj);
1438 if (wd->mode == mode) return;
1441 double tz = wd->zoom;
1443 elm_photocam_zoom_set(wd->obj, tz);
1447 EAPI Elm_Photocam_Zoom_Mode
1448 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1450 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1451 Widget_Data *wd = elm_widget_data_get(obj);
1452 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1457 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1459 ELM_CHECK_WIDTYPE(obj, widtype);
1460 Widget_Data *wd = elm_widget_data_get(obj);
1462 if (w) *w = wd->size.imw;
1463 if (h) *h = wd->size.imh;
1467 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1469 ELM_CHECK_WIDTYPE(obj, widtype);
1470 Widget_Data *wd = elm_widget_data_get(obj);
1471 Evas_Coord sx, sy, sw, sh;
1473 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1474 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1479 *x = (wd->size.imw * sx) / wd->size.w;
1480 if (*x > wd->size.imw) *x = wd->size.imw;
1481 else if (*x < 0) *x = 0;
1485 *w = (wd->size.imw * sw) / wd->size.w;
1486 if (*w > wd->size.imw) *w = wd->size.imw;
1487 else if (*w < 0) *w = 0;
1500 *y = (wd->size.imh * sy) / wd->size.h;
1501 if (*y > wd->size.imh) *y = wd->size.imh;
1502 else if (*y < 0) *y = 0;
1506 *h = (wd->size.imh * sh) / wd->size.h;
1507 if (*h > wd->size.imh) *h = wd->size.imh;
1508 else if (*h < 0) *h = 0;
1519 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1521 ELM_CHECK_WIDTYPE(obj, widtype);
1522 Widget_Data *wd = elm_widget_data_get(obj);
1525 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1526 rx = (x * wd->size.w) / wd->size.imw;
1527 ry = (y * wd->size.h) / wd->size.imh;
1528 rw = (w * wd->size.w) / wd->size.imw;
1529 rh = (h * wd->size.h) / wd->size.imh;
1532 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1533 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1534 if (wd->zoom_animator)
1537 ecore_animator_del(wd->zoom_animator);
1538 wd->zoom_animator = NULL;
1540 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1542 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1546 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1548 ELM_CHECK_WIDTYPE(obj, widtype);
1549 Widget_Data *wd = elm_widget_data_get(obj);
1552 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1553 rx = (x * wd->size.w) / wd->size.imw;
1554 ry = (y * wd->size.h) / wd->size.imh;
1555 rw = (w * wd->size.w) / wd->size.imw;
1556 rh = (h * wd->size.h) / wd->size.imh;
1559 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1560 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1561 if (wd->zoom_animator)
1564 if (!wd->nosmooth) _smooth_update(obj);
1565 ecore_animator_del(wd->zoom_animator);
1566 wd->zoom_animator = NULL;
1568 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1570 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1574 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1576 ELM_CHECK_WIDTYPE(obj, widtype);
1577 Widget_Data *wd = elm_widget_data_get(obj);
1579 if (wd->paused == !!paused) return;
1580 wd->paused = paused;
1583 if (wd->zoom_animator)
1585 ecore_animator_del(wd->zoom_animator);
1586 wd->zoom_animator = NULL;
1588 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1594 elm_photocam_paused_get(const Evas_Object *obj)
1596 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1597 Widget_Data *wd = elm_widget_data_get(obj);
1598 if (!wd) return EINA_FALSE;
1603 elm_photocam_internal_image_get(const Evas_Object *obj)
1605 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1606 Widget_Data *wd = elm_widget_data_get(obj);
1607 if (!wd) return NULL;
1612 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1614 ELM_CHECK_WIDTYPE(obj, widtype);
1615 Widget_Data *wd = elm_widget_data_get(obj);
1617 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1621 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1623 ELM_CHECK_WIDTYPE(obj, widtype);
1624 Widget_Data *wd = elm_widget_data_get(obj);
1626 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);