summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Harrington <bryce@osg.samsung.com>2017-07-11 11:29:07 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-07-11 11:29:07 +0900
commit0e19bde33c902c0765edb38090b383619f00882c (patch)
tree242c7c8a4320517cddc64cbf002dafee4be42569
parenta795629e8c9d7a7f444f8ce655eb9e24dce51429 (diff)
examples: Move introduction to Ecore-Evas to evas-transparent.c
Summary: The evas-transparent.c example is quite short, and so will allow for more detailed explanation of setting up Ecore-Evas. Then evas-object-manipulation.c can focus more on the explanation of objects in Ecore-Evas. Reviewers: cedric Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D5011
-rw-r--r--src/examples/evas/README4
-rw-r--r--src/examples/evas/evas-object-manipulation.c28
-rw-r--r--src/examples/evas/evas-transparent.c77
3 files changed, 80 insertions, 29 deletions
diff --git a/src/examples/evas/README b/src/examples/evas/README
index 8bd00468ae..e32ad1ecd3 100644
--- a/src/examples/evas/README
+++ b/src/examples/evas/README
@@ -10,9 +10,9 @@ points to start from in learning more advanced topics.
10== Basic Evas == 10== Basic Evas ==
11 11
12evas-init-shutdown.c - Introduction to Evas 12evas-init-shutdown.c - Introduction to Evas
13evas-buffer-simple.c - Using the buffer engine 13evas-buffer-simple.c - Using the Evas buffer engine
14evas-transparent.c - Introduction to Ecore-Evas
14evas-object-manipulation.c - Introduction to object manipulation 15evas-object-manipulation.c - Introduction to object manipulation
15evas-transparent.c - Setting alpha transparency on objects
16 16
17 17
18== Event Handling == 18== Event Handling ==
diff --git a/src/examples/evas/evas-object-manipulation.c b/src/examples/evas/evas-object-manipulation.c
index c1735ba941..e5be8c0aaf 100644
--- a/src/examples/evas/evas-object-manipulation.c
+++ b/src/examples/evas/evas-object-manipulation.c
@@ -1,11 +1,8 @@
1/** 1/**
2 * Example of basic object manipulation in Evas. 2 * Example of basic object manipulation in Evas.
3 * 3 *
4 * The evas-buffer-simple.c example shows how to manually create and 4 * This example shows how to manipulate objects within an Ecore-Evas
5 * manage buffers, but mentioned that real code would use higher level 5 * canvas.
6 * functionality from Ecore's Ecore-Evas submodule. This example
7 * shows the use of that submodule to create an Evas canvas and
8 * manipulate the objects within it.
9 * 6 *
10 * Please note that this example uses Evas' legacy API. Compare this 7 * Please note that this example uses Evas' legacy API. Compare this
11 * implementation with evas-object-manipulation-eo.c to learn how the 8 * implementation with evas-object-manipulation-eo.c to learn how the
@@ -28,6 +25,7 @@
28 25
29#include <Ecore.h> 26#include <Ecore.h>
30#include <Ecore_Evas.h> 27#include <Ecore_Evas.h>
28
31#include <stdio.h> 29#include <stdio.h>
32#include <errno.h> 30#include <errno.h>
33#include "evas-common.h" 31#include "evas-common.h"
@@ -167,32 +165,16 @@ main(void)
167{ 165{
168 int err; 166 int err;
169 167
170 /* In other examples, evas_init() has been used to turn Evas on. In this
171 * example we're using Ecore-Evas' init routine, which takes care of
172 * bringing up Evas.
173 */
174 if (!ecore_evas_init()) 168 if (!ecore_evas_init())
175 return EXIT_FAILURE; 169 return EXIT_FAILURE;
176 170
177 /* In the evas-buffer-simple.c example, we coded our own
178 * create_canvas() routine. Here we make use of Ecore-Evas's
179 * ecore_evas_new() routine to do it. The first argument of this
180 * function is used to specify the name of an engine we wish to use;
181 * by passing NULL instead, we are requesting a window with an Evas
182 * canvas using the first engine available.
183 */
184 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL); 171 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
185 if (!d.ee) 172 if (!d.ee)
186 goto error; 173 goto error;
187 174
188 /* Like other windowing systems, Ecore-Evas provides hooks for a
189 * number of different events. We can register our own functions to
190 * be called when the events occur in our window.
191 */
192 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb); 175 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
193 ecore_evas_show(d.ee); 176 ecore_evas_show(d.ee);
194 177
195 /* Retrieve a pointer to the canvas we created. */
196 d.canvas = ecore_evas_get(d.ee); 178 d.canvas = ecore_evas_get(d.ee);
197 179
198 /* Create background. As mentioned earlier, the evas_object_* 180 /* Create background. As mentioned earlier, the evas_object_*
@@ -206,10 +188,6 @@ main(void)
206 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */ 188 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
207 evas_object_show(d.bg); 189 evas_object_show(d.bg);
208 190
209 /* Callbacks can also be set on Evas objects. We'll add a keyboard
210 * handler routine to the background rectangle, for processing user
211 * key hits.
212 */
213 evas_object_focus_set(d.bg, EINA_TRUE); 191 evas_object_focus_set(d.bg, EINA_TRUE);
214 evas_object_event_callback_add( 192 evas_object_event_callback_add(
215 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); 193 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
diff --git a/src/examples/evas/evas-transparent.c b/src/examples/evas/evas-transparent.c
index 4ea74866cf..1d4d67d210 100644
--- a/src/examples/evas/evas-transparent.c
+++ b/src/examples/evas/evas-transparent.c
@@ -1,5 +1,23 @@
1/** 1/**
2 * Example of transparent windows in Evas. 2 * Example of basic usage of Ecore-Evas and transparent windows.
3 *
4 * The evas-buffer-simple.c example shows how to manually create and
5 * manage buffers, but mentioned that real code would use higher level
6 * functionality from Ecore's Ecore-Evas submodule. This example
7 * shows the use of that submodule to create a simple Evas canvas.
8 *
9 * This example also demonstrates how to create transparent windows with
10 * Evas. Like in most other graphics software, transparency and
11 * translucency is calculated using an integer parameter called an
12 * 'alpha channel'. Support for alpha transparency is platform
13 * dependent, and even where it is supported it may not be needed,
14 * so Ecore-Evas provides a simple API to turn it on and off, which
15 * this example will demonstrate by allowing it to be toggled via
16 * the 'n' and 'm' keys on the keyboard.
17 *
18 * The keyboard input will introduce 'event handling' in Ecore-Evas, but
19 * only briefly - we'll be exploring event handling in later examples
20 * more deeply.
3 * 21 *
4 * @verbatim 22 * @verbatim
5 * gcc -o evas-transparent evas-transparent.c `pkg-config --libs --cflags evas ecore ecore-evas eina` 23 * gcc -o evas-transparent evas-transparent.c `pkg-config --libs --cflags evas ecore ecore-evas eina`
@@ -37,6 +55,9 @@ struct exemple_data
37 55
38static struct exemple_data d; 56static struct exemple_data d;
39 57
58/* Keyboard event callback routine, to enable toggling transparency on
59 * and off.
60 */
40static void 61static void
41_on_keydown(void *data EINA_UNUSED, 62_on_keydown(void *data EINA_UNUSED,
42 Evas *evas EINA_UNUSED, 63 Evas *evas EINA_UNUSED,
@@ -45,14 +66,16 @@ _on_keydown(void *data EINA_UNUSED,
45{ 66{
46 Evas_Event_Key_Down *ev = einfo; 67 Evas_Event_Key_Down *ev = einfo;
47 68
48 if (strcmp(ev->key, "h") == 0) /* print help */ 69 if (strcmp(ev->key, "h") == 0)
49 { 70 {
71 /* h - print help */
50 printf("%s", commands); 72 printf("%s", commands);
51 return; 73 return;
52 } 74 }
53 75
54 if (strcmp(ev->key, "n") == 0) 76 if (strcmp(ev->key, "n") == 0)
55 { 77 {
78 /* n - turn alpha transparency on */
56 ecore_evas_alpha_set(d.ee, EINA_TRUE); 79 ecore_evas_alpha_set(d.ee, EINA_TRUE);
57 80
58 printf("turn on alpha\n"); 81 printf("turn on alpha\n");
@@ -61,6 +84,7 @@ _on_keydown(void *data EINA_UNUSED,
61 84
62 if (strcmp(ev->key, "m") == 0) 85 if (strcmp(ev->key, "m") == 0)
63 { 86 {
87 /* m - turn alpha transparency off */
64 ecore_evas_alpha_set(d.ee, EINA_FALSE); 88 ecore_evas_alpha_set(d.ee, EINA_FALSE);
65 89
66 printf("turn off alpha\n"); 90 printf("turn off alpha\n");
@@ -71,32 +95,81 @@ _on_keydown(void *data EINA_UNUSED,
71static void 95static void
72_on_delete(Ecore_Evas *ee EINA_UNUSED) 96_on_delete(Ecore_Evas *ee EINA_UNUSED)
73{ 97{
98 /* Communicate to ecore that the application is finished. Calling
99 * this routine allows any pending events to get processed and allow
100 * the main loop to finish the current iteration.
101 */
74 ecore_main_loop_quit(); 102 ecore_main_loop_quit();
75} 103}
76 104
77int 105int
78main(void) 106main(void)
79{ 107{
108 /* In other examples, evas_init() has been used to turn Evas on. In this
109 * example we're using Ecore-Evas' init routine, which takes care of
110 * bringing up Evas.
111 */
80 if (!ecore_evas_init()) 112 if (!ecore_evas_init())
81 return EXIT_FAILURE; 113 return EXIT_FAILURE;
82 114
115 /* In the evas-buffer-simple.c example, we coded our own
116 * create_canvas() routine. Here we make use of Ecore-Evas's
117 * ecore_evas_new() routine to do it. The first argument of this
118 * function is used to specify the name of an engine we wish to use;
119 * by passing NULL instead, we are requesting a window with an Evas
120 * canvas using the first engine available.
121 *
122 * The next arguments set the canvas's position to 0,0 and its
123 * height and width to our desired size.
124 *
125 * The last parameter for ecore_evas_new() allows setting extra
126 * options, but for this example we don't need anything special
127 * so just pass NULL.
128 */
83 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); 129 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
84 if (!d.ee) 130 if (!d.ee)
85 goto panic; 131 goto panic;
86 132
133 /* Like other windowing systems, Ecore-Evas provides hooks for a
134 * number of different events. We can register our own functions to
135 * be called when the events occur in our window. Here we'll register
136 * a callback to be triggered when the window is closed.
137 */
87 ecore_evas_callback_delete_request_set(d.ee, _on_delete); 138 ecore_evas_callback_delete_request_set(d.ee, _on_delete);
139
140 /* As in evas-buffer-simple.c, we need to explicitly 'unhide' our
141 * Evas objects. But here we'll use the Ecore-Evas API to do this,
142 * as it also manages some of the underlying device state.
143 */
88 ecore_evas_show(d.ee); 144 ecore_evas_show(d.ee);
89 145
146 /* Retrieve a pointer to the canvas we created. */
90 d.evas = ecore_evas_get(d.ee); 147 d.evas = ecore_evas_get(d.ee);
91 148
149 /* Add a black background rectangle */
92 d.bg = evas_object_rectangle_add(d.evas); 150 d.bg = evas_object_rectangle_add(d.evas);
93 evas_object_color_set(d.bg, 0, 0, 0, 0); 151 evas_object_color_set(d.bg, 0, 0, 0, 0);
94 evas_object_show(d.bg); 152 evas_object_show(d.bg);
95 153
154 /* Callbacks can also be set on Evas objects. We'll add a keyboard
155 * handler routine to the background rectangle, for processing user
156 * key hits.
157 */
96 evas_object_focus_set(d.bg, EINA_TRUE); 158 evas_object_focus_set(d.bg, EINA_TRUE);
97 evas_object_event_callback_add(d.bg, EVAS_CALLBACK_KEY_DOWN, 159 evas_object_event_callback_add(d.bg, EVAS_CALLBACK_KEY_DOWN,
98 _on_keydown, NULL); 160 _on_keydown, NULL);
161
162 /* Run the application until ecore_main_loop_quit() gets called by
163 * our _on_delete() handler. While this function is active, it will
164 * repeatedly call ecore_main_loop_iterate() to iterate through
165 * various internal processes, checking for keyboard input, updating
166 * the screen as needed, and so forth.
167 */
99 ecore_main_loop_begin(); 168 ecore_main_loop_begin();
169
170 /* With the application finished, we now direct the Ecore and Evas
171 * libraries to perform final cleanup and terminate the system.
172 */
100 ecore_evas_shutdown(); 173 ecore_evas_shutdown();
101 return 0; 174 return 0;
102 175