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 _show_region_hook(void *data, Evas_Object *obj);
144 static void _sizing_eval(Evas_Object *obj);
145 static void _calc_job(void *data);
146 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);
147 static void grid_clear(Evas_Object *obj, Grid *g);
148 static Grid *grid_create(Evas_Object *obj);
149 static void grid_load(Evas_Object *obj, Grid *g);
152 nearest_pow2(int num)
154 unsigned int n = num - 1;
164 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
166 Widget_Data *wd = elm_widget_data_get(obj);
167 Evas_Coord ax, ay, gw, gh;
173 if (ow > gw) ax = (ow - gw) / 2;
174 if (oh > gh) ay = (oh - gh) / 2;
175 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
176 evas_object_resize(wd->img, gw, gh);
180 wd->show.show = EINA_FALSE;
181 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
186 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)
188 Widget_Data *wd = elm_widget_data_get(obj);
189 Evas_Coord ax, ay, gw, gh, tx, ty;
196 if (ow > gw) ax = (ow - gw) / 2;
197 if (oh > gh) ay = (oh - gh) / 2;
198 for (y = 0; y < g->gh; y++)
200 for (x = 0; x < g->gw; x++)
202 int tn, xx, yy, ww, hh;
204 tn = (y * g->gw) + x;
205 xx = g->grid[tn].out.x;
206 yy = g->grid[tn].out.y;
207 ww = g->grid[tn].out.w;
208 hh = g->grid[tn].out.h;
209 if ((gw != g->w) && (g->w > 0))
212 xx = (gw * xx) / g->w;
213 ww = ((gw * (tx + ww)) / g->w) - xx;
215 if ((gh != g->h) && (g->h > 0))
218 yy = (gh * yy) / g->h;
219 hh = ((gh * (ty + hh)) / g->h) - yy;
221 evas_object_move(g->grid[tn].img,
224 evas_object_resize(g->grid[tn].img, ww, hh);
230 grid_clear(Evas_Object *obj, Grid *g)
232 Widget_Data *wd = elm_widget_data_get(obj);
235 if (!g->grid) return;
236 for (y = 0; y < g->gh; y++)
238 for (x = 0; x < g->gw; x++)
242 tn = (y * g->gw) + x;
243 evas_object_del(g->grid[tn].img);
244 if (g->grid[tn].want)
247 if (wd->preload_num == 0)
249 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
250 "elm,state,busy,stop", "elm");
251 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
263 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
265 Grid_Item *git = data;
270 evas_object_show(git->img);
272 git->wd->preload_num--;
273 if (git->wd->preload_num == 0)
275 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
276 "elm,state,busy,stop", "elm");
277 evas_object_smart_callback_call(git->wd->obj, "loaded,detail", NULL);
283 grid_zoom_calc(double zoom)
287 return nearest_pow2(z);
291 grid_create(Evas_Object *obj)
293 Widget_Data *wd = elm_widget_data_get(obj);
297 if (!wd) return NULL;
298 g = calloc(1, sizeof(Grid));
300 g->zoom = grid_zoom_calc(wd->zoom);
301 g->tsize = wd->tsize;
302 g->iw = wd->size.imw;
303 g->ih = wd->size.imh;
305 g->w = g->iw / g->zoom;
306 g->h = g->ih / g->zoom;
307 if (g->zoom >= 8) return NULL;
308 g->gw = (g->w + g->tsize - 1) / g->tsize;
309 g->gh = (g->h + g->tsize - 1) / g->tsize;
310 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
317 for (y = 0; y < g->gh; y++)
319 for (x = 0; x < g->gw; x++)
323 tn = (y * g->gw) + x;
324 g->grid[tn].src.x = x * g->tsize;
325 if (x == (g->gw - 1))
326 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
328 g->grid[tn].src.w = g->tsize;
329 g->grid[tn].src.y = y * g->tsize;
330 if (y == (g->gh - 1))
331 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
333 g->grid[tn].src.h = g->tsize;
335 g->grid[tn].out.x = g->grid[tn].src.x;
336 g->grid[tn].out.y = g->grid[tn].src.y;
337 g->grid[tn].out.w = g->grid[tn].src.w;
338 g->grid[tn].out.h = g->grid[tn].src.h;
342 evas_object_image_add(evas_object_evas_get(obj));
343 evas_object_image_scale_hint_set
344 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
345 evas_object_pass_events_set(g->grid[tn].img, 1);
346 evas_object_smart_member_add(g->grid[tn].img,
348 elm_widget_sub_object_add(obj, g->grid[tn].img);
349 evas_object_image_filled_set(g->grid[tn].img, 1);
350 evas_object_event_callback_add(g->grid[tn].img,
351 EVAS_CALLBACK_IMAGE_PRELOADED,
360 grid_load(Evas_Object *obj, Grid *g)
362 Widget_Data *wd = elm_widget_data_get(obj);
364 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, ax, ay, tx, ty;
366 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
367 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
372 if (ow > gw) ax = (ow - gw) / 2;
373 if (oh > gh) ay = (oh - gh) / 2;
374 for (y = 0; y < g->gh; y++)
376 for (x = 0; x < g->gw; x++)
378 int tn, xx, yy, ww, hh;
379 Eina_Bool visible = EINA_FALSE;
381 tn = (y * g->gw) + x;
382 xx = g->grid[tn].out.x;
383 yy = g->grid[tn].out.y;
384 ww = g->grid[tn].out.w;
385 hh = g->grid[tn].out.h;
386 if ((gw != g->w) && (g->w > 0))
389 xx = (gw * xx) / g->w;
390 ww = ((gw * (tx + ww)) / g->w) - xx;
392 if ((gh != g->h) && (g->h > 0))
395 yy = (gh * yy) / g->h;
396 hh = ((gh * (ty + hh)) / g->h) - yy;
400 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
405 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
407 g->grid[tn].want = 1;
408 evas_object_hide(g->grid[tn].img);
409 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
410 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
411 evas_object_image_load_region_set(g->grid[tn].img,
416 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
417 evas_object_image_preload(g->grid[tn].img, 0);
419 if (wd->preload_num == 1)
421 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
422 "elm,state,busy,start", "elm");
423 evas_object_smart_callback_call(obj, "load,detail", NULL);
426 else if ((g->grid[tn].want) && (!visible))
429 if (wd->preload_num == 0)
431 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
432 "elm,state,busy,stop", "elm");
433 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
435 g->grid[tn].want = 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);
440 else if ((g->grid[tn].have) && (!visible))
442 g->grid[tn].have = 0;
443 evas_object_hide(g->grid[tn].img);
444 evas_object_image_preload(g->grid[tn].img, 1);
445 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
452 grid_clearall(Evas_Object *obj)
454 Widget_Data *wd = elm_widget_data_get(obj);
457 EINA_LIST_FREE(wd->grids, g)
465 _smooth_update(Evas_Object *obj)
467 Widget_Data *wd = elm_widget_data_get(obj);
472 EINA_LIST_FOREACH(wd->grids, l, g)
474 for (y = 0; y < g->gh; y++)
476 for (x = 0; x < g->gw; x++)
480 tn = (y * g->gw) + x;
481 evas_object_image_smooth_scale_set(g->grid[tn].img, (wd->nosmooth == 0));
485 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
493 for (y = 0; y < g->gh; y++)
495 for (x = 0; x < g->gw; x++)
499 tn = (y * g->gw) + x;
500 evas_object_raise(g->grid[tn].img);
506 _scr_timeout(void *data)
508 Widget_Data *wd = elm_widget_data_get(data);
511 if (wd->nosmooth == 0) _smooth_update(data);
512 wd->scr_timer = NULL;
517 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
519 Widget_Data *wd = elm_widget_data_get(data);
524 if (wd->nosmooth == 1) _smooth_update(data);
526 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
527 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
531 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
533 Evas_Object *obj = data;
534 Widget_Data *wd = elm_widget_data_get(obj);
537 evas_object_show(wd->img);
538 wd->main_load_pending = 0;
539 g = grid_create(obj);
542 wd->grids = eina_list_prepend(wd->grids, g);
543 grid_load(wd->obj, g);
545 if (wd->calc_job) ecore_job_del(wd->calc_job);
546 wd->calc_job = ecore_job_add(_calc_job, wd);
547 evas_object_smart_callback_call(data, "loaded", NULL);
549 if (wd->preload_num == 0)
551 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
552 "elm,state,busy,stop", "elm");
553 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
558 zoom_do(Evas_Object *obj, double t)
560 Widget_Data *wd = elm_widget_data_get(obj);
561 Evas_Coord xx, yy, ow, oh;
563 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
564 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
565 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
566 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
567 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
569 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
571 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
573 wd->show.show = EINA_TRUE;
579 if (wd->calc_job) ecore_job_del(wd->calc_job);
580 wd->calc_job = ecore_job_add(_calc_job, wd);
583 Eina_List *l, *l_next;
586 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
590 wd->grids = eina_list_remove_list(wd->grids, l);
602 _zoom_anim(void *data)
604 Evas_Object *obj = data;
605 Widget_Data *wd = elm_widget_data_get(obj);
609 t = ecore_loop_time_get();
612 else if (wd->t_end > wd->t_start)
613 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
618 go = zoom_do(obj, t);
622 if (wd->nosmooth == 0) _smooth_update(data);
623 wd->zoom_animator = NULL;
624 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
630 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
632 Widget_Data *wd = elm_widget_data_get(data);
633 // Evas_Event_Mouse_Move *ev = event_info;
638 _long_press(void *data)
640 Widget_Data *wd = elm_widget_data_get(data);
642 wd->long_timer = NULL;
643 wd->longpressed = EINA_TRUE;
644 evas_object_smart_callback_call(data, "longpressed", NULL);
649 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
651 Widget_Data *wd = elm_widget_data_get(data);
652 Evas_Event_Mouse_Down *ev = event_info;
654 if (ev->button != 1) return;
655 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
656 else wd->on_hold = EINA_FALSE;
657 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
658 evas_object_smart_callback_call(data, "clicked,double", NULL);
660 evas_object_smart_callback_call(data, "press", NULL);
661 wd->longpressed = EINA_FALSE;
662 if (wd->long_timer) ecore_timer_del(wd->long_timer);
663 wd->long_timer = ecore_timer_add(1.0, _long_press, data);
667 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
669 Widget_Data *wd = elm_widget_data_get(data);
670 Evas_Event_Mouse_Up *ev = event_info;
672 if (ev->button != 1) return;
673 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
674 else wd->on_hold = EINA_FALSE;
677 ecore_timer_del(wd->long_timer);
678 wd->long_timer = NULL;
681 evas_object_smart_callback_call(data, "clicked", NULL);
682 wd->on_hold = EINA_FALSE;
685 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
688 _del_hook(Evas_Object *obj)
690 Widget_Data *wd = elm_widget_data_get(obj);
693 EINA_LIST_FREE(wd->grids, g)
695 if (g->grid) free(g->grid);
698 evas_object_del(wd->pan_smart);
699 wd->pan_smart = NULL;
700 if (wd->file) eina_stringshare_del(wd->file);
701 if (wd->calc_job) ecore_job_del(wd->calc_job);
702 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
703 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
704 if (wd->long_timer) ecore_timer_del(wd->long_timer);
709 _theme_hook(Evas_Object *obj)
711 Widget_Data *wd = elm_widget_data_get(obj);
713 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
714 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
720 _show_region_hook(void *data, Evas_Object *obj)
722 Widget_Data *wd = elm_widget_data_get(data);
723 Evas_Coord x, y, w, h;
725 elm_widget_show_region_get(obj, &x, &y, &w, &h);
726 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
731 _sizing_eval(Evas_Object *obj)
733 Widget_Data *wd = elm_widget_data_get(obj);
734 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
736 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
737 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
740 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
741 evas_object_size_hint_min_set(obj, minw, minh);
742 evas_object_size_hint_max_set(obj, maxw, maxh);
746 _calc_job(void *data)
748 Widget_Data *wd = data;
749 Evas_Coord minw, minh;
756 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
758 double tz = wd->zoom;
760 elm_photocam_zoom_set(wd->obj, tz);
763 if ((minw != wd->minw) || (minh != wd->minh))
767 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
768 _sizing_eval(wd->obj);
771 evas_object_smart_changed(wd->pan_smart);
775 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
777 Pan *sd = evas_object_smart_data_get(obj);
779 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
782 evas_object_smart_changed(obj);
786 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
788 Pan *sd = evas_object_smart_data_get(obj);
790 if (x) *x = sd->wd->pan_x;
791 if (y) *y = sd->wd->pan_y;
795 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
797 Pan *sd = evas_object_smart_data_get(obj);
800 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
801 ow = sd->wd->minw - ow;
803 oh = sd->wd->minh - oh;
810 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
812 Pan *sd = evas_object_smart_data_get(obj);
814 if (w) *w = sd->wd->minw;
815 if (h) *h = sd->wd->minh;
819 _pan_add(Evas_Object *obj)
822 Evas_Object_Smart_Clipped_Data *cd;
824 cd = evas_object_smart_data_get(obj);
826 sd = calloc(1, sizeof(Pan));
828 sd->__clipped_data = *cd;
830 evas_object_smart_data_set(obj, sd);
834 _pan_del(Evas_Object *obj)
836 Pan *sd = evas_object_smart_data_get(obj);
842 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
844 Pan *sd = evas_object_smart_data_get(obj);
847 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
848 if ((ow == w) && (oh == h)) return;
850 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
851 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
855 _pan_calculate(Evas_Object *obj)
857 Pan *sd = evas_object_smart_data_get(obj);
858 Evas_Coord ox, oy, ow, oh;
862 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
863 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
864 EINA_LIST_FOREACH(sd->wd->grids, l, g)
866 grid_load(sd->wd->obj, g);
867 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
872 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
874 Pan *sd = evas_object_smart_data_get(obj);
876 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
877 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
881 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
883 Widget_Data *wd = elm_widget_data_get(obj);
885 elm_smart_scroller_hold_set(wd->scr, 1);
889 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
891 Widget_Data *wd = elm_widget_data_get(obj);
893 elm_smart_scroller_hold_set(wd->scr, 0);
897 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
899 Widget_Data *wd = elm_widget_data_get(obj);
901 elm_smart_scroller_freeze_set(wd->scr, 1);
905 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
907 Widget_Data *wd = elm_widget_data_get(obj);
909 elm_smart_scroller_freeze_set(wd->scr, 0);
913 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
915 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
919 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
921 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
925 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
927 evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
931 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
933 evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
937 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
939 evas_object_smart_callback_call(data, "scroll", NULL);
943 * Add a new Photocam object
945 * @param parent The parent object
946 * @return The new object or NULL if it cannot be created
951 elm_photocam_add(Evas_Object *parent)
956 Evas_Coord minw, minh;
957 static Evas_Smart *smart = NULL;
959 wd = ELM_NEW(Widget_Data);
960 e = evas_object_evas_get(parent);
961 obj = elm_widget_add(e);
962 ELM_SET_WIDTYPE(widtype, "photocam");
963 elm_widget_type_set(obj, "photocam");
964 elm_widget_sub_object_add(parent, obj);
965 elm_widget_data_set(obj, wd);
966 elm_widget_del_hook_set(obj, _del_hook);
967 elm_widget_theme_hook_set(obj, _theme_hook);
969 wd->scr = elm_smart_scroller_add(e);
970 elm_smart_scroller_widget_set(wd->scr, obj);
971 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
972 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
973 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
974 elm_widget_resize_object_set(obj, wd->scr);
976 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
977 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
978 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
979 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
980 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
982 elm_smart_scroller_bounce_allow_set(wd->scr, 1, 1);
986 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
987 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
988 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
989 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
993 static Evas_Smart_Class sc;
995 evas_object_smart_clipped_smart_set(&_pan_sc);
997 sc.name = "elm_photocam_pan";
998 sc.version = EVAS_SMART_CLASS_VERSION;
1001 sc.resize = _pan_resize;
1002 sc.move = _pan_move;
1003 sc.calculate = _pan_calculate;
1004 smart = evas_smart_class_new(&sc);
1008 wd->pan_smart = evas_object_smart_add(e, smart);
1009 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1013 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1015 _pan_max_get, _pan_child_size_get);
1018 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1022 wd->img = evas_object_image_add(e);
1023 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1024 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1026 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1028 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1030 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1031 evas_object_smart_member_add(wd->img, wd->pan_smart);
1032 elm_widget_sub_object_add(obj, wd->img);
1033 evas_object_image_filled_set(wd->img, 1);
1034 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1035 _main_preloaded, obj);
1037 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1039 evas_object_size_hint_min_set(obj, minw, minh);
1046 * Set the photo file to be shown
1048 * This sets (and shows) the specified file (with a relative or absolute path)
1049 * and will return a load error (same error that
1050 * evas_object_image_load_error_get() will return). The image will change and
1051 * adjust its size at this point and begin a background load process for this
1052 * photo that at some time in the future will be displayed at the full quality
1055 * @param obj The photocam object
1056 * @param file The photo file
1057 * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1062 elm_photocam_file_set(Evas_Object *obj, const char *file)
1064 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1065 Widget_Data *wd = elm_widget_data_get(obj);
1067 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1068 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1069 evas_object_hide(wd->img);
1070 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1071 evas_object_image_file_set(wd->img, NULL, NULL);
1072 evas_object_image_load_scale_down_set(wd->img, 0);
1073 evas_object_image_file_set(wd->img, wd->file, NULL);
1074 evas_object_image_size_get(wd->img, &w, &h);
1077 wd->size.w = wd->size.imw / wd->zoom;
1078 wd->size.h = wd->size.imh / wd->zoom;
1079 if (wd->zoom_animator)
1082 if (wd->nosmooth == 0) _smooth_update(obj);
1083 ecore_animator_del(wd->zoom_animator);
1084 wd->zoom_animator = NULL;
1086 evas_object_image_file_set(wd->img, NULL, NULL);
1087 evas_object_image_load_scale_down_set(wd->img, 8);
1088 evas_object_image_file_set(wd->img, wd->file, NULL);
1089 evas_object_image_preload(wd->img, 0);
1090 wd->main_load_pending = 1;
1092 if (wd->calc_job) ecore_job_del(wd->calc_job);
1093 wd->calc_job = ecore_job_add(_calc_job, wd);
1094 evas_object_smart_callback_call(obj, "load", NULL);
1096 if (wd->preload_num == 1)
1098 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1099 "elm,state,busy,start", "elm");
1100 evas_object_smart_callback_call(obj, "load,detail", NULL);
1103 double tz = wd->zoom;
1105 elm_photocam_zoom_set(wd->obj, tz);
1107 return evas_object_image_load_error_get(wd->img);
1111 * Returns the path of the current image file
1113 * @param obj The photocam object
1114 * @return Returns the path
1119 elm_photocam_file_get(const Evas_Object *obj)
1121 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1122 Widget_Data *wd = elm_widget_data_get(obj);
1123 if (!wd) return NULL;
1128 * Set the zoom level of the photo
1130 * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1131 * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1132 * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1133 * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1136 * @param obj The photocam object
1137 * @param zoom The zoom level to set
1142 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1144 ELM_CHECK_WIDTYPE(obj, widtype);
1145 Widget_Data *wd = elm_widget_data_get(obj);
1147 Grid *g, *g_zoom = NULL;
1148 Evas_Coord pw, ph, rx, ry, rw, rh;
1150 int zoom_changed = 0, started = 0;
1153 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1154 if (zoom == wd->zoom) return;
1156 wd->size.ow = wd->size.w;
1157 wd->size.oh = wd->size.h;
1158 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1159 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1160 if ((rw <= 0) || (rh <= 0)) return;
1162 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1164 wd->size.nw = (double)wd->size.imw / wd->zoom;
1165 wd->size.nh = (double)wd->size.imh / wd->zoom;
1167 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1169 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1176 ph = (wd->size.imh * rw) / wd->size.imw;
1179 pw = (wd->size.imw * rh) / wd->size.imh;
1186 if (wd->size.imw > wd->size.imh)
1187 z = wd->size.imw / pw;
1189 z = wd->size.imh / ph;
1191 else if (z >= 4) z = 4;
1192 else if (z >= 2) z = 2;
1194 if (z != wd->zoom) zoom_changed = 1;
1200 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1202 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1209 ph = (wd->size.imh * rw) / wd->size.imw;
1212 pw = (wd->size.imw * rh) / wd->size.imh;
1219 if (wd->size.imw > wd->size.imh)
1220 z = wd->size.imw / pw;
1222 z = wd->size.imh / ph;
1224 else if (z >= 4) z = 4;
1225 else if (z >= 2) z = 2;
1227 if (z != wd->zoom) zoom_changed = 1;
1233 if (wd->main_load_pending)
1235 wd->size.w = wd->size.nw;
1236 wd->size.h = wd->size.nh;
1239 EINA_LIST_FOREACH(wd->grids, l, g)
1241 if (g->zoom == grid_zoom_calc(wd->zoom))
1243 wd->grids = eina_list_remove(wd->grids, g);
1244 wd->grids = eina_list_prepend(wd->grids, g);
1249 g = grid_create(obj);
1252 if (eina_list_count(wd->grids) > 1)
1254 g_zoom = eina_list_last(wd->grids)->data;
1255 wd->grids = eina_list_remove(wd->grids, g_zoom);
1256 grid_clear(obj, g_zoom);
1258 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1263 wd->grids = eina_list_prepend(wd->grids, g);
1267 EINA_LIST_FREE(wd->grids, g)
1274 wd->t_start = ecore_loop_time_get();
1275 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1276 if ((wd->size.w > 0) && (wd->size.h > 0))
1278 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1279 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1283 wd->size.spos.x = 0.5;
1284 wd->size.spos.y = 0.5;
1286 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1287 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1288 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1289 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1296 if (!wd->zoom_animator)
1298 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1300 if (wd->nosmooth == 1) _smooth_update(obj);
1304 an = wd->zoom_animator;
1307 if (!_zoom_anim(obj))
1309 ecore_animator_del(an);
1313 if (wd->calc_job) ecore_job_del(wd->calc_job);
1314 wd->calc_job = ecore_job_add(_calc_job, wd);
1318 evas_object_smart_callback_call(obj, "zoom,start", NULL);
1320 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1323 evas_object_smart_callback_call(obj, "zoom,change", NULL);
1327 * Get the zoom level of the photo
1329 * This returns the current zoom level of the photocam object. Note that if
1330 * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1331 * (which is the default), the zoom level may be changed at any time by the
1332 * photocam object itself to account for photo size and photocam viewpoer size
1334 * @param obj The photocam object
1335 * @return The current zoom level
1340 elm_photocam_zoom_get(const Evas_Object *obj)
1342 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1343 Widget_Data *wd = elm_widget_data_get(obj);
1344 if (!wd) return 1.0;
1351 * This sets the zoom mode to manual or one of several automatic levels.
1352 * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1353 * elm_photocam_zoom_set() and will stay at that level until changed by code
1354 * or until zoom mode is changed. This is the default mode.
1355 * The Automatic modes will allow the photocam object to automatically
1356 * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1357 * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1358 * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1359 * ensure no pixels within the frame are left unfilled.
1361 * @param obj The photocam object
1362 * @param mode The desired mode
1367 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1369 ELM_CHECK_WIDTYPE(obj, widtype);
1370 Widget_Data *wd = elm_widget_data_get(obj);
1372 if (wd->mode == mode) return;
1375 double tz = wd->zoom;
1377 elm_photocam_zoom_set(wd->obj, tz);
1384 * This gets the current zoom mode of the photocam object
1386 * @param obj The photocam object
1387 * @return The current zoom mode
1391 EAPI Elm_Photocam_Zoom_Mode
1392 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1394 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1395 Widget_Data *wd = elm_widget_data_get(obj);
1396 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1401 * Get the current image pixel width and height
1403 * This gets the current photo pixel width and height (for the original).
1404 * The size will be returned in the integers @p w and @p h that are pointed
1407 * @param obj The photocam object
1408 * @param w A pointer to the width return
1409 * @param h A pointer to the height return
1414 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1416 ELM_CHECK_WIDTYPE(obj, widtype);
1417 Widget_Data *wd = elm_widget_data_get(obj);
1419 if (w) *w = wd->size.imw;
1420 if (h) *h = wd->size.imh;
1424 * Get the current area of the image that is currently shown
1426 * This gets the region
1430 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1432 ELM_CHECK_WIDTYPE(obj, widtype);
1433 Widget_Data *wd = elm_widget_data_get(obj);
1434 Evas_Coord sx, sy, sw, sh;
1436 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1437 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1442 *x = (wd->size.imw * sx) / wd->size.w;
1443 if (*x > wd->size.imw) *x = wd->size.imw;
1444 else if (*x < 0) *x = 0;
1448 *w = (wd->size.imw * sw) / wd->size.w;
1449 if (*w > wd->size.imw) *w = wd->size.imw;
1450 else if (*w < 0) *w = 0;
1463 *y = (wd->size.imh * sy) / wd->size.h;
1464 if (*y > wd->size.imh) *y = wd->size.imh;
1465 else if (*y < 0) *y = 0;
1469 *h = (wd->size.imh * sh) / wd->size.h;
1470 if (*h > wd->size.imh) *h = wd->size.imh;
1471 else if (*h < 0) *h = 0;
1482 * Set the viewed portion of the image
1484 * This sets the region of the image to be viewed
1486 * @param obj The photocam object
1487 * @param x X-coordinate of region in image original pixels
1488 * @param y Y-coordinate of region in image original pixels
1489 * @param w Width of region in image original pixels
1490 * @param h Height of region in image original pixels
1495 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1497 ELM_CHECK_WIDTYPE(obj, widtype);
1498 Widget_Data *wd = elm_widget_data_get(obj);
1501 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1502 rx = (x * wd->size.w) / wd->size.imw;
1503 ry = (y * wd->size.h) / wd->size.imh;
1504 rw = (w * wd->size.w) / wd->size.imw;
1505 rh = (w * wd->size.h) / wd->size.imh;
1508 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1509 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1510 if (wd->zoom_animator)
1513 ecore_animator_del(wd->zoom_animator);
1514 wd->zoom_animator = NULL;
1516 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1518 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1522 * Bring in the viewed portion of the image
1524 * This brings in the region of the image over time
1526 * @param obj The photocam object
1527 * @param x X-coordinate of region in image original pixels
1528 * @param y Y-coordinate of region in image original pixels
1529 * @param w Width of region in image original pixels
1530 * @param h Height of region in image original pixels
1535 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1537 ELM_CHECK_WIDTYPE(obj, widtype);
1538 Widget_Data *wd = elm_widget_data_get(obj);
1541 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1542 rx = (x * wd->size.w) / wd->size.imw;
1543 ry = (y * wd->size.h) / wd->size.imh;
1544 rw = (w * wd->size.w) / wd->size.imw;
1545 rh = (w * wd->size.h) / wd->size.imh;
1548 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1549 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1550 if (wd->zoom_animator)
1553 if (wd->nosmooth == 0) _smooth_update(obj);
1554 ecore_animator_del(wd->zoom_animator);
1555 wd->zoom_animator = NULL;
1557 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1559 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1563 * Set the paused state for photocam
1565 * This sets the paused state to on (1) or off (0) for photocam. The default
1566 * is on. This will stop zooming using animation ch change zoom levels and
1567 * change instantly. This will stop any existing animations that are running.
1569 * @param obj The photocam object
1570 * @param paused The pause state to set
1575 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1577 ELM_CHECK_WIDTYPE(obj, widtype);
1578 Widget_Data *wd = elm_widget_data_get(obj);
1580 if (wd->paused == !!paused) return;
1581 wd->paused = paused;
1584 if (wd->zoom_animator)
1586 ecore_animator_del(wd->zoom_animator);
1587 wd->zoom_animator = NULL;
1589 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1595 * Get the paused state for photocam
1597 * This gets the current paused state for the photocam object.
1599 * @param obj The photocam object
1600 * @return The current paused state
1605 elm_photocam_paused_get(const Evas_Object *obj)
1607 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1608 Widget_Data *wd = elm_widget_data_get(obj);
1609 if (!wd) return EINA_FALSE;
1614 * Get ther internal low-res image used for photocam
1616 * This gets the internal image object inside photocam. Do not modify it. It
1617 * is for inspection only, and hooking callbacks to. Nothing else. It may be
1618 * deleted at any time as well.
1620 * @param obj The photocam object
1621 * @return The internal image object handle, or NULL if none exists
1626 elm_photocam_internal_image_get(const Evas_Object *obj)
1628 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1629 Widget_Data *wd = elm_widget_data_get(obj);
1630 if (!wd) return NULL;