| 1 | /* |
| 2 | SDL - Simple DirectMedia Layer |
| 3 | Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public |
| 16 | License along with this library; if not, write to the Free |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | Sam Lantinga |
| 20 | slouken@libsdl.org |
| 21 | */ |
| 22 | |
| 23 | #ifdef SAVE_RCSID |
| 24 | static char rcsid = |
| 25 | "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $"; |
| 26 | #endif |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | |
| 30 | #include <caca.h> |
| 31 | #ifdef CACA_API_VERSION_1 |
| 32 | #include <caca0.h> |
| 33 | #endif |
| 34 | |
| 35 | #include "SDL.h" |
| 36 | #include "../../events/SDL_sysevents.h" |
| 37 | #include "../../events/SDL_events_c.h" |
| 38 | #include "SDL_cacavideo.h" |
| 39 | #include "SDL_cacaevents_c.h" |
| 40 | |
| 41 | void Caca_PumpEvents(_THIS) |
| 42 | { |
| 43 | int posted = 0; |
| 44 | int event; |
| 45 | SDL_keysym keysym; |
| 46 | |
| 47 | if( ! this->screen ) /* Wait till we got the screen initialised */ |
| 48 | return; |
| 49 | |
| 50 | do { |
| 51 | posted = 0; |
| 52 | |
| 53 | /* Get libcaca event */ |
| 54 | SDL_mutexP(Caca_mutex); |
| 55 | event = caca_get_event(CACA_EVENT_ANY); |
| 56 | SDL_mutexV(Caca_mutex); |
| 57 | |
| 58 | if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) { |
| 59 | int key; |
| 60 | switch ( event & 0xffffff ) |
| 61 | { |
| 62 | case CACA_KEY_LEFT: key = SDLK_LEFT; break; |
| 63 | case CACA_KEY_RIGHT: key = SDLK_RIGHT; break; |
| 64 | case CACA_KEY_UP: key = SDLK_UP; break; |
| 65 | case CACA_KEY_DOWN: key = SDLK_DOWN; break; |
| 66 | default: key = event & 0xff; break; |
| 67 | } |
| 68 | /* Key pressed */ |
| 69 | /* printf("Key pressed: %d (%c)\n", key, key); */ |
| 70 | keysym.scancode = key; |
| 71 | keysym.sym = key; |
| 72 | keysym.mod = KMOD_NONE; |
| 73 | keysym.unicode = 0; |
| 74 | if ( SDL_TranslateUNICODE ) { |
| 75 | keysym.unicode = key; |
| 76 | } |
| 77 | posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym); |
| 78 | } |
| 79 | else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) { |
| 80 | /* FIXME: we currently ignore the button type! */ |
| 81 | int button = event & 0x00ffffff; |
| 82 | if ( button > 3 ) { |
| 83 | button = 1; |
| 84 | } |
| 85 | posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0); |
| 86 | } |
| 87 | else if ( event & CACA_EVENT_MOUSE_MOTION ) { |
| 88 | int new_x = 0, new_y = 0; |
| 89 | new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width(); |
| 90 | new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height(); |
| 91 | posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y); |
| 92 | } |
| 93 | } while ( posted ); |
| 94 | } |
| 95 | |
| 96 | void Caca_InitOSKeymap(_THIS) |
| 97 | { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | |