summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-01-21 15:18:31 -0500
committerFranklin Wei <git@fwei.tk>2017-12-23 21:01:26 -0500
commita855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch)
tree8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
parent01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff)
downloadrockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz
rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL for Rockbox. Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c')
-rw-r--r--apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c b/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
new file mode 100644
index 0000000000..f19ad1b966
--- /dev/null
+++ b/apps/plugins/sdl/src/video/maccommon/SDL_macmouse.c
@@ -0,0 +1,129 @@
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