summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/video/maccommon
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-07 20:04:46 -0500
committerFranklin Wei <git@fwei.tk>2018-03-12 20:52:01 -0400
commit6039eb05ba6d82ef56f2868c96654c552d117bf9 (patch)
tree9db7016bcbf66cfdf7b9bc998d84c6eaff9c8378 /apps/plugins/sdl/src/video/maccommon
parentef373c03b96b0be08babca581d9f10bccfd4931f (diff)
downloadrockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.tar.gz
rockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.zip
sdl: remove non-rockbox drivers
We never use any of these other drivers, so having them around just takes up space. Change-Id: Iced812162df1fef3fd55522b7e700acb6c3bcd41
Diffstat (limited to 'apps/plugins/sdl/src/video/maccommon')
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_lowvideo.h102
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macevents.c746
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macevents_c.h32
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macgl.c197
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macgl_c.h47
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_mackeys.h140
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c129
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macmouse_c.h34
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macwm.c442
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macwm_c.h41
10 files changed, 0 insertions, 1910 deletions
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_lowvideo.h b/apps/plugins/sdl/src/video/maccommon/SDL_lowvideo.h
deleted file mode 100644
index f3dac29091..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_lowvideo.h
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _SDL_lowvideo_h
25#define _SDL_lowvideo_h
26
27#if defined(__APPLE__) && defined(__MACH__)
28#include <Carbon/Carbon.h>
29#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
30#include <Carbon.h>
31#else
32#include <Quickdraw.h>
33#include <Palettes.h>
34#include <Menus.h>
35#include <DrawSprocket.h>
36#endif
37
38#if SDL_VIDEO_OPENGL
39typedef struct __AGLContextRec *AGLContext;
40#endif
41
42#include "SDL_video.h"
43#include "../SDL_sysvideo.h"
44
45/* Hidden "this" pointer for the video functions */
46#define _THIS SDL_VideoDevice *this
47
48#if !TARGET_API_MAC_CARBON /* not available in OS X (or more accurately, Carbon) */
49/* Global QuickDraw data */
50extern QDGlobals *theQD;
51#endif
52
53/* Private display data */
54struct SDL_PrivateVideoData {
55 GDevice **SDL_Display;
56 WindowRef SDL_Window;
57 SDL_Rect **SDL_modelist;
58 CTabHandle SDL_CTab;
59 PaletteHandle SDL_CPal;
60
61#if TARGET_API_MAC_CARBON
62 /* For entering and leaving fullscreen mode */
63 Ptr fullscreen_ctx;
64#endif
65
66 /* The current window document style */
67 int current_style;
68
69 /* Information about the last cursor position */
70 Point last_where;
71
72 /* Information about the last keys down */
73 EventModifiers last_mods;
74 KeyMap last_keys;
75
76 /* A handle to the Apple Menu */
77 MenuRef apple_menu;
78
79 /* Information used by DrawSprocket driver */
80 struct DSpInfo *dspinfo;
81
82#if SDL_VIDEO_OPENGL
83 AGLContext appleGLContext;
84
85 void *libraryHandle;
86#endif
87};
88/* Old variable names */
89#define SDL_Display (this->hidden->SDL_Display)
90#define SDL_Window (this->hidden->SDL_Window)
91#define SDL_modelist (this->hidden->SDL_modelist)
92#define SDL_CTab (this->hidden->SDL_CTab)
93#define SDL_CPal (this->hidden->SDL_CPal)
94#define fullscreen_ctx (this->hidden->fullscreen_ctx)
95#define current_style (this->hidden->current_style)
96#define last_where (this->hidden->last_where)
97#define last_mods (this->hidden->last_mods)
98#define last_keys (this->hidden->last_keys)
99#define apple_menu (this->hidden->apple_menu)
100#define glContext (this->hidden->appleGLContext)
101
102#endif /* _SDL_lowvideo_h */
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macevents.c b/apps/plugins/sdl/src/video/maccommon/SDL_macevents.c
deleted file mode 100644
index 6e3fef2d60..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macevents.c
+++ /dev/null
@@ -1,746 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <stdio.h>
25
26#if defined(__APPLE__) && defined(__MACH__)
27#include <Carbon/Carbon.h>
28#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
29#include <Carbon.h>
30#else
31#include <Script.h>
32#include <LowMem.h>
33#include <Devices.h>
34#include <DiskInit.h>
35#include <ToolUtils.h>
36#endif
37
38#include "SDL_events.h"
39#include "SDL_video.h"
40#include "SDL_syswm.h"
41#include "../../events/SDL_events_c.h"
42#include "../../events/SDL_sysevents.h"
43#include "../SDL_cursor_c.h"
44#include "SDL_macevents_c.h"
45#include "SDL_mackeys.h"
46#include "SDL_macmouse_c.h"
47
48/* Define this to be able to collapse SDL windows.
49#define USE_APPEARANCE_MANAGER
50 */
51
52/* Macintosh resource constants */
53#define mApple 128 /* Apple menu resource */
54#define iAbout 1 /* About menu item */
55
56/* Functions to handle the About menu */
57static void Mac_DoAppleMenu(_THIS, long item);
58
59/* The translation table from a macintosh key scancode to a SDL keysym */
60static SDLKey MAC_keymap[256];
61static SDL_keysym *TranslateKey(int scancode, int modifiers,
62 SDL_keysym *keysym, int pressed);
63
64/* Handle activation and deactivation -- returns whether an event was posted */
65static int Mac_HandleActivate(int activate)
66{
67 if ( activate ) {
68 /* Show the current SDL application cursor */
69 SDL_SetCursor(NULL);
70
71 /* put our mask back case it changed during context switch */
72 SetEventMask(everyEvent & ~autoKeyMask);
73 } else {
74#if TARGET_API_MAC_CARBON
75 { Cursor cursor;
76 SetCursor(GetQDGlobalsArrow(&cursor));
77 }
78#else
79 SetCursor(&theQD->arrow);
80#endif
81 if ( ! Mac_cursor_showing ) {
82 ShowCursor();
83 Mac_cursor_showing = 1;
84 }
85 }
86 return(SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS));
87}
88
89static void myGlobalToLocal(_THIS, Point *pt)
90{
91 if ( SDL_VideoSurface && !(SDL_VideoSurface->flags&SDL_FULLSCREEN) ) {
92 GrafPtr saveport;
93 GetPort(&saveport);
94#if TARGET_API_MAC_CARBON
95 SetPort(GetWindowPort(SDL_Window));
96#else
97 SetPort(SDL_Window);
98#endif
99 GlobalToLocal(pt);
100 SetPort(saveport);
101 }
102}
103
104/* The main MacOS event handler */
105static int Mac_HandleEvents(_THIS, int wait4it)
106{
107 static int mouse_button = 1;
108 int i;
109 EventRecord event;
110
111#if TARGET_API_MAC_CARBON
112 /* There's no GetOSEvent() in the Carbon API. *sigh* */
113#define cooperative_multitasking 1
114#else
115 int cooperative_multitasking;
116 /* If we're running fullscreen, we can hog the MacOS events,
117 otherwise we had better play nicely with the other apps.
118 */
119 if ( this->screen && (this->screen->flags & SDL_FULLSCREEN) ) {
120 cooperative_multitasking = 0;
121 } else {
122 cooperative_multitasking = 1;
123 }
124#endif
125
126 /* If we call WaitNextEvent(), MacOS will check other processes
127 * and allow them to run, and perform other high-level processing.
128 */
129 if ( cooperative_multitasking || wait4it ) {
130 UInt32 wait_time;
131
132 /* Are we polling or not? */
133 if ( wait4it ) {
134 wait_time = 2147483647;
135 } else {
136 wait_time = 0;
137 }
138 WaitNextEvent(everyEvent, &event, wait_time, nil);
139 } else {
140#if ! TARGET_API_MAC_CARBON
141 GetOSEvent(everyEvent, &event);
142#endif
143 }
144
145#if TARGET_API_MAC_CARBON
146 /* for some reason, event.where isn't set ? */
147 GetGlobalMouse ( &event.where );
148#endif
149
150 /* Check for mouse motion */
151 if ( (event.where.h != last_where.h) ||
152 (event.where.v != last_where.v) ) {
153 Point pt;
154 pt = last_where = event.where;
155 myGlobalToLocal(this, &pt);
156 SDL_PrivateMouseMotion(0, 0, pt.h, pt.v);
157 }
158
159 /* Check the current state of the keyboard */
160 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
161 KeyMap keys;
162 const Uint32 *keysptr = (Uint32 *) &keys;
163 const Uint32 *last_keysptr = (Uint32 *) &last_keys;
164
165 /* Check for special non-event keys */
166 if ( event.modifiers != last_mods ) {
167 static struct {
168 EventModifiers mask;
169 SDLKey key;
170 } mods[] = {
171 { alphaLock, SDLK_CAPSLOCK },
172#if 0 /* These are handled below in the GetKeys() code */
173 { cmdKey, SDLK_LMETA },
174 { shiftKey, SDLK_LSHIFT },
175 { rightShiftKey, SDLK_RSHIFT },
176 { optionKey, SDLK_LALT },
177 { rightOptionKey, SDLK_RALT },
178 { controlKey, SDLK_LCTRL },
179 { rightControlKey, SDLK_RCTRL },
180#endif /* 0 */
181 { 0, 0 }
182 };
183 SDL_keysym keysym;
184 Uint8 mode;
185 EventModifiers mod, mask;
186
187
188 /* Set up the keyboard event */
189 keysym.scancode = 0;
190 keysym.sym = SDLK_UNKNOWN;
191 keysym.mod = KMOD_NONE;
192 keysym.unicode = 0;
193
194 /* See what has changed, and generate events */
195 mod = event.modifiers;
196 for ( i=0; mods[i].mask; ++i ) {
197 mask = mods[i].mask;
198 if ( (mod&mask) != (last_mods&mask) ) {
199 keysym.sym = mods[i].key;
200 if ( (mod&mask) ||
201 (mods[i].key == SDLK_CAPSLOCK) ) {
202 mode = SDL_PRESSED;
203 } else {
204 mode = SDL_RELEASED;
205 }
206 SDL_PrivateKeyboard(mode, &keysym);
207 }
208 }
209
210 /* Save state for next time */
211 last_mods = mod;
212 }
213
214 /* Check for normal event keys, but we have to scan the
215 actual keyboard state because on Mac OS X a keydown event
216 is immediately followed by a keyup event.
217 */
218 GetKeys(keys);
219 if ( (keysptr[0] != last_keysptr[0]) ||
220 (keysptr[1] != last_keysptr[1]) ||
221 (keysptr[2] != last_keysptr[2]) ||
222 (keysptr[3] != last_keysptr[3]) ) {
223 SDL_keysym keysym;
224 int old_bit, new_bit;
225
226#ifdef DEBUG_KEYBOARD
227 fprintf(sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n",
228 new_keys[0], new_keys[1],
229 new_keys[2], new_keys[3]);
230#endif
231 for ( i=0; i<128; ++i ) {
232 old_bit = (((Uint8 *)last_keys)[i/8]>>(i%8)) & 0x01;
233 new_bit = (((Uint8 *)keys)[i/8]>>(i%8)) & 0x01;
234 if ( old_bit != new_bit ) {
235 /* Post the keyboard event */
236#ifdef DEBUG_KEYBOARD
237 fprintf(stderr,"Scancode: 0x%2.2X\n",i);
238#endif
239 SDL_PrivateKeyboard(new_bit,
240 TranslateKey(i, event.modifiers,
241 &keysym, new_bit));
242 }
243 }
244
245 /* Save state for next time */
246 last_keys[0] = keys[0];
247 last_keys[1] = keys[1];
248 last_keys[2] = keys[2];
249 last_keys[3] = keys[3];
250 }
251 }
252
253 /* Handle normal events */
254 switch (event.what) {
255 case mouseDown: {
256 WindowRef win;
257 short area;
258
259 area = FindWindow(event.where, &win);
260 /* Support switching between the SIOUX console
261 and SDL_Window by clicking in the window.
262 */
263 if ( win && (win != FrontWindow()) ) {
264 SelectWindow(win);
265 }
266 switch (area) {
267 case inMenuBar: /* Only the apple menu exists */
268 Mac_DoAppleMenu(this, MenuSelect(event.where));
269 HiliteMenu(0);
270 break;
271 case inDrag:
272#if TARGET_API_MAC_CARBON
273 DragWindow(win, event.where, NULL);
274#else
275 DragWindow(win, event.where, &theQD->screenBits.bounds);
276#endif
277 break;
278 case inGoAway:
279 if ( TrackGoAway(win, event.where) ) {
280 SDL_PrivateQuit();
281 }
282 break;
283 case inContent:
284 myGlobalToLocal(this, &event.where);
285 /* Treat command-click as right mouse button */
286 if ( event.modifiers & optionKey ) {
287 mouse_button = 2;
288 } else if ( event.modifiers & cmdKey ) {
289 mouse_button = 3;
290 } else {
291 mouse_button = 1;
292 }
293 SDL_PrivateMouseButton(SDL_PRESSED,
294 mouse_button, event.where.h, event.where.v);
295 break;
296 case inGrow: {
297 int newSize;
298
299 /* Don't allow resize if video mode isn't resizable */
300 if ( ! SDL_PublicSurface ||
301 ! (SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
302 break;
303 }
304#if TARGET_API_MAC_CARBON
305 newSize = GrowWindow(win, event.where, NULL);
306#else
307 newSize = GrowWindow(win, event.where, &theQD->screenBits.bounds);
308#endif
309 if ( newSize ) {
310#if !TARGET_API_MAC_CARBON
311 EraseRect ( &theQD->screenBits.bounds );
312#endif
313 SizeWindow ( win, LoWord (newSize), HiWord (newSize), 1 );
314 SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) );
315 }
316 } break;
317 case inZoomIn:
318 case inZoomOut:
319 if ( TrackBox (win, event.where, area )) {
320 Rect rect;
321#if !TARGET_API_MAC_CARBON
322 EraseRect ( &theQD->screenBits.bounds );
323#endif
324 ZoomWindow ( win, area, 0);
325 if ( area == inZoomIn ) {
326 GetWindowUserState(SDL_Window, &rect);
327 } else {
328 GetWindowStandardState(SDL_Window, &rect);
329 }
330 SDL_PrivateResize (rect.right-rect.left,
331 rect.bottom-rect.top);
332 }
333 break;
334#if TARGET_API_MAC_CARBON
335 case inCollapseBox:
336 if ( TrackBox (win, event.where, area )) {
337 if ( IsWindowCollapsable(win) ) {
338 CollapseWindow (win, !IsWindowCollapsed(win));
339 /* There should be something done like in inGrow case, but... */
340 }
341 }
342 break;
343#endif /* TARGET_API_MAC_CARBON */
344 case inSysWindow:
345#if TARGET_API_MAC_CARBON
346 /* Never happens in Carbon? */
347#else
348 SystemClick(&event, win);
349#endif
350 break;
351 default:
352 break;
353 }
354 }
355 break;
356 case mouseUp: {
357 myGlobalToLocal(this, &event.where);
358 /* Release the mouse button we simulated in the last press.
359 The drawback of this methos is we cannot press more than
360 one button. However, this doesn't matter, since there is
361 only a single logical mouse button, even if you have a
362 multi-button mouse, this doesn't matter at all.
363 */
364 SDL_PrivateMouseButton(SDL_RELEASED,
365 mouse_button, event.where.h, event.where.v);
366 }
367 break;
368#if 0 /* Handled above the switch statement */
369 case keyDown: {
370 SDL_keysym keysym;
371
372 SDL_PrivateKeyboard(SDL_PRESSED,
373 TranslateKey((event.message&keyCodeMask)>>8
374 event.modifiers, &keysym, 1));
375 }
376 break;
377 case keyUp: {
378 SDL_keysym keysym;
379
380 SDL_PrivateKeyboard(SDL_RELEASED,
381 TranslateKey((event.message&keyCodeMask)>>8
382 event.modifiers, &keysym, 0));
383 }
384 break;
385#endif
386 case updateEvt: {
387 BeginUpdate(SDL_Window);
388 #if SDL_VIDEO_OPENGL
389 if (SDL_VideoSurface->flags & SDL_OPENGL)
390 SDL_GL_SwapBuffers();
391 else
392 #endif
393 if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) ==
394 SDL_SWSURFACE ) {
395 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0);
396 }
397 EndUpdate(SDL_Window);
398 }
399 /* If this was an update event for the SIOUX console, we return 0
400 in order to stop an endless series of updates being triggered.
401 */
402 if ( (WindowRef) event.message != SDL_Window ) {
403 return 0;
404 }
405 break;
406 case activateEvt: {
407 Mac_HandleActivate(!!(event.modifiers & activeFlag));
408 }
409 break;
410 case diskEvt: {
411#if TARGET_API_MAC_CARBON
412 /* What are we supposed to do? */;
413#else
414 if ( ((event.message>>16)&0xFFFF) != noErr ) {
415 Point spot;
416 SetPt(&spot, 0x0070, 0x0050);
417 DIBadMount(spot, event.message);
418 }
419#endif
420 }
421 break;
422 case osEvt: {
423 switch ((event.message>>24) & 0xFF) {
424#if 0 /* Handled above the switch statement */
425 case mouseMovedMessage: {
426 myGlobalToLocal(this, &event.where);
427 SDL_PrivateMouseMotion(0, 0,
428 event.where.h, event.where.v);
429 }
430 break;
431#endif /* 0 */
432 case suspendResumeMessage: {
433 Mac_HandleActivate(!!(event.message & resumeFlag));
434 }
435 break;
436 }
437 }
438 break;
439 default: {
440 ;
441 }
442 break;
443 }
444 return (event.what != nullEvent);
445}
446
447
448void Mac_PumpEvents(_THIS)
449{
450 /* Process pending MacOS events */
451 while ( Mac_HandleEvents(this, 0) ) {
452 /* Loop and check again */;
453 }
454}
455
456void Mac_InitOSKeymap(_THIS)
457{
458 const void *KCHRPtr;
459 UInt32 state;
460 UInt32 value;
461 int i;
462 int world = SDLK_WORLD_0;
463
464 /* Map the MAC keysyms */
465 for ( i=0; i<SDL_arraysize(MAC_keymap); ++i )
466 MAC_keymap[i] = SDLK_UNKNOWN;
467
468 /* Defined MAC_* constants */
469 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE;
470 MAC_keymap[MK_F1] = SDLK_F1;
471 MAC_keymap[MK_F2] = SDLK_F2;
472 MAC_keymap[MK_F3] = SDLK_F3;
473 MAC_keymap[MK_F4] = SDLK_F4;
474 MAC_keymap[MK_F5] = SDLK_F5;
475 MAC_keymap[MK_F6] = SDLK_F6;
476 MAC_keymap[MK_F7] = SDLK_F7;
477 MAC_keymap[MK_F8] = SDLK_F8;
478 MAC_keymap[MK_F9] = SDLK_F9;
479 MAC_keymap[MK_F10] = SDLK_F10;
480 MAC_keymap[MK_F11] = SDLK_F11;
481 MAC_keymap[MK_F12] = SDLK_F12;
482 MAC_keymap[MK_PRINT] = SDLK_PRINT;
483 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK;
484 MAC_keymap[MK_PAUSE] = SDLK_PAUSE;
485 MAC_keymap[MK_POWER] = SDLK_POWER;
486 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE;
487 MAC_keymap[MK_1] = SDLK_1;
488 MAC_keymap[MK_2] = SDLK_2;
489 MAC_keymap[MK_3] = SDLK_3;
490 MAC_keymap[MK_4] = SDLK_4;
491 MAC_keymap[MK_5] = SDLK_5;
492 MAC_keymap[MK_6] = SDLK_6;
493 MAC_keymap[MK_7] = SDLK_7;
494 MAC_keymap[MK_8] = SDLK_8;
495 MAC_keymap[MK_9] = SDLK_9;
496 MAC_keymap[MK_0] = SDLK_0;
497 MAC_keymap[MK_MINUS] = SDLK_MINUS;
498 MAC_keymap[MK_EQUALS] = SDLK_EQUALS;
499 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE;
500 MAC_keymap[MK_INSERT] = SDLK_INSERT;
501 MAC_keymap[MK_HOME] = SDLK_HOME;
502 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP;
503 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK;
504 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
505 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
506 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
507 MAC_keymap[MK_TAB] = SDLK_TAB;
508 MAC_keymap[MK_q] = SDLK_q;
509 MAC_keymap[MK_w] = SDLK_w;
510 MAC_keymap[MK_e] = SDLK_e;
511 MAC_keymap[MK_r] = SDLK_r;
512 MAC_keymap[MK_t] = SDLK_t;
513 MAC_keymap[MK_y] = SDLK_y;
514 MAC_keymap[MK_u] = SDLK_u;
515 MAC_keymap[MK_i] = SDLK_i;
516 MAC_keymap[MK_o] = SDLK_o;
517 MAC_keymap[MK_p] = SDLK_p;
518 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET;
519 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
520 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH;
521 MAC_keymap[MK_DELETE] = SDLK_DELETE;
522 MAC_keymap[MK_END] = SDLK_END;
523 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN;
524 MAC_keymap[MK_KP7] = SDLK_KP7;
525 MAC_keymap[MK_KP8] = SDLK_KP8;
526 MAC_keymap[MK_KP9] = SDLK_KP9;
527 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
528 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK;
529 MAC_keymap[MK_a] = SDLK_a;
530 MAC_keymap[MK_s] = SDLK_s;
531 MAC_keymap[MK_d] = SDLK_d;
532 MAC_keymap[MK_f] = SDLK_f;
533 MAC_keymap[MK_g] = SDLK_g;
534 MAC_keymap[MK_h] = SDLK_h;
535 MAC_keymap[MK_j] = SDLK_j;
536 MAC_keymap[MK_k] = SDLK_k;
537 MAC_keymap[MK_l] = SDLK_l;
538 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON;
539 MAC_keymap[MK_QUOTE] = SDLK_QUOTE;
540 MAC_keymap[MK_RETURN] = SDLK_RETURN;
541 MAC_keymap[MK_KP4] = SDLK_KP4;
542 MAC_keymap[MK_KP5] = SDLK_KP5;
543 MAC_keymap[MK_KP6] = SDLK_KP6;
544 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
545 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT;
546 MAC_keymap[MK_z] = SDLK_z;
547 MAC_keymap[MK_x] = SDLK_x;
548 MAC_keymap[MK_c] = SDLK_c;
549 MAC_keymap[MK_v] = SDLK_v;
550 MAC_keymap[MK_b] = SDLK_b;
551 MAC_keymap[MK_n] = SDLK_n;
552 MAC_keymap[MK_m] = SDLK_m;
553 MAC_keymap[MK_COMMA] = SDLK_COMMA;
554 MAC_keymap[MK_PERIOD] = SDLK_PERIOD;
555 MAC_keymap[MK_SLASH] = SDLK_SLASH;
556#if 0 /* These are the same as the left versions - use left by default */
557 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT;
558#endif
559 MAC_keymap[MK_UP] = SDLK_UP;
560 MAC_keymap[MK_KP1] = SDLK_KP1;
561 MAC_keymap[MK_KP2] = SDLK_KP2;
562 MAC_keymap[MK_KP3] = SDLK_KP3;
563 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
564 MAC_keymap[MK_LCTRL] = SDLK_LCTRL;
565 MAC_keymap[MK_LALT] = SDLK_LALT;
566 MAC_keymap[MK_LMETA] = SDLK_LMETA;
567 MAC_keymap[MK_SPACE] = SDLK_SPACE;
568#if 0 /* These are the same as the left versions - use left by default */
569 MAC_keymap[MK_RMETA] = SDLK_RMETA;
570 MAC_keymap[MK_RALT] = SDLK_RALT;
571 MAC_keymap[MK_RCTRL] = SDLK_RCTRL;
572#endif
573 MAC_keymap[MK_LEFT] = SDLK_LEFT;
574 MAC_keymap[MK_DOWN] = SDLK_DOWN;
575 MAC_keymap[MK_RIGHT] = SDLK_RIGHT;
576 MAC_keymap[MK_KP0] = SDLK_KP0;
577 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
578
579#if defined(__APPLE__) && defined(__MACH__)
580 /* Wierd, these keys are on my iBook under Mac OS X
581 Note that the left arrow keysym is the same as left ctrl!?
582 */
583 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER;
584 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT;
585 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN;
586 MAC_keymap[MK_IBOOK_UP] = SDLK_UP;
587 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;
588#endif /* Mac OS X */
589
590 /* Up there we setup a static scancode->keysym map. However, it will not
591 * work very well on international keyboard. Hence we now query MacOS
592 * for its own keymap to adjust our own mapping table. However, this is
593 * bascially only useful for ascii char keys. This is also the reason
594 * why we keep the static table, too.
595 */
596
597 /* Get a pointer to the systems cached KCHR */
598 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
599 if (KCHRPtr)
600 {
601 /* Loop over all 127 possible scan codes */
602 for (i = 0; i < 0x7F; i++)
603 {
604 /* We pretend a clean start to begin with (i.e. no dead keys active */
605 state = 0;
606
607 /* Now translate the key code to a key value */
608 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
609
610 /* If the state become 0, it was a dead key. We need to translate again,
611 passing in the new state, to get the actual key value */
612 if (state != 0)
613 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
614
615 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
616 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
617 MAC_keymap[i] = world++;
618 else if (value >= 32) /* non-control ASCII char */
619 MAC_keymap[i] = value;
620 }
621 }
622
623 /* The keypad codes are re-setup here, because the loop above cannot
624 * distinguish between a key on the keypad and a regular key. We maybe
625 * could get around this problem in another fashion: NSEvent's flags
626 * include a "NSNumericPadKeyMask" bit; we could check that and modify
627 * the symbol we return on the fly. However, this flag seems to exhibit
628 * some weird behaviour related to the num lock key
629 */
630 MAC_keymap[MK_KP0] = SDLK_KP0;
631 MAC_keymap[MK_KP1] = SDLK_KP1;
632 MAC_keymap[MK_KP2] = SDLK_KP2;
633 MAC_keymap[MK_KP3] = SDLK_KP3;
634 MAC_keymap[MK_KP4] = SDLK_KP4;
635 MAC_keymap[MK_KP5] = SDLK_KP5;
636 MAC_keymap[MK_KP6] = SDLK_KP6;
637 MAC_keymap[MK_KP7] = SDLK_KP7;
638 MAC_keymap[MK_KP8] = SDLK_KP8;
639 MAC_keymap[MK_KP9] = SDLK_KP9;
640 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
641 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
642 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
643 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
644 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
645 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
646 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
647}
648
649static SDL_keysym *TranslateKey(int scancode, int modifiers,
650 SDL_keysym *keysym, int pressed)
651{
652 /* Set the keysym information */
653 keysym->scancode = scancode;
654 keysym->sym = MAC_keymap[keysym->scancode];
655 keysym->mod = KMOD_NONE;
656 keysym->unicode = 0;
657 if ( pressed && SDL_TranslateUNICODE ) {
658 static unsigned long state = 0;
659 static Ptr keymap = nil;
660 Ptr new_keymap;
661
662 /* Get the current keyboard map resource */
663 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache);
664 if ( new_keymap != keymap ) {
665 keymap = new_keymap;
666 state = 0;
667 }
668 keysym->unicode = KeyTranslate(keymap,
669 keysym->scancode|modifiers, &state) & 0xFFFF;
670 }
671 return(keysym);
672}
673
674void Mac_InitEvents(_THIS)
675{
676 /* Create apple menu bar */
677 apple_menu = GetMenu(mApple);
678 if ( apple_menu != nil ) {
679 AppendResMenu(apple_menu, 'DRVR');
680 InsertMenu(apple_menu, 0);
681 }
682 DrawMenuBar();
683
684 /* Get rid of spurious events at startup */
685 FlushEvents(everyEvent, 0);
686
687 /* Allow every event but keyrepeat */
688 SetEventMask(everyEvent & ~autoKeyMask);
689}
690
691void Mac_QuitEvents(_THIS)
692{
693 ClearMenuBar();
694 if ( apple_menu != nil ) {
695 ReleaseResource((char **)apple_menu);
696 }
697
698 /* Clean up pending events */
699 FlushEvents(everyEvent, 0);
700}
701
702static void Mac_DoAppleMenu(_THIS, long choice)
703{
704#if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */
705 short menu, item;
706
707 item = (choice&0xFFFF);
708 choice >>= 16;
709 menu = (choice&0xFFFF);
710
711 switch (menu) {
712 case mApple: {
713 switch (item) {
714 case iAbout: {
715 /* Run the about box */;
716 }
717 break;
718 default: {
719 Str255 name;
720
721 GetMenuItemText(apple_menu, item, name);
722 OpenDeskAcc(name);
723 }
724 break;
725 }
726 }
727 break;
728 default: {
729 /* Ignore other menus */;
730 }
731 }
732#endif /* !TARGET_API_MAC_CARBON */
733}
734
735#if !TARGET_API_MAC_CARBON
736/* Since we don't initialize QuickDraw, we need to get a pointer to qd */
737struct QDGlobals *theQD = NULL;
738#endif
739
740/* Exported to the macmain code */
741void SDL_InitQuickDraw(struct QDGlobals *the_qd)
742{
743#if !TARGET_API_MAC_CARBON
744 theQD = the_qd;
745#endif
746}
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macevents_c.h b/apps/plugins/sdl/src/video/maccommon/SDL_macevents_c.h
deleted file mode 100644
index f9a983bde1..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macevents_c.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "../macrom/SDL_romvideo.h"
25
26/* Functions exported by SDL_macevents.c for the video subsystem
27*/
28extern void Mac_InitEvents(_THIS);
29extern void Mac_QuitEvents(_THIS);
30
31extern void Mac_InitOSKeymap(_THIS);
32extern void Mac_PumpEvents(_THIS);
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macgl.c b/apps/plugins/sdl/src/video/maccommon/SDL_macgl.c
deleted file mode 100644
index b7ded9bc5a..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macgl.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* AGL implementation of SDL OpenGL support */
25
26#include "SDL_lowvideo.h"
27#include "SDL_macgl_c.h"
28#include "SDL_loadso.h"
29
30
31/* krat: adding OpenGL support */
32int Mac_GL_Init(_THIS)
33{
34#if SDL_VIDEO_OPENGL
35 AGLPixelFormat format;
36 int i = 0;
37 GLint attributes [ 26 ]; /* 26 is max possible in this setup */
38 GLboolean noerr;
39
40 /* load the gl driver from a default path */
41 if ( ! this->gl_config.driver_loaded ) {
42 /* no driver has been loaded, use default (ourselves) */
43 if ( Mac_GL_LoadLibrary(this, NULL) < 0 ) {
44 return(-1);
45 }
46 }
47
48 attributes[i++] = AGL_RGBA;
49 if ( this->gl_config.red_size != 0 &&
50 this->gl_config.blue_size != 0 &&
51 this->gl_config.green_size != 0 ) {
52 attributes[i++] = AGL_RED_SIZE;
53 attributes[i++] = this->gl_config.red_size;
54 attributes[i++] = AGL_GREEN_SIZE;
55 attributes[i++] = this->gl_config.green_size;
56 attributes[i++] = AGL_BLUE_SIZE;
57 attributes[i++] = this->gl_config.blue_size;
58 attributes[i++] = AGL_ALPHA_SIZE;
59 attributes[i++] = this->gl_config.alpha_size;
60 }
61 if ( this->gl_config.double_buffer ) {
62 attributes[i++] = AGL_DOUBLEBUFFER;
63 }
64 if ( this->gl_config.depth_size != 0 ) {
65 attributes[i++] = AGL_DEPTH_SIZE;
66 attributes[i++] = this->gl_config.depth_size;
67 }
68 if ( this->gl_config.stencil_size != 0 ) {
69 attributes[i++] = AGL_STENCIL_SIZE;
70 attributes[i++] = this->gl_config.stencil_size;
71 }
72 if ( this->gl_config.accum_red_size != 0 &&
73 this->gl_config.accum_blue_size != 0 &&
74 this->gl_config.accum_green_size != 0 ) {
75
76 attributes[i++] = AGL_ACCUM_RED_SIZE;
77 attributes[i++] = this->gl_config.accum_red_size;
78 attributes[i++] = AGL_ACCUM_GREEN_SIZE;
79 attributes[i++] = this->gl_config.accum_green_size;
80 attributes[i++] = AGL_ACCUM_BLUE_SIZE;
81 attributes[i++] = this->gl_config.accum_blue_size;
82 attributes[i++] = AGL_ACCUM_ALPHA_SIZE;
83 attributes[i++] = this->gl_config.accum_alpha_size;
84 }
85 if ( this->gl_config.stereo ) {
86 attributes[i++] = AGL_STEREO;
87 }
88#if defined(AGL_SAMPLE_BUFFERS_ARB) && defined(AGL_SAMPLES_ARB)
89 if ( this->gl_config.multisamplebuffers != 0 ) {
90 attributes[i++] = AGL_SAMPLE_BUFFERS_ARB;
91 attributes[i++] = this->gl_config.multisamplebuffers;
92 }
93 if ( this->gl_config.multisamplesamples != 0 ) {
94 attributes[i++] = AGL_SAMPLES_ARB;
95 attributes[i++] = this->gl_config.multisamplesamples;
96 }
97#endif
98 if ( this->gl_config.accelerated > 0 ) {
99 attributes[i++] = AGL_ACCELERATED;
100 attributes[i++] = AGL_NO_RECOVERY;
101 }
102
103 attributes[i++] = AGL_ALL_RENDERERS;
104 attributes[i] = AGL_NONE;
105
106 format = aglChoosePixelFormat(NULL, 0, attributes);
107 if ( format == NULL ) {
108 SDL_SetError("Couldn't match OpenGL desired format");
109 return(-1);
110 }
111
112 glContext = aglCreateContext(format, NULL);
113 if ( glContext == NULL ) {
114 SDL_SetError("Couldn't create OpenGL context");
115 return(-1);
116 }
117 aglDestroyPixelFormat(format);
118
119 #if TARGET_API_MAC_CARBON
120 noerr = aglSetDrawable(glContext, GetWindowPort(SDL_Window));
121 #else
122 noerr = aglSetDrawable(glContext, (AGLDrawable)SDL_Window);
123 #endif
124
125 if(!noerr) {
126 SDL_SetError("Unable to bind GL context to window");
127 return(-1);
128 }
129 return(0);
130#else
131 SDL_SetError("OpenGL support not configured");
132 return(-1);
133#endif
134}
135
136void Mac_GL_Quit(_THIS)
137{
138#if SDL_VIDEO_OPENGL
139 if ( glContext != NULL ) {
140 aglSetCurrentContext(NULL);
141 aglSetDrawable(glContext, NULL);
142 aglDestroyContext(glContext);
143 glContext = NULL;
144 }
145#endif
146}
147
148#if SDL_VIDEO_OPENGL
149
150/* Make the current context active */
151int Mac_GL_MakeCurrent(_THIS)
152{
153 int retval;
154
155 retval = 0;
156 if( ! aglSetCurrentContext(glContext) ) {
157 SDL_SetError("Unable to make GL context current");
158 retval = -1;
159 }
160 return(retval);
161}
162
163void Mac_GL_SwapBuffers(_THIS)
164{
165 aglSwapBuffers(glContext);
166}
167
168int Mac_GL_LoadLibrary(_THIS, const char *location)
169{
170 if (location == NULL)
171#if __MACH__
172 location = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
173#else
174 location = "OpenGLLibrary";
175#endif
176
177 this->hidden->libraryHandle = SDL_LoadObject(location);
178
179 this->gl_config.driver_loaded = 1;
180 return (this->hidden->libraryHandle != NULL) ? 0 : -1;
181}
182
183void Mac_GL_UnloadLibrary(_THIS)
184{
185 SDL_UnloadObject(this->hidden->libraryHandle);
186
187 this->hidden->libraryHandle = NULL;
188 this->gl_config.driver_loaded = 0;
189}
190
191void* Mac_GL_GetProcAddress(_THIS, const char *proc)
192{
193 return SDL_LoadFunction( this->hidden->libraryHandle, proc );
194}
195
196#endif /* SDL_VIDEO_OPENGL */
197
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macgl_c.h b/apps/plugins/sdl/src/video/maccommon/SDL_macgl_c.h
deleted file mode 100644
index 42cd70fbd2..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macgl_c.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22
23/* AGL implementation of SDL OpenGL support */
24
25#include "SDL_config.h"
26
27#if SDL_VIDEO_OPENGL
28#include "SDL_opengl.h"
29#if __MACOSX__
30#include <AGL/agl.h> /* AGL.framework */
31#else
32#include <agl.h>
33#endif
34#endif /* SDL_VIDEO_OPENGL */
35
36/* OpenGL functions */
37extern int Mac_GL_Init(_THIS);
38extern void Mac_GL_Quit(_THIS);
39#if SDL_VIDEO_OPENGL
40extern int Mac_GL_MakeCurrent(_THIS);
41extern int Mac_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
42extern void Mac_GL_SwapBuffers(_THIS);
43extern int Mac_GL_LoadLibrary(_THIS, const char *location);
44extern void Mac_GL_UnloadLibrary(_THIS);
45extern void* Mac_GL_GetProcAddress(_THIS, const char *proc);
46#endif
47
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_mackeys.h b/apps/plugins/sdl/src/video/maccommon/SDL_mackeys.h
deleted file mode 100644
index dfed30da23..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_mackeys.h
+++ /dev/null
@@ -1,140 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22
23/* These are the Macintosh key scancode constants -- from Inside Macintosh */
24
25#define MK_ESCAPE 0x35
26#define MK_F1 0x7A
27#define MK_F2 0x78
28#define MK_F3 0x63
29#define MK_F4 0x76
30#define MK_F5 0x60
31#define MK_F6 0x61
32#define MK_F7 0x62
33#define MK_F8 0x64
34#define MK_F9 0x65
35#define MK_F10 0x6D
36#define MK_F11 0x67
37#define MK_F12 0x6F
38#define MK_PRINT 0x69
39#define MK_SCROLLOCK 0x6B
40#define MK_PAUSE 0x71
41#define MK_POWER 0x7F
42#define MK_BACKQUOTE 0x32
43#define MK_1 0x12
44#define MK_2 0x13
45#define MK_3 0x14
46#define MK_4 0x15
47#define MK_5 0x17
48#define MK_6 0x16
49#define MK_7 0x1A
50#define MK_8 0x1C
51#define MK_9 0x19
52#define MK_0 0x1D
53#define MK_MINUS 0x1B
54#define MK_EQUALS 0x18
55#define MK_BACKSPACE 0x33
56#define MK_INSERT 0x72
57#define MK_HOME 0x73
58#define MK_PAGEUP 0x74
59#define MK_NUMLOCK 0x47
60#define MK_KP_EQUALS 0x51
61#define MK_KP_DIVIDE 0x4B
62#define MK_KP_MULTIPLY 0x43
63#define MK_TAB 0x30
64#define MK_q 0x0C
65#define MK_w 0x0D
66#define MK_e 0x0E
67#define MK_r 0x0F
68#define MK_t 0x11
69#define MK_y 0x10
70#define MK_u 0x20
71#define MK_i 0x22
72#define MK_o 0x1F
73#define MK_p 0x23
74#define MK_LEFTBRACKET 0x21
75#define MK_RIGHTBRACKET 0x1E
76#define MK_BACKSLASH 0x2A
77#define MK_DELETE 0x75
78#define MK_END 0x77
79#define MK_PAGEDOWN 0x79
80#define MK_KP7 0x59
81#define MK_KP8 0x5B
82#define MK_KP9 0x5C
83#define MK_KP_MINUS 0x4E
84#define MK_CAPSLOCK 0x39
85#define MK_a 0x00
86#define MK_s 0x01
87#define MK_d 0x02
88#define MK_f 0x03
89#define MK_g 0x05
90#define MK_h 0x04
91#define MK_j 0x26
92#define MK_k 0x28
93#define MK_l 0x25
94#define MK_SEMICOLON 0x29
95#define MK_QUOTE 0x27
96#define MK_RETURN 0x24
97#define MK_KP4 0x56
98#define MK_KP5 0x57
99#define MK_KP6 0x58
100#define MK_KP_PLUS 0x45
101#define MK_LSHIFT 0x38
102#define MK_z 0x06
103#define MK_x 0x07
104#define MK_c 0x08
105#define MK_v 0x09
106#define MK_b 0x0B
107#define MK_n 0x2D
108#define MK_m 0x2E
109#define MK_COMMA 0x2B
110#define MK_PERIOD 0x2F
111#define MK_SLASH 0x2C
112#if 0 /* These are the same as the left versions - use left by default */
113#define MK_RSHIFT 0x38
114#endif
115#define MK_UP 0x7E
116#define MK_KP1 0x53
117#define MK_KP2 0x54
118#define MK_KP3 0x55
119#define MK_KP_ENTER 0x4C
120#define MK_LCTRL 0x3B
121#define MK_LALT 0x3A
122#define MK_LMETA 0x37
123#define MK_SPACE 0x31
124#if 0 /* These are the same as the left versions - use left by default */
125#define MK_RMETA 0x37
126#define MK_RALT 0x3A
127#define MK_RCTRL 0x3B
128#endif
129#define MK_LEFT 0x7B
130#define MK_DOWN 0x7D
131#define MK_RIGHT 0x7C
132#define MK_KP0 0x52
133#define MK_KP_PERIOD 0x41
134
135/* Wierd, these keys are on my iBook under Mac OS X */
136#define MK_IBOOK_ENTER 0x34
137#define MK_IBOOK_LEFT 0x3B
138#define MK_IBOOK_RIGHT 0x3C
139#define MK_IBOOK_DOWN 0x3D
140#define MK_IBOOK_UP 0x3E
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c b/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
deleted file mode 100644
index f19ad1b966..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#if defined(__APPLE__) && defined(__MACH__)
25#include <Carbon/Carbon.h>
26#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
27#include <Carbon.h>
28#else
29#include <Quickdraw.h>
30#endif
31
32/* Routines that are not supported by the Carbon API... */
33#if !TARGET_API_MAC_CARBON
34#include <CursorDevices.h>
35#endif
36
37#include "SDL_mouse.h"
38#include "SDL_macmouse_c.h"
39
40
41/* The implementation dependent data for the window manager cursor */
42struct WMcursor {
43 Cursor curs;
44};
45
46
47void Mac_FreeWMCursor(_THIS, WMcursor *cursor)
48{
49 SDL_free(cursor);
50}
51
52WMcursor *Mac_CreateWMCursor(_THIS,
53 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
54{
55 WMcursor *cursor;
56 int row, bytes;
57
58 /* Allocate the cursor memory */
59 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
60 if ( cursor == NULL ) {
61 SDL_OutOfMemory();
62 return(NULL);
63 }
64 SDL_memset(cursor, 0, sizeof(*cursor));
65
66 if (w > 16)
67 w = 16;
68
69 if (h > 16)
70 h = 16;
71
72 bytes = (w+7)/8;
73
74 for ( row=0; row<h; ++row ) {
75 SDL_memcpy(&cursor->curs.data[row], data, bytes);
76 data += bytes;
77 }
78 for ( row=0; row<h; ++row ) {
79 SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
80 mask += bytes;
81 }
82 cursor->curs.hotSpot.h = hot_x;
83 cursor->curs.hotSpot.v = hot_y;
84
85 /* That was easy. :) */
86 return(cursor);
87}
88
89int Mac_cursor_showing = 1;
90
91int Mac_ShowWMCursor(_THIS, WMcursor *cursor)
92{
93 if ( cursor == NULL ) {
94 if ( Mac_cursor_showing ) {
95 HideCursor();
96 Mac_cursor_showing = 0;
97 }
98 } else {
99 SetCursor(&cursor->curs);
100 if ( ! Mac_cursor_showing ) {
101 ShowCursor();
102 Mac_cursor_showing = 1;
103 }
104 }
105 return(1);
106}
107
108void Mac_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
109{
110#if !TARGET_API_MAC_CARBON
111 CursorDevice *cursordevice;
112
113 cursordevice = nil;
114 CursorDeviceNextDevice(&cursordevice);
115 if ( cursordevice != nil ) {
116 WindowPtr saveport;
117 Point where;
118
119 GetPort(&saveport);
120 SetPort(SDL_Window);
121 where.h = x;
122 where.v = y;
123 LocalToGlobal(&where);
124 SetPort(saveport);
125 CursorDeviceMoveTo(cursordevice, where.h, where.v);
126 }
127#endif /* !TARGET_API_MAC_CARBON */
128}
129
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macmouse_c.h b/apps/plugins/sdl/src/video/maccommon/SDL_macmouse_c.h
deleted file mode 100644
index 18fb438b16..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macmouse_c.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "../macrom/SDL_romvideo.h"
25
26/* Functions to be exported */
27extern void Mac_FreeWMCursor(_THIS, WMcursor *cursor);
28extern WMcursor *Mac_CreateWMCursor(_THIS,
29 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
30extern int Mac_ShowWMCursor(_THIS, WMcursor *cursor);
31extern void Mac_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
32
33/* Data to be exported */
34extern int Mac_cursor_showing;
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macwm.c b/apps/plugins/sdl/src/video/maccommon/SDL_macwm.c
deleted file mode 100644
index 6f485a3fa9..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macwm.c
+++ /dev/null
@@ -1,442 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#if defined(__APPLE__) && defined(__MACH__)
25#include <Carbon/Carbon.h>
26#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
27#include <Carbon.h>
28#else
29#include <Windows.h>
30#include <Strings.h>
31#endif
32
33#if SDL_MACCLASSIC_GAMMA_SUPPORT
34#include <Devices.h>
35#include <Files.h>
36#include <MacTypes.h>
37#include <QDOffscreen.h>
38#include <Quickdraw.h>
39#include <Video.h>
40#endif
41
42#include "SDL_stdinc.h"
43#include "SDL_macwm_c.h"
44
45void Mac_SetCaption(_THIS, const char *title, const char *icon)
46{
47 /* Don't convert C to P string in place, because it may be read-only */
48 Str255 ptitle; /* MJS */
49 ptitle[0] = strlen (title);
50 SDL_memcpy(ptitle+1, title, ptitle[0]); /* MJS */
51 if (SDL_Window)
52 SetWTitle(SDL_Window, ptitle); /* MJS */
53}
54
55#if SDL_MACCLASSIC_GAMMA_SUPPORT
56/*
57 * ADC Gamma Ramp support...
58 *
59 * Mac Gamma Ramp code was originally from sample code provided by
60 * Apple Developer Connection, and not written specifically for SDL:
61 * "Contains: Functions to enable Mac OS device gamma adjustments using 3 channel 256 element 8 bit gamma ramps
62 * Written by: Geoff Stahl (ggs)
63 * Copyright: Copyright (c) 1999 Apple Computer, Inc., All Rights Reserved
64 * Disclaimer: You may incorporate this sample code into your applications without
65 * restriction, though the sample code has been provided "AS IS" and the
66 * responsibility for its operation is 100% yours. However, what you are
67 * not permitted to do is to redistribute the source as "DSC Sample Code"
68 * after having made changes. If you're going to re-distribute the source,
69 * we require that you make it clear in the source that the code was
70 * descended from Apple Sample Code, but that you've made changes."
71 * (The sample code has been integrated into this file, and thus is modified from the original Apple sources.)
72 */
73
74typedef struct recDeviceGamma /* storage for device handle and gamma table */
75{
76 GDHandle hGD; /* handle to device */
77 GammaTblPtr pDeviceGamma; /* pointer to device gamma table */
78} recDeviceGamma;
79typedef recDeviceGamma * precDeviceGamma;
80
81typedef struct recSystemGamma /* storage for system devices and gamma tables */
82{
83 short numDevices; /* number of devices */
84 precDeviceGamma * devGamma; /* array of pointers to device gamma records */
85} recSystemGamma;
86typedef recSystemGamma * precSystemGamma;
87
88static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
89{
90 GammaTblPtr pTableGammaOut = NULL;
91 short tableSize, dataWidth;
92
93 if (pTableGammaIn) /* if there is a table to copy */
94 {
95 dataWidth = (pTableGammaIn->gDataWidth + 7) / 8; /* number of bytes per entry */
96 tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
97 (pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
98 pTableGammaOut = (GammaTblPtr) NewPtr (tableSize); /* allocate new table */
99 if (pTableGammaOut)
100 BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize); /* move everything */
101 }
102 return (Ptr)pTableGammaOut; /* return whatever we allocated, could be NULL */
103}
104
105static OSErr GetGammaTable (GDHandle hGD, GammaTblPtr * ppTableGammaOut)
106{
107 VDGammaRecord DeviceGammaRec;
108 CntrlParam cParam;
109 OSErr err;
110
111 cParam.ioCompletion = NULL; /* set up control params */
112 cParam.ioNamePtr = NULL;
113 cParam.ioVRefNum = 0;
114 cParam.ioCRefNum = (**hGD).gdRefNum;
115 cParam.csCode = cscGetGamma; /* Get Gamma commnd to device */
116 *(Ptr *)cParam.csParam = (Ptr) &DeviceGammaRec; /* record for gamma */
117
118 err = PBStatusSync( (ParmBlkPtr)&cParam ); /* get gamma */
119
120 *ppTableGammaOut = (GammaTblPtr)(DeviceGammaRec.csGTable); /* pull table out of record */
121
122 return err;
123}
124
125static Ptr GetDeviceGamma (GDHandle hGD)
126{
127 GammaTblPtr pTableGammaDevice = NULL;
128 GammaTblPtr pTableGammaReturn = NULL;
129 OSErr err;
130
131 err = GetGammaTable (hGD, &pTableGammaDevice); /* get a pointer to the devices table */
132 if ((noErr == err) && pTableGammaDevice) /* if succesful */
133 pTableGammaReturn = (GammaTblPtr) CopyGammaTable (pTableGammaDevice); /* copy to global */
134
135 return (Ptr) pTableGammaReturn;
136}
137
138static void DisposeGammaTable (Ptr pGamma)
139{
140 if (pGamma)
141 DisposePtr((Ptr) pGamma); /* get rid of it */
142}
143
144static void DisposeSystemGammas (Ptr* ppSystemGammas)
145{
146 precSystemGamma pSysGammaIn;
147 if (ppSystemGammas)
148 {
149 pSysGammaIn = (precSystemGamma) *ppSystemGammas;
150 if (pSysGammaIn)
151 {
152 short i;
153 for (i = 0; i < pSysGammaIn->numDevices; i++) /* for all devices */
154 if (pSysGammaIn->devGamma [i]) /* if pointer is valid */
155 {
156 DisposeGammaTable ((Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma); /* dump gamma table */
157 DisposePtr ((Ptr) pSysGammaIn->devGamma [i]); /* dump device info */
158 }
159 DisposePtr ((Ptr) pSysGammaIn->devGamma); /* dump device pointer array */
160 DisposePtr ((Ptr) pSysGammaIn); /* dump system structure */
161 *ppSystemGammas = NULL;
162 }
163 }
164}
165
166static Boolean GetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp)
167{
168 GammaTblPtr pTableGammaTemp = NULL;
169 long indexChan, indexEntry;
170 OSErr err;
171
172 if (pRamp) /* ensure pRamp is allocated */
173 {
174 err = GetGammaTable (hGD, &pTableGammaTemp); /* get a pointer to the current gamma */
175 if ((noErr == err) && pTableGammaTemp) /* if successful */
176 {
177 /* fill ramp */
178 unsigned char * pEntry = (unsigned char *) &pTableGammaTemp->gFormulaData + pTableGammaTemp->gFormulaSize; /* base of table */
179 short bytesPerEntry = (pTableGammaTemp->gDataWidth + 7) / 8; /* size, in bytes, of the device table entries */
180 short shiftRightValue = pTableGammaTemp->gDataWidth - 8; /* number of right shifts device -> ramp */
181 short channels = pTableGammaTemp->gChanCnt;
182 short entries = pTableGammaTemp->gDataCnt;
183 if (3 == channels) /* RGB format */
184 { /* note, this will create runs of entries if dest. is bigger (not linear interpolate) */
185 for (indexChan = 0; indexChan < channels; indexChan++)
186 for (indexEntry = 0; indexEntry < 256; indexEntry++)
187 *((unsigned char *) pRamp + (indexChan * 256) + indexEntry) =
188 *(pEntry + indexChan * entries * bytesPerEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue;
189 }
190 else /* single channel format */
191 {
192 for (indexChan = 0; indexChan < 768; indexChan += 256) /* repeat for all 3 channels (step by ramp size) */
193 for (indexEntry = 0; indexEntry < 256; indexEntry++) /* for all entries set vramp value */
194 *((unsigned char *) pRamp + indexChan + indexEntry) =
195 *(pEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue;
196 }
197 return true;
198 }
199 }
200 return false;
201}
202
203static Ptr GetSystemGammas (void)
204{
205 precSystemGamma pSysGammaOut; /* return pointer to system device gamma info */
206 short devCount = 0; /* number of devices attached */
207 Boolean fail = false;
208 GDHandle hGDevice;
209
210 pSysGammaOut = (precSystemGamma) NewPtr (sizeof (recSystemGamma)); /* allocate for structure */
211
212 hGDevice = GetDeviceList (); /* top of device list */
213 do /* iterate */
214 {
215 devCount++; /* count devices */
216 hGDevice = GetNextDevice (hGDevice); /* next device */
217 } while (hGDevice);
218
219 pSysGammaOut->devGamma = (precDeviceGamma *) NewPtr (sizeof (precDeviceGamma) * devCount); /* allocate for array of pointers to device records */
220 if (pSysGammaOut)
221 {
222 pSysGammaOut->numDevices = devCount; /* stuff count */
223
224 devCount = 0; /* reset iteration */
225 hGDevice = GetDeviceList ();
226 do
227 {
228 pSysGammaOut->devGamma [devCount] = (precDeviceGamma) NewPtr (sizeof (recDeviceGamma)); /* new device record */
229 if (pSysGammaOut->devGamma [devCount]) /* if we actually allocated memory */
230 {
231 pSysGammaOut->devGamma [devCount]->hGD = hGDevice; /* stuff handle */
232 pSysGammaOut->devGamma [devCount]->pDeviceGamma = (GammaTblPtr)GetDeviceGamma (hGDevice); /* copy gamma table */
233 }
234 else /* otherwise dump record on exit */
235 fail = true;
236 devCount++; /* next device */
237 hGDevice = GetNextDevice (hGDevice);
238 } while (hGDevice);
239 }
240 if (!fail) /* if we did not fail */
241 return (Ptr) pSysGammaOut; /* return pointer to structure */
242 else
243 {
244 DisposeSystemGammas ((Ptr *) &pSysGammaOut); /* otherwise dump the current structures (dispose does error checking) */
245 return NULL; /* could not complete */
246 }
247}
248
249static void RestoreDeviceGamma (GDHandle hGD, Ptr pGammaTable)
250{
251 VDSetEntryRecord setEntriesRec;
252 VDGammaRecord gameRecRestore;
253 CTabHandle hCTabDeviceColors;
254 Ptr csPtr;
255 OSErr err = noErr;
256
257 if (pGammaTable) /* if we have a table to restore */
258 {
259 gameRecRestore.csGTable = pGammaTable; /* setup restore record */
260 csPtr = (Ptr) &gameRecRestore;
261 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma */
262
263 if ((noErr == err) && (8 == (**(**hGD).gdPMap).pixelSize)) /* if successful and on an 8 bit device */
264 {
265 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */
266 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
267 setEntriesRec.csStart = 0;
268 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
269 csPtr = (Ptr) &setEntriesRec;
270
271 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */
272 }
273 }
274}
275
276static void RestoreSystemGammas (Ptr pSystemGammas)
277{
278 short i;
279 precSystemGamma pSysGammaIn = (precSystemGamma) pSystemGammas;
280 if (pSysGammaIn)
281 for (i = 0; i < pSysGammaIn->numDevices; i++) /* for all devices */
282 RestoreDeviceGamma (pSysGammaIn->devGamma [i]->hGD, (Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma); /* restore gamma */
283}
284
285static Ptr CreateEmptyGammaTable (short channels, short entries, short bits)
286{
287 GammaTblPtr pTableGammaOut = NULL;
288 short tableSize, dataWidth;
289
290 dataWidth = (bits + 7) / 8; /* number of bytes per entry */
291 tableSize = sizeof (GammaTbl) + (channels * entries * dataWidth);
292 pTableGammaOut = (GammaTblPtr) NewPtrClear (tableSize); /* allocate new tabel */
293
294 if (pTableGammaOut) /* if we successfully allocated */
295 {
296 pTableGammaOut->gVersion = 0; /* set parameters based on input */
297 pTableGammaOut->gType = 0;
298 pTableGammaOut->gFormulaSize = 0;
299 pTableGammaOut->gChanCnt = channels;
300 pTableGammaOut->gDataCnt = entries;
301 pTableGammaOut->gDataWidth = bits;
302 }
303 return (Ptr)pTableGammaOut; /* return whatever we allocated */
304}
305
306static Boolean SetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp)
307{
308 VDSetEntryRecord setEntriesRec;
309 VDGammaRecord gameRecRestore;
310 GammaTblPtr pTableGammaNew;
311 GammaTblPtr pTableGammaCurrent = NULL;
312 CTabHandle hCTabDeviceColors;
313 Ptr csPtr;
314 OSErr err;
315 short dataBits, entries, channels = 3; /* force three channels in the gamma table */
316
317 if (pRamp) /* ensure pRamp is allocated */
318 {
319 err= GetGammaTable (hGD, &pTableGammaCurrent); /* get pointer to current table */
320 if ((noErr == err) && pTableGammaCurrent)
321 {
322 dataBits = pTableGammaCurrent->gDataWidth; /* table must have same data width */
323 entries = pTableGammaCurrent->gDataCnt; /* table must be same size */
324 pTableGammaNew = (GammaTblPtr) CreateEmptyGammaTable (channels, entries, dataBits); /* our new table */
325 if (pTableGammaNew) /* if successful fill table */
326 {
327 unsigned char * pGammaBase = (unsigned char *) &pTableGammaNew->gFormulaData + pTableGammaNew->gFormulaSize; /* base of table */
328 if ((256 == entries) && (8 == dataBits)) /* simple case: direct mapping */
329 BlockMove ((Ptr)pRamp, (Ptr)pGammaBase, channels * entries); /* move everything */
330 else /* tough case handle entry, channel and data size disparities */
331 {
332 short indexChan, indexEntry;
333 short bytesPerEntry = (dataBits + 7) / 8; /* size, in bytes, of the device table entries */
334 short shiftRightValue = 8 - dataBits; /* number of right shifts ramp -> device */
335 shiftRightValue += ((bytesPerEntry - 1) * 8); /* multibyte entries and the need to map a byte at a time most sig. to least sig. */
336 for (indexChan = 0; indexChan < channels; indexChan++) /* for all the channels */
337 for (indexEntry = 0; indexEntry < entries; indexEntry++) /* for all the entries */
338 {
339 short currentShift = shiftRightValue; /* reset current bit shift */
340 long temp = *((unsigned char *)pRamp + (indexChan << 8) + (indexEntry << 8) / entries); /* get data from ramp */
341 short indexByte;
342 for (indexByte = 0; indexByte < bytesPerEntry; indexByte++) /* for all bytes */
343 {
344 if (currentShift < 0) /* shift data correctly for current byte */
345 *(pGammaBase++) = temp << -currentShift;
346 else
347 *(pGammaBase++) = temp >> currentShift;
348 currentShift -= 8; /* increment shift to align to next less sig. byte */
349 }
350 }
351 }
352
353 /* set gamma */
354 gameRecRestore.csGTable = (Ptr) pTableGammaNew; /* setup restore record */
355 csPtr = (Ptr) &gameRecRestore;
356 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma (note, display drivers may delay returning from this until VBL) */
357
358 if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err)) /* if successful and on an 8 bit device */
359 {
360 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */
361 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
362 setEntriesRec.csStart = 0;
363 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
364 csPtr = (Ptr) &setEntriesRec;
365 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */
366 }
367 DisposeGammaTable ((Ptr) pTableGammaNew); /* dump table */
368 if (noErr == err)
369 return true;
370 }
371 }
372 }
373 else /* set NULL gamma -> results in linear map */
374 {
375 gameRecRestore.csGTable = (Ptr) NULL; /* setup restore record */
376 csPtr = (Ptr) &gameRecRestore;
377 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma */
378
379 if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err)) /* if successful and on an 8 bit device */
380 {
381 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */
382 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
383 setEntriesRec.csStart = 0;
384 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
385 csPtr = (Ptr) &setEntriesRec;
386 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */
387 }
388 if (noErr == err)
389 return true;
390 }
391 return false; /* memory allocation or device control failed if we get here */
392}
393
394/* end of ADC Gamma Ramp support code... */
395
396static Ptr systemGammaPtr;
397
398void Mac_QuitGamma(_THIS)
399{
400 if (systemGammaPtr)
401 {
402 RestoreSystemGammas(systemGammaPtr);
403 DisposeSystemGammas(&systemGammaPtr);
404 }
405}
406
407static unsigned char shiftedRamp[3 * 256];
408
409int Mac_SetGammaRamp(_THIS, Uint16 *ramp)
410{
411 int i;
412 if (!systemGammaPtr)
413 systemGammaPtr = GetSystemGammas();
414 for (i = 0; i < 3 * 256; i++)
415 {
416 shiftedRamp[i] = ramp[i] >> 8;
417 }
418
419 if (SetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp))
420 return 0;
421 else
422 return -1;
423}
424
425int Mac_GetGammaRamp(_THIS, Uint16 *ramp)
426{
427 if (GetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp))
428 {
429 int i;
430 for (i = 0; i < 3 * 256; i++)
431 {
432 ramp[i] = shiftedRamp[i] << 8;
433 }
434 return 0;
435 }
436 else
437 return -1;
438}
439
440#endif /* SDL_MACCLASSIC_GAMMA_SUPPORT */
441
442
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macwm_c.h b/apps/plugins/sdl/src/video/maccommon/SDL_macwm_c.h
deleted file mode 100644
index a0554d16dc..0000000000
--- a/apps/plugins/sdl/src/video/maccommon/SDL_macwm_c.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
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.
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 Lesser General Public License for more details.
14
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
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "../macrom/SDL_romvideo.h"
25
26/* Functions to be exported */
27extern void Mac_SetCaption(_THIS, const char *title, const char *icon);
28
29/*
30 * There's no Carbonized gamma support in Mac OS X, since PBStatusSync() and
31 * Control() aren't supported in OS X's Carbonlib. Use the Quartz driver
32 * instead.
33 */
34#define SDL_MACCLASSIC_GAMMA_SUPPORT ((defined(__APPLE__) && defined(__MACH__)) == 0)
35
36#if SDL_MACCLASSIC_GAMMA_SUPPORT
37extern void Mac_QuitGamma(_THIS);
38extern int Mac_SetGammaRamp(_THIS, Uint16 *ramp);
39extern int Mac_GetGammaRamp(_THIS, Uint16 *ramp);
40#endif
41