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