1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Pan Pan;
6 typedef struct _Grid Grid;
7 typedef struct _Grid_Item Grid_Item;
23 int tsize; // size of tile (tsize x tsize pixels)
24 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
25 int iw, ih; // size of image in pixels
26 int w, h; // size of grid image in pixels (represented by grid)
27 int gw, gh; // size of grid in tiles
28 Grid_Item *grid; // the grid (gw * gh items)
29 Eina_Bool dead : 1; // old grid. will die as soon as anim is over
36 Evas_Object *pan_smart;
38 Evas_Coord pan_x, pan_y, minw, minh;
41 Elm_Photocam_Zoom_Mode mode;
45 Ecore_Timer *scr_timer;
46 Ecore_Timer *long_timer;
47 Ecore_Animator *zoom_animator;
48 double t_start, t_end;
62 Evas_Coord x, y ,w ,h;
65 Evas_Object *img; // low res version of image (scale down == 8)
69 Eina_Bool main_load_pending : 1;
70 Eina_Bool resized : 1;
71 Eina_Bool longpressed : 1;
72 Eina_Bool on_hold : 1;
78 Evas_Object_Smart_Clipped_Data __clipped_data;
82 static const char *widtype = NULL;
83 static void _del_hook(Evas_Object *obj);
84 static void _theme_hook(Evas_Object *obj);
85 static void _on_focus_hook(void *data, Evas_Object *obj);
86 //static void _show_region_hook(void *data, Evas_Object *obj);
87 static void _sizing_eval(Evas_Object *obj);
88 static void _calc_job(void *data);
89 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
90 Evas_Callback_Type type, void *event_info);
91 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);
92 static void grid_clear(Evas_Object *obj, Grid *g);
93 static Grid *grid_create(Evas_Object *obj);
94 static void grid_load(Evas_Object *obj, Grid *g);
96 static const char SIG_CLICKED[] = "clicked";
97 static const char SIG_PRESS[] = "press";
98 static const char SIG_LONGPRESSED[] = "longpressed";
99 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
100 static const char SIG_LOAD[] = "load";
101 static const char SIG_LOADED[] = "loaded";
102 static const char SIG_LOAD_DETAIL[] = "load,detail";
103 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
104 static const char SIG_ZOOM_START[] = "zoom,start";
105 static const char SIG_ZOOM_STOP[] = "zoom,stop";
106 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
107 static const char SIG_SCROLL[] = "scroll";
108 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
109 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
110 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
111 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
113 static const Evas_Smart_Cb_Description _signals[] = {
116 {SIG_LONGPRESSED, ""},
117 {SIG_CLICKED_DOUBLE, ""},
120 {SIG_LOAD_DETAIL, ""},
121 {SIG_LOADED_DETAIL, ""},
122 {SIG_ZOOM_START, ""},
124 {SIG_ZOOM_CHANGE, ""},
126 {SIG_SCROLL_ANIM_START, ""},
127 {SIG_SCROLL_ANIM_STOP, ""},
128 {SIG_SCROLL_DRAG_START, ""},
129 {SIG_SCROLL_DRAG_STOP, ""},
135 nearest_pow2(int num)
137 unsigned int n = num - 1;
147 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
149 Widget_Data *wd = elm_widget_data_get(obj);
150 Evas_Coord ax, ay, gw, gh;
156 if (ow > gw) ax = (ow - gw) / 2;
157 if (oh > gh) ay = (oh - gh) / 2;
158 evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
159 evas_object_resize(wd->img, gw, gh);
163 wd->show.show = EINA_FALSE;
164 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
169 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)
171 Widget_Data *wd = elm_widget_data_get(obj);
172 Evas_Coord ax, ay, gw, gh, tx, ty;
179 if (ow > gw) ax = (ow - gw) / 2;
180 if (oh > gh) ay = (oh - gh) / 2;
181 for (y = 0; y < g->gh; y++)
183 for (x = 0; x < g->gw; x++)
185 int tn, xx, yy, ww, hh;
187 tn = (y * g->gw) + x;
188 xx = g->grid[tn].out.x;
189 yy = g->grid[tn].out.y;
190 ww = g->grid[tn].out.w;
191 hh = g->grid[tn].out.h;
192 if ((gw != g->w) && (g->w > 0))
195 xx = (gw * xx) / g->w;
196 ww = ((gw * (tx + ww)) / g->w) - xx;
198 if ((gh != g->h) && (g->h > 0))
201 yy = (gh * yy) / g->h;
202 hh = ((gh * (ty + hh)) / g->h) - yy;
204 evas_object_move(g->grid[tn].img,
207 evas_object_resize(g->grid[tn].img, ww, hh);
213 grid_clear(Evas_Object *obj, Grid *g)
215 Widget_Data *wd = elm_widget_data_get(obj);
218 if (!g->grid) return;
219 for (y = 0; y < g->gh; y++)
221 for (x = 0; x < g->gw; x++)
225 tn = (y * g->gw) + x;
226 evas_object_del(g->grid[tn].img);
227 if (g->grid[tn].want)
230 if (!wd->preload_num)
232 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
233 "elm,state,busy,stop", "elm");
234 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
246 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
248 Grid_Item *git = data;
253 evas_object_show(git->img);
255 git->wd->preload_num--;
256 if (!git->wd->preload_num)
258 edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
259 "elm,state,busy,stop", "elm");
260 evas_object_smart_callback_call(git->wd->obj, SIG_LOADED_DETAIL, NULL);
266 grid_zoom_calc(double zoom)
270 return nearest_pow2(z);
274 grid_create(Evas_Object *obj)
276 Widget_Data *wd = elm_widget_data_get(obj);
280 if (!wd) return NULL;
281 g = calloc(1, sizeof(Grid));
283 g->zoom = grid_zoom_calc(wd->zoom);
284 g->tsize = wd->tsize;
285 g->iw = wd->size.imw;
286 g->ih = wd->size.imh;
288 g->w = g->iw / g->zoom;
289 g->h = g->ih / g->zoom;
290 if (g->zoom >= 8) return NULL;
291 g->gw = (g->w + g->tsize - 1) / g->tsize;
292 g->gh = (g->h + g->tsize - 1) / g->tsize;
293 g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
300 for (y = 0; y < g->gh; y++)
302 for (x = 0; x < g->gw; x++)
306 tn = (y * g->gw) + x;
307 g->grid[tn].src.x = x * g->tsize;
308 if (x == (g->gw - 1))
309 g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
311 g->grid[tn].src.w = g->tsize;
312 g->grid[tn].src.y = y * g->tsize;
313 if (y == (g->gh - 1))
314 g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
316 g->grid[tn].src.h = g->tsize;
318 g->grid[tn].out.x = g->grid[tn].src.x;
319 g->grid[tn].out.y = g->grid[tn].src.y;
320 g->grid[tn].out.w = g->grid[tn].src.w;
321 g->grid[tn].out.h = g->grid[tn].src.h;
325 evas_object_image_add(evas_object_evas_get(obj));
326 evas_object_image_scale_hint_set
327 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
328 evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
329 evas_object_smart_member_add(g->grid[tn].img,
331 elm_widget_sub_object_add(obj, g->grid[tn].img);
332 evas_object_image_filled_set(g->grid[tn].img, 1);
333 evas_object_event_callback_add(g->grid[tn].img,
334 EVAS_CALLBACK_IMAGE_PRELOADED,
343 grid_load(Evas_Object *obj, Grid *g)
345 Widget_Data *wd = elm_widget_data_get(obj);
347 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
349 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
350 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
353 for (y = 0; y < g->gh; y++)
355 for (x = 0; x < g->gw; x++)
357 int tn, xx, yy, ww, hh;
358 Eina_Bool visible = EINA_FALSE;
360 tn = (y * g->gw) + x;
361 xx = g->grid[tn].out.x;
362 yy = g->grid[tn].out.y;
363 ww = g->grid[tn].out.w;
364 hh = g->grid[tn].out.h;
365 if ((gw != g->w) && (g->w > 0))
368 xx = (gw * xx) / g->w;
369 ww = ((gw * (tx + ww)) / g->w) - xx;
371 if ((gh != g->h) && (g->h > 0))
374 yy = (gh * yy) / g->h;
375 hh = ((gh * (ty + hh)) / g->h) - yy;
377 if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
382 if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
384 g->grid[tn].want = 1;
385 evas_object_hide(g->grid[tn].img);
386 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
387 evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
388 evas_object_image_load_region_set(g->grid[tn].img,
393 evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
394 evas_object_image_preload(g->grid[tn].img, 0);
396 if (wd->preload_num == 1)
398 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
399 "elm,state,busy,start", "elm");
400 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
403 else if ((g->grid[tn].want) && (!visible))
406 if (!wd->preload_num)
408 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
409 "elm,state,busy,stop", "elm");
410 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
412 g->grid[tn].want = 0;
413 evas_object_hide(g->grid[tn].img);
414 evas_object_image_preload(g->grid[tn].img, 1);
415 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
417 else if ((g->grid[tn].have) && (!visible))
419 g->grid[tn].have = 0;
420 evas_object_hide(g->grid[tn].img);
421 evas_object_image_preload(g->grid[tn].img, 1);
422 evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
429 grid_clearall(Evas_Object *obj)
431 Widget_Data *wd = elm_widget_data_get(obj);
434 EINA_LIST_FREE(wd->grids, g)
442 _smooth_update(Evas_Object *obj)
444 Widget_Data *wd = elm_widget_data_get(obj);
449 EINA_LIST_FOREACH(wd->grids, l, g)
451 for (y = 0; y < g->gh; y++)
453 for (x = 0; x < g->gw; x++)
457 tn = (y * g->gw) + x;
458 evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
462 evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
470 for (y = 0; y < g->gh; y++)
472 for (x = 0; x < g->gw; x++)
476 tn = (y * g->gw) + x;
477 evas_object_raise(g->grid[tn].img);
483 _scr_timeout(void *data)
485 Widget_Data *wd = elm_widget_data_get(data);
486 if (!wd) return ECORE_CALLBACK_CANCEL;
488 if (!wd->nosmooth) _smooth_update(data);
489 wd->scr_timer = NULL;
490 return ECORE_CALLBACK_CANCEL;
494 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
496 Widget_Data *wd = elm_widget_data_get(data);
501 if (wd->nosmooth == 1) _smooth_update(data);
503 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
504 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
508 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
510 Evas_Object *obj = data;
511 Widget_Data *wd = elm_widget_data_get(obj);
514 evas_object_show(wd->img);
515 wd->main_load_pending = 0;
516 g = grid_create(obj);
519 wd->grids = eina_list_prepend(wd->grids, g);
520 grid_load(wd->obj, g);
522 if (wd->calc_job) ecore_job_del(wd->calc_job);
523 wd->calc_job = ecore_job_add(_calc_job, wd);
524 evas_object_smart_callback_call(data, SIG_LOADED, NULL);
526 if (!wd->preload_num)
528 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
529 "elm,state,busy,stop", "elm");
530 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
535 zoom_do(Evas_Object *obj, double t)
537 Widget_Data *wd = elm_widget_data_get(obj);
538 Evas_Coord xx, yy, ow, oh;
539 if (!wd) return ECORE_CALLBACK_CANCEL;
540 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
541 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
542 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
543 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
544 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
546 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
548 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
550 wd->show.show = EINA_TRUE;
556 if (wd->calc_job) ecore_job_del(wd->calc_job);
557 wd->calc_job = ecore_job_add(_calc_job, wd);
560 Eina_List *l, *l_next;
563 EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
567 wd->grids = eina_list_remove_list(wd->grids, l);
572 return ECORE_CALLBACK_CANCEL;
574 return ECORE_CALLBACK_RENEW;
579 _zoom_anim(void *data)
581 Evas_Object *obj = data;
582 Widget_Data *wd = elm_widget_data_get(obj);
585 if (!wd) return ECORE_CALLBACK_CANCEL;
586 t = ecore_loop_time_get();
589 else if (wd->t_end > wd->t_start)
590 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
595 go = zoom_do(obj, t);
599 if (!wd->nosmooth) _smooth_update(data);
600 wd->zoom_animator = NULL;
601 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
607 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
609 Widget_Data *wd = elm_widget_data_get(data);
610 // Evas_Event_Mouse_Move *ev = event_info;
615 _long_press(void *data)
617 Widget_Data *wd = elm_widget_data_get(data);
618 if (!wd) return ECORE_CALLBACK_CANCEL;
619 wd->long_timer = NULL;
620 wd->longpressed = EINA_TRUE;
621 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
622 return ECORE_CALLBACK_CANCEL;
626 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
628 Widget_Data *wd = elm_widget_data_get(data);
629 Evas_Event_Mouse_Down *ev = event_info;
631 if (ev->button != 1) return;
632 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
633 else wd->on_hold = EINA_FALSE;
634 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
635 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
637 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
638 wd->longpressed = EINA_FALSE;
639 if (wd->long_timer) ecore_timer_del(wd->long_timer);
640 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
644 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
646 Widget_Data *wd = elm_widget_data_get(data);
647 Evas_Event_Mouse_Up *ev = event_info;
649 if (ev->button != 1) return;
650 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
651 else wd->on_hold = EINA_FALSE;
654 ecore_timer_del(wd->long_timer);
655 wd->long_timer = NULL;
658 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
659 wd->on_hold = EINA_FALSE;
662 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
665 _del_hook(Evas_Object *obj)
667 Widget_Data *wd = elm_widget_data_get(obj);
670 EINA_LIST_FREE(wd->grids, g)
672 if (g->grid) free(g->grid);
675 evas_object_del(wd->pan_smart);
676 wd->pan_smart = NULL;
677 if (wd->file) eina_stringshare_del(wd->file);
678 if (wd->calc_job) ecore_job_del(wd->calc_job);
679 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
680 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
681 if (wd->long_timer) ecore_timer_del(wd->long_timer);
686 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
688 Widget_Data *wd = elm_widget_data_get(obj);
690 if (elm_widget_focus_get(obj))
692 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
693 evas_object_focus_set(wd->obj, EINA_TRUE);
697 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
698 evas_object_focus_set(wd->obj, EINA_FALSE);
703 _theme_hook(Evas_Object *obj)
705 Widget_Data *wd = elm_widget_data_get(obj);
707 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
708 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
714 _show_region_hook(void *data, Evas_Object *obj)
716 Widget_Data *wd = elm_widget_data_get(data);
717 Evas_Coord x, y, w, h;
719 elm_widget_show_region_get(obj, &x, &y, &w, &h);
720 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
725 _sizing_eval(Evas_Object *obj)
727 Widget_Data *wd = elm_widget_data_get(obj);
728 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
730 // evas_object_size_hint_min_get(wd->scr, &minw, &minh);
731 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
734 // if (wd->mode != ELM_LIST_LIMIT) minw = -1;
735 evas_object_size_hint_min_set(obj, minw, minh);
736 evas_object_size_hint_max_set(obj, maxw, maxh);
740 _calc_job(void *data)
742 Widget_Data *wd = data;
743 Evas_Coord minw, minh;
750 if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
752 double tz = wd->zoom;
754 elm_photocam_zoom_set(wd->obj, tz);
757 if ((minw != wd->minw) || (minh != wd->minh))
761 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
762 _sizing_eval(wd->obj);
765 evas_object_smart_changed(wd->pan_smart);
769 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
771 Pan *sd = evas_object_smart_data_get(obj);
773 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
776 evas_object_smart_changed(obj);
780 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
782 Pan *sd = evas_object_smart_data_get(obj);
784 if (x) *x = sd->wd->pan_x;
785 if (y) *y = sd->wd->pan_y;
789 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
791 Pan *sd = evas_object_smart_data_get(obj);
794 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
795 ow = sd->wd->minw - ow;
797 oh = sd->wd->minh - oh;
804 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
811 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
813 Pan *sd = evas_object_smart_data_get(obj);
815 if (w) *w = sd->wd->minw;
816 if (h) *h = sd->wd->minh;
820 _pan_add(Evas_Object *obj)
823 Evas_Object_Smart_Clipped_Data *cd;
825 cd = evas_object_smart_data_get(obj);
827 sd = calloc(1, sizeof(Pan));
829 sd->__clipped_data = *cd;
831 evas_object_smart_data_set(obj, sd);
835 _pan_del(Evas_Object *obj)
837 Pan *sd = evas_object_smart_data_get(obj);
843 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
845 Pan *sd = evas_object_smart_data_get(obj);
848 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
849 if ((ow == w) && (oh == h)) return;
851 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
852 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
856 _pan_calculate(Evas_Object *obj)
858 Pan *sd = evas_object_smart_data_get(obj);
859 Evas_Coord ox, oy, ow, oh;
863 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
864 img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
865 EINA_LIST_FOREACH(sd->wd->grids, l, g)
867 grid_load(sd->wd->obj, g);
868 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
873 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
875 Pan *sd = evas_object_smart_data_get(obj);
877 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
878 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
882 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
884 Widget_Data *wd = elm_widget_data_get(obj);
886 elm_smart_scroller_hold_set(wd->scr, 1);
890 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
892 Widget_Data *wd = elm_widget_data_get(obj);
894 elm_smart_scroller_hold_set(wd->scr, 0);
898 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
900 Widget_Data *wd = elm_widget_data_get(obj);
902 elm_smart_scroller_freeze_set(wd->scr, 1);
906 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
908 Widget_Data *wd = elm_widget_data_get(obj);
910 elm_smart_scroller_freeze_set(wd->scr, 0);
914 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
916 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
920 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
922 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
926 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
928 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
932 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
934 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
938 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
940 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
944 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
945 Evas_Callback_Type type, void *event_info)
948 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
949 Evas_Event_Key_Down *ev = event_info;
950 Widget_Data *wd = elm_widget_data_get(obj);
951 if (!wd) return EINA_FALSE;
952 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
956 Evas_Coord step_x = 0;
957 Evas_Coord step_y = 0;
960 Evas_Coord page_x = 0;
961 Evas_Coord page_y = 0;
963 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
964 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
965 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
966 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
968 if ((!strcmp(ev->keyname, "Left")) ||
969 (!strcmp(ev->keyname, "KP_Left")))
973 else if ((!strcmp(ev->keyname, "Right")) ||
974 (!strcmp(ev->keyname, "KP_Right")))
978 else if ((!strcmp(ev->keyname, "Up")) ||
979 (!strcmp(ev->keyname, "KP_Up")))
983 else if ((!strcmp(ev->keyname, "Down")) ||
984 (!strcmp(ev->keyname, "KP_Down")))
988 else if ((!strcmp(ev->keyname, "Prior")) ||
989 (!strcmp(ev->keyname, "KP_Prior")))
992 y -= -(page_y * v_h) / 100;
996 else if ((!strcmp(ev->keyname, "Next")) ||
997 (!strcmp(ev->keyname, "KP_Next")))
1000 y += -(page_y * v_h) / 100;
1004 else if ((!strcmp(ev->keyname, "KP_Add")))
1006 zoom = elm_photocam_zoom_get(obj);
1008 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1009 elm_photocam_zoom_set(obj, zoom);
1012 else if ((!strcmp(ev->keyname, "KP_Subtract")))
1014 zoom = elm_photocam_zoom_get(obj);
1016 elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1017 elm_photocam_zoom_set(obj, zoom);
1020 else return EINA_FALSE;
1022 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1023 elm_smart_scroller_child_pos_set(wd->scr, x, y);
1029 elm_photocam_add(Evas_Object *parent)
1034 Evas_Coord minw, minh;
1035 static Evas_Smart *smart = NULL;
1036 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1038 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1040 ELM_SET_WIDTYPE(widtype, "photocam");
1041 elm_widget_type_set(obj, "photocam");
1042 elm_widget_sub_object_add(parent, obj);
1043 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1044 elm_widget_data_set(obj, wd);
1045 elm_widget_del_hook_set(obj, _del_hook);
1046 elm_widget_theme_hook_set(obj, _theme_hook);
1047 elm_widget_can_focus_set(obj, EINA_TRUE);
1048 elm_widget_event_hook_set(obj, _event_hook);
1050 wd->scr = elm_smart_scroller_add(e);
1051 elm_smart_scroller_widget_set(wd->scr, obj);
1052 elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
1053 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
1054 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
1055 elm_widget_resize_object_set(obj, wd->scr);
1057 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1058 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1059 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1060 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1061 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1063 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1067 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1068 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1069 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1070 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1074 static Evas_Smart_Class sc;
1076 evas_object_smart_clipped_smart_set(&_pan_sc);
1078 sc.name = "elm_photocam_pan";
1079 sc.version = EVAS_SMART_CLASS_VERSION;
1082 sc.resize = _pan_resize;
1083 sc.move = _pan_move;
1084 sc.calculate = _pan_calculate;
1085 smart = evas_smart_class_new(&sc);
1089 wd->pan_smart = evas_object_smart_add(e, smart);
1090 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1094 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1095 _pan_set, _pan_get, _pan_max_get,
1096 _pan_min_get, _pan_child_size_get);
1099 wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1103 wd->img = evas_object_image_add(e);
1104 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1105 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1107 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1109 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1111 evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1112 evas_object_smart_member_add(wd->img, wd->pan_smart);
1113 elm_widget_sub_object_add(obj, wd->img);
1114 evas_object_image_filled_set(wd->img, 1);
1115 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1116 _main_preloaded, obj);
1118 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1120 evas_object_size_hint_min_set(obj, minw, minh);
1122 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1128 EAPI Evas_Load_Error
1129 elm_photocam_file_set(Evas_Object *obj, const char *file)
1131 ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1132 Widget_Data *wd = elm_widget_data_get(obj);
1134 if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1135 if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1138 evas_object_hide(wd->img);
1139 evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1140 evas_object_image_file_set(wd->img, NULL, NULL);
1141 evas_object_image_load_scale_down_set(wd->img, 0);
1142 evas_object_image_file_set(wd->img, wd->file, NULL);
1143 evas_object_image_size_get(wd->img, &w, &h);
1146 wd->size.w = wd->size.imw / wd->zoom;
1147 wd->size.h = wd->size.imh / wd->zoom;
1148 if (wd->zoom_animator)
1151 if (wd->nosmooth == 0) _smooth_update(obj);
1152 ecore_animator_del(wd->zoom_animator);
1153 wd->zoom_animator = NULL;
1155 evas_object_image_file_set(wd->img, NULL, NULL);
1156 evas_object_image_load_scale_down_set(wd->img, 8);
1157 evas_object_image_file_set(wd->img, wd->file, NULL);
1158 evas_object_image_preload(wd->img, 0);
1159 wd->main_load_pending = 1;
1160 if (wd->calc_job) ecore_job_del(wd->calc_job);
1161 wd->calc_job = ecore_job_add(_calc_job, wd);
1162 evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1164 if (wd->preload_num == 1)
1166 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1167 "elm,state,busy,start", "elm");
1168 evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1171 double tz = wd->zoom;
1173 elm_photocam_zoom_set(wd->obj, tz);
1175 return evas_object_image_load_error_get(wd->img);
1179 elm_photocam_file_get(const Evas_Object *obj)
1181 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1182 Widget_Data *wd = elm_widget_data_get(obj);
1183 if (!wd) return NULL;
1188 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1190 ELM_CHECK_WIDTYPE(obj, widtype);
1191 Widget_Data *wd = elm_widget_data_get(obj);
1193 Grid *g, *g_zoom = NULL;
1194 Evas_Coord pw, ph, rx, ry, rw, rh;
1196 int zoom_changed = 0, started = 0;
1199 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1200 if (zoom == wd->zoom) return;
1202 wd->size.ow = wd->size.w;
1203 wd->size.oh = wd->size.h;
1204 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1205 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1206 if ((rw <= 0) || (rh <= 0)) return;
1208 if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1210 wd->size.nw = (double)wd->size.imw / wd->zoom;
1211 wd->size.nh = (double)wd->size.imh / wd->zoom;
1213 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1215 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1222 ph = (wd->size.imh * rw) / wd->size.imw;
1225 pw = (wd->size.imw * rh) / wd->size.imh;
1232 if (wd->size.imw > wd->size.imh)
1233 z = wd->size.imw / pw;
1235 z = wd->size.imh / ph;
1237 else if (z >= 4) z = 4;
1238 else if (z >= 2) z = 2;
1240 if (z != wd->zoom) zoom_changed = 1;
1246 else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1248 if ((wd->size.imw < 1) || (wd->size.imh < 1))
1255 ph = (wd->size.imh * rw) / wd->size.imw;
1258 pw = (wd->size.imw * rh) / wd->size.imh;
1265 if (wd->size.imw > wd->size.imh)
1266 z = wd->size.imw / pw;
1268 z = wd->size.imh / ph;
1270 else if (z >= 4) z = 4;
1271 else if (z >= 2) z = 2;
1273 if (z != wd->zoom) zoom_changed = 1;
1279 if (wd->main_load_pending)
1281 wd->size.w = wd->size.nw;
1282 wd->size.h = wd->size.nh;
1285 EINA_LIST_FOREACH(wd->grids, l, g)
1287 if (g->zoom == grid_zoom_calc(wd->zoom))
1289 wd->grids = eina_list_remove(wd->grids, g);
1290 wd->grids = eina_list_prepend(wd->grids, g);
1295 g = grid_create(obj);
1298 if (eina_list_count(wd->grids) > 1)
1300 g_zoom = eina_list_last(wd->grids)->data;
1301 wd->grids = eina_list_remove(wd->grids, g_zoom);
1302 grid_clear(obj, g_zoom);
1304 EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1309 wd->grids = eina_list_prepend(wd->grids, g);
1313 EINA_LIST_FREE(wd->grids, g)
1320 wd->t_start = ecore_loop_time_get();
1321 wd->t_end = wd->t_start + _elm_config->zoom_friction;
1322 if ((wd->size.w > 0) && (wd->size.h > 0))
1324 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1325 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1329 wd->size.spos.x = 0.5;
1330 wd->size.spos.y = 0.5;
1332 if (rw > wd->size.w) wd->size.spos.x = 0.5;
1333 if (rh > wd->size.h) wd->size.spos.y = 0.5;
1334 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1335 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1342 if (!wd->zoom_animator)
1344 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1346 if (wd->nosmooth == 1) _smooth_update(obj);
1350 an = wd->zoom_animator;
1353 if (!_zoom_anim(obj))
1355 ecore_animator_del(an);
1359 if (wd->calc_job) ecore_job_del(wd->calc_job);
1360 wd->calc_job = ecore_job_add(_calc_job, wd);
1364 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1366 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1369 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1373 elm_photocam_zoom_get(const Evas_Object *obj)
1375 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1376 Widget_Data *wd = elm_widget_data_get(obj);
1377 if (!wd) return 1.0;
1382 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1384 ELM_CHECK_WIDTYPE(obj, widtype);
1385 Widget_Data *wd = elm_widget_data_get(obj);
1387 if (wd->mode == mode) return;
1390 double tz = wd->zoom;
1392 elm_photocam_zoom_set(wd->obj, tz);
1396 EAPI Elm_Photocam_Zoom_Mode
1397 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1399 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1400 Widget_Data *wd = elm_widget_data_get(obj);
1401 if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1406 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1408 ELM_CHECK_WIDTYPE(obj, widtype);
1409 Widget_Data *wd = elm_widget_data_get(obj);
1411 if (w) *w = wd->size.imw;
1412 if (h) *h = wd->size.imh;
1416 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1418 ELM_CHECK_WIDTYPE(obj, widtype);
1419 Widget_Data *wd = elm_widget_data_get(obj);
1420 Evas_Coord sx, sy, sw, sh;
1422 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1423 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1428 *x = (wd->size.imw * sx) / wd->size.w;
1429 if (*x > wd->size.imw) *x = wd->size.imw;
1430 else if (*x < 0) *x = 0;
1434 *w = (wd->size.imw * sw) / wd->size.w;
1435 if (*w > wd->size.imw) *w = wd->size.imw;
1436 else if (*w < 0) *w = 0;
1449 *y = (wd->size.imh * sy) / wd->size.h;
1450 if (*y > wd->size.imh) *y = wd->size.imh;
1451 else if (*y < 0) *y = 0;
1455 *h = (wd->size.imh * sh) / wd->size.h;
1456 if (*h > wd->size.imh) *h = wd->size.imh;
1457 else if (*h < 0) *h = 0;
1468 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1470 ELM_CHECK_WIDTYPE(obj, widtype);
1471 Widget_Data *wd = elm_widget_data_get(obj);
1474 if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1475 rx = (x * wd->size.w) / wd->size.imw;
1476 ry = (y * wd->size.h) / wd->size.imh;
1477 rw = (w * wd->size.w) / wd->size.imw;
1478 rh = (w * wd->size.h) / wd->size.imh;
1481 if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1482 if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1483 if (wd->zoom_animator)
1486 ecore_animator_del(wd->zoom_animator);
1487 wd->zoom_animator = NULL;
1489 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1491 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1495 elm_photocam_image_region_bring_in(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 if (!wd->nosmooth) _smooth_update(obj);
1514 ecore_animator_del(wd->zoom_animator);
1515 wd->zoom_animator = NULL;
1517 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1519 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1523 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1525 ELM_CHECK_WIDTYPE(obj, widtype);
1526 Widget_Data *wd = elm_widget_data_get(obj);
1528 if (wd->paused == !!paused) return;
1529 wd->paused = paused;
1532 if (wd->zoom_animator)
1534 ecore_animator_del(wd->zoom_animator);
1535 wd->zoom_animator = NULL;
1537 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1543 elm_photocam_paused_get(const Evas_Object *obj)
1545 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1546 Widget_Data *wd = elm_widget_data_get(obj);
1547 if (!wd) return EINA_FALSE;
1552 elm_photocam_internal_image_get(const Evas_Object *obj)
1554 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1555 Widget_Data *wd = elm_widget_data_get(obj);
1556 if (!wd) return NULL;
1561 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1563 ELM_CHECK_WIDTYPE(obj, widtype);
1564 Widget_Data *wd = elm_widget_data_get(obj);
1566 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1570 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1572 ELM_CHECK_WIDTYPE(obj, widtype);
1573 Widget_Data *wd = elm_widget_data_get(obj);
1575 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);