aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/photocam_example_01.c
blob: 7826591fc1188fdc2d726dd590df9a6abf1de37c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//Compile with:
//gcc -o photocam_example_01 photocam_example_01.c -g `pkg-config --cflags --libs elementary` -DDATA_DIR="\"<directory>\""
//where directory is the path where images/insanely_huge_test_image.jpg can be found.

#include <Elementary.h>

static void _fit(void *data, Evas_Object *obj, void *event_info);
static void _unfit(void *data, Evas_Object *obj, void *event_info);
static void _zoom(void *data, Evas_Object *obj, void *event_info);
static void _bring_in(void *data, Evas_Object *obj, void *event_info);
static void _orient(void *data, Evas_Object *obj, void *event_info);
static void _orient_do(void *data, Evas_Object *obj, void *event_info);

typedef struct _Orient_Data Orient_Data;
struct _Orient_Data
{
   Evas_Object *ph;
   Evas_Image_Orient orient;
};

EAPI_MAIN int
elm_main(int argc, char **argv)
{
   Evas_Object *win, *obj, *photocam, *menu;
   Orient_Data *orient_data;
   char buf[PATH_MAX];

   elm_app_info_set(elm_main, "elementary", "images/insanely_huge_test_image.jpg");
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add("photocam", "Photocam");
   elm_win_autodel_set(win, EINA_TRUE);

   photocam = elm_photocam_add(win);
   snprintf(buf, sizeof(buf), "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
   elm_photocam_file_set(photocam, buf);
   elm_scroller_bounce_set(photocam, EINA_FALSE, EINA_TRUE);
   evas_object_smart_callback_add(photocam, "loaded,detail", _bring_in, NULL);
   evas_object_resize(photocam, 500, 400);
   evas_object_show(photocam);

   obj = elm_button_add(win);
   elm_object_text_set(obj, "Fit");
   evas_object_show(obj);
   evas_object_resize(obj, 50, 30);
   evas_object_move(obj, 10, 410);
   evas_object_smart_callback_add(obj, "clicked", _fit, photocam);

   obj = elm_button_add(win);
   elm_object_text_set(obj, "Unfit");
   evas_object_show(obj);
   evas_object_resize(obj, 70, 30);
   evas_object_move(obj, 70, 410);
   evas_object_smart_callback_add(obj, "clicked", _unfit, photocam);

   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 0;
   menu = elm_menu_add(win);
   elm_menu_item_add(menu, NULL, NULL, "orient 0", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 1;
   elm_menu_item_add(menu, NULL, NULL, "orient 90", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 2;
   elm_menu_item_add(menu, NULL, NULL, "orient 180", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 3;
   elm_menu_item_add(menu, NULL, NULL, "orient 270", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 4;
   elm_menu_item_add(menu, NULL, NULL, "flip horizontal", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 5;
   elm_menu_item_add(menu, NULL, NULL, "flip vertical", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 6;
   elm_menu_item_add(menu, NULL, NULL, "flip transverse", _orient_do, orient_data);
   orient_data = (Orient_Data *)malloc(sizeof(Orient_Data));
   orient_data->ph = photocam;
   orient_data->orient = 7;
   elm_menu_item_add(menu, NULL, NULL, "flip transpose", _orient_do, orient_data);

   obj = elm_button_add(win);
   elm_object_text_set(obj, "Orient");
   evas_object_show(obj);
   evas_object_resize(obj, 70, 30);
   evas_object_move(obj, 470, 410);
   evas_object_smart_callback_add(obj, "clicked", _orient, menu);

   obj = elm_slider_add(win);
   elm_object_text_set(obj, "Zoom");
   evas_object_show(obj);
   evas_object_resize(obj, 300, 30);
   evas_object_move(obj, 150, 410);
   evas_object_smart_callback_add(obj, "changed", _zoom, photocam);

   evas_object_resize(win, 500, 440);
   evas_object_show(win);

   elm_run();

   return 0;
}
ELM_MAIN()

static void
_bring_in(void *data, Evas_Object *obj, void *event_info)
{
   int w, h;
   elm_photocam_image_size_get(obj, &w, &h);
   elm_photocam_image_region_bring_in(obj, w/2, h/2, 500, 400);
}

static void
_fit(void *data, Evas_Object *obj, void *event_info)
{
   int x, y, w, h;
   elm_photocam_image_region_get(data, &x, &y, &w, &h);
   printf("region: {%d, %d, %d, %d}\n", x, y, w, h);
   elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT);
}

static void
_unfit(void *data, Evas_Object *obj, void *event_info)
{
   elm_photocam_zoom_mode_set(data, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
}

static void
_zoom(void *data, Evas_Object *obj, void *event_info)
{
   double z = elm_slider_value_get(obj) * 8;
   elm_photocam_zoom_set(data, z);
}

static void
_orient(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *mn = data;
   if (!mn) return;

   evas_object_show(mn);
}

static void
_orient_do(void *data, Evas_Object *obj, void *event_info)
{
   Orient_Data *orient_data = data;
   if (!orient_data) return;

   elm_photocam_image_orient_set(orient_data->ph, orient_data->orient);
}