aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/examples/evas-images2.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/examples/evas-images2.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/examples/evas-images2.c')
-rw-r--r--libraries/evas/src/examples/evas-images2.c204
1 files changed, 204 insertions, 0 deletions
diff --git a/libraries/evas/src/examples/evas-images2.c b/libraries/evas/src/examples/evas-images2.c
new file mode 100644
index 0000000..ba7766c
--- /dev/null
+++ b/libraries/evas/src/examples/evas-images2.c
@@ -0,0 +1,204 @@
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-images2 evas-images2.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
32static const char *commands = \
33 "commands are:\n"
34 "\tp - change proxy image's source\n"
35 "\ts - print noise image's stride value\n"
36 "\ta - save noise image to disk (/tmp dir)\n"
37 "\th - print help\n";
38
39const char *file_path = "/tmp/evas-images2-example.png";
40const char *quality_str = "quality=100";
41
42struct test_data
43{
44 Ecore_Evas *ee;
45 Evas *evas;
46 Evas_Object *logo, *noise_img, *proxy_img, *bg;
47};
48
49static struct test_data d = {0};
50
51static void
52_on_preloaded(void *data __UNUSED__,
53 Evas *e __UNUSED__,
54 Evas_Object *obj __UNUSED__,
55 void *event_info __UNUSED__)
56{
57 fprintf(stdout, "Image has been pre-loaded!\n");
58}
59
60static void
61_on_destroy(Ecore_Evas *ee __UNUSED__)
62{
63 ecore_main_loop_quit();
64}
65
66/* here just to keep our example's window size and background image's
67 * size in synchrony */
68static void
69_canvas_resize_cb(Ecore_Evas *ee)
70{
71 int w, h;
72
73 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
74 evas_object_resize(d.bg, w, h);
75}
76
77static void
78_on_keydown(void *data __UNUSED__,
79 Evas *evas __UNUSED__,
80 Evas_Object *o __UNUSED__,
81 void *einfo)
82{
83 Evas_Event_Key_Down *ev = einfo;
84
85 if (strcmp(ev->keyname, "h") == 0) /* print help */
86 {
87 fprintf(stdout, commands);
88 return;
89 }
90
91 if (strcmp(ev->keyname, "s") == 0) /* print proxy image' stride value */
92 {
93 int stride = evas_object_image_stride_get(d.noise_img);
94
95 fprintf(stdout, "Image has row stride value of %d, which accounts"
96 " for %d pixels\n", stride, stride / 4);
97
98 return;
99 }
100
101 if (strcmp(ev->keyname, "p") == 0) /* change proxy's source */
102 {
103 Evas_Object *source = evas_object_image_source_get(d.proxy_img);
104
105 if (source == d.logo) source = d.noise_img;
106 else source = d.logo;
107
108 evas_object_image_source_set(d.proxy_img, source);
109
110 fprintf(stdout, "Proxy image's source changed\n");
111
112 return;
113 }
114
115 if (strcmp(ev->keyname, "a") == 0) /* save noise image to disk */
116 {
117 if (!evas_object_image_save(d.noise_img, file_path, NULL, quality_str))
118 fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
119 file_path, quality_str);
120 else
121 fprintf(stdout, "Image saved to '%s' (flags '%s'), check it out with "
122 "an image viewer\n", file_path, quality_str);
123
124 return;
125 }
126}
127
128int
129main(void)
130{
131 unsigned int i;
132 unsigned int pixels[(WIDTH / 4) * (HEIGHT / 4)];
133
134 srand(time(NULL));
135
136 if (!ecore_evas_init())
137 return EXIT_FAILURE;
138
139 /* this will give you a window with an Evas canvas under the first
140 * engine available */
141 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
142 if (!d.ee)
143 goto error;
144
145 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
146 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
147 ecore_evas_show(d.ee);
148
149 /* the canvas pointer, de facto */
150 d.evas = ecore_evas_get(d.ee);
151
152 d.bg = evas_object_rectangle_add(d.evas);
153 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
154 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
155 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
156 evas_object_show(d.bg);
157
158 evas_object_focus_set(d.bg, EINA_TRUE);
159 evas_object_event_callback_add(
160 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
161
162 d.logo = evas_object_image_filled_add(d.evas);
163
164 evas_object_event_callback_add(
165 d.logo, EVAS_CALLBACK_IMAGE_PRELOADED, _on_preloaded, NULL);
166 evas_object_image_preload(d.logo, EINA_TRUE);
167
168 evas_object_image_file_set(d.logo, img_path, NULL);
169 evas_object_resize(d.logo, WIDTH / 2, HEIGHT / 2);
170 evas_object_show(d.logo);
171
172 /* creating noise image */
173 for (i = 0; i < sizeof(pixels) / sizeof(pixels[0]); i++)
174 pixels[i] = rand();
175
176 d.noise_img = evas_object_image_add(d.evas);
177 evas_object_image_size_set(d.noise_img, WIDTH / 4, HEIGHT / 4);
178 evas_object_image_data_set(d.noise_img, pixels);
179 evas_object_image_filled_set(d.noise_img, EINA_TRUE);
180 evas_object_move(d.noise_img, (WIDTH * 3) / 4, 0);
181 evas_object_resize(d.noise_img, WIDTH / 4, HEIGHT / 4);
182 evas_object_show(d.noise_img);
183 fprintf(stdout, "Creating noise image with size %d, %d\n",
184 WIDTH / 4, HEIGHT / 4);
185
186 d.proxy_img = evas_object_image_filled_add(d.evas);
187 evas_object_image_source_set(d.proxy_img, d.logo);
188 evas_object_move(d.proxy_img, WIDTH / 4, HEIGHT / 2);
189 evas_object_resize(d.proxy_img, WIDTH / 2, HEIGHT / 2);
190 evas_object_show(d.proxy_img);
191
192 fprintf(stdout, commands);
193 ecore_main_loop_begin();
194
195 ecore_evas_free(d.ee);
196 ecore_evas_shutdown();
197 return 0;
198
199error:
200 fprintf(stderr, "you got to have at least one evas engine built and linked"
201 " up to ecore-evas for this example to run properly.\n");
202 ecore_evas_shutdown();
203 return -1;
204}