1 #include <Elementary.h>
5 * @defgroup Photocam Photocam
8 * This is a widget specifically for displaying high-resolution digital
9 * camera photos giving speedy feedback (fast load), low memory footprint
10 * and zooming and panning as well as fitting logic. It is entirely focused
11 * on jpeg images, and takes advantage of properties of the jpeg format (via
12 * evas loader features in the jpeg loader).
14 * Signals that you can add callbacks for are:
16 * clicked - This is called when a user has clicked the photo without dragging
19 * press - This is called when a user has pressed down on the photo.
21 * longpressed - This is called when a user has pressed down on the photo for
22 * a long time without dragging around.
24 * clicked,double - This is called when a user has double-clicked the photo.
26 * load - Photo load begins.
28 * loaded - This is called when the image file load is complete for the first
29 * view (low resolution blurry version).
31 * load,details - Photo detailed data load begins.
33 * loaded,details - This is called when the image file load is complete for the
34 * detailed image data (full resolution needed).
36 * zoom,start - Zoom animation started.
38 * zoom,stop - Zoom animation stopped.
40 * zoom,change - Zoom changed when using an auto zoom mode.
42 * scroll - the content has been scrolled (moved)
44 * scroll,anim,start - scrolling animation has started
46 * scroll,anim,stop - scrolling animation has stopped
48 * scroll,drag,start - dragging the contents around has started
50 * scroll,drag,stop - dragging the contents around has stopped
54 * TODO (maybe - optional future stuff):
56 * 1. wrap photo in theme edje so u can have styling around photo (like white
59 * 3. rotation flags in exif handling (nasty! should have rot in evas)
62 typedef struct _Widget_Data Widget_Data;
63 typedef struct _Pan Pan;
64 typedef struct _Grid Grid;
65 typedef struct _Grid_Item Grid_Item;
81 int tsize; // size of tile (tsize x tsize pixels)
82 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
83 int iw, ih; // size of image in pixels
84 int w, h; // size of grid image in pixels (represented by grid)
85 int gw, gh; // size of grid in tiles
86 Grid_Item *grid; // the grid (gw * gh items)
87 Eina_Bool dead : 1; // old grid. will die as soon as anim is over
94 Evas_Object *pan_smart;
96 Evas_Coord pan_x, pan_y, minw, minh;
99 Elm_Photocam_Zoom_Mode mode;
103 Ecore_Timer *scr_timer;
104 Ecore_Timer *long_timer;
105 Ecore_Animator *zoom_animator;
106 double t_start, t_end;
120 Evas_Coord x, y ,w ,h;
123 Evas_Object *img; // low res version of image (scale down == 8)
127 Eina_Bool main_load_pending : 1;
128 Eina_Bool resized : 1;
129 Eina_Bool longpressed : 1;
130 Eina_Bool on_hold : 1;
131 Eina_Bool paused : 1;
136 Evas_Object_Smart_Clipped_Data __clipped_data;
140 static const char *widtype = NULL;
141 static void _del_hook(Evas_Object *obj);
142 static void _theme_hook(Evas_Object *obj);
143 static void _on_focus_hook(void *data, Evas_Object *obj);
144 //static void _show_region_hook(void *data, Evas_Object *obj);
145 static void _sizing_eval(Evas_Object *obj);
146 static void _calc_job(void *data);
147 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);
148 static void grid_clear(Evas_Object *obj, Grid *g);
149 static Grid *grid_create(Evas_Object *obj);
150 static void grid_load(Evas_Object *obj, Grid *g);
153 nearest_pow2(int num)
155 unsigned int n = num - 1;
165 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
167 Widget_Data *wd = elm_widget_data_get(obj);
168 Evas_Coord ax, ay, gw, gh;
174 if (ow > gw) ax = (ow - gw) / 2;
175 if (oh > gh) ay = (oh - gh) / 2;
176 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
177 evas_object_resize(wd->img, gw, gh);
181 wd->show.show = EINA_FALSE;
182 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
187 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)
189 Widget_Data *wd = elm_widget_data_get(obj);
190 Evas_Coord ax, ay, gw, gh, tx, ty;
197 if (ow > gw) ax = (ow - gw) / 2;
198 if (oh > gh) ay = (oh - gh) / 2;
199 for (y = 0; y < g->gh; y++)
201 for (x = 0; x < g->gw; x++)
203 int tn, xx, yy, ww, hh;
205 tn = (y * g->gw) + x;
206 xx = g->grid[tn].out.x;
207 yy = g->grid[tn].out.y;
208 ww = g->grid[tn].out.w;
209 hh = g->grid[tn].out.h;
210 if ((gw != g->w) && (g->w > 0))
213 xx = (gw * xx) / g->w;
214 ww = ((gw * (tx + ww)) / g->w) - xx;
216 if ((gh != g->h) && (g->h > 0))
219 yy = (gh * yy) / g->h;
220 hh = ((gh * (ty + hh)) / g->h) - yy;
222 evas_object_move(g->grid[tn].img,
225 evas_object_resize(g->grid[tn].img, ww, hh);
231 grid_clear(Evas_Object *obj, Grid *g)
233 Widget_Data *wd = elm_widget_data_get(obj);
236 if (!g->grid) return;
237 for (y = 0; y < g->gh; y++)
239 for (x = 0; x < g->gw; x++)
243 tn = (y * g->gw) + x;
244 evas_object_del(g->grid[tn].img);
245 if (g->grid[tn].want)
248 if (!wd->preload_num)
250 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
251 "elm,state,busy,stop", "elm");
252 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
264 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
266 Grid_Item *git = data;
271 evas_object_show(git->img);
273 git->wd->preload_num--;
274 if (!git->wd->preload_num)
276 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
277 "elm,state,busy,stop", "elm");
278 evas_object_smart_callback_call(git->wd->obj, "loaded,detail", NULL);
284 grid_zoom_calc(double zoom)
288 return nearest_pow2(z);
292 grid_create(Evas_Object *obj)
294 Widget_Data *wd = elm_widget_data_get(obj);
298 if (!wd) return NULL;
299 g = calloc(1, sizeof(Grid));
301 g->zoom = grid_zoom_calc(wd->zoom);
302 g->tsize = wd->tsize;
303 g->iw = wd->size.imw;
304 g->ih = wd->size.imh;
306 g->w = g->iw / g->zoom;
307 g->h = g->ih / g->zoom;
308 if (g->zoom >= 8) return NULL;
309 g->gw = (g->w + g->tsize - 1) / g->tsize;
310 g->gh = (g->h + g->tsize - 1) / g->tsize;
311 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
318 for (y = 0; y < g->gh; y++)
320 for (x = 0; x < g->gw; x++)
324 tn = (y * g->gw) + x;
325 g->grid[tn].src.x = x * g->tsize;
326 if (x == (g->gw - 1))
327 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
329 g->grid[tn].src.w = g->tsize;
330 g->grid[tn].src.y = y * g->tsize;
331 if (y == (g->gh - 1))
332 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
334 g->grid[tn].src.h = g->tsize;
336 g->grid[tn].out.x = g->grid[tn].src.x;
337 g->grid[tn].out.y = g->grid[tn].src.y;
338 g->grid[tn].out.w = g->grid[tn].src.w;
339 g->grid[tn].out.h = g->grid[tn].src.h;
343 evas_object_image_add(evas_object_evas_get(obj));
344 evas_object_image_scale_hint_set
345 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
346 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
347 evas_object_smart_member_add(g->grid[tn].img,
349 elm_widget_sub_object_add(obj, g->grid[tn].img);
350 evas_object_image_filled_set(g->grid[tn].img, 1);
351 evas_object_event_callback_add(g->grid[tn].img,
352 EVAS_CALLBACK_IMAGE_PRELOADED,
361 grid_load(Evas_Object *obj, Grid *g)
363 Widget_Data *wd = elm_widget_data_get(obj);
365 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
367 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
368 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
371 for (y = 0; y < g->gh; y++)
373 for (x = 0; x < g->gw; x++)
375 int tn, xx, yy, ww, hh;
376 Eina_Bool visible = EINA_FALSE;
378 tn = (y * g->gw) + x;
379 xx = g->grid[tn].out.x;
380 yy = g->grid[tn].out.y;
381 ww = g->grid[tn].out.w;
382 hh = g->grid[tn].out.h;
383 if ((gw != g->w) && (g->w > 0))
386 xx = (gw * xx) / g->w;
387 ww = ((gw * (tx + ww)) / g->w) - xx;
389 if ((gh != g->h) && (g->h > 0))
392 yy = (gh * yy) / g->h;
393 hh = ((gh * (ty + hh)) / g->h) - yy;
395 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
400 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
402 g->grid[tn].want = 1;
403 evas_object_hide(g->grid[tn].img);
404 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
405 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
406 evas_object_image_load_region_set(g->grid[tn].img,
411 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
412 evas_object_image_preload(g->grid[tn].img, 0);
414 if (wd->preload_num == 1)
416 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
417 "elm,state,busy,start", "elm");
418 evas_object_smart_callback_call(obj, "load,detail", NULL);
421 else if ((g->grid[tn].want) && (!visible))
424 if (!wd->preload_num)
426 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
427 "elm,state,busy,stop", "elm");
428 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
430 g->grid[tn].want = 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);
435 else if ((g->grid[tn].have) && (!visible))
437 g->grid[tn].have = 0;
438 evas_object_hide(g->grid[tn].img);
439 evas_object_image_preload(g->grid[tn].img, 1);
440 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
447 grid_clearall(Evas_Object *obj)
449 Widget_Data *wd = elm_widget_data_get(obj);
452 EINA_LIST_FREE(wd->grids, g)
460 _smooth_update(Evas_Object *obj)
462 Widget_Data *wd = elm_widget_data_get(obj);
467 EINA_LIST_FOREACH(wd->grids, l, g)
469 for (y = 0; y < g->gh; y++)
471 for (x = 0; x < g->gw; x++)
475 tn = (y * g->gw) + x;
476 evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
480 evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
488 for (y = 0; y < g->gh; y++)
490 for (x = 0; x < g->gw; x++)
494 tn = (y * g->gw) + x;
495 evas_object_raise(g->grid[tn].img);
501 _scr_timeout(void *data)
503 Widget_Data *wd = elm_widget_data_get(data);
504 if (!wd) return ECORE_CALLBACK_CANCEL;
506 if (!wd->nosmooth) _smooth_update(data);
507 wd->scr_timer = NULL;
508 return ECORE_CALLBACK_CANCEL;
512 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
514 Widget_Data *wd = elm_widget_data_get(data);
519 if (wd->nosmooth == 1) _smooth_update(data);
521 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
522 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
526 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
528 Evas_Object *obj = data;
529 Widget_Data *wd = elm_widget_data_get(obj);
532 evas_object_show(wd->img);
533 wd->main_load_pending = 0;
534 g = grid_create(obj);
537 wd->grids = eina_list_prepend(wd->grids, g);
538 grid_load(wd->obj, g);
540 if (wd->calc_job) ecore_job_del(wd->calc_job);
541 wd->calc_job = ecore_job_add(_calc_job, wd);
542 evas_object_smart_callback_call(data, "loaded", NULL);
544 if (!wd->preload_num)
546 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
547 "elm,state,busy,stop", "elm");
548 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
553 zoom_do(Evas_Object *obj, double t)
555 Widget_Data *wd = elm_widget_data_get(obj);
556 Evas_Coord xx, yy, ow, oh;
557 if (!wd) return ECORE_CALLBACK_CANCEL;
558 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
559 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
560 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
561 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
562 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
564 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
566 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
568 wd->show.show = EINA_TRUE;
574 if (wd->calc_job) ecore_job_del(wd->calc_job);
575 wd->calc_job = ecore_job_add(_calc_job, wd);
578 Eina_List *l, *l_next;
581 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
585 wd->grids = eina_list_remove_list(wd->grids, l);
590 return ECORE_CALLBACK_CANCEL;
592 return ECORE_CALLBACK_RENEW;
597 _zoom_anim(void *data)
599 Evas_Object *obj = data;
600 Widget_Data *wd = elm_widget_data_get(obj);
603 if (!wd) return ECORE_CALLBACK_CANCEL;
604 t = ecore_loop_time_get();
607 else if (wd->t_end > wd->t_start)
608 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
613 go = zoom_do(obj, t);
617 if (!wd->nosmooth) _smooth_update(data);
618 wd->zoom_animator = NULL;
619 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
625 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
627 Widget_Data *wd = elm_widget_data_get(data);
628 // Evas_Event_Mouse_Move *ev = event_info;
633 _long_press(void *data)
635 Widget_Data *wd = elm_widget_data_get(data);
636 if (!wd) return ECORE_CALLBACK_CANCEL;
637 wd->long_timer = NULL;
638 wd->longpressed = EINA_TRUE;
639 evas_object_smart_callback_call(data, "longpressed", NULL);
640 return ECORE_CALLBACK_CANCEL;
644 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
646 Widget_Data *wd = elm_widget_data_get(data);
647 Evas_Event_Mouse_Down *ev = event_info;
649 if (ev->button != 1) return;
650 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
651 else wd->on_hold = EINA_FALSE;
652 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
653 evas_object_smart_callback_call(data, "clicked,double", NULL);
655 evas_object_smart_callback_call(data, "press", NULL);
656 wd->longpressed = EINA_FALSE;
657 if (wd->long_timer) ecore_timer_del(wd->long_timer);
658 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
662 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
664 Widget_Data *wd = elm_widget_data_get(data);
665 Evas_Event_Mouse_Up *ev = event_info;
667 if (ev->button != 1) return;
668 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
669 else wd->on_hold = EINA_FALSE;
672 ecore_timer_del(wd->long_timer);
673 wd->long_timer = NULL;
676 evas_object_smart_callback_call(data, "clicked", NULL);
677 wd->on_hold = EINA_FALSE;
680 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
683 _del_hook(Evas_Object *obj)
685 Widget_Data *wd = elm_widget_data_get(obj);
688 EINA_LIST_FREE(wd->grids, g)
690 if (g->grid) free(g->grid);
693 evas_object_del(wd->pan_smart);
694 wd->pan_smart = NULL;
695 if (wd->file) eina_stringshare_del(wd->file);
696 if (wd->calc_job) ecore_job_del(wd->calc_job);
697 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
698 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
699 if (wd->long_timer) ecore_timer_del(wd->long_timer);
704 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
706 Widget_Data *wd = elm_widget_data_get(obj);
708 if (elm_widget_focus_get(obj))
710 edje_object_signal_emit(wd->obj, "elm,action,focus", "elm");
711 evas_object_focus_set(wd->obj, EINA_TRUE);
715 edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
716 evas_object_focus_set(wd->obj, EINA_FALSE);
721 _theme_hook(Evas_Object *obj)
723 Widget_Data *wd = elm_widget_data_get(obj);
725 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
726 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
732 _show_region_hook(void *data, Evas_Object *obj)
734 Widget_Data *wd = elm_widget_data_get(data);
735 Evas_Coord x, y, w, h;
737 elm_widget_show_region_get(obj, &x, &y, &w, &h);
738 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
743 _sizing_eval(Evas_Object *obj)
745 Widget_Data *wd = elm_widget_data_get(obj);
746 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
748 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
749 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
752 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
753 evas_object_size_hint_min_set(obj, minw, minh);
754 evas_object_size_hint_max_set(obj, maxw, maxh);
758 _calc_job(void *data)
760 Widget_Data *wd = data;
761 Evas_Coord minw, minh;
768 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
770 double tz = wd->zoom;
772 elm_photocam_zoom_set(wd->obj, tz);
775 if ((minw != wd->minw) || (minh != wd->minh))
779 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
780 _sizing_eval(wd->obj);
783 evas_object_smart_changed(wd->pan_smart);
787 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
789 Pan *sd = evas_object_smart_data_get(obj);
791 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
794 evas_object_smart_changed(obj);
798 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
800 Pan *sd = evas_object_smart_data_get(obj);
802 if (x) *x = sd->wd->pan_x;
803 if (y) *y = sd->wd->pan_y;
807 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
809 Pan *sd = evas_object_smart_data_get(obj);
812 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
813 ow = sd->wd->minw - ow;
815 oh = sd->wd->minh - oh;
822 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
829 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
831 Pan *sd = evas_object_smart_data_get(obj);
833 if (w) *w = sd->wd->minw;
834 if (h) *h = sd->wd->minh;
838 _pan_add(Evas_Object *obj)
841 Evas_Object_Smart_Clipped_Data *cd;
843 cd = evas_object_smart_data_get(obj);
845 sd = calloc(1, sizeof(Pan));
847 sd->__clipped_data = *cd;
849 evas_object_smart_data_set(obj, sd);
853 _pan_del(Evas_Object *obj)
855 Pan *sd = evas_object_smart_data_get(obj);
861 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
863 Pan *sd = evas_object_smart_data_get(obj);
866 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
867 if ((ow == w) && (oh == h)) return;
869 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
870 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
874 _pan_calculate(Evas_Object *obj)
876 Pan *sd = evas_object_smart_data_get(obj);
877 Evas_Coord ox, oy, ow, oh;
881 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
882 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
883 EINA_LIST_FOREACH(sd->wd->grids, l, g)
885 grid_load(sd->wd->obj, g);
886 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
891 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
893 Pan *sd = evas_object_smart_data_get(obj);
895 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
896 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
900 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
902 Widget_Data *wd = elm_widget_data_get(obj);
904 elm_smart_scroller_hold_set(wd->scr, 1);
908 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
910 Widget_Data *wd = elm_widget_data_get(obj);
912 elm_smart_scroller_hold_set(wd->scr, 0);
916 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
918 Widget_Data *wd = elm_widget_data_get(obj);
920 elm_smart_scroller_freeze_set(wd->scr, 1);
924 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
926 Widget_Data *wd = elm_widget_data_get(obj);
928 elm_smart_scroller_freeze_set(wd->scr, 0);
932 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
934 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
938 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
940 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
944 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
946 evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
950 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
952 evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
956 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
958 evas_object_smart_callback_call(data, "scroll", NULL);
962 * Add a new Photocam object
964 * @param parent The parent object
965 * @return The new object or NULL if it cannot be created
970 elm_photocam_add(Evas_Object *parent)
975 Evas_Coord minw, minh;
976 static Evas_Smart *smart = NULL;
977 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
979 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
981 wd = ELM_NEW(Widget_Data);
982 e = evas_object_evas_get(parent);
984 obj = elm_widget_add(e);
985 ELM_SET_WIDTYPE(widtype, "photocam");
986 elm_widget_type_set(obj, "photocam");
987 elm_widget_sub_object_add(parent, obj);
988 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
989 elm_widget_data_set(obj, wd);
990 elm_widget_del_hook_set(obj, _del_hook);
991 elm_widget_theme_hook_set(obj, _theme_hook);
992 elm_widget_can_focus_set(obj, EINA_TRUE);
994 wd->scr = elm_smart_scroller_add(e);
995 elm_smart_scroller_widget_set(wd->scr, obj);
996 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
997 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
998 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
999 elm_widget_resize_object_set(obj, wd->scr);
1001 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1002 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1003 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1004 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1005 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1007 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1011 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1012 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1013 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1014 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1018 static Evas_Smart_Class sc;
1020 evas_object_smart_clipped_smart_set(&_pan_sc);
1022 sc.name = "elm_photocam_pan";
1023 sc.version = EVAS_SMART_CLASS_VERSION;
1026 sc.resize = _pan_resize;
1027 sc.move = _pan_move;
1028 sc.calculate = _pan_calculate;
1029 smart = evas_smart_class_new(&sc);
1033 wd->pan_smart = evas_object_smart_add(e, smart);
1034 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1038 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1039 _pan_set, _pan_get, _pan_max_get,
1040 _pan_min_get, _pan_child_size_get);
1043 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1047 wd->img = evas_object_image_add(e);
1048 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1049 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1051 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1053 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1055 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1056 evas_object_smart_member_add(wd->img, wd->pan_smart);
1057 elm_widget_sub_object_add(obj, wd->img);
1058 evas_object_image_filled_set(wd->img, 1);
1059 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1060 _main_preloaded, obj);
1062 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1064 evas_object_size_hint_min_set(obj, minw, minh);
1071 * Set the photo file to be shown
1073 * This sets (and shows) the specified file (with a relative or absolute path)
1074 * and will return a load error (same error that
1075 * evas_object_image_load_error_get() will return). The image will change and
1076 * adjust its size at this point and begin a background load process for this
1077 * photo that at some time in the future will be displayed at the full quality
1080 * @param obj The photocam object
1081 * @param file The photo file
1082 * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1086 EAPI Evas_Load_Error
1087 elm_photocam_file_set(Evas_Object *obj, const char *file)
1089 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1090 Widget_Data *wd = elm_widget_data_get(obj);
1092 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1093 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1094 evas_object_hide(wd->img);
1095 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1096 evas_object_image_file_set(wd->img, NULL, NULL);
1097 evas_object_image_load_scale_down_set(wd->img, 0);
1098 evas_object_image_file_set(wd->img, wd->file, NULL);
1099 evas_object_image_size_get(wd->img, &w, &h);
1102 wd->size.w = wd->size.imw / wd->zoom;
1103 wd->size.h = wd->size.imh / wd->zoom;
1104 if (wd->zoom_animator)
1107 if (wd->nosmooth == 0) _smooth_update(obj);
1108 ecore_animator_del(wd->zoom_animator);
1109 wd->zoom_animator = NULL;
1111 evas_object_image_file_set(wd->img, NULL, NULL);
1112 evas_object_image_load_scale_down_set(wd->img, 8);
1113 evas_object_image_file_set(wd->img, wd->file, NULL);
1114 evas_object_image_preload(wd->img, 0);
1115 wd->main_load_pending = 1;
1117 if (wd->calc_job) ecore_job_del(wd->calc_job);
1118 wd->calc_job = ecore_job_add(_calc_job, wd);
1119 evas_object_smart_callback_call(obj, "load", NULL);
1121 if (wd->preload_num == 1)
1123 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1124 "elm,state,busy,start", "elm");
1125 evas_object_smart_callback_call(obj, "load,detail", NULL);
1128 double tz = wd->zoom;
1130 elm_photocam_zoom_set(wd->obj, tz);
1132 return evas_object_image_load_error_get(wd->img);
1136 * Returns the path of the current image file
1138 * @param obj The photocam object
1139 * @return Returns the path
1144 elm_photocam_file_get(const Evas_Object *obj)
1146 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1147 Widget_Data *wd = elm_widget_data_get(obj);
1148 if (!wd) return NULL;
1153 * Set the zoom level of the photo
1155 * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1156 * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1157 * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1158 * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1161 * @param obj The photocam object
1162 * @param zoom The zoom level to set
1167 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1169 ELM_CHECK_WIDTYPE(obj, widtype);
1170 Widget_Data *wd = elm_widget_data_get(obj);
1172 Grid *g, *g_zoom = NULL;
1173 Evas_Coord pw, ph, rx, ry, rw, rh;
1175 int zoom_changed = 0, started = 0;
1178 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1179 if (zoom == wd->zoom) return;
1181 wd->size.ow = wd->size.w;
1182 wd->size.oh = wd->size.h;
1183 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1184 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1185 if ((rw <= 0) || (rh <= 0)) return;
1187 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1189 wd->size.nw = (double)wd->size.imw / wd->zoom;
1190 wd->size.nh = (double)wd->size.imh / wd->zoom;
1192 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1194 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1201 ph = (wd->size.imh * rw) / wd->size.imw;
1204 pw = (wd->size.imw * rh) / wd->size.imh;
1211 if (wd->size.imw > wd->size.imh)
1212 z = wd->size.imw / pw;
1214 z = wd->size.imh / ph;
1216 else if (z >= 4) z = 4;
1217 else if (z >= 2) z = 2;
1219 if (z != wd->zoom) zoom_changed = 1;
1225 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
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 if (wd->main_load_pending)
1260 wd->size.w = wd->size.nw;
1261 wd->size.h = wd->size.nh;
1264 EINA_LIST_FOREACH(wd->grids, l, g)
1266 if (g->zoom == grid_zoom_calc(wd->zoom))
1268 wd->grids = eina_list_remove(wd->grids, g);
1269 wd->grids = eina_list_prepend(wd->grids, g);
1274 g = grid_create(obj);
1277 if (eina_list_count(wd->grids) > 1)
1279 g_zoom = eina_list_last(wd->grids)->data;
1280 wd->grids = eina_list_remove(wd->grids, g_zoom);
1281 grid_clear(obj, g_zoom);
1283 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1288 wd->grids = eina_list_prepend(wd->grids, g);
1292 EINA_LIST_FREE(wd->grids, g)
1299 wd->t_start = ecore_loop_time_get();
1300 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1301 if ((wd->size.w > 0) && (wd->size.h > 0))
1303 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1304 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1308 wd->size.spos.x = 0.5;
1309 wd->size.spos.y = 0.5;
1311 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1312 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1313 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1314 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1321 if (!wd->zoom_animator)
1323 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1325 if (wd->nosmooth == 1) _smooth_update(obj);
1329 an = wd->zoom_animator;
1332 if (!_zoom_anim(obj))
1334 ecore_animator_del(an);
1338 if (wd->calc_job) ecore_job_del(wd->calc_job);
1339 wd->calc_job = ecore_job_add(_calc_job, wd);
1343 evas_object_smart_callback_call(obj, "zoom,start", NULL);
1345 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1348 evas_object_smart_callback_call(obj, "zoom,change", NULL);
1352 * Get the zoom level of the photo
1354 * This returns the current zoom level of the photocam object. Note that if
1355 * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1356 * (which is the default), the zoom level may be changed at any time by the
1357 * photocam object itself to account for photo size and photocam viewpoer size
1359 * @param obj The photocam object
1360 * @return The current zoom level
1365 elm_photocam_zoom_get(const Evas_Object *obj)
1367 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1368 Widget_Data *wd = elm_widget_data_get(obj);
1369 if (!wd) return 1.0;
1376 * This sets the zoom mode to manual or one of several automatic levels.
1377 * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1378 * elm_photocam_zoom_set() and will stay at that level until changed by code
1379 * or until zoom mode is changed. This is the default mode.
1380 * The Automatic modes will allow the photocam object to automatically
1381 * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1382 * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1383 * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1384 * ensure no pixels within the frame are left unfilled.
1386 * @param obj The photocam object
1387 * @param mode The desired mode
1392 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1394 ELM_CHECK_WIDTYPE(obj, widtype);
1395 Widget_Data *wd = elm_widget_data_get(obj);
1397 if (wd->mode == mode) return;
1400 double tz = wd->zoom;
1402 elm_photocam_zoom_set(wd->obj, tz);
1409 * This gets the current zoom mode of the photocam object
1411 * @param obj The photocam object
1412 * @return The current zoom mode
1416 EAPI Elm_Photocam_Zoom_Mode
1417 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1419 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1420 Widget_Data *wd = elm_widget_data_get(obj);
1421 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1426 * Get the current image pixel width and height
1428 * This gets the current photo pixel width and height (for the original).
1429 * The size will be returned in the integers @p w and @p h that are pointed
1432 * @param obj The photocam object
1433 * @param w A pointer to the width return
1434 * @param h A pointer to the height return
1439 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1441 ELM_CHECK_WIDTYPE(obj, widtype);
1442 Widget_Data *wd = elm_widget_data_get(obj);
1444 if (w) *w = wd->size.imw;
1445 if (h) *h = wd->size.imh;
1449 * Get the current area of the image that is currently shown
1451 * This gets the region
1455 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1457 ELM_CHECK_WIDTYPE(obj, widtype);
1458 Widget_Data *wd = elm_widget_data_get(obj);
1459 Evas_Coord sx, sy, sw, sh;
1461 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1462 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1467 *x = (wd->size.imw * sx) / wd->size.w;
1468 if (*x > wd->size.imw) *x = wd->size.imw;
1469 else if (*x < 0) *x = 0;
1473 *w = (wd->size.imw * sw) / wd->size.w;
1474 if (*w > wd->size.imw) *w = wd->size.imw;
1475 else if (*w < 0) *w = 0;
1488 *y = (wd->size.imh * sy) / wd->size.h;
1489 if (*y > wd->size.imh) *y = wd->size.imh;
1490 else if (*y < 0) *y = 0;
1494 *h = (wd->size.imh * sh) / wd->size.h;
1495 if (*h > wd->size.imh) *h = wd->size.imh;
1496 else if (*h < 0) *h = 0;
1507 * Set the viewed portion of the image
1509 * This sets the region of the image to be viewed
1511 * @param obj The photocam object
1512 * @param x X-coordinate of region in image original pixels
1513 * @param y Y-coordinate of region in image original pixels
1514 * @param w Width of region in image original pixels
1515 * @param h Height of region in image original pixels
1520 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1522 ELM_CHECK_WIDTYPE(obj, widtype);
1523 Widget_Data *wd = elm_widget_data_get(obj);
1526 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1527 rx = (x * wd->size.w) / wd->size.imw;
1528 ry = (y * wd->size.h) / wd->size.imh;
1529 rw = (w * wd->size.w) / wd->size.imw;
1530 rh = (w * wd->size.h) / wd->size.imh;
1533 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1534 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1535 if (wd->zoom_animator)
1538 ecore_animator_del(wd->zoom_animator);
1539 wd->zoom_animator = NULL;
1541 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1543 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1547 * Bring in the viewed portion of the image
1549 * This brings in the region of the image over time
1551 * @param obj The photocam object
1552 * @param x X-coordinate of region in image original pixels
1553 * @param y Y-coordinate of region in image original pixels
1554 * @param w Width of region in image original pixels
1555 * @param h Height of region in image original pixels
1560 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1562 ELM_CHECK_WIDTYPE(obj, widtype);
1563 Widget_Data *wd = elm_widget_data_get(obj);
1566 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1567 rx = (x * wd->size.w) / wd->size.imw;
1568 ry = (y * wd->size.h) / wd->size.imh;
1569 rw = (w * wd->size.w) / wd->size.imw;
1570 rh = (w * wd->size.h) / wd->size.imh;
1573 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1574 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1575 if (wd->zoom_animator)
1578 if (!wd->nosmooth) _smooth_update(obj);
1579 ecore_animator_del(wd->zoom_animator);
1580 wd->zoom_animator = NULL;
1582 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1584 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1588 * Set the paused state for photocam
1590 * This sets the paused state to on (1) or off (0) for photocam. The default
1591 * is on. This will stop zooming using animation ch change zoom levels and
1592 * change instantly. This will stop any existing animations that are running.
1594 * @param obj The photocam object
1595 * @param paused The pause state to set
1600 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1602 ELM_CHECK_WIDTYPE(obj, widtype);
1603 Widget_Data *wd = elm_widget_data_get(obj);
1605 if (wd->paused == !!paused) return;
1606 wd->paused = paused;
1609 if (wd->zoom_animator)
1611 ecore_animator_del(wd->zoom_animator);
1612 wd->zoom_animator = NULL;
1614 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1620 * Get the paused state for photocam
1622 * This gets the current paused state for the photocam object.
1624 * @param obj The photocam object
1625 * @return The current paused state
1630 elm_photocam_paused_get(const Evas_Object *obj)
1632 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1633 Widget_Data *wd = elm_widget_data_get(obj);
1634 if (!wd) return EINA_FALSE;
1639 * Get the internal low-res image used for photocam
1641 * This gets the internal image object inside photocam. Do not modify it. It
1642 * is for inspection only, and hooking callbacks to. Nothing else. It may be
1643 * deleted at any time as well.
1645 * @param obj The photocam object
1646 * @return The internal image object handle, or NULL if none exists
1651 elm_photocam_internal_image_get(const Evas_Object *obj)
1653 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1654 Widget_Data *wd = elm_widget_data_get(obj);
1655 if (!wd) return NULL;
1660 * Set the photocam scrolling bouncing.
1662 * @param obj The photocam object
1663 * @param h_bounce bouncing for horizontal
1664 * @param v_bounce bouncing for vertical
1668 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1670 ELM_CHECK_WIDTYPE(obj, widtype);
1671 Widget_Data *wd = elm_widget_data_get(obj);
1673 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1678 * Get the photocam scrolling bouncing.
1680 * @param obj The photocam object
1681 * @param h_bounce bouncing for horizontal
1682 * @param v_bounce bouncing for vertical
1686 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1688 ELM_CHECK_WIDTYPE(obj, widtype);
1689 Widget_Data *wd = elm_widget_data_get(obj);
1691 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);