diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c')
-rw-r--r-- | libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c | 859 |
1 files changed, 0 insertions, 859 deletions
diff --git a/libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c b/libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c deleted file mode 100644 index 16487ad..0000000 --- a/libraries/ecore/src/lib/ecore_psl1ght/ecore_psl1ght.c +++ /dev/null | |||
@@ -1,859 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <sysutil/video.h> | ||
6 | #include <sysutil/sysutil.h> | ||
7 | #include <sysmodule/sysmodule.h> | ||
8 | #include <io/pad.h> | ||
9 | #include <io/mouse.h> | ||
10 | #include <io/kb.h> | ||
11 | #include <io/camera.h> | ||
12 | #include <io/move.h> | ||
13 | #include <sys/process.h> | ||
14 | |||
15 | #include "moveutil.h" | ||
16 | |||
17 | #include "Eina.h" | ||
18 | #include "Ecore_Psl1ght.h" | ||
19 | #include "Ecore_Input.h" | ||
20 | #include "Ecore.h" | ||
21 | #include "ecore_psl1ght_private.h" | ||
22 | #include "ecore_private.h" | ||
23 | #include "Ecore_Psl1ght_Keys.h" | ||
24 | |||
25 | /* Allocate 1MB stack to avoid overflows */ | ||
26 | SYS_PROCESS_PARAM(1001, 0x100000); | ||
27 | |||
28 | int _ecore_psl1ght_log_dom = -1; | ||
29 | |||
30 | EAPI int ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0; | ||
31 | EAPI int ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0; | ||
32 | EAPI int ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0; | ||
33 | EAPI int ECORE_PSL1GHT_EVENT_EXPOSE = 0; | ||
34 | EAPI int ECORE_PSL1GHT_EVENT_QUIT = 0; | ||
35 | |||
36 | static int _ecore_psl1ght_init_count = 0; | ||
37 | static int window_width = 0; | ||
38 | static int window_height = 0; | ||
39 | /* Mouse support */ | ||
40 | static int mouse_connected = FALSE; | ||
41 | static u8 mouse_buttons = 0; | ||
42 | static int mouse_x = 0; | ||
43 | static int mouse_y = 0; | ||
44 | /* Keyboard support */ | ||
45 | static int keyboard_connected = FALSE; | ||
46 | static KbLed keyboard_leds = {{0}}; | ||
47 | static KbMkey keyboard_mods = {{0}}; | ||
48 | static u16 keyboard_old_key = 0; | ||
49 | /* Pad support */ | ||
50 | static padData pad_data; | ||
51 | static padData old_pad_data = {0}; | ||
52 | static int pad_old_x = 0; | ||
53 | static int pad_old_o = 0; | ||
54 | /* Move support */ | ||
55 | static int move_connected = FALSE; | ||
56 | static moveContext *move_context = NULL; | ||
57 | u16 move_buttons = 0; | ||
58 | |||
59 | static void xmb_event_handler(u64 status, u64 param, void *user_data); | ||
60 | |||
61 | /** | ||
62 | * @defgroup Ecore_Psl1ght_Library_Group PSL1GHT Library Functions | ||
63 | * | ||
64 | * Functions used to set up and shut down the Ecore_Psl1ght functions. | ||
65 | */ | ||
66 | |||
67 | /** | ||
68 | * Sets up the Ecore_Psl1ght library. | ||
69 | * @param name device target name | ||
70 | * @return @c 0 on failure. Otherwise, the number of times the library has | ||
71 | * been initialised without being shut down. | ||
72 | * @ingroup Ecore_PSL1GHT_Library_Group | ||
73 | */ | ||
74 | EAPI int | ||
75 | ecore_psl1ght_init(const char *name __UNUSED__) | ||
76 | { | ||
77 | videoState state; | ||
78 | videoResolution resolution; | ||
79 | int ret, camera_loaded, gem_loaded; | ||
80 | |||
81 | if (++_ecore_psl1ght_init_count != 1) | ||
82 | return _ecore_psl1ght_init_count; | ||
83 | _ecore_psl1ght_log_dom = eina_log_domain_register | ||
84 | ("ecore_psl1ght", ECORE_PSL1GHT_DEFAULT_LOG_COLOR); | ||
85 | if (_ecore_psl1ght_log_dom < 0) | ||
86 | { | ||
87 | EINA_LOG_ERR("Impossible to create a log domain for the Ecore PSL1GHT module."); | ||
88 | return --_ecore_psl1ght_init_count; | ||
89 | } | ||
90 | if (!ecore_event_init()) | ||
91 | { | ||
92 | eina_log_domain_unregister(_ecore_psl1ght_log_dom); | ||
93 | _ecore_psl1ght_log_dom = -1; | ||
94 | return --_ecore_psl1ght_init_count; | ||
95 | } | ||
96 | |||
97 | if (videoGetState (0, 0, &state) == 0 && | ||
98 | videoGetResolution (state.displayMode.resolution, &resolution) == 0) | ||
99 | { | ||
100 | ecore_psl1ght_resolution_set (resolution.width, resolution.height); | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | ecore_event_shutdown(); | ||
105 | eina_log_domain_unregister(_ecore_psl1ght_log_dom); | ||
106 | _ecore_psl1ght_log_dom = -1; | ||
107 | return --_ecore_psl1ght_init_count; | ||
108 | } | ||
109 | |||
110 | /* Pad support */ | ||
111 | ioPadInit (7); | ||
112 | /* Mouse support */ | ||
113 | ioMouseInit(2); | ||
114 | mouse_buttons = 0; | ||
115 | mouse_x = 0; | ||
116 | mouse_y = 0; | ||
117 | |||
118 | /* Keyboard support */ | ||
119 | ioKbInit(2); | ||
120 | keyboard_leds._KbLedU.leds = 0; | ||
121 | keyboard_mods._KbMkeyU.mkeys = 0; | ||
122 | |||
123 | /* Initialize Move */ | ||
124 | move_context = NULL; | ||
125 | move_buttons = 0; | ||
126 | |||
127 | camera_loaded = !sysModuleIsLoaded (SYSMODULE_CAMERA); | ||
128 | if (!camera_loaded) | ||
129 | ret = sysModuleLoad (SYSMODULE_CAMERA); | ||
130 | else | ||
131 | ret = 0; | ||
132 | if (ret == 0) | ||
133 | { | ||
134 | gem_loaded = !sysModuleIsLoaded (SYSMODULE_GEM); | ||
135 | if (!gem_loaded) | ||
136 | ret = sysModuleLoad (SYSMODULE_GEM); | ||
137 | if (ret == 0) | ||
138 | { | ||
139 | move_context = initMove (); | ||
140 | } | ||
141 | else { | ||
142 | if (gem_loaded) | ||
143 | sysModuleUnload (SYSMODULE_CAMERA); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | sysUtilRegisterCallback (SYSUTIL_EVENT_SLOT0, xmb_event_handler, NULL); | ||
148 | |||
149 | ECORE_PSL1GHT_EVENT_GOT_FOCUS = ecore_event_type_new(); | ||
150 | ECORE_PSL1GHT_EVENT_LOST_FOCUS = ecore_event_type_new(); | ||
151 | ECORE_PSL1GHT_EVENT_EXPOSE = ecore_event_type_new(); | ||
152 | ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = ecore_event_type_new(); | ||
153 | ECORE_PSL1GHT_EVENT_QUIT = ecore_event_type_new(); | ||
154 | |||
155 | mouse_x = 0; | ||
156 | mouse_y = 0; | ||
157 | |||
158 | return _ecore_psl1ght_init_count; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * Shuts down the Ecore_Psl1ght library. | ||
163 | * @return @c The number of times the system has been initialised without | ||
164 | * being shut down. | ||
165 | * @ingroup Ecore_PSL1GHT_Library_Group | ||
166 | */ | ||
167 | EAPI int | ||
168 | ecore_psl1ght_shutdown(void) | ||
169 | { | ||
170 | if (--_ecore_psl1ght_init_count != 0) | ||
171 | return _ecore_psl1ght_init_count; | ||
172 | |||
173 | ecore_event_shutdown(); | ||
174 | eina_log_domain_unregister(_ecore_psl1ght_log_dom); | ||
175 | _ecore_psl1ght_log_dom = -1; | ||
176 | |||
177 | ECORE_PSL1GHT_EVENT_GOT_FOCUS = 0; | ||
178 | ECORE_PSL1GHT_EVENT_LOST_FOCUS = 0; | ||
179 | ECORE_PSL1GHT_EVENT_EXPOSE = 0; | ||
180 | ECORE_PSL1GHT_EVENT_KEY_MODIFIERS = 0; | ||
181 | ECORE_PSL1GHT_EVENT_QUIT = 0; | ||
182 | |||
183 | ioPadEnd(); | ||
184 | ioMouseEnd(); | ||
185 | ioKbEnd(); | ||
186 | |||
187 | if (move_context) | ||
188 | { | ||
189 | endMove (move_context); | ||
190 | move_context = NULL; | ||
191 | sysModuleUnload (SYSMODULE_CAMERA); | ||
192 | sysModuleUnload (SYSMODULE_GEM); | ||
193 | } | ||
194 | |||
195 | sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); | ||
196 | |||
197 | return _ecore_psl1ght_init_count; | ||
198 | } | ||
199 | |||
200 | static unsigned int | ||
201 | _ecore_psl1ght_get_time(void) | ||
202 | { | ||
203 | return (unsigned int)((unsigned long long) | ||
204 | (ecore_time_get() * 1000.0) & 0xffffffff); | ||
205 | } | ||
206 | |||
207 | static unsigned int | ||
208 | _ecore_psl1ght_get_modifiers(void) | ||
209 | { | ||
210 | unsigned int modifiers = 0; | ||
211 | |||
212 | if (keyboard_mods._KbMkeyU._KbMkeyS.r_shift || | ||
213 | keyboard_mods._KbMkeyU._KbMkeyS.l_shift) | ||
214 | modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
215 | if (keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl || | ||
216 | keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl) | ||
217 | modifiers |= ECORE_EVENT_MODIFIER_CTRL; | ||
218 | if (keyboard_mods._KbMkeyU._KbMkeyS.r_alt || | ||
219 | keyboard_mods._KbMkeyU._KbMkeyS.l_alt) | ||
220 | modifiers |= ECORE_EVENT_MODIFIER_ALT; | ||
221 | if (keyboard_mods._KbMkeyU._KbMkeyS.r_win || | ||
222 | keyboard_mods._KbMkeyU._KbMkeyS.l_win) | ||
223 | modifiers |= ECORE_EVENT_MODIFIER_WIN; | ||
224 | |||
225 | if (keyboard_leds._KbLedU._KbLedS.num_lock) | ||
226 | modifiers |= ECORE_EVENT_LOCK_NUM; | ||
227 | if (keyboard_leds._KbLedU._KbLedS.caps_lock) | ||
228 | modifiers |= ECORE_EVENT_LOCK_CAPS; | ||
229 | if (keyboard_leds._KbLedU._KbLedS.scroll_lock) | ||
230 | modifiers |= ECORE_EVENT_LOCK_SCROLL; | ||
231 | |||
232 | return modifiers; | ||
233 | } | ||
234 | |||
235 | static void | ||
236 | _ecore_psl1ght_key_modifiers(KbMkey *mods, KbLed *leds) | ||
237 | { | ||
238 | Ecore_Psl1ght_Event_Key_Modifiers *ev; | ||
239 | Eina_Bool emit = EINA_FALSE; | ||
240 | |||
241 | ev = malloc(sizeof(Ecore_Psl1ght_Event_Key_Modifiers)); | ||
242 | if (!ev) return; | ||
243 | |||
244 | if (mods->_KbMkeyU._KbMkeyS.l_shift != | ||
245 | keyboard_mods._KbMkeyU._KbMkeyS.l_shift || | ||
246 | mods->_KbMkeyU._KbMkeyS.r_shift != | ||
247 | keyboard_mods._KbMkeyU._KbMkeyS.r_shift) | ||
248 | { | ||
249 | emit = EINA_TRUE; | ||
250 | ev->shift_changed = EINA_TRUE; | ||
251 | ev->shift = mods->_KbMkeyU._KbMkeyS.r_shift | | ||
252 | mods->_KbMkeyU._KbMkeyS.l_shift; | ||
253 | } | ||
254 | if (mods->_KbMkeyU._KbMkeyS.l_ctrl != | ||
255 | keyboard_mods._KbMkeyU._KbMkeyS.l_ctrl || | ||
256 | mods->_KbMkeyU._KbMkeyS.r_ctrl != | ||
257 | keyboard_mods._KbMkeyU._KbMkeyS.r_ctrl) | ||
258 | { | ||
259 | emit = EINA_TRUE; | ||
260 | ev->ctrl_changed = EINA_TRUE; | ||
261 | ev->ctrl = mods->_KbMkeyU._KbMkeyS.r_ctrl | | ||
262 | mods->_KbMkeyU._KbMkeyS.l_ctrl; | ||
263 | } | ||
264 | if (mods->_KbMkeyU._KbMkeyS.l_alt != | ||
265 | keyboard_mods._KbMkeyU._KbMkeyS.l_alt || | ||
266 | mods->_KbMkeyU._KbMkeyS.r_alt != | ||
267 | keyboard_mods._KbMkeyU._KbMkeyS.r_alt) | ||
268 | { | ||
269 | emit = EINA_TRUE; | ||
270 | ev->alt_changed = EINA_TRUE; | ||
271 | ev->alt = mods->_KbMkeyU._KbMkeyS.r_alt | | ||
272 | mods->_KbMkeyU._KbMkeyS.l_alt; | ||
273 | } | ||
274 | if (mods->_KbMkeyU._KbMkeyS.l_win != | ||
275 | keyboard_mods._KbMkeyU._KbMkeyS.l_win || | ||
276 | mods->_KbMkeyU._KbMkeyS.r_win != | ||
277 | keyboard_mods._KbMkeyU._KbMkeyS.r_win) | ||
278 | { | ||
279 | emit = EINA_TRUE; | ||
280 | ev->win_changed = EINA_TRUE; | ||
281 | ev->win = mods->_KbMkeyU._KbMkeyS.r_win | | ||
282 | mods->_KbMkeyU._KbMkeyS.l_win; | ||
283 | } | ||
284 | keyboard_mods = *mods; | ||
285 | |||
286 | if (leds->_KbLedU._KbLedS.num_lock != | ||
287 | keyboard_leds._KbLedU._KbLedS.num_lock) | ||
288 | { | ||
289 | emit = EINA_TRUE; | ||
290 | ev->num_lock_changed = EINA_TRUE; | ||
291 | ev->num_lock = leds->_KbLedU._KbLedS.num_lock; | ||
292 | } | ||
293 | if (leds->_KbLedU._KbLedS.caps_lock != | ||
294 | keyboard_leds._KbLedU._KbLedS.caps_lock) | ||
295 | { | ||
296 | emit = EINA_TRUE; | ||
297 | ev->caps_lock_changed = EINA_TRUE; | ||
298 | ev->caps_lock = leds->_KbLedU._KbLedS.caps_lock; | ||
299 | } | ||
300 | if (leds->_KbLedU._KbLedS.scroll_lock != | ||
301 | keyboard_leds._KbLedU._KbLedS.scroll_lock) | ||
302 | { | ||
303 | emit = EINA_TRUE; | ||
304 | ev->scroll_lock_changed = EINA_TRUE; | ||
305 | ev->scroll_lock = leds->_KbLedU._KbLedS.scroll_lock; | ||
306 | } | ||
307 | keyboard_leds = *leds; | ||
308 | |||
309 | if (emit) | ||
310 | { | ||
311 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
312 | ev->modifiers = _ecore_psl1ght_get_modifiers(); | ||
313 | ecore_event_add(ECORE_PSL1GHT_EVENT_KEY_MODIFIERS, ev, NULL, NULL); | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | free(ev); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | static void | ||
322 | unicodeToUtf8(u16 w, char *utf8buf) | ||
323 | { | ||
324 | unsigned char *utf8s = (unsigned char *)utf8buf; | ||
325 | |||
326 | if ( w < 0x0080 ) | ||
327 | { | ||
328 | utf8s[0] = ( unsigned char )w; | ||
329 | utf8s[1] = 0; | ||
330 | } | ||
331 | else if ( w < 0x0800 ) | ||
332 | { | ||
333 | utf8s[0] = 0xc0 | ((w) >> 6); | ||
334 | utf8s[1] = 0x80 | ((w) & 0x3f); | ||
335 | utf8s[2] = 0; | ||
336 | } | ||
337 | else { | ||
338 | utf8s[0] = 0xe0 | ((w) >> 12); | ||
339 | utf8s[1] = 0x80 | (((w) >> 6) & 0x3f); | ||
340 | utf8s[2] = 0x80 | ((w) & 0x3f); | ||
341 | utf8s[3] = 0; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | static Ecore_Event_Key * | ||
346 | _ecore_psl1ght_event_key(u16 key) | ||
347 | { | ||
348 | Ecore_Event_Key *ev; | ||
349 | char utf8[4]; | ||
350 | u16 utf16; | ||
351 | unsigned int i; | ||
352 | |||
353 | ev = malloc(sizeof(Ecore_Event_Key)); | ||
354 | if (!ev) return NULL; | ||
355 | |||
356 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
357 | ev->window = 0; | ||
358 | ev->event_window = 0; | ||
359 | ev->modifiers = _ecore_psl1ght_get_modifiers(); | ||
360 | |||
361 | key &= ~KB_KEYPAD; | ||
362 | for (i = 0; i < sizeof(keystable) / sizeof(struct _ecore_psl1ght_keys_s); ++i) | ||
363 | if (keystable[i].code == key) | ||
364 | { | ||
365 | ev->keyname = keystable[i].name; | ||
366 | ev->key = keystable[i].name; | ||
367 | ev->string = keystable[i].compose; | ||
368 | ev->compose = keystable[i].compose; | ||
369 | |||
370 | return ev; | ||
371 | } | ||
372 | |||
373 | utf16 = ioKbCnvRawCode (KB_MAPPING_101, keyboard_mods, keyboard_leds, key); | ||
374 | unicodeToUtf8(utf16, utf8); | ||
375 | ev->keyname = ev->key = ev->string = ev->compose = strdup (utf8); | ||
376 | |||
377 | return ev; | ||
378 | } | ||
379 | |||
380 | static void | ||
381 | _ecore_psl1ght_mouse_move(s32 x_axis, s32 y_axis) | ||
382 | { | ||
383 | Ecore_Event_Mouse_Move *ev; | ||
384 | |||
385 | ev = malloc(sizeof(Ecore_Event_Mouse_Move)); | ||
386 | if (!ev) return; | ||
387 | |||
388 | mouse_x += x_axis; | ||
389 | mouse_y += y_axis; | ||
390 | if (mouse_x < 0) mouse_x = 0; | ||
391 | if (mouse_y < 0) mouse_y = 0; | ||
392 | if (mouse_x > window_width) mouse_x = window_width; | ||
393 | if (mouse_y > window_height) mouse_y = window_height; | ||
394 | |||
395 | ev->window = 0; | ||
396 | ev->root_window = 0; | ||
397 | ev->event_window = 0; | ||
398 | ev->same_screen = 0; | ||
399 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
400 | ev->modifiers = _ecore_psl1ght_get_modifiers (); | ||
401 | ev->x = ev->root.x = mouse_x; | ||
402 | ev->y = ev->root.x = mouse_y; | ||
403 | |||
404 | ev->multi.device = 0; | ||
405 | ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0; | ||
406 | ev->multi.pressure = ev->multi.angle = 0; | ||
407 | ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0; | ||
408 | |||
409 | ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); | ||
410 | } | ||
411 | |||
412 | static void | ||
413 | _ecore_psl1ght_mouse_button(int button, int pressed) | ||
414 | { | ||
415 | Ecore_Event_Mouse_Button *ev; | ||
416 | static unsigned int previous_timestamp = 0; | ||
417 | |||
418 | ev = malloc(sizeof(Ecore_Event_Mouse_Button)); | ||
419 | if (!ev) return; | ||
420 | |||
421 | ev->window = 0; | ||
422 | ev->root_window = 0; | ||
423 | ev->event_window = 0; | ||
424 | ev->same_screen = 0; | ||
425 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
426 | ev->modifiers = _ecore_psl1ght_get_modifiers (); | ||
427 | ev->buttons = button; | ||
428 | if (ev->timestamp - previous_timestamp <= 500) | ||
429 | ev->double_click = 1; | ||
430 | ev->triple_click = 0; | ||
431 | previous_timestamp = ev->timestamp; | ||
432 | |||
433 | ev->x = ev->root.x = mouse_x; | ||
434 | ev->y = ev->root.y = mouse_y; | ||
435 | ev->multi.device = 0; | ||
436 | ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0; | ||
437 | ev->multi.pressure = ev->multi.angle = 0; | ||
438 | ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0; | ||
439 | |||
440 | if (pressed) | ||
441 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); | ||
442 | else | ||
443 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); | ||
444 | } | ||
445 | |||
446 | static void | ||
447 | _ecore_psl1ght_mouse_wheel(s8 wheel, s8 tilt) | ||
448 | { | ||
449 | Ecore_Event_Mouse_Wheel *ev; | ||
450 | |||
451 | ev = malloc(sizeof(Ecore_Event_Mouse_Wheel)); | ||
452 | if (!ev) return; | ||
453 | |||
454 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
455 | ev->window = 0; | ||
456 | ev->event_window = 0; | ||
457 | ev->modifiers = _ecore_psl1ght_get_modifiers (); | ||
458 | ev->direction = 0; | ||
459 | ev->z = wheel; | ||
460 | |||
461 | ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL); | ||
462 | } | ||
463 | |||
464 | static void | ||
465 | _ecore_psl1ght_pad_button (const char *name, int pressed) | ||
466 | { | ||
467 | Ecore_Event_Key *ev = NULL; | ||
468 | |||
469 | ev = malloc(sizeof(Ecore_Event_Key)); | ||
470 | if (!ev) return; | ||
471 | |||
472 | ev->timestamp = _ecore_psl1ght_get_time (); | ||
473 | ev->window = 0; | ||
474 | ev->event_window = 0; | ||
475 | ev->modifiers = 0; | ||
476 | |||
477 | ev->keyname = name; | ||
478 | ev->key = name; | ||
479 | ev->string = ""; | ||
480 | ev->compose = ""; | ||
481 | |||
482 | if (pressed) | ||
483 | ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL); | ||
484 | else | ||
485 | ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL); | ||
486 | } | ||
487 | |||
488 | #define PAD_STICK_DEADZONE 0x20 | ||
489 | |||
490 | static void | ||
491 | _ecore_psl1ght_poll_joypad(void) | ||
492 | { | ||
493 | padInfo padinfo; | ||
494 | int i; | ||
495 | |||
496 | /**/ | ||
497 | /* Check mouse events */ | ||
498 | ioPadGetInfo (&padinfo); | ||
499 | |||
500 | for (i = 0; i < 4; i++) /* Ignore the move */ | ||
501 | { | ||
502 | if (padinfo.status[i]) | ||
503 | { | ||
504 | int analog_h, analog_v; | ||
505 | |||
506 | if (ioPadGetData (i, &pad_data) != 0) | ||
507 | continue; | ||
508 | analog_h = pad_data.ANA_L_H - 0x80; | ||
509 | analog_v = pad_data.ANA_L_V - 0x80; | ||
510 | |||
511 | if (analog_h > PAD_STICK_DEADZONE) | ||
512 | analog_h -= PAD_STICK_DEADZONE; | ||
513 | else if (analog_h < -PAD_STICK_DEADZONE) | ||
514 | analog_h += PAD_STICK_DEADZONE; | ||
515 | else | ||
516 | analog_h = 0; | ||
517 | analog_h /= 10; | ||
518 | |||
519 | if (analog_v > PAD_STICK_DEADZONE) | ||
520 | analog_v -= PAD_STICK_DEADZONE; | ||
521 | else if (analog_v < -PAD_STICK_DEADZONE) | ||
522 | analog_v += PAD_STICK_DEADZONE; | ||
523 | else | ||
524 | analog_v = 0; | ||
525 | analog_v /= 10; | ||
526 | |||
527 | if (analog_h != 0 || analog_v != 0) | ||
528 | _ecore_psl1ght_mouse_move (analog_h, analog_v); | ||
529 | |||
530 | if (old_pad_data.BTN_CROSS ^ pad_data.BTN_CROSS) { | ||
531 | _ecore_psl1ght_pad_button ("Cross", pad_data.BTN_CROSS); | ||
532 | _ecore_psl1ght_mouse_button (1, pad_data.BTN_CROSS); | ||
533 | } | ||
534 | if (old_pad_data.BTN_CIRCLE ^ pad_data.BTN_CIRCLE) { | ||
535 | _ecore_psl1ght_pad_button ("Circle", pad_data.BTN_CIRCLE); | ||
536 | _ecore_psl1ght_mouse_button (3, pad_data.BTN_CIRCLE); | ||
537 | } | ||
538 | if (old_pad_data.BTN_SQUARE ^ pad_data.BTN_SQUARE) | ||
539 | _ecore_psl1ght_pad_button ("Square", pad_data.BTN_SQUARE); | ||
540 | if (old_pad_data.BTN_TRIANGLE ^ pad_data.BTN_TRIANGLE) | ||
541 | _ecore_psl1ght_pad_button ("Triangle", pad_data.BTN_TRIANGLE); | ||
542 | if (old_pad_data.BTN_UP ^ pad_data.BTN_UP) | ||
543 | _ecore_psl1ght_pad_button ("Up", pad_data.BTN_UP); | ||
544 | if (old_pad_data.BTN_DOWN ^ pad_data.BTN_DOWN) | ||
545 | _ecore_psl1ght_pad_button ("Down", pad_data.BTN_DOWN); | ||
546 | if (old_pad_data.BTN_LEFT ^ pad_data.BTN_LEFT) | ||
547 | _ecore_psl1ght_pad_button ("Left", pad_data.BTN_LEFT); | ||
548 | if (old_pad_data.BTN_RIGHT ^ pad_data.BTN_RIGHT) | ||
549 | _ecore_psl1ght_pad_button ("Right", pad_data.BTN_RIGHT); | ||
550 | if (old_pad_data.BTN_L1 ^ pad_data.BTN_L1) | ||
551 | _ecore_psl1ght_pad_button ("L1", pad_data.BTN_L1); | ||
552 | if (old_pad_data.BTN_L2 ^ pad_data.BTN_L2) | ||
553 | _ecore_psl1ght_pad_button ("L2", pad_data.BTN_L2); | ||
554 | if (old_pad_data.BTN_L3 ^ pad_data.BTN_L3) | ||
555 | _ecore_psl1ght_pad_button ("L3", pad_data.BTN_L3); | ||
556 | if (old_pad_data.BTN_R1 ^ pad_data.BTN_R1) | ||
557 | _ecore_psl1ght_pad_button ("R1", pad_data.BTN_R1); | ||
558 | if (old_pad_data.BTN_R2 ^ pad_data.BTN_R2) | ||
559 | _ecore_psl1ght_pad_button ("R2", pad_data.BTN_R2); | ||
560 | if (old_pad_data.BTN_R3 ^ pad_data.BTN_R3) | ||
561 | _ecore_psl1ght_pad_button ("R3", pad_data.BTN_R3); | ||
562 | if (old_pad_data.BTN_START ^ pad_data.BTN_START) | ||
563 | _ecore_psl1ght_pad_button ("Start", pad_data.BTN_START); | ||
564 | if (old_pad_data.BTN_SELECT ^ pad_data.BTN_SELECT) | ||
565 | _ecore_psl1ght_pad_button ("Select", pad_data.BTN_SELECT); | ||
566 | |||
567 | old_pad_data = pad_data; | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | |||
572 | static void | ||
573 | _ecore_psl1ght_poll_mouse(void) | ||
574 | { | ||
575 | mouseInfo mouseinfo; | ||
576 | u32 i; | ||
577 | |||
578 | /**/ | ||
579 | /* Check mouse events */ | ||
580 | ioMouseGetInfo(&mouseinfo); | ||
581 | |||
582 | if (mouseinfo.status[0] == 1 && !mouse_connected) // Connected | ||
583 | { | ||
584 | mouse_connected = TRUE; | ||
585 | mouse_buttons = 0; | ||
586 | |||
587 | // Old events in the queue are discarded | ||
588 | ioMouseClearBuf(0); | ||
589 | } | ||
590 | else if (mouseinfo.status[0] != 1 && mouse_connected) // Disconnected | ||
591 | { | ||
592 | mouse_connected = FALSE; | ||
593 | mouse_buttons = 0; | ||
594 | } | ||
595 | |||
596 | if (mouse_connected) | ||
597 | { | ||
598 | mouseDataList datalist; | ||
599 | |||
600 | ioMouseGetDataList(0, &datalist); | ||
601 | |||
602 | for (i = 0; i < datalist.count; i++) | ||
603 | { | ||
604 | u8 old_left = mouse_buttons & 1; | ||
605 | u8 new_left = datalist.list[i].buttons & 1; | ||
606 | u8 old_right = mouse_buttons & 2; | ||
607 | u8 new_right = datalist.list[i].buttons & 2; | ||
608 | u8 old_middle = mouse_buttons & 4; | ||
609 | u8 new_middle = datalist.list[i].buttons & 4; | ||
610 | |||
611 | if (datalist.list[i].x_axis != 0 || | ||
612 | datalist.list[i].y_axis != 0) | ||
613 | _ecore_psl1ght_mouse_move (datalist.list[i].x_axis, | ||
614 | datalist.list[i].y_axis); | ||
615 | |||
616 | if (old_left != new_left) | ||
617 | _ecore_psl1ght_mouse_button (1, new_left); | ||
618 | if (old_middle != new_middle) | ||
619 | _ecore_psl1ght_mouse_button (2, new_middle); | ||
620 | if (old_right != new_right) | ||
621 | _ecore_psl1ght_mouse_button (3, new_right); | ||
622 | |||
623 | if (datalist.list[i].wheel != 0) | ||
624 | _ecore_psl1ght_mouse_wheel (datalist.list[i].wheel, | ||
625 | datalist.list[i].tilt); | ||
626 | |||
627 | mouse_buttons = datalist.list[i].buttons; | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | |||
632 | static void | ||
633 | _ecore_psl1ght_poll_move(void) | ||
634 | { | ||
635 | int i; | ||
636 | u16 new_buttons; | ||
637 | static int t_pressed = 0; | ||
638 | static int calibrated = 0; | ||
639 | static float prev_x = 0; | ||
640 | static float prev_y = 0; | ||
641 | static int gyro = 0; | ||
642 | float x, y, z; | ||
643 | |||
644 | /* Check move events */ | ||
645 | processMove (move_context); | ||
646 | new_buttons = move_context->state.paddata.buttons & (~move_buttons); | ||
647 | move_buttons = move_context->state.paddata.buttons; | ||
648 | |||
649 | moveGet3DPosition (move_context, &x, &y, &z); | ||
650 | //printf ("Move 3D position is : %f, %f, %f\n", x,y,z); | ||
651 | |||
652 | switch (new_buttons) { | ||
653 | case 1: | ||
654 | gyro = !gyro; | ||
655 | break; | ||
656 | |||
657 | case 4: | ||
658 | // Move button | ||
659 | //printf ("Calibrating\n"); | ||
660 | gemCalibrate (0); | ||
661 | calibrated = 1; | ||
662 | break; | ||
663 | |||
664 | case 8: | ||
665 | // start button | ||
666 | _ecore_psl1ght_mouse_move ((window_width / 2) - mouse_x, (window_height / 2) - mouse_y); | ||
667 | break; | ||
668 | } | ||
669 | |||
670 | if (calibrated) | ||
671 | { | ||
672 | float x_axis, y_axis; | ||
673 | |||
674 | if (gyro) | ||
675 | { | ||
676 | gemInertialState gem_inert; | ||
677 | |||
678 | gemGetInertialState (0, 0, 0, &gem_inert); | ||
679 | x_axis = -vec_array (gem_inert.gyro, 1) * 25; | ||
680 | y_axis = -vec_array (gem_inert.gyro, 0) * 25; | ||
681 | if (abs (x_axis) > 2 || abs (y_axis) > 2) | ||
682 | _ecore_psl1ght_mouse_move (x_axis, y_axis); | ||
683 | } | ||
684 | else { | ||
685 | x_axis = (x - prev_x) * 2.5; | ||
686 | y_axis = -(y - prev_y) * 2.5; | ||
687 | prev_x = x; | ||
688 | prev_y = y; | ||
689 | _ecore_psl1ght_mouse_move (x_axis, y_axis); | ||
690 | } | ||
691 | |||
692 | if (!t_pressed && (move_buttons & 0x2)) | ||
693 | _ecore_psl1ght_mouse_button (1, 1); | ||
694 | else if (t_pressed && (move_buttons & 0x2) == 0) | ||
695 | _ecore_psl1ght_mouse_button (1, 0); | ||
696 | t_pressed = move_buttons & 0x2; | ||
697 | } | ||
698 | } | ||
699 | |||
700 | static void | ||
701 | _ecore_psl1ght_poll_keyboard(void) | ||
702 | { | ||
703 | KbInfo kbInfo; | ||
704 | int i; | ||
705 | |||
706 | /* Check keyboard events */ | ||
707 | ioKbGetInfo(&kbInfo); | ||
708 | |||
709 | if (kbInfo.status[0] == 1 && !keyboard_connected) | ||
710 | { | ||
711 | /* Connected */ | ||
712 | keyboard_connected = true; | ||
713 | |||
714 | // Old events in the queue are discarded | ||
715 | ioKbClearBuf(0); | ||
716 | keyboard_leds._KbLedU.leds = 0; | ||
717 | keyboard_mods._KbMkeyU.mkeys = 0; | ||
718 | keyboard_old_key = 0; | ||
719 | |||
720 | // Set raw keyboard code types to get scan codes | ||
721 | ioKbSetCodeType(0, KB_CODETYPE_RAW); | ||
722 | ioKbSetReadMode(0, KB_RMODE_INPUTCHAR); | ||
723 | } | ||
724 | else if (kbInfo.status[0] != 1 && keyboard_connected) | ||
725 | { | ||
726 | /* Disconnected keyboard */ | ||
727 | keyboard_connected = FALSE; | ||
728 | } | ||
729 | |||
730 | if (keyboard_connected) | ||
731 | { | ||
732 | KbData Keys; | ||
733 | |||
734 | // Read data from the keyboard buffer | ||
735 | if (ioKbRead(0, &Keys) == 0 && Keys.nb_keycode > 0) | ||
736 | { | ||
737 | Ecore_Event_Key *ev = NULL; | ||
738 | |||
739 | _ecore_psl1ght_key_modifiers (&Keys.mkey, &Keys.led); | ||
740 | |||
741 | if (Keys.nb_keycode == 0 && keyboard_old_key != 0) | ||
742 | { | ||
743 | ev = _ecore_psl1ght_event_key (keyboard_old_key); | ||
744 | if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL); | ||
745 | } | ||
746 | for (i = 0; i < Keys.nb_keycode; i++) | ||
747 | { | ||
748 | if (Keys.keycode[i] != keyboard_old_key) | ||
749 | { | ||
750 | if (Keys.keycode[i] != 0) | ||
751 | { | ||
752 | ev = _ecore_psl1ght_event_key (Keys.keycode[i]); | ||
753 | if (ev) | ||
754 | ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, | ||
755 | NULL, NULL); | ||
756 | } | ||
757 | else | ||
758 | { | ||
759 | ev = _ecore_psl1ght_event_key (keyboard_old_key); | ||
760 | if (ev) | ||
761 | ecore_event_add(ECORE_EVENT_KEY_UP, ev, | ||
762 | NULL, NULL); | ||
763 | } | ||
764 | keyboard_old_key = Keys.keycode[0]; | ||
765 | } | ||
766 | } | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | |||
771 | static void | ||
772 | xmb_event_handler(u64 status, u64 param, void *user_data) | ||
773 | { | ||
774 | //printf ("Received event %lX\n", status); | ||
775 | switch (status) { | ||
776 | case SYSUTIL_EXIT_GAME: | ||
777 | ecore_event_add(ECORE_PSL1GHT_EVENT_QUIT, NULL, NULL, NULL); | ||
778 | break; | ||
779 | case SYSUTIL_DRAW_BEGIN: | ||
780 | ecore_event_add(ECORE_PSL1GHT_EVENT_EXPOSE, NULL, NULL, NULL); | ||
781 | case SYSUTIL_MENU_OPEN: | ||
782 | ecore_event_add(ECORE_PSL1GHT_EVENT_LOST_FOCUS, NULL, NULL, NULL); | ||
783 | break; | ||
784 | case SYSUTIL_DRAW_END: | ||
785 | ecore_event_add(ECORE_PSL1GHT_EVENT_EXPOSE, NULL, NULL, NULL); | ||
786 | case SYSUTIL_MENU_CLOSE: | ||
787 | ecore_event_add(ECORE_PSL1GHT_EVENT_GOT_FOCUS, NULL, NULL, NULL); | ||
788 | break; | ||
789 | default: | ||
790 | break; | ||
791 | } | ||
792 | } | ||
793 | |||
794 | EAPI void | ||
795 | ecore_psl1ght_poll_events(void) | ||
796 | { | ||
797 | _ecore_psl1ght_poll_joypad (); | ||
798 | _ecore_psl1ght_poll_mouse (); | ||
799 | if (move_context) | ||
800 | _ecore_psl1ght_poll_move (); | ||
801 | _ecore_psl1ght_poll_keyboard (); | ||
802 | |||
803 | sysUtilCheckCallback (); | ||
804 | } | ||
805 | |||
806 | EAPI void | ||
807 | ecore_psl1ght_resolution_set(int width, int height) | ||
808 | { | ||
809 | window_width = width; | ||
810 | window_height = height; | ||
811 | if (mouse_x > window_width) mouse_x = window_width; | ||
812 | if (mouse_y > window_height) mouse_y = window_height; | ||
813 | } | ||
814 | |||
815 | EAPI void | ||
816 | ecore_psl1ght_screen_resolution_get(int *w, int *h) | ||
817 | { | ||
818 | videoState state; | ||
819 | videoResolution resolution; | ||
820 | |||
821 | /* Get the state of the display */ | ||
822 | if (videoGetState (0, 0, &state) == 0 && | ||
823 | videoGetResolution (state.displayMode.resolution, &resolution) == 0) | ||
824 | { | ||
825 | if (w) *w = resolution.width; | ||
826 | if (h) *h = resolution.height; | ||
827 | } | ||
828 | else { | ||
829 | if (w) *w = 0; | ||
830 | if (h) *h = 0; | ||
831 | } | ||
832 | } | ||
833 | |||
834 | EAPI void | ||
835 | ecore_psl1ght_optimal_screen_resolution_get(int *w, int *h) | ||
836 | { | ||
837 | videoDeviceInfo info; | ||
838 | videoResolution res; | ||
839 | int area = 720 * 480; | ||
840 | int mode_area; | ||
841 | int i; | ||
842 | |||
843 | if (w) *w = 720; | ||
844 | if (h) *h = 480; | ||
845 | |||
846 | videoGetDeviceInfo(0, 0, &info); | ||
847 | |||
848 | for (i = 0; i < info.availableModeCount; i++) { | ||
849 | videoGetResolution (info.availableModes[i].resolution, &res); | ||
850 | mode_area = res.width * res.height; | ||
851 | if (mode_area > area) | ||
852 | { | ||
853 | area = mode_area; | ||
854 | if (w) *w = res.width; | ||
855 | if (h) *h = res.height; | ||
856 | } | ||
857 | } | ||
858 | } | ||
859 | |||