elementary: Updated test_bubble.c to do API testing
[framework/uifw/elementary.git] / src / bin / test_photocam.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static Evas_Object *rect;
8
9 static void
10 my_ph_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
11 {
12    printf("clicked\n");
13 }
14
15 static void
16 my_ph_press(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
17 {
18    printf("press\n");
19 }
20
21 static void
22 my_ph_longpressed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
23 {
24    printf("longpressed\n");
25 }
26
27 static void
28 my_ph_clicked_double(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
29 {
30    printf("clicked,double\n");
31 }
32
33 static void
34 my_ph_load(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
35 {
36    printf("load\n");
37 }
38
39 static void
40 my_ph_loaded(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
41 {
42    printf("loaded\n");
43 }
44
45 static void
46 my_ph_load_details(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
47 {
48    printf("load,details\n");
49 }
50
51 static void
52 my_ph_loaded_details(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
53 {
54    printf("loaded,details\n");
55 }
56
57 static void
58 my_ph_zoom_start(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
59 {
60    printf("zoom,start\n");
61 }
62
63 static void
64 my_ph_zoom_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
65 {
66    printf("zoom,stop\n");
67 }
68
69 static void
70 my_ph_zoom_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
71 {
72    printf("zoom,change\n");
73 }
74
75 static void
76 my_ph_anim_start(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
77 {
78    printf("anim,start\n");
79 }
80
81 static void
82 my_ph_anim_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
83 {
84    printf("anim,stop\n");
85 }
86
87 static void
88 my_ph_drag_start(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
89 {
90    printf("drag,start\n");
91 }
92
93 static void
94 my_ph_drag_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
95 {
96    printf("drag_stop\n");
97 }
98
99 static void
100 my_ph_scroll(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
101 {
102    int x, y, w, h;
103    elm_photocam_region_get(obj, &x, &y, &w, &h);
104    printf("scroll %i %i %ix%i\n", x, y, w, h);
105 }
106
107 static void
108 my_bt_open(void *data, Evas_Object *obj __UNUSED__, void *event_info)
109 {
110    Evas_Object *ph = data;
111    const char *file = event_info;
112
113    if (file)
114      elm_photocam_file_set(ph, file);
115 }
116
117 static void
118 my_bt_show_reg(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
119 {
120    elm_photocam_image_region_show(data, 30, 50, 500, 300);
121 }
122
123 static void
124 my_bt_bring_reg(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
125
126 {
127    elm_photocam_image_region_bring_in(data, 800, 300, 500, 300);
128 }
129
130 static void
131 my_bt_zoom_in(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
132 {
133    double zoom;
134
135    zoom = elm_photocam_zoom_get(data);
136    zoom -= 0.5;
137    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
138    if (zoom >= (1.0 / 32.0)) elm_photocam_zoom_set(data, zoom);
139 }
140
141 static void
142 my_bt_zoom_out(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
143 {
144    double zoom;
145
146    zoom = elm_photocam_zoom_get(data);
147    zoom += 0.5;
148    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
149    if (zoom <= 256.0) elm_photocam_zoom_set(data, zoom);
150 }
151
152 static void
153 my_bt_pause(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
154 {
155    elm_photocam_paused_set(data, !elm_photocam_paused_get(data));
156 }
157
158 static void
159 my_bt_zoom_fit_in(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
160 {
161    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN);
162 }
163
164 static void
165 my_bt_zoom_fit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
166 {
167    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT);
168 }
169
170 static void
171 my_bt_zoom_fill(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
172 {
173    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL);
174 }
175
176 static void
177 _photocam_mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
178 {
179    Evas_Object *photocam = data;
180    Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
181    int zoom;
182    double val;
183    //unset the mouse wheel
184    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
185
186    zoom = elm_photocam_zoom_get(photocam);
187    if ((ev->z>0) && (zoom == 1)) return;
188
189    if (ev->z > 0)
190      zoom /= 2;
191    else
192      zoom *= 2;
193
194    val = 1;
195    int _zoom = zoom;
196    while (_zoom>1)
197      {
198         _zoom /= 2;
199         val++;
200      }
201
202    elm_photocam_zoom_mode_set(photocam, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
203    if (zoom >= 1) elm_photocam_zoom_set(photocam, zoom);
204 }
205
206 static void
207 _photocam_move_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
208 {
209    int x,y,w,h;
210
211    evas_object_geometry_get(data,&x,&y,&w,&h);
212    evas_object_resize(rect,w,h);
213    evas_object_move(rect,x,y);
214 }
215
216 void
217 test_photocam(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
218 {
219    Evas_Object *win, *bg, *ph, *tb2, *bt, *box;
220    // these were just testing - use the "select photo" browser to select one
221    const char *img[5] =
222      {
223         "/home/raster/t1.jpg",  //   5 mpixel
224         "/home/raster/t2.jpg",  //  18 mpixel
225         "/home/raster/t3.jpg",  //  39 mpixel
226         "/home/raster/t4.jpg",  // 192 mpixel
227         "/home/raster/t5.jpg"   // 466 mpixel
228      };
229
230    win = elm_win_add(NULL, "photocam", ELM_WIN_BASIC);
231    elm_win_title_set(win, "Photocam");
232    elm_win_autodel_set(win, EINA_TRUE);
233
234    bg = elm_bg_add(win);
235    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
236    elm_win_resize_object_add(win, bg);
237    evas_object_show(bg);
238
239    ph = elm_photocam_add(win);
240    evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
241    elm_win_resize_object_add(win, ph);
242    evas_object_data_set(ph, "window", win);
243
244    rect = evas_object_rectangle_add(evas_object_evas_get(win));
245    evas_object_color_set(rect, 0, 0, 0, 0);
246    evas_object_repeat_events_set(rect,1);
247    evas_object_show(rect);
248    evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_WHEEL, _photocam_mouse_wheel_cb, ph);
249    evas_object_raise(rect);
250
251    evas_object_event_callback_add(ph, EVAS_CALLBACK_RESIZE, _photocam_move_resize_cb, ph);
252    evas_object_event_callback_add(ph, EVAS_CALLBACK_MOVE, _photocam_move_resize_cb, ph);
253
254    evas_object_smart_callback_add(ph, "clicked", my_ph_clicked, win);
255    evas_object_smart_callback_add(ph, "press", my_ph_press, win);
256    evas_object_smart_callback_add(ph, "longpressed", my_ph_longpressed, win);
257    evas_object_smart_callback_add(ph, "clicked,double", my_ph_clicked_double, win);
258    evas_object_smart_callback_add(ph, "load", my_ph_load, win);
259    evas_object_smart_callback_add(ph, "loaded", my_ph_loaded, win);
260    evas_object_smart_callback_add(ph, "load,details", my_ph_load_details, win);
261    evas_object_smart_callback_add(ph, "loaded,details", my_ph_loaded_details, win);
262    evas_object_smart_callback_add(ph, "zoom,start", my_ph_zoom_start, win);
263    evas_object_smart_callback_add(ph, "zoom,stop", my_ph_zoom_stop, win);
264    evas_object_smart_callback_add(ph, "zoom,change", my_ph_zoom_change, win);
265    evas_object_smart_callback_add(ph, "scroll,anim,start", my_ph_anim_start, win);
266    evas_object_smart_callback_add(ph, "scroll,anim,stop", my_ph_anim_stop, win);
267    evas_object_smart_callback_add(ph, "scroll,drag,start", my_ph_drag_start, win);
268    evas_object_smart_callback_add(ph, "scroll,drag,stop", my_ph_drag_stop, win);
269    evas_object_smart_callback_add(ph, "scroll", my_ph_scroll, win);
270
271    elm_photocam_file_set(ph, img[1]);
272
273    evas_object_show(ph);
274
275    tb2 = elm_table_add(win);
276    evas_object_size_hint_weight_set(tb2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
277    elm_win_resize_object_add(win, tb2);
278
279    bt = elm_button_add(win);
280    elm_object_text_set(bt, "Z -");
281    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_out, ph);
282    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
283    evas_object_size_hint_align_set(bt, 0.1, 0.1);
284    elm_table_pack(tb2, bt, 0, 0, 1, 1);
285    evas_object_show(bt);
286
287    bt = elm_fileselector_button_add(win);
288    elm_object_text_set(bt, "Select Photo");
289    evas_object_smart_callback_add(bt, "file,chosen", my_bt_open, ph);
290    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
291    evas_object_size_hint_align_set(bt, 0.5, 0.1);
292    elm_table_pack(tb2, bt, 1, 0, 1, 1);
293    evas_object_show(bt);
294
295    bt = elm_button_add(win);
296    elm_object_text_set(bt, "Z +");
297    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_in, ph);
298    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
299    evas_object_size_hint_align_set(bt, 0.9, 0.1);
300    elm_table_pack(tb2, bt, 2, 0, 1, 1);
301    evas_object_show(bt);
302
303    bt = elm_button_add(win);
304    elm_object_text_set(bt, "Show 30,50 500x300");
305    evas_object_smart_callback_add(bt, "clicked", my_bt_show_reg, ph);
306    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
307    evas_object_size_hint_align_set(bt, 0.1, 0.5);
308    elm_table_pack(tb2, bt, 0, 1, 1, 1);
309    evas_object_show(bt);
310
311    bt = elm_button_add(win);
312    elm_object_text_set(bt, "Bring 800,300 500x300");
313    evas_object_smart_callback_add(bt, "clicked", my_bt_bring_reg, ph);
314    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
315    evas_object_size_hint_align_set(bt, 0.9, 0.5);
316    elm_table_pack(tb2, bt, 2, 1, 1, 1);
317    evas_object_show(bt);
318
319    bt = elm_button_add(win);
320    elm_object_text_set(bt, "Pause On/Off");
321    evas_object_smart_callback_add(bt, "clicked", my_bt_pause, ph);
322    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
323    evas_object_size_hint_align_set(bt, 0.1, 0.9);
324    elm_table_pack(tb2, bt, 0, 2, 1, 1);
325    evas_object_show(bt);
326
327    box = elm_box_add(win);
328    elm_box_horizontal_set(box, EINA_TRUE);
329    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330    evas_object_size_hint_align_set(box, 0.9, 0.9);
331    elm_table_pack(tb2, box, 2, 2, 1, 1);
332
333    bt = elm_button_add(win);
334    elm_object_text_set(bt, "Fit");
335    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_fit, ph);
336    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337    elm_box_pack_end(box, bt);
338    evas_object_show(bt);
339
340    bt = elm_button_add(win);
341    elm_object_text_set(bt, "Fit_In");
342    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_fit_in, ph);
343    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
344    elm_box_pack_end(box, bt);
345    evas_object_show(bt);
346
347    bt = elm_button_add(win);
348    elm_object_text_set(bt, "Fill");
349    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_fill, ph);
350    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351    elm_box_pack_end(box, bt);
352    evas_object_show(bt);
353
354    evas_object_show(box);
355    evas_object_show(tb2);
356
357    evas_object_resize(win, 800, 800);
358    evas_object_show(win);
359 }
360 #endif