Elm fileselector_btn: Fix code to use the new elm_object_text_set/get API.
[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(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
160 {
161    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT);
162 }
163
164 static void
165 my_bt_zoom_fill(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
166 {
167    elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL);
168 }
169
170 static void
171 _photocam_mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
172 {
173    Evas_Object *photocam = data;
174    Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
175    int zoom;
176    double val;
177    //unset the mouse wheel
178    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
179
180    zoom = elm_photocam_zoom_get(photocam);
181    if ((ev->z>0) && (zoom == 1)) return;
182
183    if (ev->z > 0)
184      zoom /= 2;
185    else
186      zoom *= 2;
187
188    val = 1;
189    int _zoom = zoom;
190    while(_zoom>1)
191      {
192         _zoom /= 2;
193         val++;
194      }
195
196    elm_photocam_zoom_mode_set(photocam, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
197    if (zoom >= 1) elm_photocam_zoom_set(photocam, zoom);
198 }
199
200 static void
201 _photocam_move_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 {
203    int x,y,w,h;
204
205    evas_object_geometry_get(data,&x,&y,&w,&h);
206    evas_object_resize(rect,w,h);
207    evas_object_move(rect,x,y);
208 }
209
210 void
211 test_photocam(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
212 {
213    Evas_Object *win, *bg, *ph, *tb2, *bt;
214    // these were just testing - use the "select photo" browser to select one
215    const char *img[5] =
216      {
217         "/home/raster/t1.jpg",  //   5 mpixel
218         "/home/raster/t2.jpg",  //  18 mpixel
219         "/home/raster/t3.jpg",  //  39 mpixel
220         "/home/raster/t4.jpg",  // 192 mpixel
221         "/home/raster/t5.jpg"   // 466 mpixel
222      };
223
224    win = elm_win_add(NULL, "photocam", ELM_WIN_BASIC);
225    elm_win_title_set(win, "Photocam");
226    elm_win_autodel_set(win, 1);
227
228    bg = elm_bg_add(win);
229    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230    elm_win_resize_object_add(win, bg);
231    evas_object_show(bg);
232
233    ph = elm_photocam_add(win);
234    evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
235    elm_win_resize_object_add(win, ph);
236    evas_object_data_set(ph, "window", win);
237
238    rect = evas_object_rectangle_add(evas_object_evas_get(win));
239    evas_object_color_set(rect, 0, 0, 0, 0);
240    evas_object_repeat_events_set(rect,1);
241    evas_object_show(rect);
242    evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_WHEEL, _photocam_mouse_wheel_cb, ph);
243    evas_object_raise(rect);
244
245    evas_object_event_callback_add(ph, EVAS_CALLBACK_RESIZE, _photocam_move_resize_cb, ph);
246    evas_object_event_callback_add(ph, EVAS_CALLBACK_MOVE, _photocam_move_resize_cb, ph);
247
248    evas_object_smart_callback_add(ph, "clicked", my_ph_clicked, win);
249    evas_object_smart_callback_add(ph, "press", my_ph_press, win);
250    evas_object_smart_callback_add(ph, "longpressed", my_ph_longpressed, win);
251    evas_object_smart_callback_add(ph, "clicked,double", my_ph_clicked_double, win);
252    evas_object_smart_callback_add(ph, "load", my_ph_load, win);
253    evas_object_smart_callback_add(ph, "loaded", my_ph_loaded, win);
254    evas_object_smart_callback_add(ph, "load,details", my_ph_load_details, win);
255    evas_object_smart_callback_add(ph, "loaded,details", my_ph_loaded_details, win);
256    evas_object_smart_callback_add(ph, "zoom,start", my_ph_zoom_start, win);
257    evas_object_smart_callback_add(ph, "zoom,stop", my_ph_zoom_stop, win);
258    evas_object_smart_callback_add(ph, "zoom,change", my_ph_zoom_change, win);
259    evas_object_smart_callback_add(ph, "scroll,anim,start", my_ph_anim_start, win);
260    evas_object_smart_callback_add(ph, "scroll,anim,stop", my_ph_anim_stop, win);
261    evas_object_smart_callback_add(ph, "scroll,drag,start", my_ph_drag_start, win);
262    evas_object_smart_callback_add(ph, "scroll,drag,stop", my_ph_drag_stop, win);
263    evas_object_smart_callback_add(ph, "scroll", my_ph_scroll, win);
264
265    elm_photocam_file_set(ph, img[1]);
266
267    evas_object_show(ph);
268
269    tb2 = elm_table_add(win);
270    evas_object_size_hint_weight_set(tb2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
271    elm_win_resize_object_add(win, tb2);
272
273    bt = elm_button_add(win);
274    elm_object_text_set(bt, "Z -");
275    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_out, ph);
276    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
277    evas_object_size_hint_align_set(bt, 0.1, 0.1);
278    elm_table_pack(tb2, bt, 0, 0, 1, 1);
279    evas_object_show(bt);
280
281    bt = elm_fileselector_button_add(win);
282    elm_object_text_set(bt, "Select Photo");
283    evas_object_smart_callback_add(bt, "file,chosen", my_bt_open, ph);
284    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
285    evas_object_size_hint_align_set(bt, 0.5, 0.1);
286    elm_table_pack(tb2, bt, 1, 0, 1, 1);
287    evas_object_show(bt);
288
289    bt = elm_button_add(win);
290    elm_object_text_set(bt, "Z +");
291    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_in, ph);
292    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
293    evas_object_size_hint_align_set(bt, 0.9, 0.1);
294    elm_table_pack(tb2, bt, 2, 0, 1, 1);
295    evas_object_show(bt);
296
297    bt = elm_button_add(win);
298    elm_object_text_set(bt, "Show 30,50 500x300");
299    evas_object_smart_callback_add(bt, "clicked", my_bt_show_reg, ph);
300    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
301    evas_object_size_hint_align_set(bt, 0.1, 0.5);
302    elm_table_pack(tb2, bt, 0, 1, 1, 1);
303    evas_object_show(bt);
304
305    bt = elm_button_add(win);
306    elm_object_text_set(bt, "Bring 800,300 500x300");
307    evas_object_smart_callback_add(bt, "clicked", my_bt_bring_reg, ph);
308    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
309    evas_object_size_hint_align_set(bt, 0.9, 0.5);
310    elm_table_pack(tb2, bt, 2, 1, 1, 1);
311    evas_object_show(bt);
312
313    bt = elm_button_add(win);
314    elm_object_text_set(bt, "Pause On/Off");
315    evas_object_smart_callback_add(bt, "clicked", my_bt_pause, ph);
316    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
317    evas_object_size_hint_align_set(bt, 0.1, 0.9);
318    elm_table_pack(tb2, bt, 0, 2, 1, 1);
319    evas_object_show(bt);
320
321    bt = elm_button_add(win);
322    elm_object_text_set(bt, "Fit");
323    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_fit, ph);
324    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
325    evas_object_size_hint_align_set(bt, 0.5, 0.9);
326    elm_table_pack(tb2, bt, 1, 2, 1, 1);
327    evas_object_show(bt);
328
329    bt = elm_button_add(win);
330    elm_object_text_set(bt, "Fill");
331    evas_object_smart_callback_add(bt, "clicked", my_bt_zoom_fill, ph);
332    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333    evas_object_size_hint_align_set(bt, 0.9, 0.9);
334    elm_table_pack(tb2, bt, 2, 2, 1, 1);
335    evas_object_show(bt);
336
337    evas_object_show(tb2);
338
339    evas_object_resize(win, 800, 800);
340    evas_object_show(win);
341 }
342 #endif