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_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, "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, "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, "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, "scroll,drag,stop", NULL);
949 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
951 evas_object_smart_callback_call(data, "scroll", NULL);
955 * Add a new Photocam object
957 * @param parent The parent object
958 * @return The new object or NULL if it cannot be created
963 elm_photocam_add(Evas_Object *parent)
968 Evas_Coord minw, minh;
969 static Evas_Smart *smart = NULL;
970 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
972 wd = ELM_NEW(Widget_Data);
973 e = evas_object_evas_get(parent);
974 obj = elm_widget_add(e);
975 ELM_SET_WIDTYPE(widtype, "photocam");
976 elm_widget_type_set(obj, "photocam");
977 elm_widget_sub_object_add(parent, obj);
978 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
979 elm_widget_data_set(obj, wd);
980 elm_widget_del_hook_set(obj, _del_hook);
981 elm_widget_theme_hook_set(obj, _theme_hook);
982 elm_widget_can_focus_set(obj, EINA_TRUE);
984 wd->scr = elm_smart_scroller_add(e);
985 elm_smart_scroller_widget_set(wd->scr, obj);
986 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
987 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
988 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
989 elm_widget_resize_object_set(obj, wd->scr);
991 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
992 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
993 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
994 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
995 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
997 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1001 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1002 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1003 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1004 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1008 static Evas_Smart_Class sc;
1010 evas_object_smart_clipped_smart_set(&_pan_sc);
1012 sc.name = "elm_photocam_pan";
1013 sc.version = EVAS_SMART_CLASS_VERSION;
1016 sc.resize = _pan_resize;
1017 sc.move = _pan_move;
1018 sc.calculate = _pan_calculate;
1019 smart = evas_smart_class_new(&sc);
1023 wd->pan_smart = evas_object_smart_add(e, smart);
1024 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1028 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1030 _pan_max_get, _pan_child_size_get);
1033 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1037 wd->img = evas_object_image_add(e);
1038 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1039 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1041 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1043 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1045 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1046 evas_object_smart_member_add(wd->img, wd->pan_smart);
1047 elm_widget_sub_object_add(obj, wd->img);
1048 evas_object_image_filled_set(wd->img, 1);
1049 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1050 _main_preloaded, obj);
1052 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1054 evas_object_size_hint_min_set(obj, minw, minh);
1061 * Set the photo file to be shown
1063 * This sets (and shows) the specified file (with a relative or absolute path)
1064 * and will return a load error (same error that
1065 * evas_object_image_load_error_get() will return). The image will change and
1066 * adjust its size at this point and begin a background load process for this
1067 * photo that at some time in the future will be displayed at the full quality
1070 * @param obj The photocam object
1071 * @param file The photo file
1072 * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1077 elm_photocam_file_set(Evas_Object *obj, const char *file)
1079 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1080 Widget_Data *wd = elm_widget_data_get(obj);
1082 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1083 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1084 evas_object_hide(wd->img);
1085 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1086 evas_object_image_file_set(wd->img, NULL, NULL);
1087 evas_object_image_load_scale_down_set(wd->img, 0);
1088 evas_object_image_file_set(wd->img, wd->file, NULL);
1089 evas_object_image_size_get(wd->img, &w, &h);
1092 wd->size.w = wd->size.imw / wd->zoom;
1093 wd->size.h = wd->size.imh / wd->zoom;
1094 if (wd->zoom_animator)
1097 if (wd->nosmooth == 0) _smooth_update(obj);
1098 ecore_animator_del(wd->zoom_animator);
1099 wd->zoom_animator = NULL;
1101 evas_object_image_file_set(wd->img, NULL, NULL);
1102 evas_object_image_load_scale_down_set(wd->img, 8);
1103 evas_object_image_file_set(wd->img, wd->file, NULL);
1104 evas_object_image_preload(wd->img, 0);
1105 wd->main_load_pending = 1;
1107 if (wd->calc_job) ecore_job_del(wd->calc_job);
1108 wd->calc_job = ecore_job_add(_calc_job, wd);
1109 evas_object_smart_callback_call(obj, "load", NULL);
1111 if (wd->preload_num == 1)
1113 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1114 "elm,state,busy,start", "elm");
1115 evas_object_smart_callback_call(obj, "load,detail", NULL);
1118 double tz = wd->zoom;
1120 elm_photocam_zoom_set(wd->obj, tz);
1122 return evas_object_image_load_error_get(wd->img);
1126 * Returns the path of the current image file
1128 * @param obj The photocam object
1129 * @return Returns the path
1134 elm_photocam_file_get(const Evas_Object *obj)
1136 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1137 Widget_Data *wd = elm_widget_data_get(obj);
1138 if (!wd) return NULL;
1143 * Set the zoom level of the photo
1145 * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1146 * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1147 * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1148 * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1151 * @param obj The photocam object
1152 * @param zoom The zoom level to set
1157 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1159 ELM_CHECK_WIDTYPE(obj, widtype);
1160 Widget_Data *wd = elm_widget_data_get(obj);
1162 Grid *g, *g_zoom = NULL;
1163 Evas_Coord pw, ph, rx, ry, rw, rh;
1165 int zoom_changed = 0, started = 0;
1168 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1169 if (zoom == wd->zoom) return;
1171 wd->size.ow = wd->size.w;
1172 wd->size.oh = wd->size.h;
1173 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1174 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1175 if ((rw <= 0) || (rh <= 0)) return;
1177 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1179 wd->size.nw = (double)wd->size.imw / wd->zoom;
1180 wd->size.nh = (double)wd->size.imh / wd->zoom;
1182 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1184 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1191 ph = (wd->size.imh * rw) / wd->size.imw;
1194 pw = (wd->size.imw * rh) / wd->size.imh;
1201 if (wd->size.imw > wd->size.imh)
1202 z = wd->size.imw / pw;
1204 z = wd->size.imh / ph;
1206 else if (z >= 4) z = 4;
1207 else if (z >= 2) z = 2;
1209 if (z != wd->zoom) zoom_changed = 1;
1215 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1217 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1224 ph = (wd->size.imh * rw) / wd->size.imw;
1227 pw = (wd->size.imw * rh) / wd->size.imh;
1234 if (wd->size.imw > wd->size.imh)
1235 z = wd->size.imw / pw;
1237 z = wd->size.imh / ph;
1239 else if (z >= 4) z = 4;
1240 else if (z >= 2) z = 2;
1242 if (z != wd->zoom) zoom_changed = 1;
1248 if (wd->main_load_pending)
1250 wd->size.w = wd->size.nw;
1251 wd->size.h = wd->size.nh;
1254 EINA_LIST_FOREACH(wd->grids, l, g)
1256 if (g->zoom == grid_zoom_calc(wd->zoom))
1258 wd->grids = eina_list_remove(wd->grids, g);
1259 wd->grids = eina_list_prepend(wd->grids, g);
1264 g = grid_create(obj);
1267 if (eina_list_count(wd->grids) > 1)
1269 g_zoom = eina_list_last(wd->grids)->data;
1270 wd->grids = eina_list_remove(wd->grids, g_zoom);
1271 grid_clear(obj, g_zoom);
1273 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1278 wd->grids = eina_list_prepend(wd->grids, g);
1282 EINA_LIST_FREE(wd->grids, g)
1289 wd->t_start = ecore_loop_time_get();
1290 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1291 if ((wd->size.w > 0) && (wd->size.h > 0))
1293 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1294 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1298 wd->size.spos.x = 0.5;
1299 wd->size.spos.y = 0.5;
1301 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1302 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1303 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1304 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1311 if (!wd->zoom_animator)
1313 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1315 if (wd->nosmooth == 1) _smooth_update(obj);
1319 an = wd->zoom_animator;
1322 if (!_zoom_anim(obj))
1324 ecore_animator_del(an);
1328 if (wd->calc_job) ecore_job_del(wd->calc_job);
1329 wd->calc_job = ecore_job_add(_calc_job, wd);
1333 evas_object_smart_callback_call(obj, "zoom,start", NULL);
1335 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1338 evas_object_smart_callback_call(obj, "zoom,change", NULL);
1342 * Get the zoom level of the photo
1344 * This returns the current zoom level of the photocam object. Note that if
1345 * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1346 * (which is the default), the zoom level may be changed at any time by the
1347 * photocam object itself to account for photo size and photocam viewpoer size
1349 * @param obj The photocam object
1350 * @return The current zoom level
1355 elm_photocam_zoom_get(const Evas_Object *obj)
1357 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1358 Widget_Data *wd = elm_widget_data_get(obj);
1359 if (!wd) return 1.0;
1366 * This sets the zoom mode to manual or one of several automatic levels.
1367 * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1368 * elm_photocam_zoom_set() and will stay at that level until changed by code
1369 * or until zoom mode is changed. This is the default mode.
1370 * The Automatic modes will allow the photocam object to automatically
1371 * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1372 * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1373 * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1374 * ensure no pixels within the frame are left unfilled.
1376 * @param obj The photocam object
1377 * @param mode The desired mode
1382 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1384 ELM_CHECK_WIDTYPE(obj, widtype);
1385 Widget_Data *wd = elm_widget_data_get(obj);
1387 if (wd->mode == mode) return;
1390 double tz = wd->zoom;
1392 elm_photocam_zoom_set(wd->obj, tz);
1399 * This gets the current zoom mode of the photocam object
1401 * @param obj The photocam object
1402 * @return The current zoom mode
1406 EAPI Elm_Photocam_Zoom_Mode
1407 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1409 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1410 Widget_Data *wd = elm_widget_data_get(obj);
1411 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1416 * Get the current image pixel width and height
1418 * This gets the current photo pixel width and height (for the original).
1419 * The size will be returned in the integers @p w and @p h that are pointed
1422 * @param obj The photocam object
1423 * @param w A pointer to the width return
1424 * @param h A pointer to the height return
1429 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1431 ELM_CHECK_WIDTYPE(obj, widtype);
1432 Widget_Data *wd = elm_widget_data_get(obj);
1434 if (w) *w = wd->size.imw;
1435 if (h) *h = wd->size.imh;
1439 * Get the current area of the image that is currently shown
1441 * This gets the region
1445 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1447 ELM_CHECK_WIDTYPE(obj, widtype);
1448 Widget_Data *wd = elm_widget_data_get(obj);
1449 Evas_Coord sx, sy, sw, sh;
1451 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1452 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1457 *x = (wd->size.imw * sx) / wd->size.w;
1458 if (*x > wd->size.imw) *x = wd->size.imw;
1459 else if (*x < 0) *x = 0;
1463 *w = (wd->size.imw * sw) / wd->size.w;
1464 if (*w > wd->size.imw) *w = wd->size.imw;
1465 else if (*w < 0) *w = 0;
1478 *y = (wd->size.imh * sy) / wd->size.h;
1479 if (*y > wd->size.imh) *y = wd->size.imh;
1480 else if (*y < 0) *y = 0;
1484 *h = (wd->size.imh * sh) / wd->size.h;
1485 if (*h > wd->size.imh) *h = wd->size.imh;
1486 else if (*h < 0) *h = 0;
1497 * Set the viewed portion of the image
1499 * This sets the region of the image to be viewed
1501 * @param obj The photocam object
1502 * @param x X-coordinate of region in image original pixels
1503 * @param y Y-coordinate of region in image original pixels
1504 * @param w Width of region in image original pixels
1505 * @param h Height of region in image original pixels
1510 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1512 ELM_CHECK_WIDTYPE(obj, widtype);
1513 Widget_Data *wd = elm_widget_data_get(obj);
1516 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1517 rx = (x * wd->size.w) / wd->size.imw;
1518 ry = (y * wd->size.h) / wd->size.imh;
1519 rw = (w * wd->size.w) / wd->size.imw;
1520 rh = (w * wd->size.h) / wd->size.imh;
1523 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1524 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1525 if (wd->zoom_animator)
1528 ecore_animator_del(wd->zoom_animator);
1529 wd->zoom_animator = NULL;
1531 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1533 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1537 * Bring in the viewed portion of the image
1539 * This brings in the region of the image over time
1541 * @param obj The photocam object
1542 * @param x X-coordinate of region in image original pixels
1543 * @param y Y-coordinate of region in image original pixels
1544 * @param w Width of region in image original pixels
1545 * @param h Height of region in image original pixels
1550 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1552 ELM_CHECK_WIDTYPE(obj, widtype);
1553 Widget_Data *wd = elm_widget_data_get(obj);
1556 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1557 rx = (x * wd->size.w) / wd->size.imw;
1558 ry = (y * wd->size.h) / wd->size.imh;
1559 rw = (w * wd->size.w) / wd->size.imw;
1560 rh = (w * wd->size.h) / wd->size.imh;
1563 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1564 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1565 if (wd->zoom_animator)
1568 if (!wd->nosmooth) _smooth_update(obj);
1569 ecore_animator_del(wd->zoom_animator);
1570 wd->zoom_animator = NULL;
1572 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1574 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1578 * Set the paused state for photocam
1580 * This sets the paused state to on (1) or off (0) for photocam. The default
1581 * is on. This will stop zooming using animation ch change zoom levels and
1582 * change instantly. This will stop any existing animations that are running.
1584 * @param obj The photocam object
1585 * @param paused The pause state to set
1590 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1592 ELM_CHECK_WIDTYPE(obj, widtype);
1593 Widget_Data *wd = elm_widget_data_get(obj);
1595 if (wd->paused == !!paused) return;
1596 wd->paused = paused;
1599 if (wd->zoom_animator)
1601 ecore_animator_del(wd->zoom_animator);
1602 wd->zoom_animator = NULL;
1604 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1610 * Get the paused state for photocam
1612 * This gets the current paused state for the photocam object.
1614 * @param obj The photocam object
1615 * @return The current paused state
1620 elm_photocam_paused_get(const Evas_Object *obj)
1622 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1623 Widget_Data *wd = elm_widget_data_get(obj);
1624 if (!wd) return EINA_FALSE;
1629 * Get the internal low-res image used for photocam
1631 * This gets the internal image object inside photocam. Do not modify it. It
1632 * is for inspection only, and hooking callbacks to. Nothing else. It may be
1633 * deleted at any time as well.
1635 * @param obj The photocam object
1636 * @return The internal image object handle, or NULL if none exists
1641 elm_photocam_internal_image_get(const Evas_Object *obj)
1643 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1644 Widget_Data *wd = elm_widget_data_get(obj);
1645 if (!wd) return NULL;
1650 * Set the photocam scrolling bouncing.
1652 * @param obj The photocam object
1653 * @param h_bounce bouncing for horizontal
1654 * @param v_bounce bouncing for vertical
1658 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1660 ELM_CHECK_WIDTYPE(obj, widtype);
1661 Widget_Data *wd = elm_widget_data_get(obj);
1663 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1668 * Get the photocam scrolling bouncing.
1670 * @param obj The photocam object
1671 * @param h_bounce bouncing for horizontal
1672 * @param v_bounce bouncing for vertical
1676 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1678 ELM_CHECK_WIDTYPE(obj, widtype);
1679 Widget_Data *wd = elm_widget_data_get(obj);
1681 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);