Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_photon_input.c @ 3566:07c8339c95c6
Fixed bug #905
Give the foreign window message proc more control over Windows events.
This may need to be adjusted when we add the capability for the app to specify whether it wants SDL to handle input for the window or not.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 15 Dec 2009 09:20:10 +0000 |
parents | 4b594623401b |
children | 64ce267332c6 |
rev | line source |
---|---|
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
1 /* |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
4 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
9 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
14 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
18 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
19 Sam Lantinga |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
20 slouken@libsdl.org |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
21 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
22 QNX Photon GUI SDL driver |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
23 Copyright (C) 2009 Mike Gorchak |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
24 (mike@malva.ua, lestat@i.com.ua) |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
25 */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
26 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
27 #include "SDL_photon_input.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
28 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
29 #include "SDL_config.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
30 #include "SDL_events.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
31 #include "../../events/SDL_mouse_c.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
32 #include "../../events/SDL_keyboard_c.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
33 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
34 #include "SDL_photon_keycodes.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
35 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
36 /* Mouse related functions */ |
3139 | 37 SDL_Cursor *photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y); |
38 int photon_showcursor(SDL_Cursor * cursor); | |
39 void photon_movecursor(SDL_Cursor * cursor); | |
40 void photon_freecursor(SDL_Cursor * cursor); | |
41 void photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y); | |
42 void photon_freemouse(SDL_Mouse * mouse); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
43 |
3139 | 44 int32_t |
45 photon_addinputdevices(_THIS) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
46 { |
3139 | 47 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
48 SDL_DisplayData *didata = NULL; | |
49 struct SDL_Mouse photon_mouse; | |
50 SDL_MouseData *mdata = NULL; | |
51 SDL_Keyboard photon_keyboard; | |
52 SDLKey keymap[SDL_NUM_SCANCODES]; | |
53 uint32_t it; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
54 |
3139 | 55 for (it = 0; it < _this->num_displays; it++) { |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
3419
diff
changeset
|
56 SDL_VideoDisplay *display = &_this->displays[it]; |
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
3419
diff
changeset
|
57 |
3139 | 58 /* Clear SDL mouse structure */ |
59 SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse)); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
60 |
3139 | 61 /* Allocate SDL_MouseData structure */ |
62 mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData)); | |
63 if (mdata == NULL) { | |
64 SDL_OutOfMemory(); | |
65 return -1; | |
66 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
67 |
3139 | 68 /* Mark this mouse with ID 0 */ |
69 photon_mouse.id = it; | |
70 photon_mouse.driverdata = (void *) mdata; | |
71 photon_mouse.CreateCursor = photon_createcursor; | |
72 photon_mouse.ShowCursor = photon_showcursor; | |
73 photon_mouse.MoveCursor = photon_movecursor; | |
74 photon_mouse.FreeCursor = photon_freecursor; | |
75 photon_mouse.WarpMouse = photon_warpmouse; | |
76 photon_mouse.FreeMouse = photon_freemouse; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
77 |
3139 | 78 /* Get display data */ |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
3419
diff
changeset
|
79 didata = (SDL_DisplayData *) display->driverdata; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
80 |
3139 | 81 /* Store SDL_DisplayData pointer in the mouse driver internals */ |
82 mdata->didata = didata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
83 |
3139 | 84 /* Register mouse cursor in SDL */ |
85 SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1); | |
86 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
87 |
3139 | 88 /* Photon maps all keyboards to one */ |
89 SDL_zero(photon_keyboard); | |
90 SDL_AddKeyboard(&photon_keyboard, -1); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
91 |
3139 | 92 /* Add default scancode to key mapping */ |
93 SDL_GetDefaultKeymap(keymap); | |
94 SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
95 |
3139 | 96 return 0; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
97 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
98 |
3139 | 99 int32_t |
100 photon_delinputdevices(_THIS) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
101 { |
3139 | 102 /* Destroy all of the mice */ |
103 SDL_MouseQuit(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
104 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
105 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
106 /*****************************************************************************/ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
107 /* Photon mouse related functions */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
108 /*****************************************************************************/ |
3139 | 109 SDL_Cursor * |
110 photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
111 { |
3139 | 112 PhCursorDef_t *internal_cursor; |
113 SDL_Cursor *sdl_cursor; | |
114 uint8_t *image0 = NULL; | |
115 uint8_t *image1 = NULL; | |
116 uint32_t it; | |
117 uint32_t jt; | |
118 uint32_t shape_color; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
119 |
3139 | 120 /* SDL converts monochrome cursor shape to 32bpp cursor shape */ |
121 /* and we must convert it back to monochrome, this routine handles */ | |
122 /* 24/32bpp surfaces only */ | |
123 if ((surface->format->BitsPerPixel != 32) | |
124 && (surface->format->BitsPerPixel != 24)) { | |
125 SDL_SetError("Photon: Cursor shape is not 24/32bpp."); | |
126 return NULL; | |
127 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
128 |
3139 | 129 /* Checking data parameters */ |
130 if ((surface->w == 0) || (surface->h == 0)) { | |
131 SDL_SetError("Photon: Cursor shape dimensions are zero"); | |
132 return NULL; | |
133 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
134 |
3139 | 135 /* Allocate memory for the internal cursor format */ |
136 internal_cursor = (PhCursorDef_t *) SDL_calloc(1, sizeof(PhCursorDef_t) + | |
137 ((((surface->w + | |
138 7) >> 3) * | |
139 surface->h) * 2) - 1); | |
140 if (internal_cursor == NULL) { | |
141 SDL_OutOfMemory(); | |
142 return NULL; | |
143 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
144 |
3139 | 145 /* Allocate memory for the SDL cursor */ |
146 sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor)); | |
147 if (sdl_cursor == NULL) { | |
148 SDL_free(internal_cursor); | |
149 SDL_OutOfMemory(); | |
150 return NULL; | |
151 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
152 |
3139 | 153 /* Set driverdata as photon cursor format */ |
154 image0 = (uint8_t *) internal_cursor; | |
155 image0 += sizeof(PhCursorDef_t) - 1; | |
156 image1 = image0; | |
157 image1 += ((surface->w + 7) >> 3) * surface->h; | |
158 sdl_cursor->driverdata = (void *) internal_cursor; | |
159 internal_cursor->hdr.len = | |
160 (sizeof(PhCursorDef_t) - sizeof(PhRegionDataHdr_t)) + | |
161 ((((surface->w + 7) >> 3) * surface->h) * 2) - 1; | |
162 internal_cursor->hdr.type = Ph_RDATA_CURSOR; | |
163 internal_cursor->size1.x = surface->w; | |
164 internal_cursor->size1.y = surface->h; | |
165 internal_cursor->size2.x = surface->w; | |
166 internal_cursor->size2.y = surface->h; | |
3419 | 167 internal_cursor->offset1.x = -hot_x; |
168 internal_cursor->offset1.y = -hot_y; | |
169 internal_cursor->offset2.x = -hot_x; | |
170 internal_cursor->offset2.y = -hot_y; | |
3139 | 171 internal_cursor->bytesperline1 = ((surface->w + 7) >> 3); |
172 internal_cursor->bytesperline2 = ((surface->w + 7) >> 3); | |
173 internal_cursor->color1 = (SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF; | |
174 internal_cursor->color2 = (SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
175 |
3139 | 176 /* Convert cursor from 32 bpp */ |
177 for (jt = 0; jt < surface->h; jt++) { | |
178 for (it = 0; it < surface->w; it++) { | |
179 shape_color = | |
180 *((uint32_t *) ((uint8_t *) surface->pixels + | |
181 jt * surface->pitch + | |
182 it * surface->format->BytesPerPixel)); | |
183 switch (shape_color) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
184 case SDL_PHOTON_MOUSE_COLOR_BLACK: |
3139 | 185 { |
186 *(image0 + jt * (internal_cursor->bytesperline1) + | |
187 (it >> 3)) |= 0x80 >> (it % 8); | |
188 *(image1 + jt * (internal_cursor->bytesperline2) + | |
189 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
190 } | |
191 break; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
192 case SDL_PHOTON_MOUSE_COLOR_WHITE: |
3139 | 193 { |
194 *(image0 + jt * (internal_cursor->bytesperline1) + | |
195 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
196 *(image1 + jt * (internal_cursor->bytesperline2) + | |
197 (it >> 3)) |= 0x80 >> (it % 8); | |
198 } | |
199 break; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
200 case SDL_PHOTON_MOUSE_COLOR_TRANS: |
3139 | 201 { |
202 *(image0 + jt * (internal_cursor->bytesperline1) + | |
203 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
204 *(image1 + jt * (internal_cursor->bytesperline2) + | |
205 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
206 } | |
207 break; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
208 default: |
3139 | 209 { |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
210 /* The same as transparent color, must not happen */ |
3139 | 211 *(image0 + jt * (internal_cursor->bytesperline1) + |
212 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
213 *(image1 + jt * (internal_cursor->bytesperline2) + | |
214 (it >> 3)) &= ~(0x80 >> (it % 8)); | |
215 } | |
216 break; | |
217 } | |
218 } | |
219 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
220 |
3139 | 221 return sdl_cursor; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
222 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
223 |
3139 | 224 int |
225 photon_showcursor(SDL_Cursor * cursor) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
226 { |
3139 | 227 SDL_VideoDisplay *display; |
228 SDL_DisplayData *didata; | |
229 SDL_Window *window; | |
230 SDL_WindowData *wdata; | |
231 SDL_WindowID window_id; | |
232 PhCursorDef_t *internal_cursor; | |
233 int32_t status; | |
234 | |
235 /* Get current window id */ | |
236 window_id = SDL_GetFocusWindow(); | |
237 if (window_id <= 0) { | |
238 SDL_MouseData *mdata = NULL; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
239 |
3139 | 240 /* If there is no current window, then someone calls this function */ |
241 /* to set global mouse settings during SDL initialization */ | |
242 if (cursor != NULL) { | |
243 /* Store cursor for future usage */ | |
244 mdata = (SDL_MouseData *) cursor->mouse->driverdata; | |
245 didata = (SDL_DisplayData *) mdata->didata; | |
246 internal_cursor = (PhCursorDef_t *) cursor->driverdata; | |
247 | |
248 if (didata->cursor_size >= | |
249 (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) { | |
250 SDL_memcpy(didata->cursor, internal_cursor, | |
251 internal_cursor->hdr.len + | |
252 sizeof(PhRegionDataHdr_t)); | |
253 } else { | |
254 /* Partitial cursor image */ | |
255 SDL_memcpy(didata->cursor, internal_cursor, | |
256 didata->cursor_size); | |
257 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
258 |
3139 | 259 didata->cursor_visible = SDL_TRUE; |
260 return 0; | |
261 } else { | |
262 /* We can't get SDL_DisplayData at this point, return fake success */ | |
263 return 0; | |
264 } | |
265 } else { | |
266 /* Sanity checks */ | |
267 window = SDL_GetWindowFromID(window_id); | |
268 if (window != NULL) { | |
269 display = SDL_GetDisplayFromWindow(window); | |
270 if (display != NULL) { | |
271 didata = (SDL_DisplayData *) display->driverdata; | |
272 if (didata != NULL) { | |
273 wdata = (SDL_WindowData *) window->driverdata; | |
274 if (wdata == NULL) { | |
275 return -1; | |
276 } | |
277 } else { | |
278 return -1; | |
279 } | |
280 } else { | |
281 return -1; | |
282 } | |
283 } else { | |
284 return -1; | |
285 } | |
286 } | |
287 | |
288 /* return if window widget has been destroyed already */ | |
289 if (wdata->window == NULL) { | |
290 return; | |
291 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
292 |
3139 | 293 /* Check if we need to set new shape or disable cursor shape */ |
294 if (cursor != NULL) { | |
295 /* Retrieve photon cursor shape */ | |
296 internal_cursor = (PhCursorDef_t *) cursor->driverdata; | |
297 if (internal_cursor == NULL) { | |
298 SDL_SetError("Photon: Internal cursor data is absent"); | |
299 return -1; | |
300 } | |
301 | |
302 /* Setup cursor type */ | |
303 status = | |
304 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, | |
305 0); | |
306 if (status != 0) { | |
307 SDL_SetError("Photon: Failed to set cursor type to bitmap"); | |
308 return -1; | |
309 } | |
310 | |
311 /* Setup cursor color to default */ | |
312 status = | |
313 PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, | |
314 Ph_CURSOR_DEFAULT_COLOR, 0); | |
315 if (status != 0) { | |
316 SDL_SetError("Photon: Failed to set cursor color"); | |
317 return -1; | |
318 } | |
319 | |
320 /* Setup cursor shape */ | |
321 status = | |
322 PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, | |
323 internal_cursor, | |
324 internal_cursor->hdr.len + | |
325 sizeof(PhRegionDataHdr_t)); | |
326 if (status != 0) { | |
327 SDL_SetError("Photon: Failed to set cursor color"); | |
328 return -1; | |
329 } | |
330 | |
331 /* Store current cursor for future usage */ | |
332 if (didata->cursor_size >= | |
333 (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) { | |
334 SDL_memcpy(didata->cursor, internal_cursor, | |
335 internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t)); | |
336 } else { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
337 /* Partitial cursor image */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
338 SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size); |
3139 | 339 } |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
340 |
3139 | 341 /* Set cursor visible */ |
342 didata->cursor_visible = SDL_TRUE; | |
343 } else { | |
344 /* SDL requests to disable cursor */ | |
345 status = | |
346 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, | |
347 0); | |
348 if (status != 0) { | |
349 SDL_SetError("Photon: Can't disable cursor"); | |
350 return -1; | |
351 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
352 |
3139 | 353 /* Set cursor invisible */ |
354 didata->cursor_visible = SDL_FALSE; | |
355 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
356 |
3139 | 357 /* Flush all pending widget data */ |
358 PtFlush(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
359 |
3139 | 360 /* New cursor shape is set */ |
361 return 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
362 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
363 |
3139 | 364 void |
365 photon_movecursor(SDL_Cursor * cursor) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
366 { |
3139 | 367 SDL_VideoDisplay *display; |
368 SDL_DisplayData *didata; | |
369 SDL_Window *window; | |
370 SDL_WindowData *wdata; | |
371 SDL_WindowID window_id; | |
372 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
373 |
3139 | 374 /* Get current window id */ |
375 window_id = SDL_GetFocusWindow(); | |
376 if (window_id <= 0) { | |
377 didata = (SDL_DisplayData *) cursor->mouse->driverdata; | |
378 } else { | |
379 /* Sanity checks */ | |
380 window = SDL_GetWindowFromID(window_id); | |
381 if (window != NULL) { | |
382 display = SDL_GetDisplayFromWindow(window); | |
383 if (display != NULL) { | |
384 didata = (SDL_DisplayData *) display->driverdata; | |
385 if (didata != NULL) { | |
386 wdata = (SDL_WindowData *) window->driverdata; | |
387 if (wdata == NULL) { | |
388 return; | |
389 } | |
390 } else { | |
391 return; | |
392 } | |
393 } else { | |
394 return; | |
3115
1102a3305928
Added handler for all window events.
Mike Gorchak <lestat@i.com.ua>
parents:
3108
diff
changeset
|
395 } |
3139 | 396 } else { |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
397 return; |
3139 | 398 } |
399 } | |
400 | |
401 /* No need to move mouse cursor manually in the photon */ | |
402 | |
403 return; | |
404 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
405 |
3139 | 406 void |
407 photon_freecursor(SDL_Cursor * cursor) | |
408 { | |
409 PhCursorDef_t *internal_cursor = NULL; | |
3115
1102a3305928
Added handler for all window events.
Mike Gorchak <lestat@i.com.ua>
parents:
3108
diff
changeset
|
410 |
3139 | 411 if (cursor != NULL) { |
412 internal_cursor = (PhCursorDef_t *) cursor->driverdata; | |
413 if (internal_cursor != NULL) { | |
414 SDL_free(internal_cursor); | |
415 cursor->driverdata = NULL; | |
416 } | |
417 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
418 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
419 |
3139 | 420 void |
421 photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
422 { |
3139 | 423 SDL_VideoDisplay *display; |
424 SDL_DisplayData *didata; | |
425 SDL_Window *window; | |
426 SDL_WindowData *wdata; | |
427 int16_t wx; | |
428 int16_t wy; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
429 |
3139 | 430 /* Sanity checks */ |
431 window = SDL_GetWindowFromID(windowID); | |
432 if (window != NULL) { | |
433 display = SDL_GetDisplayFromWindow(window); | |
434 if (display != NULL) { | |
435 didata = (SDL_DisplayData *) display->driverdata; | |
436 if (didata != NULL) { | |
437 wdata = (SDL_WindowData *) window->driverdata; | |
438 if (wdata == NULL) { | |
439 return; | |
440 } | |
441 } else { | |
442 return; | |
443 } | |
444 } else { | |
445 return; | |
446 } | |
447 } else { | |
448 return; | |
449 } | |
450 | |
451 PtGetAbsPosition(wdata->window, &wx, &wy); | |
452 PhMoveCursorAbs(PhInputGroup(NULL), wx + x, wy + y); | |
453 | |
454 return; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
455 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
456 |
3139 | 457 void |
458 photon_freemouse(SDL_Mouse * mouse) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
459 { |
3139 | 460 if (mouse->driverdata == NULL) { |
461 return; | |
462 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
463 |
3139 | 464 /* Mouse framework doesn't deletes automatically our driverdata */ |
465 SDL_free(mouse->driverdata); | |
466 mouse->driverdata = NULL; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
467 |
3139 | 468 return; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
469 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
470 |
3139 | 471 SDL_scancode |
472 photon_to_sdl_keymap(uint32_t key) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
473 { |
3139 | 474 SDL_scancode scancode = SDL_SCANCODE_UNKNOWN; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
475 |
3139 | 476 switch (key & 0x0000007F) { |
477 case PHOTON_SCANCODE_ESCAPE: | |
478 scancode = SDL_SCANCODE_ESCAPE; | |
479 break; | |
480 case PHOTON_SCANCODE_F1: | |
481 scancode = SDL_SCANCODE_F1; | |
482 break; | |
483 case PHOTON_SCANCODE_F2: | |
484 scancode = SDL_SCANCODE_F2; | |
485 break; | |
486 case PHOTON_SCANCODE_F3: | |
487 scancode = SDL_SCANCODE_F3; | |
488 break; | |
489 case PHOTON_SCANCODE_F4: | |
490 scancode = SDL_SCANCODE_F4; | |
491 break; | |
492 case PHOTON_SCANCODE_F5: | |
493 scancode = SDL_SCANCODE_F5; | |
494 break; | |
495 case PHOTON_SCANCODE_F6: | |
496 scancode = SDL_SCANCODE_F6; | |
497 break; | |
498 case PHOTON_SCANCODE_F7: | |
499 scancode = SDL_SCANCODE_F7; | |
500 break; | |
501 case PHOTON_SCANCODE_F8: | |
502 scancode = SDL_SCANCODE_F8; | |
503 break; | |
504 case PHOTON_SCANCODE_F9: | |
505 scancode = SDL_SCANCODE_F9; | |
506 break; | |
507 case PHOTON_SCANCODE_F10: | |
508 scancode = SDL_SCANCODE_F10; | |
509 break; | |
510 case PHOTON_SCANCODE_F11: | |
511 scancode = SDL_SCANCODE_F11; | |
512 break; | |
513 case PHOTON_SCANCODE_F12: | |
514 scancode = SDL_SCANCODE_F12; | |
515 break; | |
516 case PHOTON_SCANCODE_BACKQOUTE: | |
517 scancode = SDL_SCANCODE_GRAVE; | |
518 break; | |
519 case PHOTON_SCANCODE_1: | |
520 scancode = SDL_SCANCODE_1; | |
521 break; | |
522 case PHOTON_SCANCODE_2: | |
523 scancode = SDL_SCANCODE_2; | |
524 break; | |
525 case PHOTON_SCANCODE_3: | |
526 scancode = SDL_SCANCODE_3; | |
527 break; | |
528 case PHOTON_SCANCODE_4: | |
529 scancode = SDL_SCANCODE_4; | |
530 break; | |
531 case PHOTON_SCANCODE_5: | |
532 scancode = SDL_SCANCODE_5; | |
533 break; | |
534 case PHOTON_SCANCODE_6: | |
535 scancode = SDL_SCANCODE_6; | |
536 break; | |
537 case PHOTON_SCANCODE_7: | |
538 scancode = SDL_SCANCODE_7; | |
539 break; | |
540 case PHOTON_SCANCODE_8: | |
541 scancode = SDL_SCANCODE_8; | |
542 break; | |
543 case PHOTON_SCANCODE_9: | |
544 scancode = SDL_SCANCODE_9; | |
545 break; | |
546 case PHOTON_SCANCODE_0: | |
547 scancode = SDL_SCANCODE_0; | |
548 break; | |
549 case PHOTON_SCANCODE_MINUS: | |
550 scancode = SDL_SCANCODE_MINUS; | |
551 break; | |
552 case PHOTON_SCANCODE_EQUAL: | |
553 scancode = SDL_SCANCODE_EQUALS; | |
554 break; | |
555 case PHOTON_SCANCODE_BACKSPACE: | |
556 scancode = SDL_SCANCODE_BACKSPACE; | |
557 break; | |
558 case PHOTON_SCANCODE_TAB: | |
559 scancode = SDL_SCANCODE_TAB; | |
560 break; | |
561 case PHOTON_SCANCODE_Q: | |
562 scancode = SDL_SCANCODE_Q; | |
563 break; | |
564 case PHOTON_SCANCODE_W: | |
565 scancode = SDL_SCANCODE_W; | |
566 break; | |
567 case PHOTON_SCANCODE_E: | |
568 scancode = SDL_SCANCODE_E; | |
569 break; | |
570 case PHOTON_SCANCODE_R: | |
571 scancode = SDL_SCANCODE_R; | |
572 break; | |
573 case PHOTON_SCANCODE_T: | |
574 scancode = SDL_SCANCODE_T; | |
575 break; | |
576 case PHOTON_SCANCODE_Y: | |
577 scancode = SDL_SCANCODE_Y; | |
578 break; | |
579 case PHOTON_SCANCODE_U: | |
580 scancode = SDL_SCANCODE_U; | |
581 break; | |
582 case PHOTON_SCANCODE_I: | |
583 scancode = SDL_SCANCODE_I; | |
584 break; | |
585 case PHOTON_SCANCODE_O: | |
586 scancode = SDL_SCANCODE_O; | |
587 break; | |
588 case PHOTON_SCANCODE_P: | |
589 scancode = SDL_SCANCODE_P; | |
590 break; | |
591 case PHOTON_SCANCODE_LEFT_SQ_BR: | |
592 scancode = SDL_SCANCODE_LEFTBRACKET; | |
593 break; | |
594 case PHOTON_SCANCODE_RIGHT_SQ_BR: | |
595 scancode = SDL_SCANCODE_RIGHTBRACKET; | |
596 break; | |
597 case PHOTON_SCANCODE_ENTER: | |
598 scancode = SDL_SCANCODE_RETURN; | |
599 break; | |
600 case PHOTON_SCANCODE_CAPSLOCK: | |
601 scancode = SDL_SCANCODE_CAPSLOCK; | |
602 break; | |
603 case PHOTON_SCANCODE_A: | |
604 scancode = SDL_SCANCODE_A; | |
605 break; | |
606 case PHOTON_SCANCODE_S: | |
607 scancode = SDL_SCANCODE_S; | |
608 break; | |
609 case PHOTON_SCANCODE_D: | |
610 scancode = SDL_SCANCODE_D; | |
611 break; | |
612 case PHOTON_SCANCODE_F: | |
613 scancode = SDL_SCANCODE_F; | |
614 break; | |
615 case PHOTON_SCANCODE_G: | |
616 scancode = SDL_SCANCODE_G; | |
617 break; | |
618 case PHOTON_SCANCODE_H: | |
619 scancode = SDL_SCANCODE_H; | |
620 break; | |
621 case PHOTON_SCANCODE_J: | |
622 scancode = SDL_SCANCODE_J; | |
623 break; | |
624 case PHOTON_SCANCODE_K: | |
625 scancode = SDL_SCANCODE_K; | |
626 break; | |
627 case PHOTON_SCANCODE_L: | |
628 scancode = SDL_SCANCODE_L; | |
629 break; | |
630 case PHOTON_SCANCODE_SEMICOLON: | |
631 scancode = SDL_SCANCODE_SEMICOLON; | |
632 break; | |
633 case PHOTON_SCANCODE_QUOTE: | |
634 scancode = SDL_SCANCODE_APOSTROPHE; | |
635 break; | |
636 case PHOTON_SCANCODE_BACKSLASH: | |
637 scancode = SDL_SCANCODE_BACKSLASH; | |
638 break; | |
639 case PHOTON_SCANCODE_LEFT_SHIFT: | |
640 scancode = SDL_SCANCODE_LSHIFT; | |
641 break; | |
642 case PHOTON_SCANCODE_Z: | |
643 scancode = SDL_SCANCODE_Z; | |
644 break; | |
645 case PHOTON_SCANCODE_X: | |
646 scancode = SDL_SCANCODE_X; | |
647 break; | |
648 case PHOTON_SCANCODE_C: | |
649 scancode = SDL_SCANCODE_C; | |
650 break; | |
651 case PHOTON_SCANCODE_V: | |
652 scancode = SDL_SCANCODE_V; | |
653 break; | |
654 case PHOTON_SCANCODE_B: | |
655 scancode = SDL_SCANCODE_B; | |
656 break; | |
657 case PHOTON_SCANCODE_N: | |
658 scancode = SDL_SCANCODE_N; | |
659 break; | |
660 case PHOTON_SCANCODE_M: | |
661 scancode = SDL_SCANCODE_M; | |
662 break; | |
663 case PHOTON_SCANCODE_COMMA: | |
664 scancode = SDL_SCANCODE_COMMA; | |
665 break; | |
666 case PHOTON_SCANCODE_POINT: | |
667 scancode = SDL_SCANCODE_PERIOD; | |
668 break; | |
669 case PHOTON_SCANCODE_SLASH: | |
670 scancode = SDL_SCANCODE_SLASH; | |
671 break; | |
672 case PHOTON_SCANCODE_RIGHT_SHIFT: | |
673 scancode = SDL_SCANCODE_RSHIFT; | |
674 break; | |
675 case PHOTON_SCANCODE_CTRL: | |
676 scancode = SDL_SCANCODE_LCTRL; | |
677 break; | |
678 case PHOTON_SCANCODE_WFLAG: | |
679 scancode = SDL_SCANCODE_LGUI; | |
680 break; | |
681 case PHOTON_SCANCODE_ALT: | |
682 scancode = SDL_SCANCODE_LALT; | |
683 break; | |
684 case PHOTON_SCANCODE_SPACE: | |
685 scancode = SDL_SCANCODE_SPACE; | |
686 break; | |
687 case PHOTON_SCANCODE_MENU: | |
688 scancode = SDL_SCANCODE_MENU; | |
689 break; | |
690 case PHOTON_SCANCODE_PRNSCR: | |
691 scancode = SDL_SCANCODE_PRINTSCREEN; | |
692 break; | |
693 case PHOTON_SCANCODE_SCROLLLOCK: | |
694 scancode = SDL_SCANCODE_SCROLLLOCK; | |
695 break; | |
696 case PHOTON_SCANCODE_INSERT: | |
697 scancode = SDL_SCANCODE_INSERT; | |
698 break; | |
699 case PHOTON_SCANCODE_HOME: | |
700 scancode = SDL_SCANCODE_HOME; | |
701 break; | |
702 case PHOTON_SCANCODE_PAGEUP: | |
703 scancode = SDL_SCANCODE_PAGEUP; | |
704 break; | |
705 case PHOTON_SCANCODE_DELETE: | |
706 scancode = SDL_SCANCODE_DELETE; | |
707 break; | |
708 case PHOTON_SCANCODE_END: | |
709 scancode = SDL_SCANCODE_END; | |
710 break; | |
711 case PHOTON_SCANCODE_PAGEDOWN: | |
712 scancode = SDL_SCANCODE_PAGEDOWN; | |
713 break; | |
714 case PHOTON_SCANCODE_UP: | |
715 scancode = SDL_SCANCODE_UP; | |
716 break; | |
717 case PHOTON_SCANCODE_DOWN: | |
718 scancode = SDL_SCANCODE_DOWN; | |
719 break; | |
720 case PHOTON_SCANCODE_LEFT: | |
721 scancode = SDL_SCANCODE_LEFT; | |
722 break; | |
723 case PHOTON_SCANCODE_RIGHT: | |
724 scancode = SDL_SCANCODE_RIGHT; | |
725 break; | |
726 case PHOTON_SCANCODE_NUMLOCK: | |
727 scancode = SDL_SCANCODE_NUMLOCKCLEAR; | |
728 break; | |
729 default: | |
730 break; | |
731 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
732 |
3139 | 733 return scancode; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
diff
changeset
|
734 } |