comparison src/video/picogui/SDL_pgevents.c @ 433:706de3956894

Added initial support for PicoGUI (thanks Micah!)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 01 Aug 2002 23:24:13 +0000
parents
children b8d311d90021
comparison
equal deleted inserted replaced
432:80a35d43a58f 433:706de3956894
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 Micah Dowty
23 micahjd@users.sourceforge.net
24 */
25
26 #ifdef SAVE_RCSID
27 static char rcsid =
28 "@(#) $Id$";
29 #endif
30
31 #include "SDL.h"
32 #include "SDL_sysevents.h"
33 #include "SDL_events_c.h"
34 #include "SDL_pgvideo.h"
35 #include "SDL_pgevents_c.h"
36
37 int PG_HandleClose(struct pgEvent *evt)
38 {
39 SDL_PrivateQuit();
40 return 1; /* Intercept the event's normal quit handling */
41 }
42
43 int PG_HandleResize(struct pgEvent *evt)
44 {
45 SDL_PrivateResize(evt->e.size.w, evt->e.size.h);
46 return 0;
47 }
48
49 int PG_HandleKey(struct pgEvent *evt)
50 {
51 SDL_keysym sym;
52 memset(&sym,0,sizeof(sym));
53 sym.sym = evt->e.kbd.key;
54 sym.mod = evt->e.kbd.mods;
55 SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
56 return 0;
57 }
58
59 int PG_HandleChar(struct pgEvent *evt)
60 {
61 SDL_keysym sym;
62 memset(&sym,0,sizeof(sym));
63 sym.unicode = evt->e.kbd.key;
64 sym.mod = evt->e.kbd.mods;
65 SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
66 return 0;
67 }
68
69 int PG_HandleMouseButton(struct pgEvent *evt)
70 {
71 /* We need to focus the canvas when it's clicked */
72 if (evt->extra) {
73 SDL_VideoDevice *this = (SDL_VideoDevice *) evt->extra;
74 pgFocus(this->hidden->wCanvas);
75 }
76 SDL_PrivateMouseButton(evt->type == PG_WE_PNTR_DOWN, evt->e.pntr.chbtn,
77 evt->e.pntr.x, evt->e.pntr.y);
78 return 0;
79 }
80
81 int PG_HandleMouseMotion(struct pgEvent *evt)
82 {
83 SDL_PrivateMouseMotion(evt->e.pntr.btn,0,evt->e.pntr.x, evt->e.pntr.y);
84 return 0;
85 }
86
87 void PG_PumpEvents(_THIS)
88 {
89 /* Process all pending events */
90 pgEventPoll();
91 }
92
93 void PG_InitOSKeymap(_THIS)
94 {
95 /* We need no keymap */
96 }
97
98 void PG_InitEvents(_THIS)
99 {
100 /* Turn on all the mouse and keyboard triggers for our canvas, normally less important
101 * events like mouse movement are ignored to save bandwidth. */
102 pgSetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK,
103 pgGetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK) |
104 PG_TRIGGER_UP | PG_TRIGGER_DOWN | PG_TRIGGER_MOVE |
105 PG_TRIGGER_KEYUP | PG_TRIGGER_KEYDOWN | PG_TRIGGER_CHAR,0);
106
107 /* Start our canvas out focused, so we get keyboard input */
108 pgFocus(this->hidden->wCanvas);
109
110 /* Set up bindings for all the above event handlers */
111 pgBind(this->hidden->wApp, PG_WE_CLOSE, &PG_HandleClose, NULL);
112 pgBind(this->hidden->wCanvas, PG_WE_BUILD, &PG_HandleResize, NULL);
113 pgBind(this->hidden->wCanvas, PG_WE_KBD_CHAR, &PG_HandleChar, NULL);
114 pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYUP, &PG_HandleKey, NULL);
115 pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYDOWN, &PG_HandleKey, NULL);
116 pgBind(this->hidden->wCanvas, PG_WE_PNTR_MOVE, &PG_HandleMouseMotion, NULL);
117 pgBind(this->hidden->wCanvas, PG_WE_PNTR_UP, &PG_HandleMouseButton, NULL);
118 pgBind(this->hidden->wCanvas, PG_WE_PNTR_DOWN, &PG_HandleMouseButton, this);
119 }
120
121 /* end of SDL_pgevents.c ... */