1 #include <Elementary.h>
4 #define SMART_NAME "elm_pan"
5 #define API_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME)))
6 #define INTERNAL_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
7 typedef struct _Smart_Data Smart_Data;
11 Evas_Object *smart_obj;
12 Evas_Object *child_obj;
13 Evas_Coord x, y, w, h;
14 Evas_Coord child_w, child_h, px, py;
15 double gravity_x, gravity_y;
16 Evas_Coord prev_cw, prev_ch, delta_posx, delta_posy;
19 /* local subsystem functions */
20 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
21 static void _smart_child_resize_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
23 static void _smart_reconfigure(Smart_Data *sd);
24 static void _smart_add(Evas_Object *obj);
25 static void _smart_del(Evas_Object *obj);
26 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
27 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
28 static void _smart_show(Evas_Object *obj);
29 static void _smart_hide(Evas_Object *obj);
30 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
31 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
32 static void _smart_clip_unset(Evas_Object *obj);
33 static void _smart_init(void);
35 /* local subsystem globals */
36 static Evas_Smart *_smart = NULL;
38 /* externally accessible functions */
40 _elm_smart_pan_add(Evas *evas)
43 return evas_object_smart_add(evas, _smart);
47 _elm_smart_pan_child_set(Evas_Object *obj, Evas_Object *child)
50 if (child == sd->child_obj) return;
53 evas_object_clip_unset(sd->child_obj);
54 evas_object_smart_member_del(sd->child_obj);
55 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
56 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
64 sd->child_obj = child;
65 evas_object_smart_member_add(sd->child_obj, sd->smart_obj);
66 evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
69 evas_object_event_callback_add(child, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
70 evas_object_event_callback_add(child, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
71 evas_object_color_get(sd->smart_obj, &r, &g, &b, &a);
72 evas_object_color_set(sd->child_obj, r, g, b, a);
73 evas_object_clip_set(sd->child_obj, evas_object_clip_get(sd->smart_obj));
74 if (evas_object_visible_get(sd->smart_obj)) evas_object_show(sd->child_obj);
75 else evas_object_hide(sd->child_obj);
76 _smart_reconfigure(sd);
78 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
82 _elm_smart_pan_child_get(Evas_Object *obj)
84 API_ENTRY return NULL;
89 _elm_smart_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
92 // if (x > (sd->child_w - sd->w)) x = sd->child_w - sd->w;
93 // if (y > (sd->child_h - sd->h)) y = sd->child_h - sd->h;
96 if ((x == sd->px) && (y == sd->py)) return;
99 _smart_reconfigure(sd);
100 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
104 _elm_smart_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
112 _elm_smart_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
117 if (sd->w < sd->child_w) *x = sd->child_w - sd->w;
122 if (sd->h < sd->child_h) *y = sd->child_h - sd->h;
128 _elm_smart_pan_min_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
138 _elm_smart_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
141 if (w) *w = sd->child_w;
142 if (h) *h = sd->child_h;
146 _elm_smart_pan_gravity_set(Evas_Object *obj, double x, double y)
151 sd->prev_cw = sd->child_w;
152 sd->prev_ch = sd->child_h;
158 _elm_smart_pan_gravity_get(Evas_Object *obj, double *x, double *y)
161 if (x) *x = sd->gravity_x;
162 if (y) *y = sd->gravity_y;
165 /* local subsystem functions */
167 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
172 sd->child_obj = NULL;
173 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
177 _smart_child_resize_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
183 evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
184 if ((w != sd->child_w) || (h != sd->child_h))
188 _smart_reconfigure(sd);
190 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
194 _smart_reconfigure(Smart_Data *sd)
196 if (sd->gravity_x || sd->gravity_y)
198 if ((!sd->px) && (!sd->py))
200 sd->px = sd->delta_posx*sd->gravity_x;
201 sd->py = sd->delta_posy*sd->gravity_y;
203 sd->delta_posx += sd->child_w - sd->prev_cw;
204 sd->prev_cw = sd->child_w;
205 sd->delta_posy += sd->child_h - sd->prev_ch;
206 sd->prev_ch = sd->child_h;
208 evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
209 sd->px = sd->delta_posx*sd->gravity_x;
210 sd->py = sd->delta_posy*sd->gravity_y;
214 evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
218 _smart_add(Evas_Object *obj)
222 sd = calloc(1, sizeof(Smart_Data));
231 evas_object_smart_data_set(obj, sd);
235 _smart_del(Evas_Object *obj)
238 _elm_smart_pan_child_set(obj, NULL);
243 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
248 _smart_reconfigure(sd);
252 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
257 _smart_reconfigure(sd);
258 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
262 _smart_show(Evas_Object *obj)
266 evas_object_show(sd->child_obj);
270 _smart_hide(Evas_Object *obj)
274 evas_object_hide(sd->child_obj);
278 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
282 evas_object_color_set(sd->child_obj, r, g, b, a);
286 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
290 evas_object_clip_set(sd->child_obj, clip);
294 _smart_clip_unset(Evas_Object *obj)
298 evas_object_clip_unset(sd->child_obj);
301 /* never need to touch this */
308 static const Evas_Smart_Class sc =
311 EVAS_SMART_CLASS_VERSION,
329 _smart = evas_smart_class_new(&sc);