1 #include <Elementary.h>
5 * @defgroup Photocam Photocam
7 * This is a widget specifically for displaying high-resolution digital
8 * camera photos giving speedy feedback (fast load), low memory footprint
9 * and zooming and panning as well as fitting logic. It is entirely focused
10 * on jpeg images, and takes advantage of properties of the jpeg format (via
11 * evas loader features in the jpeg loader).
13 * Signals that you can add callbacks for are:
15 * clicked - This is called when a user has clicked the photo without dragging
18 * press - This is called when a user has pressed down on the photo.
20 * longpressed - This is called when a user has pressed down on the photo for
21 * a long time without dragging around.
23 * clicked,double - This is called when a user has double-clicked the photo.
25 * load - Photo load begins.
27 * loaded - This is called when the image file load is complete for the first
28 * view (low resolution blurry version).
30 * load,details - Photo detailed data load begins.
32 * loaded,details - This is called when the image file load is complete for the
33 * detailed image data (full resolution needed).
35 * zoom,start - Zoom animation started.
37 * zoom,stop - Zoom animation stopped.
39 * zoom,change - Zoom changed when using an auto zoom mode.
41 * scroll - the content has been scrolled (moved)
43 * scroll,anim,start - scrolling animation has started
45 * scroll,anim,stop - scrolling animation has stopped
47 * scroll,drag,start - dragging the contents around has started
49 * scroll,drag,stop - dragging the contents around has stopped
53 * TODO (maybe - optional future stuff):
55 * 1. wrap photo in theme edje so u can have styling around photo (like white
58 * 3. rotation flags in exif handling (nasty! should have rot in evas)
61 typedef struct _Widget_Data Widget_Data;
62 typedef struct _Pan Pan;
63 typedef struct _Grid Grid;
64 typedef struct _Grid_Item Grid_Item;
80 int tsize; // size of tile (tsize x tsize pixels)
81 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
82 int iw, ih; // size of image in pixels
83 int w, h; // size of grid image in pixels (represented by grid)
84 int gw, gh; // size of grid in tiles
85 Grid_Item *grid; // the grid (gw * gh items)
86 Eina_Bool dead : 1; // old grid. will die as soon as anim is over
93 Evas_Object *pan_smart;
95 Evas_Coord pan_x, pan_y, minw, minh;
98 Elm_Photocam_Zoom_Mode mode;
102 Ecore_Timer *scr_timer;
103 Ecore_Timer *long_timer;
104 Ecore_Animator *zoom_animator;
105 double t_start, t_end;
119 Evas_Coord x, y ,w ,h;
122 Evas_Object *img; // low res version of image (scale down == 8)
126 Eina_Bool main_load_pending : 1;
127 Eina_Bool resized : 1;
128 Eina_Bool longpressed : 1;
129 Eina_Bool on_hold : 1;
130 Eina_Bool paused : 1;
135 Evas_Object_Smart_Clipped_Data __clipped_data;
139 static const char *widtype = NULL;
140 static void _del_hook(Evas_Object *obj);
141 static void _theme_hook(Evas_Object *obj);
142 //static void _show_region_hook(void *data, Evas_Object *obj);
143 static void _sizing_eval(Evas_Object *obj);
144 static void _calc_job(void *data);
145 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);
146 static void grid_clear(Evas_Object *obj, Grid *g);
147 static Grid *grid_create(Evas_Object *obj);
148 static void grid_load(Evas_Object *obj, Grid *g);
151 nearest_pow2(int num)
153 unsigned int n = num - 1;
163 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
165 Widget_Data *wd = elm_widget_data_get(obj);
166 Evas_Coord ax, ay, gw, gh;
172 if (ow > gw) ax = (ow - gw) / 2;
173 if (oh > gh) ay = (oh - gh) / 2;
174 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
175 evas_object_resize(wd->img, gw, gh);
179 wd->show.show = EINA_FALSE;
180 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
185 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)
187 Widget_Data *wd = elm_widget_data_get(obj);
188 Evas_Coord ax, ay, gw, gh, tx, ty;
195 if (ow > gw) ax = (ow - gw) / 2;
196 if (oh > gh) ay = (oh - gh) / 2;
197 for (y = 0; y < g->gh; y++)
199 for (x = 0; x < g->gw; x++)
201 int tn, xx, yy, ww, hh;
203 tn = (y * g->gw) + x;
204 xx = g->grid[tn].out.x;
205 yy = g->grid[tn].out.y;
206 ww = g->grid[tn].out.w;
207 hh = g->grid[tn].out.h;
208 if ((gw != g->w) && (g->w > 0))
211 xx = (gw * xx) / g->w;
212 ww = ((gw * (tx + ww)) / g->w) - xx;
214 if ((gh != g->h) && (g->h > 0))
217 yy = (gh * yy) / g->h;
218 hh = ((gh * (ty + hh)) / g->h) - yy;
220 evas_object_move(g->grid[tn].img,
223 evas_object_resize(g->grid[tn].img, ww, hh);
229 grid_clear(Evas_Object *obj, Grid *g)
231 Widget_Data *wd = elm_widget_data_get(obj);
234 if (!g->grid) return;
235 for (y = 0; y < g->gh; y++)
237 for (x = 0; x < g->gw; x++)
241 tn = (y * g->gw) + x;
242 evas_object_del(g->grid[tn].img);
243 if (g->grid[tn].want)
246 if (wd->preload_num == 0)
248 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
249 "elm,state,busy,stop", "elm");
250 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
262 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
264 Grid_Item *git = data;
269 evas_object_show(git->img);
271 git->wd->preload_num--;
272 if (git->wd->preload_num == 0)
274 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
275 "elm,state,busy,stop", "elm");
276 evas_object_smart_callback_call(git->wd->obj, "loaded,detail", NULL);
282 grid_zoom_calc(double zoom)
286 return nearest_pow2(z);
290 grid_create(Evas_Object *obj)
292 Widget_Data *wd = elm_widget_data_get(obj);
296 if (!wd) return NULL;
297 g = calloc(1, sizeof(Grid));
299 g->zoom = grid_zoom_calc(wd->zoom);
300 g->tsize = wd->tsize;
301 g->iw = wd->size.imw;
302 g->ih = wd->size.imh;
304 g->w = g->iw / g->zoom;
305 g->h = g->ih / g->zoom;
306 if (g->zoom >= 8) return NULL;
307 g->gw = (g->w + g->tsize - 1) / g->tsize;
308 g->gh = (g->h + g->tsize - 1) / g->tsize;
309 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
316 for (y = 0; y < g->gh; y++)
318 for (x = 0; x < g->gw; x++)
322 tn = (y * g->gw) + x;
323 g->grid[tn].src.x = x * g->tsize;
324 if (x == (g->gw - 1))
325 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
327 g->grid[tn].src.w = g->tsize;
328 g->grid[tn].src.y = y * g->tsize;
329 if (y == (g->gh - 1))
330 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
332 g->grid[tn].src.h = g->tsize;
334 g->grid[tn].out.x = g->grid[tn].src.x;
335 g->grid[tn].out.y = g->grid[tn].src.y;
336 g->grid[tn].out.w = g->grid[tn].src.w;
337 g->grid[tn].out.h = g->grid[tn].src.h;
341 evas_object_image_add(evas_object_evas_get(obj));
342 evas_object_image_scale_hint_set
343 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
344 evas_object_pass_events_set(g->grid[tn].img, 1);
345 evas_object_smart_member_add(g->grid[tn].img,
347 elm_widget_sub_object_add(obj, g->grid[tn].img);
348 evas_object_image_filled_set(g->grid[tn].img, 1);
349 evas_object_event_callback_add(g->grid[tn].img,
350 EVAS_CALLBACK_IMAGE_PRELOADED,
359 grid_load(Evas_Object *obj, Grid *g)
361 Widget_Data *wd = elm_widget_data_get(obj);
363 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, ax, ay, tx, ty;
365 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
366 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
371 if (ow > gw) ax = (ow - gw) / 2;
372 if (oh > gh) ay = (oh - gh) / 2;
373 for (y = 0; y < g->gh; y++)
375 for (x = 0; x < g->gw; x++)
377 int tn, xx, yy, ww, hh;
378 Eina_Bool visible = EINA_FALSE;
380 tn = (y * g->gw) + x;
381 xx = g->grid[tn].out.x;
382 yy = g->grid[tn].out.y;
383 ww = g->grid[tn].out.w;
384 hh = g->grid[tn].out.h;
385 if ((gw != g->w) && (g->w > 0))
388 xx = (gw * xx) / g->w;
389 ww = ((gw * (tx + ww)) / g->w) - xx;
391 if ((gh != g->h) && (g->h > 0))
394 yy = (gh * yy) / g->h;
395 hh = ((gh * (ty + hh)) / g->h) - yy;
399 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
404 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
406 g->grid[tn].want = 1;
407 evas_object_hide(g->grid[tn].img);
408 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
409 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
410 evas_object_image_load_region_set(g->grid[tn].img,
415 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
416 evas_object_image_preload(g->grid[tn].img, 0);
418 if (wd->preload_num == 1)
420 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
421 "elm,state,busy,start", "elm");
422 evas_object_smart_callback_call(obj, "load,detail", NULL);
425 else if ((g->grid[tn].want) && (!visible))
428 if (wd->preload_num == 0)
430 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
431 "elm,state,busy,stop", "elm");
432 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
434 g->grid[tn].want = 0;
435 evas_object_hide(g->grid[tn].img);
436 evas_object_image_preload(g->grid[tn].img, 1);
437 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
439 else if ((g->grid[tn].have) && (!visible))
441 g->grid[tn].have = 0;
442 evas_object_hide(g->grid[tn].img);
443 evas_object_image_preload(g->grid[tn].img, 1);
444 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
451 grid_clearall(Evas_Object *obj)
453 Widget_Data *wd = elm_widget_data_get(obj);
456 EINA_LIST_FREE(wd->grids, g)
464 _smooth_update(Evas_Object *obj)
466 Widget_Data *wd = elm_widget_data_get(obj);
471 EINA_LIST_FOREACH(wd->grids, l, g)
473 for (y = 0; y < g->gh; y++)
475 for (x = 0; x < g->gw; x++)
479 tn = (y * g->gw) + x;
480 evas_object_image_smooth_scale_set(g->grid[tn].img, (wd->nosmooth == 0));
484 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
492 for (y = 0; y < g->gh; y++)
494 for (x = 0; x < g->gw; x++)
498 tn = (y * g->gw) + x;
499 evas_object_raise(g->grid[tn].img);
505 _scr_timeout(void *data)
507 Widget_Data *wd = elm_widget_data_get(data);
510 if (wd->nosmooth == 0) _smooth_update(data);
511 wd->scr_timer = NULL;
516 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
518 Widget_Data *wd = elm_widget_data_get(data);
523 if (wd->nosmooth == 1) _smooth_update(data);
525 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
526 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
530 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
532 Evas_Object *obj = data;
533 Widget_Data *wd = elm_widget_data_get(obj);
536 evas_object_show(wd->img);
537 wd->main_load_pending = 0;
538 g = grid_create(obj);
541 wd->grids = eina_list_prepend(wd->grids, g);
542 grid_load(wd->obj, g);
544 if (wd->calc_job) ecore_job_del(wd->calc_job);
545 wd->calc_job = ecore_job_add(_calc_job, wd);
546 evas_object_smart_callback_call(data, "loaded", NULL);
548 if (wd->preload_num == 0)
550 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
551 "elm,state,busy,stop", "elm");
552 evas_object_smart_callback_call(obj, "loaded,detail", NULL);
557 zoom_do(Evas_Object *obj, double t)
559 Widget_Data *wd = elm_widget_data_get(obj);
560 Evas_Coord xx, yy, ow, oh;
562 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
563 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
564 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
565 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
566 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
568 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
570 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
572 wd->show.show = EINA_TRUE;
578 if (wd->calc_job) ecore_job_del(wd->calc_job);
579 wd->calc_job = ecore_job_add(_calc_job, wd);
582 Eina_List *l, *l_next;
585 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
589 wd->grids = eina_list_remove_list(wd->grids, l);
601 _zoom_anim(void *data)
603 Evas_Object *obj = data;
604 Widget_Data *wd = elm_widget_data_get(obj);
608 t = ecore_loop_time_get();
611 else if (wd->t_end > wd->t_start)
612 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
617 go = zoom_do(obj, t);
621 if (wd->nosmooth == 0) _smooth_update(data);
622 wd->zoom_animator = NULL;
623 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
629 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
631 Widget_Data *wd = elm_widget_data_get(data);
632 // Evas_Event_Mouse_Move *ev = event_info;
637 _long_press(void *data)
639 Widget_Data *wd = elm_widget_data_get(data);
641 wd->long_timer = NULL;
642 wd->longpressed = EINA_TRUE;
643 evas_object_smart_callback_call(data, "longpressed", NULL);
648 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
650 Widget_Data *wd = elm_widget_data_get(data);
651 Evas_Event_Mouse_Down *ev = event_info;
653 if (ev->button != 1) return;
654 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
655 else wd->on_hold = EINA_FALSE;
656 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
657 evas_object_smart_callback_call(data, "clicked,double", NULL);
659 evas_object_smart_callback_call(data, "press", NULL);
660 wd->longpressed = EINA_FALSE;
661 if (wd->long_timer) ecore_timer_del(wd->long_timer);
662 wd->long_timer = ecore_timer_add(1.0, _long_press, data);
666 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
668 Widget_Data *wd = elm_widget_data_get(data);
669 Evas_Event_Mouse_Up *ev = event_info;
671 if (ev->button != 1) return;
672 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
673 else wd->on_hold = EINA_FALSE;
676 ecore_timer_del(wd->long_timer);
677 wd->long_timer = NULL;
680 evas_object_smart_callback_call(data, "clicked", NULL);
681 wd->on_hold = EINA_FALSE;
684 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
687 _del_hook(Evas_Object *obj)
689 Widget_Data *wd = elm_widget_data_get(obj);
692 EINA_LIST_FREE(wd->grids, g)
694 if (g->grid) free(g->grid);
697 evas_object_del(wd->pan_smart);
698 wd->pan_smart = NULL;
699 if (wd->file) eina_stringshare_del(wd->file);
700 if (wd->calc_job) ecore_job_del(wd->calc_job);
701 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
702 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
703 if (wd->long_timer) ecore_timer_del(wd->long_timer);
708 _theme_hook(Evas_Object *obj)
710 Widget_Data *wd = elm_widget_data_get(obj);
712 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
713 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
719 _show_region_hook(void *data, Evas_Object *obj)
721 Widget_Data *wd = elm_widget_data_get(data);
722 Evas_Coord x, y, w, h;
724 elm_widget_show_region_get(obj, &x, &y, &w, &h);
725 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
730 _sizing_eval(Evas_Object *obj)
732 Widget_Data *wd = elm_widget_data_get(obj);
733 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
735 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
736 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
739 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
740 evas_object_size_hint_min_set(obj, minw, minh);
741 evas_object_size_hint_max_set(obj, maxw, maxh);
745 _calc_job(void *data)
747 Widget_Data *wd = data;
748 Evas_Coord minw, minh;
755 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
757 double tz = wd->zoom;
759 elm_photocam_zoom_set(wd->obj, tz);
762 if ((minw != wd->minw) || (minh != wd->minh))
766 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
767 _sizing_eval(wd->obj);
770 evas_object_smart_changed(wd->pan_smart);
774 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
776 Pan *sd = evas_object_smart_data_get(obj);
778 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
781 evas_object_smart_changed(obj);
785 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
787 Pan *sd = evas_object_smart_data_get(obj);
789 if (x) *x = sd->wd->pan_x;
790 if (y) *y = sd->wd->pan_y;
794 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
796 Pan *sd = evas_object_smart_data_get(obj);
799 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
800 ow = sd->wd->minw - ow;
802 oh = sd->wd->minh - oh;
809 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
811 Pan *sd = evas_object_smart_data_get(obj);
813 if (w) *w = sd->wd->minw;
814 if (h) *h = sd->wd->minh;
818 _pan_add(Evas_Object *obj)
821 Evas_Object_Smart_Clipped_Data *cd;
823 cd = evas_object_smart_data_get(obj);
825 sd = calloc(1, sizeof(Pan));
827 sd->__clipped_data = *cd;
829 evas_object_smart_data_set(obj, sd);
833 _pan_del(Evas_Object *obj)
835 Pan *sd = evas_object_smart_data_get(obj);
841 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
843 Pan *sd = evas_object_smart_data_get(obj);
846 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
847 if ((ow == w) && (oh == h)) return;
849 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
850 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
854 _pan_calculate(Evas_Object *obj)
856 Pan *sd = evas_object_smart_data_get(obj);
857 Evas_Coord ox, oy, ow, oh;
861 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
862 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
863 EINA_LIST_FOREACH(sd->wd->grids, l, g)
865 grid_load(sd->wd->obj, g);
866 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
871 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
873 Pan *sd = evas_object_smart_data_get(obj);
875 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
876 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
880 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
882 Widget_Data *wd = elm_widget_data_get(obj);
884 elm_smart_scroller_hold_set(wd->scr, 1);
888 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
890 Widget_Data *wd = elm_widget_data_get(obj);
892 elm_smart_scroller_hold_set(wd->scr, 0);
896 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
898 Widget_Data *wd = elm_widget_data_get(obj);
900 elm_smart_scroller_freeze_set(wd->scr, 1);
904 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
906 Widget_Data *wd = elm_widget_data_get(obj);
908 elm_smart_scroller_freeze_set(wd->scr, 0);
912 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
914 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
918 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
920 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
924 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
926 evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
930 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
932 evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
936 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
938 evas_object_smart_callback_call(data, "scroll", NULL);
942 * Add a new Photocam object
944 * @param parent The parent object
945 * @return The new object or NULL if it cannot be created
950 elm_photocam_add(Evas_Object *parent)
955 Evas_Coord minw, minh;
956 static Evas_Smart *smart = NULL;
958 wd = ELM_NEW(Widget_Data);
959 e = evas_object_evas_get(parent);
960 obj = elm_widget_add(e);
961 ELM_SET_WIDTYPE(widtype, "photocam");
962 elm_widget_type_set(obj, "photocam");
963 elm_widget_sub_object_add(parent, obj);
964 elm_widget_data_set(obj, wd);
965 elm_widget_del_hook_set(obj, _del_hook);
966 elm_widget_theme_hook_set(obj, _theme_hook);
968 wd->scr = elm_smart_scroller_add(e);
969 elm_smart_scroller_widget_set(wd->scr, obj);
970 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
971 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
972 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
973 elm_widget_resize_object_set(obj, wd->scr);
975 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
976 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
977 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
978 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
979 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
981 elm_smart_scroller_bounce_allow_set(wd->scr, 1, 1);
985 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
986 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
987 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
988 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
992 static Evas_Smart_Class sc;
994 evas_object_smart_clipped_smart_set(&_pan_sc);
996 sc.name = "elm_photocam_pan";
997 sc.version = EVAS_SMART_CLASS_VERSION;
1000 sc.resize = _pan_resize;
1001 sc.move = _pan_move;
1002 sc.calculate = _pan_calculate;
1003 smart = evas_smart_class_new(&sc);
1007 wd->pan_smart = evas_object_smart_add(e, smart);
1008 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1012 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1014 _pan_max_get, _pan_child_size_get);
1017 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1021 wd->img = evas_object_image_add(e);
1022 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1023 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1025 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1027 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1029 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1030 evas_object_smart_member_add(wd->img, wd->pan_smart);
1031 elm_widget_sub_object_add(obj, wd->img);
1032 evas_object_image_filled_set(wd->img, 1);
1033 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1034 _main_preloaded, obj);
1036 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1038 evas_object_size_hint_min_set(obj, minw, minh);
1045 * Set the photo file to be shown
1047 * This sets (and shows) the specified file (with a relative or absolute path)
1048 * and will return a load error (same error that
1049 * evas_object_image_load_error_get() will return). The image will change and
1050 * adjust its size at this point and begin a background load process for this
1051 * photo that at some time in the future will be displayed at the full quality
1054 * @param obj The photocam object
1055 * @param file The photo file
1056 * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1061 elm_photocam_file_set(Evas_Object *obj, const char *file)
1063 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1064 Widget_Data *wd = elm_widget_data_get(obj);
1066 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1067 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1068 evas_object_hide(wd->img);
1069 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1070 evas_object_image_file_set(wd->img, NULL, NULL);
1071 evas_object_image_load_scale_down_set(wd->img, 0);
1072 evas_object_image_file_set(wd->img, wd->file, NULL);
1073 evas_object_image_size_get(wd->img, &w, &h);
1076 wd->size.w = wd->size.imw / wd->zoom;
1077 wd->size.h = wd->size.imh / wd->zoom;
1078 if (wd->zoom_animator)
1081 if (wd->nosmooth == 0) _smooth_update(obj);
1082 ecore_animator_del(wd->zoom_animator);
1083 wd->zoom_animator = NULL;
1085 evas_object_image_file_set(wd->img, NULL, NULL);
1086 evas_object_image_load_scale_down_set(wd->img, 8);
1087 evas_object_image_file_set(wd->img, wd->file, NULL);
1088 evas_object_image_preload(wd->img, 0);
1089 wd->main_load_pending = 1;
1091 if (wd->calc_job) ecore_job_del(wd->calc_job);
1092 wd->calc_job = ecore_job_add(_calc_job, wd);
1093 evas_object_smart_callback_call(obj, "load", NULL);
1095 if (wd->preload_num == 1)
1097 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1098 "elm,state,busy,start", "elm");
1099 evas_object_smart_callback_call(obj, "load,detail", NULL);
1102 double tz = wd->zoom;
1104 elm_photocam_zoom_set(wd->obj, tz);
1106 return evas_object_image_load_error_get(wd->img);
1110 * Returns the path of the current image file
1112 * @param obj The photocam object
1113 * @return Returns the path
1118 elm_photocam_file_get(const Evas_Object *obj)
1120 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1121 Widget_Data *wd = elm_widget_data_get(obj);
1122 if (!wd) return NULL;
1127 * Set the zoom level of the photo
1129 * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1130 * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1131 * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1132 * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1135 * @param obj The photocam object
1136 * @param zoom The zoom level to set
1141 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1143 ELM_CHECK_WIDTYPE(obj, widtype);
1144 Widget_Data *wd = elm_widget_data_get(obj);
1146 Grid *g, *g_zoom = NULL;
1147 Evas_Coord pw, ph, rx, ry, rw, rh;
1149 int zoom_changed = 0, started = 0;
1152 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1153 if (zoom == wd->zoom) return;
1155 wd->size.ow = wd->size.w;
1156 wd->size.oh = wd->size.h;
1157 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1158 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1159 if ((rw <= 0) || (rh <= 0)) return;
1161 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1163 wd->size.nw = (double)wd->size.imw / wd->zoom;
1164 wd->size.nh = (double)wd->size.imh / wd->zoom;
1166 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1168 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1175 ph = (wd->size.imh * rw) / wd->size.imw;
1178 pw = (wd->size.imw * rh) / wd->size.imh;
1185 if (wd->size.imw > wd->size.imh)
1186 z = wd->size.imw / pw;
1188 z = wd->size.imh / ph;
1190 else if (z >= 4) z = 4;
1191 else if (z >= 2) z = 2;
1193 if (z != wd->zoom) zoom_changed = 1;
1199 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1201 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1208 ph = (wd->size.imh * rw) / wd->size.imw;
1211 pw = (wd->size.imw * rh) / wd->size.imh;
1218 if (wd->size.imw > wd->size.imh)
1219 z = wd->size.imw / pw;
1221 z = wd->size.imh / ph;
1223 else if (z >= 4) z = 4;
1224 else if (z >= 2) z = 2;
1226 if (z != wd->zoom) zoom_changed = 1;
1232 if (wd->main_load_pending)
1234 wd->size.w = wd->size.nw;
1235 wd->size.h = wd->size.nh;
1238 EINA_LIST_FOREACH(wd->grids, l, g)
1240 if (g->zoom == grid_zoom_calc(wd->zoom))
1242 wd->grids = eina_list_remove(wd->grids, g);
1243 wd->grids = eina_list_prepend(wd->grids, g);
1248 g = grid_create(obj);
1251 if (eina_list_count(wd->grids) > 1)
1253 g_zoom = eina_list_last(wd->grids)->data;
1254 wd->grids = eina_list_remove(wd->grids, g_zoom);
1255 grid_clear(obj, g_zoom);
1257 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1262 wd->grids = eina_list_prepend(wd->grids, g);
1266 EINA_LIST_FREE(wd->grids, g)
1273 wd->t_start = ecore_loop_time_get();
1274 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1275 if ((wd->size.w > 0) && (wd->size.h > 0))
1277 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1278 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1282 wd->size.spos.x = 0.5;
1283 wd->size.spos.y = 0.5;
1285 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1286 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1287 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1288 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1295 if (!wd->zoom_animator)
1297 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1299 if (wd->nosmooth == 1) _smooth_update(obj);
1303 an = wd->zoom_animator;
1306 if (!_zoom_anim(obj))
1308 ecore_animator_del(an);
1312 if (wd->calc_job) ecore_job_del(wd->calc_job);
1313 wd->calc_job = ecore_job_add(_calc_job, wd);
1317 evas_object_smart_callback_call(obj, "zoom,start", NULL);
1319 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1322 evas_object_smart_callback_call(obj, "zoom,change", NULL);
1326 * Get the zoom level of the photo
1328 * This returns the current zoom level of the photocam object. Note that if
1329 * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1330 * (which is the default), the zoom level may be changed at any time by the
1331 * photocam object itself to account for photo size and photocam viewpoer size
1333 * @param obj The photocam object
1334 * @return The current zoom level
1339 elm_photocam_zoom_get(const Evas_Object *obj)
1341 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1342 Widget_Data *wd = elm_widget_data_get(obj);
1343 if (!wd) return 1.0;
1350 * This sets the zoom mode to manual or one of several automatic levels.
1351 * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1352 * elm_photocam_zoom_set() and will stay at that level until changed by code
1353 * or until zoom mode is changed. This is the default mode.
1354 * The Automatic modes will allow the photocam object to automatically
1355 * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1356 * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1357 * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1358 * ensure no pixels within the frame are left unfilled.
1360 * @param obj The photocam object
1361 * @param mode The desired mode
1366 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1368 ELM_CHECK_WIDTYPE(obj, widtype);
1369 Widget_Data *wd = elm_widget_data_get(obj);
1371 if (wd->mode == mode) return;
1374 double tz = wd->zoom;
1376 elm_photocam_zoom_set(wd->obj, tz);
1383 * This gets the current zoom mode of the photocam object
1385 * @param obj The photocam object
1386 * @return The current zoom mode
1390 EAPI Elm_Photocam_Zoom_Mode
1391 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1393 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1394 Widget_Data *wd = elm_widget_data_get(obj);
1395 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1400 * Get the current image pixel width and height
1402 * This gets the current photo pixel width and height (for the original).
1403 * The size will be returned in the integers @p w and @p h that are pointed
1406 * @param obj The photocam object
1407 * @param w A pointer to the width return
1408 * @param h A pointer to the height return
1413 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1415 ELM_CHECK_WIDTYPE(obj, widtype);
1416 Widget_Data *wd = elm_widget_data_get(obj);
1418 if (w) *w = wd->size.imw;
1419 if (h) *h = wd->size.imh;
1423 * Get the current area of the image that is currently shown
1425 * This gets the region
1429 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1431 ELM_CHECK_WIDTYPE(obj, widtype);
1432 Widget_Data *wd = elm_widget_data_get(obj);
1433 Evas_Coord sx, sy, sw, sh;
1435 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1436 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1441 *x = (wd->size.imw * sx) / wd->size.w;
1442 if (*x > wd->size.imw) *x = wd->size.imw;
1443 else if (*x < 0) *x = 0;
1447 *w = (wd->size.imw * sw) / wd->size.w;
1448 if (*w > wd->size.imw) *w = wd->size.imw;
1449 else if (*w < 0) *w = 0;
1462 *y = (wd->size.imh * sy) / wd->size.h;
1463 if (*y > wd->size.imh) *y = wd->size.imh;
1464 else if (*y < 0) *y = 0;
1468 *h = (wd->size.imh * sh) / wd->size.h;
1469 if (*h > wd->size.imh) *h = wd->size.imh;
1470 else if (*h < 0) *h = 0;
1481 * Set the viewed portion of the image
1483 * This sets the region of the image to be viewed
1485 * @param obj The photocam object
1486 * @param x X-coordinate of region in image original pixels
1487 * @param y Y-coordinate of region in image original pixels
1488 * @param w Width of region in image original pixels
1489 * @param h Height of region in image original pixels
1494 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1496 ELM_CHECK_WIDTYPE(obj, widtype);
1497 Widget_Data *wd = elm_widget_data_get(obj);
1500 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1501 rx = (x * wd->size.w) / wd->size.imw;
1502 ry = (y * wd->size.h) / wd->size.imh;
1503 rw = (w * wd->size.w) / wd->size.imw;
1504 rh = (w * wd->size.h) / wd->size.imh;
1507 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1508 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1509 if (wd->zoom_animator)
1512 ecore_animator_del(wd->zoom_animator);
1513 wd->zoom_animator = NULL;
1515 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1517 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1521 * Bring in the viewed portion of the image
1523 * This brings in the region of the image over time
1525 * @param obj The photocam object
1526 * @param x X-coordinate of region in image original pixels
1527 * @param y Y-coordinate of region in image original pixels
1528 * @param w Width of region in image original pixels
1529 * @param h Height of region in image original pixels
1534 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1536 ELM_CHECK_WIDTYPE(obj, widtype);
1537 Widget_Data *wd = elm_widget_data_get(obj);
1540 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1541 rx = (x * wd->size.w) / wd->size.imw;
1542 ry = (y * wd->size.h) / wd->size.imh;
1543 rw = (w * wd->size.w) / wd->size.imw;
1544 rh = (w * wd->size.h) / wd->size.imh;
1547 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1548 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1549 if (wd->zoom_animator)
1552 if (wd->nosmooth == 0) _smooth_update(obj);
1553 ecore_animator_del(wd->zoom_animator);
1554 wd->zoom_animator = NULL;
1556 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1558 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1562 * Set the paused state for photocam
1564 * This sets the paused state to on (1) or off (0) for photocam. The default
1565 * is on. This will stop zooming using animation ch change zoom levels and
1566 * change instantly. This will stop any existing animations that are running.
1568 * @param obj The photocam object
1569 * @param paused The pause state to set
1574 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1576 ELM_CHECK_WIDTYPE(obj, widtype);
1577 Widget_Data *wd = elm_widget_data_get(obj);
1579 if (wd->paused == !!paused) return;
1580 wd->paused = paused;
1583 if (wd->zoom_animator)
1585 ecore_animator_del(wd->zoom_animator);
1586 wd->zoom_animator = NULL;
1588 evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1594 * Get the paused state for photocam
1596 * This gets the current paused state for the photocam object.
1598 * @param obj The photocam object
1599 * @return The current paused state
1604 elm_photocam_paused_get(const Evas_Object *obj)
1606 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1607 Widget_Data *wd = elm_widget_data_get(obj);
1608 if (!wd) return EINA_FALSE;
1613 * Get ther internal low-res image used for photocam
1615 * This gets the internal image object inside photocam. Do not modify it. It
1616 * is for inspection only, and hooking callbacks to. Nothing else. It may be
1617 * deleted at any time as well.
1619 * @param obj The photocam object
1620 * @return The internal image object handle, or NULL if none exists
1625 elm_photocam_internal_image_get(const Evas_Object *obj)
1627 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1628 Widget_Data *wd = elm_widget_data_get(obj);
1629 if (!wd) return NULL;