3 #include "ecore_private.h"
4 #include "ecore_evas_private.h"
5 #include "Ecore_Evas.h"
6 #ifdef BUILD_ECORE_EVAS_SDL
8 #include "Evas_Engine_SDL.h"
11 #ifdef BUILD_ECORE_EVAS_SDL
13 /* static char *ecore_evas_default_display = "0"; */
14 /* static Ecore_List *ecore_evas_input_devices = NULL; */
16 static int _ecore_evas_init_count = 0;
18 static int _ecore_evas_fps_debug = 0;
20 static Ecore_Evas *ecore_evases = NULL;
21 static Ecore_Event_Handler *ecore_evas_event_handlers[10] = {
22 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
24 static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL;
25 static Ecore_Idler *ecore_evas_event = NULL;
27 static const char *ecore_evas_sdl_default = "EFL SDL";
30 _ecore_evas_mouse_move_process(Ecore_Evas *ee, int x, int y, unsigned int timestamp)
34 if (ee->prop.cursor.object)
36 evas_object_show(ee->prop.cursor.object);
37 evas_object_move(ee->prop.cursor.object,
38 x - ee->prop.cursor.hot.x,
39 y - ee->prop.cursor.hot.y);
41 evas_event_feed_mouse_move(ee->evas, x, y, timestamp, NULL);
45 _ecore_evas_sdl_match(void)
51 _ecore_evas_sdl_event_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
53 Ecore_Sdl_Event_Key_Down *e;
57 ee = _ecore_evas_sdl_match();
61 evas_event_feed_key_down(ee->evas, e->keyname, NULL, e->keycompose, NULL, e->time, NULL);
63 return 0; /* dont pass it on */
67 _ecore_evas_sdl_event_key_up(void *data __UNUSED__, int type __UNUSED__, void *event)
69 Ecore_Sdl_Event_Key_Up *e;
73 ee = _ecore_evas_sdl_match();
77 evas_event_feed_key_up(ee->evas, e->keyname, NULL, e->keycompose, NULL, e->time, NULL);
83 _ecore_evas_sdl_event_mouse_move(void *data __UNUSED__, int type __UNUSED__, void *event)
85 Ecore_Sdl_Event_Mouse_Move *e;
89 ee = _ecore_evas_sdl_match();
91 if (!ee) return 1; /* pass on event */
92 _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
98 _ecore_evas_sdl_event_button_down(void *data __UNUSED__, int type __UNUSED__, void *event)
100 Ecore_Sdl_Event_Mouse_Button_Down *e;
102 Evas_Button_Flags flags;
105 ee = _ecore_evas_sdl_match();
106 flags = EVAS_BUTTON_NONE;
110 _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
111 if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
112 if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
113 evas_event_feed_mouse_down(ee->evas, e->button, flags, e->time, NULL);
119 _ecore_evas_sdl_event_button_up(void *data __UNUSED__, int type __UNUSED__, void *event)
121 Ecore_Sdl_Event_Mouse_Button_Up *e;
123 Evas_Button_Flags flags;
126 ee = _ecore_evas_sdl_match();
127 flags = EVAS_BUTTON_NONE;
131 _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
132 if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
133 if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
134 evas_event_feed_mouse_up(ee->evas, e->button, flags, e->time, NULL);
140 _ecore_evas_sdl_event_mouse_wheel(void *data __UNUSED__, int type __UNUSED__, void *event)
142 Ecore_Sdl_Event_Mouse_Wheel *e;
146 ee = _ecore_evas_sdl_match();
148 if (!ee) return 1; /* pass on event */
149 _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
150 evas_event_feed_mouse_wheel(ee->evas, e->direction, e->wheel, e->time, NULL);
156 _ecore_evas_sdl_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event)
160 ee = _ecore_evas_sdl_match();
164 ee->prop.focused = 1;
170 _ecore_evas_sdl_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event)
174 ee = _ecore_evas_sdl_match();
178 ee->prop.focused = 0;
184 _ecore_evas_sdl_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event)
186 Ecore_Sdl_Event_Video_Resize *e;
190 ee = _ecore_evas_sdl_match();
192 if (!ee) return 1; /* pass on event */
193 evas_output_size_set(ee->evas, e->w, e->h);
199 _ecore_evas_sdl_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
205 ee = _ecore_evas_sdl_match();
208 evas_output_size_get(ee->evas, &w, &h);
209 evas_damage_rectangle_add(ee->evas, 0, 0, w, h);
215 _ecore_evas_idle_enter(void *data __UNUSED__)
222 if (_ecore_evas_fps_debug)
224 t1 = ecore_time_get();
227 for (l = (Ecore_List2 *)ecore_evases; l; l = l->next)
231 ee = (Ecore_Evas *)l;
236 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
238 updates = evas_render_updates(ee->evas);
241 evas_render_updates_free(updates);
242 _ecore_evas_idle_timeout_update(ee);
244 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
247 evas_norender(ee->evas);
250 if (_ecore_evas_fps_debug)
252 t2 = ecore_time_get();
253 _ecore_evas_fps_debug_rendertime_add(t2 - t1);
260 _ecore_evas_sdl_event(void *data)
262 ecore_sdl_feed_events();
268 _ecore_evas_sdl_init(int w, int h)
270 _ecore_evas_init_count++;
271 if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
274 if (getenv("ECORE_EVAS_FPS_DEBUG")) _ecore_evas_fps_debug = 1;
276 ecore_evas_idle_enterer = ecore_idle_enterer_add(_ecore_evas_idle_enter, NULL);
277 ecore_evas_event = ecore_timer_add(0.008, _ecore_evas_sdl_event, NULL);
279 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_init();
282 ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_SDL_EVENT_KEY_DOWN, _ecore_evas_sdl_event_key_down, NULL);
283 ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_SDL_EVENT_KEY_UP, _ecore_evas_sdl_event_key_up, NULL);
284 ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_SDL_EVENT_MOUSE_BUTTON_DOWN, _ecore_evas_sdl_event_button_down, NULL);
285 ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_SDL_EVENT_MOUSE_BUTTON_UP, _ecore_evas_sdl_event_button_up, NULL);
286 ecore_evas_event_handlers[4] = ecore_event_handler_add(ECORE_SDL_EVENT_MOUSE_MOVE, _ecore_evas_sdl_event_mouse_move, NULL);
287 ecore_evas_event_handlers[5] = ecore_event_handler_add(ECORE_SDL_EVENT_MOUSE_WHEEL, _ecore_evas_sdl_event_mouse_wheel, NULL);
288 ecore_evas_event_handlers[6] = ecore_event_handler_add(ECORE_SDL_EVENT_GOT_FOCUS, _ecore_evas_sdl_event_got_focus, NULL);
289 ecore_evas_event_handlers[7] = ecore_event_handler_add(ECORE_SDL_EVENT_LOST_FOCUS, _ecore_evas_sdl_event_lost_focus, NULL);
290 ecore_evas_event_handlers[8] = ecore_event_handler_add(ECORE_SDL_EVENT_RESIZE, _ecore_evas_sdl_event_video_resize, NULL);
291 ecore_evas_event_handlers[9] = ecore_event_handler_add(ECORE_SDL_EVENT_EXPOSE, _ecore_evas_sdl_event_video_expose, NULL);
293 return _ecore_evas_init_count;
297 _ecore_evas_sdl_shutdown(void)
299 _ecore_evas_init_count--;
300 if (_ecore_evas_init_count == 0)
304 while (ecore_evases) _ecore_evas_free(ecore_evases);
305 for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
306 ecore_event_handler_del(ecore_evas_event_handlers[i]);
307 ecore_idle_enterer_del(ecore_evas_idle_enterer);
308 ecore_evas_idle_enterer = NULL;
309 ecore_timer_del(ecore_evas_event);
310 ecore_evas_event = NULL;
312 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_shutdown();
315 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
316 return _ecore_evas_init_count;
320 _ecore_evas_sdl_free(Ecore_Evas *ee)
322 ecore_evases = _ecore_list2_remove(ecore_evases, ee);
323 _ecore_evas_sdl_shutdown();
324 ecore_sdl_shutdown();
328 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
330 if ((w == ee->w) && (h == ee->h)) return;
334 evas_output_size_set(ee->evas, ee->w, ee->h);
335 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
336 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
338 if (ee->func.fn_resize) ee->func.fn_resize(ee);
342 _ecore_evas_move_resize(Ecore_Evas *ee, int x __UNUSED__, int y __UNUSED__, int w, int h)
344 if ((w == ee->w) && (h == ee->h)) return;
348 evas_output_size_set(ee->evas, ee->w, ee->h);
349 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
350 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
352 if (ee->func.fn_resize) ee->func.fn_resize(ee);
356 _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
360 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
364 ee->prop.cursor.object = NULL;
365 ee->prop.cursor.layer = 0;
366 ee->prop.cursor.hot.x = 0;
367 ee->prop.cursor.hot.y = 0;
371 ee->prop.cursor.object = obj;
372 ee->prop.cursor.layer = layer;
373 ee->prop.cursor.hot.x = hot_x;
374 ee->prop.cursor.hot.y = hot_y;
375 evas_pointer_output_xy_get(ee->evas, &x, &y);
376 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
377 evas_object_move(ee->prop.cursor.object,
378 x - ee->prop.cursor.hot.x,
379 y - ee->prop.cursor.hot.y);
380 evas_object_pass_events_set(ee->prop.cursor.object, 1);
381 if (evas_pointer_inside_get(ee->evas))
382 evas_object_show(ee->prop.cursor.object);
385 static const Ecore_Evas_Engine_Func _ecore_sdl_engine_func =
387 _ecore_evas_sdl_free,
405 _ecore_evas_move_resize,
419 _ecore_evas_object_cursor_set,
435 ecore_evas_sdl_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
437 #ifdef BUILD_ECORE_EVAS_SDL
438 Evas_Engine_Info_SDL *einfo;
443 name = ecore_evas_sdl_default;
445 rmethod = evas_render_method_lookup("software_sdl");
446 if (!rmethod) return NULL;
448 if (!ecore_sdl_init(name)) return NULL;
450 ee = calloc(1, sizeof(Ecore_Evas));
451 if (!ee) return NULL;
453 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
455 _ecore_evas_sdl_init(w, h);
457 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func;
460 if (name) ee->name = strdup(name);
471 ee->prop.focused = 1;
472 ee->prop.borderless = 1;
473 ee->prop.override = 1;
474 ee->prop.maximized = 1;
475 ee->prop.fullscreen = fullscreen;
476 ee->prop.withdrawn = 0;
480 ee->evas = evas_new();
481 evas_data_attach_set(ee->evas, ee);
482 evas_output_method_set(ee->evas, rmethod);
484 evas_output_size_set(ee->evas, w, h);
485 evas_output_viewport_set(ee->evas, 0, 0, w, h);
487 einfo = (Evas_Engine_Info_SDL*) evas_engine_info_get(ee->evas);
490 einfo->info.fullscreen = fullscreen;
491 einfo->info.hwsurface = hwsurface;
492 einfo->info.noframe = noframe;
493 einfo->info.alpha = alpha;
494 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
496 evas_key_modifier_add(ee->evas, "Shift");
497 evas_key_modifier_add(ee->evas, "Control");
498 evas_key_modifier_add(ee->evas, "Alt");
499 evas_key_modifier_add(ee->evas, "Meta");
500 evas_key_modifier_add(ee->evas, "Hyper");
501 evas_key_modifier_add(ee->evas, "Super");
502 evas_key_lock_add(ee->evas, "Caps_Lock");
503 evas_key_lock_add(ee->evas, "Num_Lock");
504 evas_key_lock_add(ee->evas, "Scroll_Lock");
506 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
508 ecore_evases = _ecore_list2_prepend(ecore_evases, ee);
511 fprintf(stderr, "OUTCH !\n");