Mercurial > sdl-ios-xcode
annotate src/video/maccommon/SDL_macmouse.c @ 1290:c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
What we really needed to do was avoid doing client rect adjustment on
zoomed windows. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 18:17:35 +0000 |
parents | 609c060fd2a2 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
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 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
30 #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
|
31 #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
|
32 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 33 #include <Carbon.h> |
34 #else | |
35 #include <Quickdraw.h> | |
36 #endif | |
37 | |
38 /* Routines that are not supported by the Carbon API... */ | |
39 #if !TARGET_API_MAC_CARBON | |
40 #include <CursorDevices.h> | |
41 #endif | |
42 | |
43 #include "SDL_error.h" | |
44 #include "SDL_mouse.h" | |
45 #include "SDL_macmouse_c.h" | |
46 | |
47 | |
48 /* The implementation dependent data for the window manager cursor */ | |
49 struct WMcursor { | |
50 Cursor curs; | |
51 }; | |
52 | |
53 | |
54 void Mac_FreeWMCursor(_THIS, WMcursor *cursor) | |
55 { | |
56 free(cursor); | |
57 } | |
58 | |
59 WMcursor *Mac_CreateWMCursor(_THIS, | |
60 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | |
61 { | |
62 WMcursor *cursor; | |
63 int row, bytes; | |
64 | |
65 /* Allocate the cursor memory */ | |
66 cursor = (WMcursor *)malloc(sizeof(WMcursor)); | |
67 if ( cursor == NULL ) { | |
68 SDL_OutOfMemory(); | |
69 return(NULL); | |
70 } | |
71 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
|
72 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
73 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
|
74 w = 16; |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
75 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
76 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
|
77 h = 16; |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
78 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
79 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
|
80 |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
81 for ( row=0; row<h; ++row ) { |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
82 memcpy(&cursor->curs.data[row], data, bytes); |
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
83 data += bytes; |
0 | 84 } |
168
e92aa316c517
Added Max's patches for building MacOS X apps on command line
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
85 for ( row=0; row<h; ++row ) { |
0 | 86 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
|
87 mask += bytes; |
0 | 88 } |
89 cursor->curs.hotSpot.h = hot_x; | |
90 cursor->curs.hotSpot.v = hot_y; | |
91 | |
92 /* That was easy. :) */ | |
93 return(cursor); | |
94 } | |
95 | |
96 int Mac_cursor_showing = 1; | |
97 | |
98 int Mac_ShowWMCursor(_THIS, WMcursor *cursor) | |
99 { | |
100 if ( cursor == NULL ) { | |
101 if ( Mac_cursor_showing ) { | |
102 HideCursor(); | |
103 Mac_cursor_showing = 0; | |
104 } | |
105 } else { | |
106 SetCursor(&cursor->curs); | |
107 if ( ! Mac_cursor_showing ) { | |
108 ShowCursor(); | |
109 Mac_cursor_showing = 1; | |
110 } | |
111 } | |
112 return(1); | |
113 } | |
114 | |
115 void Mac_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
116 { | |
117 #if !TARGET_API_MAC_CARBON | |
118 CursorDevice *cursordevice; | |
119 | |
120 cursordevice = nil; | |
121 CursorDeviceNextDevice(&cursordevice); | |
122 if ( cursordevice != nil ) { | |
123 WindowPtr saveport; | |
124 Point where; | |
125 | |
126 GetPort(&saveport); | |
127 SetPort(SDL_Window); | |
128 where.h = x; | |
129 where.v = y; | |
130 LocalToGlobal(&where); | |
131 SetPort(saveport); | |
132 CursorDeviceMoveTo(cursordevice, where.h, where.v); | |
133 } | |
134 #endif /* !TARGET_API_MAC_CARBON */ | |
135 } | |
136 |