summaryrefslogtreecommitdiff
path: root/unsorted/evas/evas-images5.c
diff options
context:
space:
mode:
authorYeshwanth Reddivari <r.yeshwanth@samsung.com>2016-04-06 10:46:04 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-04-06 10:46:39 +0900
commiteaa5e65d483b1b71ff16f541457c0235d3dcb6e2 (patch)
treea3830c636e663278e515ad2062498b405a3727c8 /unsorted/evas/evas-images5.c
parent97806b0a3fb1374ec905ccb894773b59ad691a23 (diff)
Interface: Flip and orientation interface
Summary: Added flip and orientation interface and used them in evas_image. Removed efl_image_orientation_set API and used efl_orientation_set and efl_flip_set API. In implementation part, converted enums back and forth in order to keep current implementation as it is. Test Plan: src/examples/evas/evas-images5.c Reviewers: singh.amitesh, raster, tasn, herdsman, woohyun, cedric, felipealmeida, jpeg Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D3844
Diffstat (limited to 'unsorted/evas/evas-images5.c')
-rw-r--r--unsorted/evas/evas-images5.c200
1 files changed, 200 insertions, 0 deletions
diff --git a/unsorted/evas/evas-images5.c b/unsorted/evas/evas-images5.c
new file mode 100644
index 00000000..3dcd88d0
--- /dev/null
+++ b/unsorted/evas/evas-images5.c
@@ -0,0 +1,200 @@
1/**
2 * Simple Evas example illustrating some image objects functions
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader/saver also built. See stdout/stderr
6 * for output.
7 *
8 * @verbatim
9 * gcc -o evas-images5 evas-images5.c `pkg-config --libs --cflags evas ecore ecore-evas efl`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#else
16#define PACKAGE_EXAMPLES_DIR "."
17#endif
18
19#define EFL_BETA_API_SUPPORT
20
21#include <Ecore.h>
22#include <Ecore_Evas.h>
23#include <stdio.h>
24#include <errno.h>
25#include <Efl.h>
26#include "evas-common.h"
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/im1.png";
32static const char *commands = \
33 "commands are:\n"
34 "\tp - print image fill property\n"
35 "\t0 - rotate by 0\n"
36 "\t1 - rotate by 90\n"
37 "\t2 - rotate by 180\n"
38 "\t3 - rotate by 270\n"
39 "\t4 - flip horizontal\n"
40 "\t5 - flip vertical\n"
41 "\t6 - flip none\n"
42 "\ts - save noise image to disk (/tmp dir)\n"
43 "\th - print help\n";
44
45const char *file_path = "/tmp/evas-images4-example.png";
46const char *quality_str = "quality=100";
47
48struct test_data
49{
50 Ecore_Evas *ee;
51 Evas *evas;
52 Evas_Object *bg, *img;
53};
54
55static struct test_data d = {0};
56
57static void
58_on_destroy(Ecore_Evas *ee EINA_UNUSED)
59{
60 ecore_main_loop_quit();
61}
62
63/* here just to keep our example's window size and background image's
64 * size in synchrony */
65static void
66_canvas_resize_cb(Ecore_Evas *ee)
67{
68 int w, h;
69
70 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
71 evas_object_resize(d.bg, w, h);
72}
73
74static void
75_on_keydown(void *data EINA_UNUSED,
76 Evas *evas EINA_UNUSED,
77 Evas_Object *o EINA_UNUSED,
78 void *einfo)
79{
80 Evas_Event_Key_Down *ev = einfo;
81
82 if (strcmp(ev->key, "h") == 0) /* print help */
83 {
84 puts(commands);
85 return;
86 }
87
88 if (strcmp(ev->key, "s") == 0) /* save noise image to disk */
89 {
90 if (!evas_object_image_save(d.img, file_path, NULL, quality_str))
91 fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
92 file_path, quality_str);
93 else
94 fprintf(stdout, "Image saved to '%s' (flags '%s'), check it out with "
95 "an image viewer\n", file_path, quality_str);
96
97 return;
98 }
99
100 if (strcmp(ev->key, "p") == 0) /* print image size*/
101 {
102 Evas_Coord w, h;
103
104 evas_object_image_size_get(d.img, &w, &h);
105 fprintf(stdout, "Image has size set to: w=%d, h=%d\n", w, h);
106 return;
107 }
108
109 int key_val = ev->key[0] - '0';
110
111 switch (key_val)
112 {
113 case 0:
114 efl_orientation_set(d.img, EFL_ORIENT_0);
115 break;
116 case 1:
117 efl_orientation_set(d.img, EFL_ORIENT_90);
118 break;
119 case 2:
120 efl_orientation_set(d.img, EFL_ORIENT_180);
121 break;
122 case 3:
123 efl_orientation_set(d.img, EFL_ORIENT_270);
124 break;
125 case 4:
126 efl_flip_set(d.img, EFL_FLIP_HORIZONTAL);
127 break;
128 case 5:
129 efl_flip_set(d.img, EFL_FLIP_VERTICAL);
130 break;
131 case 6:
132 efl_flip_set(d.img, EFL_FLIP_NONE);
133 break;
134 }
135}
136
137int
138main(void)
139{
140 int err;
141
142 if (!ecore_evas_init())
143 return EXIT_FAILURE;
144
145 /* this will give you a window with an Evas canvas under the first
146 * engine available */
147 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
148 if (!d.ee)
149 goto error;
150
151 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
152 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
153 ecore_evas_show(d.ee);
154
155 /* the canvas pointer, de facto */
156 d.evas = ecore_evas_get(d.ee);
157
158 d.bg = evas_object_rectangle_add(d.evas);
159 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
160 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
161 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
162 evas_object_show(d.bg);
163
164 d.img = evas_object_image_add(d.evas);
165 evas_object_image_file_set(d.img, img_path, NULL);
166 err = evas_object_image_load_error_get(d.img);
167 if (err != EVAS_LOAD_ERROR_NONE)
168 {
169 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
170 img_path, evas_load_error_str(err));
171 }
172 else
173 {
174 fprintf(stdout,
175 "loaded image '%s' with succes! error string is \"%s\"\n",
176 img_path, evas_load_error_str(err));
177
178 evas_object_move(d.img, WIDTH / 2, HEIGHT / 2);
179 evas_object_image_fill_set(d.img, 0, 0, WIDTH / 2, HEIGHT / 2);
180 evas_object_resize(d.img, WIDTH / 2, HEIGHT / 2);
181 evas_object_show(d.img);
182
183 evas_object_focus_set(d.bg, EINA_TRUE);
184 evas_object_event_callback_add(
185 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
186 }
187
188 puts(commands);
189 ecore_main_loop_begin();
190
191 ecore_evas_free(d.ee);
192 ecore_evas_shutdown();
193 return 0;
194
195error:
196 fprintf(stderr, "you got to have at least one evas engine built and linked"
197 " up to ecore-evas for this example to run properly.\n");
198 ecore_evas_shutdown();
199 return -1;
200}