summaryrefslogtreecommitdiff
path: root/unsorted/evas/evas-images5.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2018-08-09 16:21:58 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-08-09 16:21:58 -0400
commitd9bc92888a11c400320c2058b3500a248e220363 (patch)
tree223be84ba5f8c1c7a725c4cca7c96488090d29bd /unsorted/evas/evas-images5.c
parent471e5a2e5ce40d56d4989a9f0d6b78e5a3df71f0 (diff)
examples
Diffstat (limited to 'unsorted/evas/evas-images5.c')
-rw-r--r--unsorted/evas/evas-images5.c197
1 files changed, 0 insertions, 197 deletions
diff --git a/unsorted/evas/evas-images5.c b/unsorted/evas/evas-images5.c
deleted file mode 100644
index ed8a4e55..00000000
--- a/unsorted/evas/evas-images5.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/**
2 * Example of rotating and flipping image objects in Evas.
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#define EFL_BETA_API_SUPPORT
18#endif
19
20#include <Ecore.h>
21#include <Ecore_Evas.h>
22#include <stdio.h>
23#include <errno.h>
24#include <Efl.h>
25#include "evas-common.h"
26
27#define WIDTH (320)
28#define HEIGHT (240)
29
30static const char *img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/im1.png";
31static const char *commands = \
32 "commands are:\n"
33 "\tp - print image fill property\n"
34 "\t0 - rotate by 0\n"
35 "\t1 - rotate by 90\n"
36 "\t2 - rotate by 180\n"
37 "\t3 - rotate by 270\n"
38 "\t4 - flip horizontal\n"
39 "\t5 - flip vertical\n"
40 "\t6 - flip none\n"
41 "\ts - save noise image to disk (/tmp dir)\n"
42 "\th - print help\n";
43
44const char *file_path = "/tmp/evas-images4-example.png";
45const char *quality_str = "quality=100";
46
47struct test_data
48{
49 Ecore_Evas *ee;
50 Evas *evas;
51 Evas_Object *bg, *img;
52};
53
54static struct test_data d = {0};
55
56static void
57_on_destroy(Ecore_Evas *ee EINA_UNUSED)
58{
59 ecore_main_loop_quit();
60}
61
62/* Keep the example's window size in sync with the background image's size */
63static void
64_canvas_resize_cb(Ecore_Evas *ee)
65{
66 int w, h;
67
68 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
69 evas_object_resize(d.bg, w, h);
70}
71
72static void
73_on_keydown(void *data EINA_UNUSED,
74 Evas *evas EINA_UNUSED,
75 Evas_Object *o EINA_UNUSED,
76 void *einfo)
77{
78 Evas_Event_Key_Down *ev = einfo;
79
80 if (strcmp(ev->key, "h") == 0) /* print help */
81 {
82 puts(commands);
83 return;
84 }
85
86 if (strcmp(ev->key, "s") == 0) /* save noise image to disk */
87 {
88 if (!evas_object_image_save(d.img, file_path, NULL, quality_str))
89 fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
90 file_path, quality_str);
91 else
92 printf("Image saved to '%s' (flags '%s'), check it out with "
93 "an image viewer\n", file_path, quality_str);
94
95 return;
96 }
97
98 if (strcmp(ev->key, "p") == 0) /* print image size*/
99 {
100 Evas_Coord w, h;
101
102 evas_object_image_size_get(d.img, &w, &h);
103 printf("Image has size set to: w=%d, h=%d\n", w, h);
104 return;
105 }
106
107 int key_val = ev->key[0] - '0';
108
109 switch (key_val)
110 {
111 case 0:
112 efl_orientation_set(d.img, EFL_ORIENT_0);
113 break;
114 case 1:
115 efl_orientation_set(d.img, EFL_ORIENT_90);
116 break;
117 case 2:
118 efl_orientation_set(d.img, EFL_ORIENT_180);
119 break;
120 case 3:
121 efl_orientation_set(d.img, EFL_ORIENT_270);
122 break;
123 case 4:
124 efl_orientation_flip_set(d.img, EFL_FLIP_HORIZONTAL);
125 break;
126 case 5:
127 efl_orientation_flip_set(d.img, EFL_FLIP_VERTICAL);
128 break;
129 case 6:
130 efl_orientation_flip_set(d.img, EFL_FLIP_NONE);
131 break;
132 }
133}
134
135int
136main(void)
137{
138 int err;
139
140 if (!ecore_evas_init())
141 return EXIT_FAILURE;
142
143 /* this will give you a window with an Evas canvas under the first
144 * engine available */
145 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
146 if (!d.ee)
147 goto error;
148
149 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
150 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
151 ecore_evas_show(d.ee);
152
153 /* the canvas pointer, de facto */
154 d.evas = ecore_evas_get(d.ee);
155
156 d.bg = evas_object_rectangle_add(d.evas);
157 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
158 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
159 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
160 evas_object_show(d.bg);
161
162 d.img = evas_object_image_add(d.evas);
163 evas_object_image_file_set(d.img, img_path, NULL);
164 err = evas_object_image_load_error_get(d.img);
165 if (err != EVAS_LOAD_ERROR_NONE)
166 {
167 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
168 img_path, evas_load_error_str(err));
169 }
170 else
171 {
172 printf("loaded image '%s' with success! error string is \"%s\"\n",
173 img_path, evas_load_error_str(err));
174
175 evas_object_move(d.img, WIDTH / 2, HEIGHT / 2);
176 evas_object_image_fill_set(d.img, 0, 0, WIDTH / 2, HEIGHT / 2);
177 evas_object_resize(d.img, WIDTH / 2, HEIGHT / 2);
178 evas_object_show(d.img);
179
180 evas_object_focus_set(d.bg, EINA_TRUE);
181 evas_object_event_callback_add(
182 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
183 }
184
185 puts(commands);
186 ecore_main_loop_begin();
187
188 ecore_evas_free(d.ee);
189 ecore_evas_shutdown();
190 return 0;
191
192error:
193 fprintf(stderr, "error: Requires at least one Evas engine built and linked"
194 " to ecore-evas for this example to run properly.\n");
195 ecore_evas_shutdown();
196 return -1;
197}