Mercurial > sdl-ios-xcode
annotate src/video/maccommon/SDL_macmouse.c @ 1574:0fd72308659e
Default to use the visibility attribute, on gcc (is this okay?)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 22 Mar 2006 04:51:44 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
168
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
24 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
25 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
26 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 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 */ | |
42 struct WMcursor { | |
43 Cursor curs; | |
44 }; | |
45 | |
46 | |
47 void Mac_FreeWMCursor(_THIS, WMcursor *cursor) | |
48 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
49 SDL_free(cursor); |
0 | 50 } |
51 | |
52 WMcursor *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 */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
59 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); |
0 | 60 if ( cursor == NULL ) { |
61 SDL_OutOfMemory(); | |
62 return(NULL); | |
63 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
64 SDL_memset(cursor, 0, sizeof(*cursor)); |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
65 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
66 if (w > 16) |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
67 w = 16; |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
68 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
69 if (h > 16) |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
70 h = 16; |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
71 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
72 bytes = (w+7)/8; |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
73 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
74 for ( row=0; row<h; ++row ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
75 SDL_memcpy(&cursor->curs.data[row], data, bytes); |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
76 data += bytes; |
0 | 77 } |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
78 for ( row=0; row<h; ++row ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
79 SDL_memcpy(&cursor->curs.mask[row], mask, bytes); |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
80 mask += bytes; |
0 | 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 | |
89 int Mac_cursor_showing = 1; | |
90 | |
91 int 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 | |
108 void 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 |