2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 micahjd@users.sourceforge.net
25 #include "SDL_config.h"
28 #include "../../events/SDL_sysevents.h"
29 #include "../../events/SDL_events_c.h"
30 #include "SDL_pgvideo.h"
31 #include "SDL_pgevents_c.h"
33 int PG_HandleClose(struct pgEvent *evt)
36 return 1; /* Intercept the event's normal quit handling */
39 int PG_HandleResize(struct pgEvent *evt)
41 SDL_PrivateResize(evt->e.size.w, evt->e.size.h);
45 int PG_HandleKey(struct pgEvent *evt)
48 SDL_memset(&sym,0,sizeof(sym));
49 sym.sym = evt->e.kbd.key;
50 sym.mod = evt->e.kbd.mods;
51 SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
55 int PG_HandleChar(struct pgEvent *evt)
58 SDL_memset(&sym,0,sizeof(sym));
59 sym.unicode = evt->e.kbd.key;
60 sym.mod = evt->e.kbd.mods;
61 SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
65 int PG_HandleMouseButton(struct pgEvent *evt)
67 /* We need to focus the canvas when it's clicked */
69 SDL_VideoDevice *this = (SDL_VideoDevice *) evt->extra;
70 pgFocus(this->hidden->wCanvas);
72 SDL_PrivateMouseButton(evt->type == PG_WE_PNTR_DOWN, evt->e.pntr.chbtn,
73 evt->e.pntr.x, evt->e.pntr.y);
77 int PG_HandleMouseMotion(struct pgEvent *evt)
79 SDL_PrivateMouseMotion(evt->e.pntr.btn,0,evt->e.pntr.x, evt->e.pntr.y);
83 void PG_PumpEvents(_THIS)
85 /* Process all pending events */
89 void PG_InitOSKeymap(_THIS)
91 /* We need no keymap */
94 void PG_InitEvents(_THIS)
96 /* Turn on all the mouse and keyboard triggers for our canvas, normally less important
97 * events like mouse movement are ignored to save bandwidth. */
98 pgSetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK,
99 pgGetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK) |
100 PG_TRIGGER_UP | PG_TRIGGER_DOWN | PG_TRIGGER_MOVE |
101 PG_TRIGGER_KEYUP | PG_TRIGGER_KEYDOWN | PG_TRIGGER_CHAR,0);
103 /* Start our canvas out focused, so we get keyboard input */
104 pgFocus(this->hidden->wCanvas);
106 /* Set up bindings for all the above event handlers */
107 pgBind(this->hidden->wApp, PG_WE_CLOSE, &PG_HandleClose, NULL);
108 pgBind(this->hidden->wCanvas, PG_WE_BUILD, &PG_HandleResize, NULL);
109 pgBind(this->hidden->wCanvas, PG_WE_KBD_CHAR, &PG_HandleChar, NULL);
110 pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYUP, &PG_HandleKey, NULL);
111 pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYDOWN, &PG_HandleKey, NULL);
112 pgBind(this->hidden->wCanvas, PG_WE_PNTR_MOVE, &PG_HandleMouseMotion, NULL);
113 pgBind(this->hidden->wCanvas, PG_WE_PNTR_UP, &PG_HandleMouseButton, NULL);
114 pgBind(this->hidden->wCanvas, PG_WE_PNTR_DOWN, &PG_HandleMouseButton, this);
117 /* end of SDL_pgevents.c ... */