summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-07 11:24:21 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-20 09:58:24 +0100
commitfa93893548858b83055e95c9e334f3d5875958be (patch)
tree36685a87de79e8d573dd9ec7aba5ceaca710dbfb /src/examples
parent9bb2df996642f046f79466cff8fefcd43d28921e (diff)
introduce efl_canvas_object_animation
this brings the animation to the canvas object. All the controls of the animation now do now require a player object anymore, you can just use the API that is directly on the Efl.Canvas.Object object. wip animation player replacement Differential Revision: https://phab.enlightenment.org/D10615
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/efl-canvas-animation.c179
-rw-r--r--src/examples/evas/meson.build1
2 files changed, 180 insertions, 0 deletions
diff --git a/src/examples/evas/efl-canvas-animation.c b/src/examples/evas/efl-canvas-animation.c
new file mode 100644
index 0000000000..2cc2355956
--- /dev/null
+++ b/src/examples/evas/efl-canvas-animation.c
@@ -0,0 +1,179 @@
1/**
2 * Example of animation in efl canvas
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one). See stdout/stderr for output.
6 *
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include <Ecore.h>
14#include <Ecore_Evas.h>
15
16#include <stdlib.h>
17#include <stdio.h>
18#include <string.h>
19
20#define WIDTH (640)
21#define HEIGHT (480)
22
23struct example_data
24{
25 Ecore_Evas *ee;
26 Evas *evas;
27 Evas_Object *bg, *scale;
28 double current_speed;
29};
30
31static struct example_data d;
32
33static Evas_Object * /* new rectangle to be put in the box */
34_new_rectangle_add(Evas *e)
35{
36 Efl_Canvas_Rectangle *rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, e);
37
38 efl_gfx_entity_size_set(rect, EINA_SIZE2D(10, 10));
39 efl_gfx_color_set(rect, 0, 255, 0, 255);
40 efl_gfx_entity_visible_set(rect, EINA_TRUE);
41
42 return rect;
43}
44
45/* use the following commands to interact with this example - 'h' is
46 * the key for help */
47static void
48_on_keydown(void *data EINA_UNUSED, const Efl_Event *ev)
49{
50 if (strcmp(efl_input_key_sym_get(ev->info) , "r") == 0)
51 {
52 Efl_Canvas_Animation *animation = efl_canvas_object_animation_get(d.scale);
53 double current_pos = efl_canvas_object_animation_progress_get(d.scale);
54 d.current_speed *= -1;
55 efl_canvas_object_animation_start(d.scale, animation, d.current_speed, 1.0 - current_pos);
56 }
57 if (strcmp(efl_input_key_sym_get(ev->info), "p") == 0)
58 {
59 efl_canvas_object_animation_pause_set(d.scale, !efl_canvas_object_animation_pause_get(d.scale));
60 }
61}
62
63static void
64_on_delete(Ecore_Evas *ee EINA_UNUSED)
65{
66 ecore_main_loop_quit();
67}
68
69static void /* adjust canvas' contents on resizes */
70_canvas_resize_cb(Ecore_Evas *ee)
71{
72 int w, h;
73
74 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
75
76 efl_gfx_entity_geometry_set(d.bg, EINA_RECT(0, 0, w, h));
77}
78
79static void
80print_help(void)
81{
82 printf("evas-animation example\n Press r to reverse the animation of the red rect.\n Press p to pause the animation of the red rect.\n");
83}
84
85int
86main(void)
87{
88 if (!ecore_evas_init())
89 return EXIT_FAILURE;
90
91 /* this will give you a window with an Evas canvas under the first
92 * engine available */
93 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
94 if (!d.ee)
95 goto panic;
96
97 print_help();
98
99 ecore_evas_name_class_set(d.ee, "Evas Animation example", "Evas Animation Example");
100 ecore_evas_callback_delete_request_set(d.ee, _on_delete);
101 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
102 ecore_evas_show(d.ee);
103
104 d.evas = ecore_evas_get(d.ee);
105
106 d.bg = _new_rectangle_add(d.evas);
107 efl_gfx_color_set(d.bg, 255, 255, 255, 255);
108 efl_gfx_entity_visible_set(d.bg, EINA_TRUE);
109 efl_canvas_object_key_focus_set(d.bg, EINA_TRUE);
110 efl_event_callback_add(d.bg, EFL_EVENT_KEY_DOWN, _on_keydown, NULL);
111
112 _canvas_resize_cb(d.ee);
113
114 Evas_Object *scale_rect = _new_rectangle_add(d.evas);
115 efl_gfx_entity_geometry_set(scale_rect, EINA_RECT(50, 50, 50, 50));
116 efl_canvas_object_animation_start(scale_rect,
117 efl_new(EFL_CANVAS_ANIMATION_SCALE_CLASS,
118 efl_animation_scale_set(efl_added, EINA_VECTOR2(1.0, 1.0), EINA_VECTOR2(3.0, 3.0), scale_rect, EINA_VECTOR2(0.5, 0.5)),
119 efl_animation_start_delay_set(efl_added, 5.0),
120 efl_animation_duration_set(efl_added, 2.0),
121 efl_animation_repeat_count_set(efl_added, EFL_ANIMATION_REPEAT_INFINITE)
122 ),
123 1.0, 0.0);
124
125 Evas_Object *scale_rect2 = _new_rectangle_add(d.evas);
126 efl_gfx_entity_geometry_set(scale_rect2, EINA_RECT(50, 200, 50, 50));
127 efl_canvas_object_animation_start(scale_rect2,
128 efl_new(EFL_CANVAS_ANIMATION_SCALE_CLASS,
129 efl_animation_scale_set(efl_added, EINA_VECTOR2(1.0, 1.0), EINA_VECTOR2(3.0, 3.0), scale_rect2, EINA_VECTOR2(0.5, 0.5)),
130 efl_animation_duration_set(efl_added, 2.0),
131 efl_animation_repeat_count_set(efl_added, EFL_ANIMATION_REPEAT_INFINITE),
132 efl_animation_repeat_mode_set(efl_added, EFL_CANVAS_ANIMATION_REPEAT_MODE_REVERSE)
133 ),
134 1.0, 0.0);
135
136 Evas_Object *scale_rect3 = _new_rectangle_add(d.evas);
137 efl_gfx_entity_geometry_set(scale_rect3, EINA_RECT(50, 350, 50, 50));
138 efl_canvas_object_animation_start(scale_rect3,
139 efl_new(EFL_CANVAS_ANIMATION_SCALE_CLASS,
140 efl_animation_scale_set(efl_added, EINA_VECTOR2(1.0, 1.0), EINA_VECTOR2(3.0, 3.0), scale_rect3, EINA_VECTOR2(0.5, 0.5)),
141 efl_animation_duration_set(efl_added, 2.0),
142 efl_animation_repeat_count_set(efl_added, 3),
143 efl_animation_repeat_mode_set(efl_added, EFL_CANVAS_ANIMATION_REPEAT_MODE_REVERSE)
144 ),
145 1.0, 0.0);
146
147 Evas_Object *scale_rect4 = _new_rectangle_add(d.evas);
148 efl_gfx_entity_geometry_set(scale_rect4, EINA_RECT(200, 50, 50, 50));
149 efl_canvas_object_animation_start(scale_rect4,
150 efl_new(EFL_CANVAS_ANIMATION_SCALE_CLASS,
151 efl_animation_scale_set(efl_added, EINA_VECTOR2(1.0, 1.0), EINA_VECTOR2(3.0, 3.0), scale_rect4, EINA_VECTOR2(0.5, 0.5)),
152 efl_animation_duration_set(efl_added, 2.0),
153 efl_animation_final_state_keep_set(efl_added, EINA_TRUE)
154 ),
155 1.0, 0.0);
156
157
158 Evas_Object *scale_rect5 = d.scale = _new_rectangle_add(d.evas);
159 efl_gfx_color_set(scale_rect5, 255, 0, 0, 255);
160 efl_gfx_entity_geometry_set(scale_rect5, EINA_RECT(200, 200, 50, 50));
161 efl_canvas_object_animation_start(scale_rect5,
162 efl_new(EFL_CANVAS_ANIMATION_SCALE_CLASS,
163 efl_animation_scale_set(efl_added, EINA_VECTOR2(1.0, 1.0), EINA_VECTOR2(5.0, 5.0), scale_rect5, EINA_VECTOR2(0.5, 0.5)),
164 efl_animation_duration_set(efl_added, 5.0),
165 efl_animation_repeat_count_set(efl_added, EFL_ANIMATION_REPEAT_INFINITE)
166 ),
167 1.0, 0.0);
168 d.current_speed = 1.0;
169
170 ecore_main_loop_begin();
171 ecore_evas_shutdown();
172 return 0;
173
174panic:
175 fprintf(stderr, "error: Requires at least one Evas engine built and linked"
176 " to ecore-evas for this example to run properly.\n");
177 return -2;
178}
179
diff --git a/src/examples/evas/meson.build b/src/examples/evas/meson.build
index 659f9a525e..93539e73b3 100644
--- a/src/examples/evas/meson.build
+++ b/src/examples/evas/meson.build
@@ -50,6 +50,7 @@ examples = [
50 'evas-vg-batman', 50 'evas-vg-batman',
51 'evas-vg-simple', 51 'evas-vg-simple',
52 'evas-vg-json', 52 'evas-vg-json',
53 'efl-canvas-animation',
53] 54]
54 55
55foreach example : examples 56foreach example : examples