1 #include <Elementary.h>
5 * TODO (maybe - optional future stuff):
7 * 1. wrap photo in theme edje so u can have styling around photo (like white
10 * 3. rotation flags in exif handling (nasty! should have rot in evas)
13 typedef struct _Widget_Data Widget_Data;
14 typedef struct _Pan Pan;
15 typedef struct _Grid Grid;
16 typedef struct _Grid_Item Grid_Item;
32 int tsize; // size of tile (tsize x tsize pixels)
33 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
34 int iw, ih; // size of image in pixels
35 int w, h; // size of grid image in pixels (represented by grid)
36 int gw, gh; // size of grid in tiles
37 Grid_Item *grid; // the grid (gw * gh items)
38 Eina_Bool dead : 1; // old grid. will die as soon as anim is over
45 Evas_Object *pan_smart;
47 Evas_Coord pan_x, pan_y, minw, minh;
50 Elm_Photocam_Zoom_Mode mode;
54 Ecore_Timer *scr_timer;
55 Ecore_Timer *long_timer;
56 Ecore_Animator *zoom_animator;
57 double t_start, t_end;
71 Evas_Coord x, y ,w ,h;
74 Evas_Object *img; // low res version of image (scale down == 8)
78 Eina_Bool main_load_pending : 1;
79 Eina_Bool resized : 1;
80 Eina_Bool longpressed : 1;
81 Eina_Bool on_hold : 1;
87 Evas_Object_Smart_Clipped_Data __clipped_data;
91 static const char *widtype = NULL;
92 static void _del_hook(Evas_Object *obj);
93 static void _theme_hook(Evas_Object *obj);
94 static void _on_focus_hook(void *data, Evas_Object *obj);
95 //static void _show_region_hook(void *data, Evas_Object *obj);
96 static void _sizing_eval(Evas_Object *obj);
97 static void _calc_job(void *data);
98 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
99 Evas_Callback_Type type, void *event_info);
100 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);
101 static void grid_clear(Evas_Object *obj, Grid *g);
102 static Grid *grid_create(Evas_Object *obj);
103 static void grid_load(Evas_Object *obj, Grid *g);
105 static const char SIG_CLICKED[] = "clicked";
106 static const char SIG_PRESS[] = "press";
107 static const char SIG_LONGPRESSED[] = "longpressed";
108 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
109 static const char SIG_LOAD[] = "load";
110 static const char SIG_LOADED[] = "loaded";
111 static const char SIG_LOAD_DETAIL[] = "load,detail";
112 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
113 static const char SIG_ZOOM_START[] = "zoom,start";
114 static const char SIG_ZOOM_STOP[] = "zoom,stop";
115 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
116 static const char SIG_SCROLL[] = "scroll";
117 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
118 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
119 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
120 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
122 static const Evas_Smart_Cb_Description _signals[] = {
125 {SIG_LONGPRESSED, ""},
126 {SIG_CLICKED_DOUBLE, ""},
129 {SIG_LOAD_DETAIL, ""},
130 {SIG_LOADED_DETAIL, ""},
131 {SIG_ZOOM_START, ""},
133 {SIG_ZOOM_CHANGE, ""},
135 {SIG_SCROLL_ANIM_START, ""},
136 {SIG_SCROLL_ANIM_STOP, ""},
137 {SIG_SCROLL_DRAG_START, ""},
138 {SIG_SCROLL_DRAG_STOP, ""},
144 nearest_pow2(int num)
146 unsigned int n = num - 1;
156 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
158 Widget_Data *wd = elm_widget_data_get(obj);
159 Evas_Coord ax, ay, gw, gh;
165 if (ow > gw) ax = (ow - gw) / 2;
166 if (oh > gh) ay = (oh - gh) / 2;
167 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
168 evas_object_resize(wd->img, gw, gh);
172 wd->show.show = EINA_FALSE;
173 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
178 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)
180 Widget_Data *wd = elm_widget_data_get(obj);
181 Evas_Coord ax, ay, gw, gh, tx, ty;
188 if (ow > gw) ax = (ow - gw) / 2;
189 if (oh > gh) ay = (oh - gh) / 2;
190 for (y = 0; y < g->gh; y++)
192 for (x = 0; x < g->gw; x++)
194 int tn, xx, yy, ww, hh;
196 tn = (y * g->gw) + x;
197 xx = g->grid[tn].out.x;
198 yy = g->grid[tn].out.y;
199 ww = g->grid[tn].out.w;
200 hh = g->grid[tn].out.h;
201 if ((gw != g->w) && (g->w > 0))
204 xx = (gw * xx) / g->w;
205 ww = ((gw * (tx + ww)) / g->w) - xx;
207 if ((gh != g->h) && (g->h > 0))
210 yy = (gh * yy) / g->h;
211 hh = ((gh * (ty + hh)) / g->h) - yy;
213 evas_object_move(g->grid[tn].img,
216 evas_object_resize(g->grid[tn].img, ww, hh);
222 grid_clear(Evas_Object *obj, Grid *g)
224 Widget_Data *wd = elm_widget_data_get(obj);
227 if (!g->grid) return;
228 for (y = 0; y < g->gh; y++)
230 for (x = 0; x < g->gw; x++)
234 tn = (y * g->gw) + x;
235 evas_object_del(g->grid[tn].img);
236 if (g->grid[tn].want)
239 if (!wd->preload_num)
241 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
242 "elm,state,busy,stop", "elm");
243 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
255 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
257 Grid_Item *git = data;
262 evas_object_show(git->img);
264 git->wd->preload_num--;
265 if (!git->wd->preload_num)
267 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
268 "elm,state,busy,stop", "elm");
269 evas_object_smart_callback_call(git->wd->obj, SIG_LOADED_DETAIL, NULL);
275 grid_zoom_calc(double zoom)
279 return nearest_pow2(z);
283 grid_create(Evas_Object *obj)
285 Widget_Data *wd = elm_widget_data_get(obj);
289 if (!wd) return NULL;
290 g = calloc(1, sizeof(Grid));
292 g->zoom = grid_zoom_calc(wd->zoom);
293 g->tsize = wd->tsize;
294 g->iw = wd->size.imw;
295 g->ih = wd->size.imh;
297 g->w = g->iw / g->zoom;
298 g->h = g->ih / g->zoom;
299 if (g->zoom >= 8) return NULL;
300 g->gw = (g->w + g->tsize - 1) / g->tsize;
301 g->gh = (g->h + g->tsize - 1) / g->tsize;
302 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
309 for (y = 0; y < g->gh; y++)
311 for (x = 0; x < g->gw; x++)
315 tn = (y * g->gw) + x;
316 g->grid[tn].src.x = x * g->tsize;
317 if (x == (g->gw - 1))
318 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
320 g->grid[tn].src.w = g->tsize;
321 g->grid[tn].src.y = y * g->tsize;
322 if (y == (g->gh - 1))
323 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
325 g->grid[tn].src.h = g->tsize;
327 g->grid[tn].out.x = g->grid[tn].src.x;
328 g->grid[tn].out.y = g->grid[tn].src.y;
329 g->grid[tn].out.w = g->grid[tn].src.w;
330 g->grid[tn].out.h = g->grid[tn].src.h;
334 evas_object_image_add(evas_object_evas_get(obj));
335 evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE);
336 evas_object_image_scale_hint_set
337 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
338 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
339 evas_object_smart_member_add(g->grid[tn].img,
341 elm_widget_sub_object_add(obj, g->grid[tn].img);
342 evas_object_image_filled_set(g->grid[tn].img, 1);
343 evas_object_event_callback_add(g->grid[tn].img,
344 EVAS_CALLBACK_IMAGE_PRELOADED,
353 grid_load(Evas_Object *obj, Grid *g)
355 Widget_Data *wd = elm_widget_data_get(obj);
357 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
359 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
360 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
363 for (y = 0; y < g->gh; y++)
365 for (x = 0; x < g->gw; x++)
367 int tn, xx, yy, ww, hh;
368 Eina_Bool visible = EINA_FALSE;
370 tn = (y * g->gw) + x;
371 xx = g->grid[tn].out.x;
372 yy = g->grid[tn].out.y;
373 ww = g->grid[tn].out.w;
374 hh = g->grid[tn].out.h;
375 if ((gw != g->w) && (g->w > 0))
378 xx = (gw * xx) / g->w;
379 ww = ((gw * (tx + ww)) / g->w) - xx;
381 if ((gh != g->h) && (g->h > 0))
384 yy = (gh * yy) / g->h;
385 hh = ((gh * (ty + hh)) / g->h) - yy;
387 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
392 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
394 g->grid[tn].want = 1;
395 evas_object_hide(g->grid[tn].img);
396 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
397 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
398 evas_object_image_load_region_set(g->grid[tn].img,
403 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
404 evas_object_image_preload(g->grid[tn].img, 0);
406 if (wd->preload_num == 1)
408 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
409 "elm,state,busy,start", "elm");
410 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
413 else if ((g->grid[tn].want) && (!visible))
416 if (!wd->preload_num)
418 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
419 "elm,state,busy,stop", "elm");
420 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
422 g->grid[tn].want = 0;
423 evas_object_hide(g->grid[tn].img);
424 evas_object_image_preload(g->grid[tn].img, 1);
425 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
427 else if ((g->grid[tn].have) && (!visible))
429 g->grid[tn].have = 0;
430 evas_object_hide(g->grid[tn].img);
431 evas_object_image_preload(g->grid[tn].img, 1);
432 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
439 grid_clearall(Evas_Object *obj)
441 Widget_Data *wd = elm_widget_data_get(obj);
444 EINA_LIST_FREE(wd->grids, g)
452 _smooth_update(Evas_Object *obj)
454 Widget_Data *wd = elm_widget_data_get(obj);
459 EINA_LIST_FOREACH(wd->grids, l, g)
461 for (y = 0; y < g->gh; y++)
463 for (x = 0; x < g->gw; x++)
467 tn = (y * g->gw) + x;
468 evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
472 evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
480 for (y = 0; y < g->gh; y++)
482 for (x = 0; x < g->gw; x++)
486 tn = (y * g->gw) + x;
487 evas_object_raise(g->grid[tn].img);
493 _scr_timeout(void *data)
495 Widget_Data *wd = elm_widget_data_get(data);
496 if (!wd) return ECORE_CALLBACK_CANCEL;
498 if (!wd->nosmooth) _smooth_update(data);
499 wd->scr_timer = NULL;
500 return ECORE_CALLBACK_CANCEL;
504 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
506 Widget_Data *wd = elm_widget_data_get(data);
511 if (wd->nosmooth == 1) _smooth_update(data);
513 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
514 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
518 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
520 Evas_Object *obj = data;
521 Widget_Data *wd = elm_widget_data_get(obj);
524 evas_object_show(wd->img);
525 wd->main_load_pending = 0;
526 g = grid_create(obj);
529 wd->grids = eina_list_prepend(wd->grids, g);
530 grid_load(wd->obj, g);
532 if (wd->calc_job) ecore_job_del(wd->calc_job);
533 wd->calc_job = ecore_job_add(_calc_job, wd);
534 evas_object_smart_callback_call(data, SIG_LOADED, NULL);
536 if (!wd->preload_num)
538 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
539 "elm,state,busy,stop", "elm");
540 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
545 zoom_do(Evas_Object *obj, double t)
547 Widget_Data *wd = elm_widget_data_get(obj);
548 Evas_Coord xx, yy, ow, oh;
549 if (!wd) return ECORE_CALLBACK_CANCEL;
550 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
551 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
552 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
553 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
554 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
556 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
558 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
560 wd->show.show = EINA_TRUE;
566 if (wd->calc_job) ecore_job_del(wd->calc_job);
567 wd->calc_job = ecore_job_add(_calc_job, wd);
570 Eina_List *l, *l_next;
573 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
577 wd->grids = eina_list_remove_list(wd->grids, l);
582 return ECORE_CALLBACK_CANCEL;
584 return ECORE_CALLBACK_RENEW;
589 _zoom_anim(void *data)
591 Evas_Object *obj = data;
592 Widget_Data *wd = elm_widget_data_get(obj);
595 if (!wd) return ECORE_CALLBACK_CANCEL;
596 t = ecore_loop_time_get();
599 else if (wd->t_end > wd->t_start)
600 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
605 go = zoom_do(obj, t);
609 if (!wd->nosmooth) _smooth_update(data);
610 wd->zoom_animator = NULL;
611 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
617 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
619 Widget_Data *wd = elm_widget_data_get(data);
620 // Evas_Event_Mouse_Move *ev = event_info;
625 _long_press(void *data)
627 Widget_Data *wd = elm_widget_data_get(data);
628 if (!wd) return ECORE_CALLBACK_CANCEL;
629 wd->long_timer = NULL;
630 wd->longpressed = EINA_TRUE;
631 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
632 return ECORE_CALLBACK_CANCEL;
636 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
638 Widget_Data *wd = elm_widget_data_get(data);
639 Evas_Event_Mouse_Down *ev = event_info;
641 if (ev->button != 1) return;
642 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
643 else wd->on_hold = EINA_FALSE;
644 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
645 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
647 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
648 wd->longpressed = EINA_FALSE;
649 if (wd->long_timer) ecore_timer_del(wd->long_timer);
650 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
654 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
656 Widget_Data *wd = elm_widget_data_get(data);
657 Evas_Event_Mouse_Up *ev = event_info;
659 if (ev->button != 1) return;
660 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
661 else wd->on_hold = EINA_FALSE;
664 ecore_timer_del(wd->long_timer);
665 wd->long_timer = NULL;
668 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
669 wd->on_hold = EINA_FALSE;
672 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
675 _del_hook(Evas_Object *obj)
677 Widget_Data *wd = elm_widget_data_get(obj);
680 EINA_LIST_FREE(wd->grids, g)
682 if (g->grid) free(g->grid);
685 evas_object_del(wd->pan_smart);
686 wd->pan_smart = NULL;
687 if (wd->file) eina_stringshare_del(wd->file);
688 if (wd->calc_job) ecore_job_del(wd->calc_job);
689 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
690 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
691 if (wd->long_timer) ecore_timer_del(wd->long_timer);
696 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
698 Widget_Data *wd = elm_widget_data_get(obj);
700 if (elm_widget_focus_get(obj))
702 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
703 evas_object_focus_set(wd->obj, EINA_TRUE);
707 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
708 evas_object_focus_set(wd->obj, EINA_FALSE);
713 _theme_hook(Evas_Object *obj)
715 Widget_Data *wd = elm_widget_data_get(obj);
717 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
718 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
724 _show_region_hook(void *data, Evas_Object *obj)
726 Widget_Data *wd = elm_widget_data_get(data);
727 Evas_Coord x, y, w, h;
729 elm_widget_show_region_get(obj, &x, &y, &w, &h);
730 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
735 _sizing_eval(Evas_Object *obj)
737 Widget_Data *wd = elm_widget_data_get(obj);
738 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
740 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
741 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
744 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
745 evas_object_size_hint_min_set(obj, minw, minh);
746 evas_object_size_hint_max_set(obj, maxw, maxh);
750 _calc_job(void *data)
752 Widget_Data *wd = data;
753 Evas_Coord minw, minh;
760 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
762 double tz = wd->zoom;
764 elm_photocam_zoom_set(wd->obj, tz);
767 if ((minw != wd->minw) || (minh != wd->minh))
771 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
772 _sizing_eval(wd->obj);
775 evas_object_smart_changed(wd->pan_smart);
779 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
781 Pan *sd = evas_object_smart_data_get(obj);
783 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
786 evas_object_smart_changed(obj);
790 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
792 Pan *sd = evas_object_smart_data_get(obj);
794 if (x) *x = sd->wd->pan_x;
795 if (y) *y = sd->wd->pan_y;
799 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
801 Pan *sd = evas_object_smart_data_get(obj);
804 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
805 ow = sd->wd->minw - ow;
807 oh = sd->wd->minh - oh;
814 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
821 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
823 Pan *sd = evas_object_smart_data_get(obj);
825 if (w) *w = sd->wd->minw;
826 if (h) *h = sd->wd->minh;
830 _pan_add(Evas_Object *obj)
833 Evas_Object_Smart_Clipped_Data *cd;
835 cd = evas_object_smart_data_get(obj);
837 sd = calloc(1, sizeof(Pan));
839 sd->__clipped_data = *cd;
841 evas_object_smart_data_set(obj, sd);
845 _pan_del(Evas_Object *obj)
847 Pan *sd = evas_object_smart_data_get(obj);
853 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
855 Pan *sd = evas_object_smart_data_get(obj);
858 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
859 if ((ow == w) && (oh == h)) return;
861 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
862 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
866 _pan_calculate(Evas_Object *obj)
868 Pan *sd = evas_object_smart_data_get(obj);
869 Evas_Coord ox, oy, ow, oh;
873 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
874 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
875 EINA_LIST_FOREACH(sd->wd->grids, l, g)
877 grid_load(sd->wd->obj, g);
878 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
883 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
885 Pan *sd = evas_object_smart_data_get(obj);
887 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
888 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
892 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
894 Widget_Data *wd = elm_widget_data_get(obj);
896 elm_smart_scroller_hold_set(wd->scr, 1);
900 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
902 Widget_Data *wd = elm_widget_data_get(obj);
904 elm_smart_scroller_hold_set(wd->scr, 0);
908 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
910 Widget_Data *wd = elm_widget_data_get(obj);
912 elm_smart_scroller_freeze_set(wd->scr, 1);
916 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
918 Widget_Data *wd = elm_widget_data_get(obj);
920 elm_smart_scroller_freeze_set(wd->scr, 0);
924 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
926 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
930 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
932 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
936 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
938 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
942 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
944 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
948 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
950 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
954 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
955 Evas_Callback_Type type, void *event_info)
958 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
959 Evas_Event_Key_Down *ev = event_info;
960 Widget_Data *wd = elm_widget_data_get(obj);
961 if (!wd) return EINA_FALSE;
962 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
966 Evas_Coord step_x = 0;
967 Evas_Coord step_y = 0;
970 Evas_Coord page_x = 0;
971 Evas_Coord page_y = 0;
973 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
974 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
975 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
976 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
978 if ((!strcmp(ev->keyname, "Left")) ||
979 (!strcmp(ev->keyname, "KP_Left")))
983 else if ((!strcmp(ev->keyname, "Right")) ||
984 (!strcmp(ev->keyname, "KP_Right")))
988 else if ((!strcmp(ev->keyname, "Up")) ||
989 (!strcmp(ev->keyname, "KP_Up")))
993 else if ((!strcmp(ev->keyname, "Down")) ||
994 (!strcmp(ev->keyname, "KP_Down")))
998 else if ((!strcmp(ev->keyname, "Prior")) ||
999 (!strcmp(ev->keyname, "KP_Prior")))
1002 y -= -(page_y * v_h) / 100;
1006 else if ((!strcmp(ev->keyname, "Next")) ||
1007 (!strcmp(ev->keyname, "KP_Next")))
1010 y += -(page_y * v_h) / 100;
1014 else if ((!strcmp(ev->keyname, "KP_Add")))
1016 zoom = elm_photocam_zoom_get(obj);
1018 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1019 elm_photocam_zoom_set(obj, zoom);
1022 else if ((!strcmp(ev->keyname, "KP_Subtract")))
1024 zoom = elm_photocam_zoom_get(obj);
1026 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1027 elm_photocam_zoom_set(obj, zoom);
1030 else return EINA_FALSE;
1032 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1033 elm_smart_scroller_child_pos_set(wd->scr, x, y);
1039 elm_photocam_add(Evas_Object *parent)
1044 Evas_Coord minw, minh;
1045 static Evas_Smart *smart = NULL;
1046 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1048 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1050 ELM_SET_WIDTYPE(widtype, "photocam");
1051 elm_widget_type_set(obj, "photocam");
1052 elm_widget_sub_object_add(parent, obj);
1053 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1054 elm_widget_data_set(obj, wd);
1055 elm_widget_del_hook_set(obj, _del_hook);
1056 elm_widget_theme_hook_set(obj, _theme_hook);
1057 elm_widget_can_focus_set(obj, EINA_TRUE);
1058 elm_widget_event_hook_set(obj, _event_hook);
1060 wd->scr = elm_smart_scroller_add(e);
1061 elm_smart_scroller_widget_set(wd->scr, obj);
1062 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
1063 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
1064 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
1065 elm_widget_resize_object_set(obj, wd->scr);
1067 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1068 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1069 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1070 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1071 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1073 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1077 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1078 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1079 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1080 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1084 static Evas_Smart_Class sc;
1086 evas_object_smart_clipped_smart_set(&_pan_sc);
1088 sc.name = "elm_photocam_pan";
1089 sc.version = EVAS_SMART_CLASS_VERSION;
1092 sc.resize = _pan_resize;
1093 sc.move = _pan_move;
1094 sc.calculate = _pan_calculate;
1095 smart = evas_smart_class_new(&sc);
1099 wd->pan_smart = evas_object_smart_add(e, smart);
1100 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1104 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1105 _pan_set, _pan_get, _pan_max_get,
1106 _pan_min_get, _pan_child_size_get);
1109 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1113 wd->img = evas_object_image_add(e);
1114 evas_object_image_load_orientation_set(wd->img, EINA_TRUE);
1115 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1116 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1118 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1120 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1122 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1123 evas_object_smart_member_add(wd->img, wd->pan_smart);
1124 elm_widget_sub_object_add(obj, wd->img);
1125 evas_object_image_filled_set(wd->img, 1);
1126 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1127 _main_preloaded, obj);
1129 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1131 evas_object_size_hint_min_set(obj, minw, minh);
1133 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1139 EAPI Evas_Load_Error
1140 elm_photocam_file_set(Evas_Object *obj, const char *file)
1142 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1143 Widget_Data *wd = elm_widget_data_get(obj);
1145 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1146 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1149 evas_object_hide(wd->img);
1150 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1151 evas_object_image_file_set(wd->img, NULL, NULL);
1152 evas_object_image_load_scale_down_set(wd->img, 0);
1153 evas_object_image_file_set(wd->img, wd->file, NULL);
1154 evas_object_image_size_get(wd->img, &w, &h);
1157 wd->size.w = wd->size.imw / wd->zoom;
1158 wd->size.h = wd->size.imh / wd->zoom;
1159 if (wd->zoom_animator)
1162 if (wd->nosmooth == 0) _smooth_update(obj);
1163 ecore_animator_del(wd->zoom_animator);
1164 wd->zoom_animator = NULL;
1166 evas_object_image_file_set(wd->img, NULL, NULL);
1167 evas_object_image_load_scale_down_set(wd->img, 8);
1168 evas_object_image_file_set(wd->img, wd->file, NULL);
1169 evas_object_image_preload(wd->img, 0);
1170 wd->main_load_pending = 1;
1171 if (wd->calc_job) ecore_job_del(wd->calc_job);
1172 wd->calc_job = ecore_job_add(_calc_job, wd);
1173 evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1175 if (wd->preload_num == 1)
1177 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1178 "elm,state,busy,start", "elm");
1179 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1182 double tz = wd->zoom;
1184 elm_photocam_zoom_set(wd->obj, tz);
1186 return evas_object_image_load_error_get(wd->img);
1190 elm_photocam_file_get(const Evas_Object *obj)
1192 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1193 Widget_Data *wd = elm_widget_data_get(obj);
1194 if (!wd) return NULL;
1199 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1201 ELM_CHECK_WIDTYPE(obj, widtype);
1202 Widget_Data *wd = elm_widget_data_get(obj);
1204 Grid *g, *g_zoom = NULL;
1205 Evas_Coord pw, ph, rx, ry, rw, rh;
1207 int zoom_changed = 0, started = 0;
1210 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1211 if (zoom == wd->zoom) return;
1213 wd->size.ow = wd->size.w;
1214 wd->size.oh = wd->size.h;
1215 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1216 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1217 if ((rw <= 0) || (rh <= 0)) return;
1219 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1221 wd->size.nw = (double)wd->size.imw / wd->zoom;
1222 wd->size.nh = (double)wd->size.imh / wd->zoom;
1224 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1226 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1233 ph = (wd->size.imh * rw) / wd->size.imw;
1236 pw = (wd->size.imw * rh) / wd->size.imh;
1243 if (wd->size.imw > wd->size.imh)
1244 z = wd->size.imw / pw;
1246 z = wd->size.imh / ph;
1248 else if (z >= 4) z = 4;
1249 else if (z >= 2) z = 2;
1251 if (z != wd->zoom) zoom_changed = 1;
1257 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1259 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1266 ph = (wd->size.imh * rw) / wd->size.imw;
1269 pw = (wd->size.imw * rh) / wd->size.imh;
1276 if (wd->size.imw > wd->size.imh)
1277 z = wd->size.imw / pw;
1279 z = wd->size.imh / ph;
1281 else if (z >= 4) z = 4;
1282 else if (z >= 2) z = 2;
1284 if (z != wd->zoom) zoom_changed = 1;
1290 if (wd->main_load_pending)
1292 wd->size.w = wd->size.nw;
1293 wd->size.h = wd->size.nh;
1296 EINA_LIST_FOREACH(wd->grids, l, g)
1298 if (g->zoom == grid_zoom_calc(wd->zoom))
1300 wd->grids = eina_list_remove(wd->grids, g);
1301 wd->grids = eina_list_prepend(wd->grids, g);
1306 g = grid_create(obj);
1309 if (eina_list_count(wd->grids) > 1)
1311 g_zoom = eina_list_last(wd->grids)->data;
1312 wd->grids = eina_list_remove(wd->grids, g_zoom);
1313 grid_clear(obj, g_zoom);
1315 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1320 wd->grids = eina_list_prepend(wd->grids, g);
1324 EINA_LIST_FREE(wd->grids, g)
1331 wd->t_start = ecore_loop_time_get();
1332 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1333 if ((wd->size.w > 0) && (wd->size.h > 0))
1335 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1336 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1340 wd->size.spos.x = 0.5;
1341 wd->size.spos.y = 0.5;
1343 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1344 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1345 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1346 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1353 if (!wd->zoom_animator)
1355 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1357 if (wd->nosmooth == 1) _smooth_update(obj);
1361 an = wd->zoom_animator;
1364 if (!_zoom_anim(obj))
1366 ecore_animator_del(an);
1370 if (wd->calc_job) ecore_job_del(wd->calc_job);
1371 wd->calc_job = ecore_job_add(_calc_job, wd);
1375 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1377 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1380 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1384 elm_photocam_zoom_get(const Evas_Object *obj)
1386 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1387 Widget_Data *wd = elm_widget_data_get(obj);
1388 if (!wd) return 1.0;
1393 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1395 ELM_CHECK_WIDTYPE(obj, widtype);
1396 Widget_Data *wd = elm_widget_data_get(obj);
1398 if (wd->mode == mode) return;
1401 double tz = wd->zoom;
1403 elm_photocam_zoom_set(wd->obj, tz);
1407 EAPI Elm_Photocam_Zoom_Mode
1408 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1410 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1411 Widget_Data *wd = elm_widget_data_get(obj);
1412 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1417 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1419 ELM_CHECK_WIDTYPE(obj, widtype);
1420 Widget_Data *wd = elm_widget_data_get(obj);
1422 if (w) *w = wd->size.imw;
1423 if (h) *h = wd->size.imh;
1427 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1429 ELM_CHECK_WIDTYPE(obj, widtype);
1430 Widget_Data *wd = elm_widget_data_get(obj);
1431 Evas_Coord sx, sy, sw, sh;
1433 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1434 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1439 *x = (wd->size.imw * sx) / wd->size.w;
1440 if (*x > wd->size.imw) *x = wd->size.imw;
1441 else if (*x < 0) *x = 0;
1445 *w = (wd->size.imw * sw) / wd->size.w;
1446 if (*w > wd->size.imw) *w = wd->size.imw;
1447 else if (*w < 0) *w = 0;
1460 *y = (wd->size.imh * sy) / wd->size.h;
1461 if (*y > wd->size.imh) *y = wd->size.imh;
1462 else if (*y < 0) *y = 0;
1466 *h = (wd->size.imh * sh) / wd->size.h;
1467 if (*h > wd->size.imh) *h = wd->size.imh;
1468 else if (*h < 0) *h = 0;
1479 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1481 ELM_CHECK_WIDTYPE(obj, widtype);
1482 Widget_Data *wd = elm_widget_data_get(obj);
1485 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1486 rx = (x * wd->size.w) / wd->size.imw;
1487 ry = (y * wd->size.h) / wd->size.imh;
1488 rw = (w * wd->size.w) / wd->size.imw;
1489 rh = (w * wd->size.h) / wd->size.imh;
1492 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1493 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1494 if (wd->zoom_animator)
1497 ecore_animator_del(wd->zoom_animator);
1498 wd->zoom_animator = NULL;
1500 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1502 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1506 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1508 ELM_CHECK_WIDTYPE(obj, widtype);
1509 Widget_Data *wd = elm_widget_data_get(obj);
1512 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1513 rx = (x * wd->size.w) / wd->size.imw;
1514 ry = (y * wd->size.h) / wd->size.imh;
1515 rw = (w * wd->size.w) / wd->size.imw;
1516 rh = (w * wd->size.h) / wd->size.imh;
1519 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1520 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1521 if (wd->zoom_animator)
1524 if (!wd->nosmooth) _smooth_update(obj);
1525 ecore_animator_del(wd->zoom_animator);
1526 wd->zoom_animator = NULL;
1528 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1530 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1534 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1536 ELM_CHECK_WIDTYPE(obj, widtype);
1537 Widget_Data *wd = elm_widget_data_get(obj);
1539 if (wd->paused == !!paused) return;
1540 wd->paused = paused;
1543 if (wd->zoom_animator)
1545 ecore_animator_del(wd->zoom_animator);
1546 wd->zoom_animator = NULL;
1548 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1554 elm_photocam_paused_get(const Evas_Object *obj)
1556 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1557 Widget_Data *wd = elm_widget_data_get(obj);
1558 if (!wd) return EINA_FALSE;
1563 elm_photocam_internal_image_get(const Evas_Object *obj)
1565 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1566 Widget_Data *wd = elm_widget_data_get(obj);
1567 if (!wd) return NULL;
1572 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1574 ELM_CHECK_WIDTYPE(obj, widtype);
1575 Widget_Data *wd = elm_widget_data_get(obj);
1577 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1581 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1583 ELM_CHECK_WIDTYPE(obj, widtype);
1584 Widget_Data *wd = elm_widget_data_get(obj);
1586 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);