efl

Форк
0
/
emotion_border_example.c 
246 строк · 6.4 Кб
1
//Compile with:
2
// gcc -o emotion_border_example emotion_border_example.c `pkg-config --libs --cflags emotion evas ecore ecore-evas eina eo`
3
#ifndef EFL_BETA_API_SUPPORT
4
# define EFL_BETA_API_SUPPORT
5
#endif
6

7
#include <Ecore.h>
8
#include <Ecore_Evas.h>
9
#include <Evas.h>
10
#include <Emotion.h>
11
#include <stdio.h>
12
#include <string.h>
13

14
#define WIDTH  (320)
15
#define HEIGHT (240)
16

17
static Eina_List *filenames = NULL;
18
static Eina_List *curfile = NULL;
19

20
static void
21
_playback_started_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
22
{
23
    printf("Emotion object started playback.\n");
24
}
25

26
static Evas_Object *
27
_create_emotion_object(Evas *e)
28
{
29
   Evas_Object *em = emotion_object_add(e);
30

31
   emotion_object_init(em, "gstreamer1");
32

33
   efl_event_callback_add(em, EFL_CANVAS_VIDEO_EVENT_PLAYBACK_START, _playback_started_cb, NULL);
34

35
   return em;
36
}
37

38
static void
39
_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
40
{
41
   Evas_Event_Key_Down *ev = event_info;
42
   Evas_Object *em = data;
43

44
   if (!strcmp(ev->key, "Return"))
45
     {
46
	emotion_object_play_set(em, EINA_TRUE);
47
     }
48
   else if (!strcmp(ev->key, "space"))
49
     {
50
	emotion_object_play_set(em, EINA_FALSE);
51
     }
52
   else if (!strcmp(ev->key, "Escape"))
53
     {
54
	ecore_main_loop_quit();
55
     }
56
   else if (!strcmp(ev->key, "n"))
57
     {
58
	const char *file;
59
	if (!curfile)
60
	  curfile = filenames;
61
	else
62
	  curfile = eina_list_next(curfile);
63
	file = eina_list_data_get(curfile);
64
	fprintf(stderr, "playing next file: %s\n", file);
65
	emotion_object_file_set(em, file);
66
     }
67
   else if (!strcmp(ev->key, "p"))
68
     {
69
	const char *file;
70
	if (!curfile)
71
	  curfile = eina_list_last(filenames);
72
	else
73
	  curfile = eina_list_prev(curfile);
74
	file = eina_list_data_get(curfile);
75
	fprintf(stderr, "playing next file: %s\n", file);
76
	emotion_object_file_set(em, file);
77
     }
78
   else if (!strcmp(ev->key, "b"))
79
     {
80
	emotion_object_border_set(em, 0, 0, 50, 50);
81
     }
82
   else if (!strcmp(ev->key, "0"))
83
     {
84
	emotion_object_keep_aspect_set(em, EMOTION_ASPECT_KEEP_NONE);
85
     }
86
   else if (!strcmp(ev->key, "w"))
87
     {
88
	emotion_object_keep_aspect_set(em, EMOTION_ASPECT_KEEP_WIDTH);
89
     }
90
   else if (!strcmp(ev->key, "h"))
91
     {
92
	emotion_object_keep_aspect_set(em, EMOTION_ASPECT_KEEP_HEIGHT);
93
     }
94
   else if (!strcmp(ev->key, "2"))
95
     {
96
	emotion_object_keep_aspect_set(em, EMOTION_ASPECT_KEEP_BOTH);
97
     }
98
   else if (!strcmp(ev->key, "c"))
99
     {
100
	emotion_object_keep_aspect_set(em, EMOTION_ASPECT_CROP);
101
     }
102
   else
103
     {
104
	fprintf(stderr, "unhandled key: %s\n", ev->key);
105
     }
106
}
107

108
static void
109
_frame_decode_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
110
{
111
   // fprintf(stderr, "smartcb: frame_decode\n");
112
}
113

114
static void
115
_length_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
116
{
117
   fprintf(stderr, "smartcb: length_change: %0.3f\n", emotion_object_play_length_get(ev->object));
118
}
119

120
static void
121
_position_update_cb(void *data EINA_UNUSED, const Efl_Event *ev)
122
{
123
   fprintf(stderr, "smartcb: position_update: %0.3f\n", emotion_object_position_get(ev->object));
124
}
125

126
static void
127
_progress_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
128
{
129
   fprintf(stderr, "smartcb: progress_change: %0.3f, %s\n",
130
	   emotion_object_progress_status_get(ev->object),
131
	   emotion_object_progress_info_get(ev->object));
132
}
133

134
static void
135
_frame_resize_cb(void *data EINA_UNUSED, const Efl_Event *ev)
136
{
137
   int w, h;
138
   emotion_object_size_get(ev->object, &w, &h);
139
   fprintf(stderr, "smartcb: frame_resize: %dx%d\n", w, h);
140
}
141

142
static void /* adjust canvas' contents on resizes */
143
_canvas_resize_cb(Ecore_Evas *ee)
144
{
145
   int w, h;
146
   Evas_Object *bg, *em;
147

148
   ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
149

150
   bg = ecore_evas_data_get(ee, "bg");
151
   em = ecore_evas_data_get(ee, "emotion");
152

153
   evas_object_resize(bg, w, h);
154
   evas_object_move(em, 10, 10);
155
   evas_object_resize(em, w - 20, h - 20);
156
}
157

158
EFL_CALLBACKS_ARRAY_DEFINE(emotion_object_example_callbacks,
159
       { EFL_CANVAS_VIDEO_EVENT_FRAME_DECODE, _frame_decode_cb },
160
       { EFL_CANVAS_VIDEO_EVENT_LENGTH_CHANGE, _length_change_cb },
161
       { EFL_CANVAS_VIDEO_EVENT_POSITION_CHANGE, _position_update_cb },
162
       { EFL_CANVAS_VIDEO_EVENT_PROGRESS_CHANGE, _progress_change_cb },
163
       { EFL_CANVAS_VIDEO_EVENT_FRAME_RESIZE, _frame_resize_cb });
164

165
int
166
main(int argc, const char *argv[])
167
{
168
   Ecore_Evas *ee;
169
   Evas *e;
170
   Evas_Object *bg, *em;
171
   int i;
172

173
   if (argc < 2)
174
     {
175
	printf("One argument is necessary. Usage:\n");
176
	printf("\t%s <filename>\n", argv[0]);
177
     }
178

179
   eina_init();
180
   for (i = 1; i < argc; i++)
181
     filenames = eina_list_append(filenames, eina_stringshare_add(argv[i]));
182

183
   curfile = filenames;
184

185
   if (!ecore_evas_init())
186
     return EXIT_FAILURE;
187

188
   /* this will give you a window with an Evas canvas under the first
189
    * engine available */
190
   ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
191
   if (!ee)
192
     goto error;
193

194
   ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
195

196
   ecore_evas_show(ee);
197

198
   /* the canvas pointer, de facto */
199
   e = ecore_evas_get(ee);
200

201
   /* adding a background to this example */
202
   bg = evas_object_rectangle_add(e);
203
   evas_object_name_set(bg, "our dear rectangle");
204
   evas_object_color_set(bg, 255, 0, 0, 255); /* white bg */
205
   evas_object_move(bg, 0, 0); /* at canvas' origin */
206
   evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
207
   evas_object_show(bg);
208

209
   ecore_evas_data_set(ee, "bg", bg);
210

211
   /* Creating the emotion object */
212
   em = _create_emotion_object(e);
213
   emotion_object_file_set(em, eina_list_data_get(curfile));
214
   evas_object_move(em, 10, 10);
215
   evas_object_resize(em, WIDTH, HEIGHT);
216
   evas_object_resize(em, WIDTH - 20, HEIGHT - 20);
217
   emotion_object_keep_aspect_set(em, EMOTION_ASPECT_KEEP_BOTH);
218
   emotion_object_bg_color_set(em, 0, 128, 0, 255);
219
   evas_object_show(em);
220

221
   ecore_evas_data_set(ee, "emotion", em);
222

223
   efl_event_callback_array_add(em, emotion_object_example_callbacks(), NULL);
224

225
   evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_key_down, em);
226
   evas_object_focus_set(bg, EINA_TRUE);
227

228
   emotion_object_play_set(em, EINA_TRUE);
229

230
   ecore_main_loop_begin();
231

232
   ecore_evas_free(ee);
233
   ecore_evas_shutdown();
234
   return 0;
235

236
error:
237
   fprintf(stderr, "error: Requires at least one Evas engine built and linked"
238
                   " to ecore-evas for this example to run properly.\n");
239

240
   EINA_LIST_FREE(filenames, curfile)
241
      eina_stringshare_del(eina_list_data_get(curfile));
242

243
   ecore_evas_shutdown();
244
   eina_shutdown();
245
   return -1;
246
}
247

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.