Mercurial > sdl-ios-xcode
comparison src/video/maccommon/SDL_macmouse.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | d910939febfa |
children |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
37 #include "SDL_mouse.h" | 37 #include "SDL_mouse.h" |
38 #include "SDL_macmouse_c.h" | 38 #include "SDL_macmouse_c.h" |
39 | 39 |
40 | 40 |
41 /* The implementation dependent data for the window manager cursor */ | 41 /* The implementation dependent data for the window manager cursor */ |
42 struct WMcursor { | 42 struct WMcursor |
43 Cursor curs; | 43 { |
44 Cursor curs; | |
44 }; | 45 }; |
45 | 46 |
46 | 47 |
47 void Mac_FreeWMCursor(_THIS, WMcursor *cursor) | 48 void |
49 Mac_FreeWMCursor(_THIS, WMcursor * cursor) | |
48 { | 50 { |
49 SDL_free(cursor); | 51 SDL_free(cursor); |
50 } | 52 } |
51 | 53 |
52 WMcursor *Mac_CreateWMCursor(_THIS, | 54 WMcursor * |
53 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | 55 Mac_CreateWMCursor(_THIS, |
56 Uint8 * data, Uint8 * mask, int w, int h, int hot_x, | |
57 int hot_y) | |
54 { | 58 { |
55 WMcursor *cursor; | 59 WMcursor *cursor; |
56 int row, bytes; | 60 int row, bytes; |
57 | 61 |
58 /* Allocate the cursor memory */ | 62 /* Allocate the cursor memory */ |
59 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); | 63 cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor)); |
60 if ( cursor == NULL ) { | 64 if (cursor == NULL) { |
61 SDL_OutOfMemory(); | 65 SDL_OutOfMemory(); |
62 return(NULL); | 66 return (NULL); |
63 } | 67 } |
64 SDL_memset(cursor, 0, sizeof(*cursor)); | 68 SDL_memset(cursor, 0, sizeof(*cursor)); |
65 | 69 |
66 if (w > 16) | 70 if (w > 16) |
67 w = 16; | 71 w = 16; |
68 | 72 |
69 if (h > 16) | 73 if (h > 16) |
70 h = 16; | 74 h = 16; |
71 | |
72 bytes = (w+7)/8; | |
73 | 75 |
74 for ( row=0; row<h; ++row ) { | 76 bytes = (w + 7) / 8; |
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 | 77 |
85 /* That was easy. :) */ | 78 for (row = 0; row < h; ++row) { |
86 return(cursor); | 79 SDL_memcpy(&cursor->curs.data[row], data, bytes); |
80 data += bytes; | |
81 } | |
82 for (row = 0; row < h; ++row) { | |
83 SDL_memcpy(&cursor->curs.mask[row], mask, bytes); | |
84 mask += bytes; | |
85 } | |
86 cursor->curs.hotSpot.h = hot_x; | |
87 cursor->curs.hotSpot.v = hot_y; | |
88 | |
89 /* That was easy. :) */ | |
90 return (cursor); | |
87 } | 91 } |
88 | 92 |
89 int Mac_cursor_showing = 1; | 93 int Mac_cursor_showing = 1; |
90 | 94 |
91 int Mac_ShowWMCursor(_THIS, WMcursor *cursor) | 95 int |
96 Mac_ShowWMCursor(_THIS, WMcursor * cursor) | |
92 { | 97 { |
93 if ( cursor == NULL ) { | 98 if (cursor == NULL) { |
94 if ( Mac_cursor_showing ) { | 99 if (Mac_cursor_showing) { |
95 HideCursor(); | 100 HideCursor(); |
96 Mac_cursor_showing = 0; | 101 Mac_cursor_showing = 0; |
97 } | 102 } |
98 } else { | 103 } else { |
99 SetCursor(&cursor->curs); | 104 SetCursor(&cursor->curs); |
100 if ( ! Mac_cursor_showing ) { | 105 if (!Mac_cursor_showing) { |
101 ShowCursor(); | 106 ShowCursor(); |
102 Mac_cursor_showing = 1; | 107 Mac_cursor_showing = 1; |
103 } | 108 } |
104 } | 109 } |
105 return(1); | 110 return (1); |
106 } | 111 } |
107 | 112 |
108 void Mac_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | 113 void |
114 Mac_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
109 { | 115 { |
110 #if !TARGET_API_MAC_CARBON | 116 #if !TARGET_API_MAC_CARBON |
111 CursorDevice *cursordevice; | 117 CursorDevice *cursordevice; |
112 | 118 |
113 cursordevice = nil; | 119 cursordevice = nil; |
114 CursorDeviceNextDevice(&cursordevice); | 120 CursorDeviceNextDevice(&cursordevice); |
115 if ( cursordevice != nil ) { | 121 if (cursordevice != nil) { |
116 WindowPtr saveport; | 122 WindowPtr saveport; |
117 Point where; | 123 Point where; |
118 | 124 |
119 GetPort(&saveport); | 125 GetPort(&saveport); |
120 SetPort(SDL_Window); | 126 SetPort(SDL_Window); |
121 where.h = x; | 127 where.h = x; |
122 where.v = y; | 128 where.v = y; |
123 LocalToGlobal(&where); | 129 LocalToGlobal(&where); |
124 SetPort(saveport); | 130 SetPort(saveport); |
125 CursorDeviceMoveTo(cursordevice, where.h, where.v); | 131 CursorDeviceMoveTo(cursordevice, where.h, where.v); |
126 } | 132 } |
127 #endif /* !TARGET_API_MAC_CARBON */ | 133 #endif /* !TARGET_API_MAC_CARBON */ |
128 } | 134 } |
129 | 135 |
136 /* vi: set ts=4 sw=4 expandtab: */ |