Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_mouse.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | e49147870aac |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
26 #include "../SDL_cursor_c.h" | 26 #include "../SDL_cursor_c.h" |
27 #include "SDL_ph_mouse_c.h" | 27 #include "SDL_ph_mouse_c.h" |
28 | 28 |
29 struct WMcursor | 29 struct WMcursor |
30 { | 30 { |
31 PhCursorDef_t *ph_cursor ; | 31 PhCursorDef_t *ph_cursor; |
32 }; | 32 }; |
33 | 33 |
34 void ph_FreeWMCursor(_THIS, WMcursor *cursor) | 34 void |
35 { | 35 ph_FreeWMCursor (_THIS, WMcursor * cursor) |
36 if (window != NULL) | 36 { |
37 { | 37 if (window != NULL) { |
38 SDL_Lock_EventThread(); | 38 SDL_Lock_EventThread (); |
39 | 39 |
40 if (PtSetResource(window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0) | 40 if (PtSetResource (window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) |
41 { | 41 < 0) { |
42 /* TODO: output error msg */ | 42 /* TODO: output error msg */ |
43 } | 43 } |
44 | 44 |
45 SDL_Unlock_EventThread(); | 45 SDL_Unlock_EventThread (); |
46 } | 46 } |
47 | 47 |
48 SDL_free(cursor); | 48 SDL_free (cursor); |
49 } | 49 } |
50 | 50 |
51 WMcursor *ph_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | 51 WMcursor * |
52 { | 52 ph_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, int w, int h, int hot_x, |
53 WMcursor* cursor; | 53 int hot_y) |
54 { | |
55 WMcursor *cursor; | |
54 int clen, i; | 56 int clen, i; |
55 unsigned char bit, databit, maskbit; | 57 unsigned char bit, databit, maskbit; |
56 | 58 |
57 /* Allocate and initialize the cursor memory */ | 59 /* Allocate and initialize the cursor memory */ |
58 if ((cursor = (WMcursor*)SDL_malloc(sizeof(WMcursor))) == NULL) | 60 if ((cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor))) == NULL) { |
59 { | 61 SDL_OutOfMemory (); |
60 SDL_OutOfMemory(); | 62 return (NULL); |
61 return(NULL); | 63 } |
62 } | 64 SDL_memset (cursor, 0, sizeof (WMcursor)); |
63 SDL_memset(cursor,0,sizeof(WMcursor)); | 65 |
64 | 66 cursor->ph_cursor = |
65 cursor->ph_cursor = (PhCursorDef_t *) SDL_malloc(sizeof(PhCursorDef_t) + 32*4*2); | 67 (PhCursorDef_t *) SDL_malloc (sizeof (PhCursorDef_t) + 32 * 4 * 2); |
66 | 68 |
67 if (cursor->ph_cursor == NULL) | 69 if (cursor->ph_cursor == NULL) { |
68 { | 70 SDL_SetError ("ph_CreateWMCursor(): cursor malloc failed !\n"); |
69 SDL_SetError("ph_CreateWMCursor(): cursor malloc failed !\n"); | |
70 return NULL; | 71 return NULL; |
71 } | 72 } |
72 | 73 |
73 SDL_memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2)); | 74 SDL_memset (cursor->ph_cursor, 0, (sizeof (PhCursorDef_t) + 32 * 4 * 2)); |
74 | 75 |
75 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR; | 76 cursor->ph_cursor->hdr.type = Ph_RDATA_CURSOR; |
76 cursor->ph_cursor->size1.x = (short)w; | 77 cursor->ph_cursor->size1.x = (short) w; |
77 cursor->ph_cursor->size1.y = (short)h; | 78 cursor->ph_cursor->size1.y = (short) h; |
78 cursor->ph_cursor->offset1.x = (short)hot_x; | 79 cursor->ph_cursor->offset1.x = (short) hot_x; |
79 cursor->ph_cursor->offset1.y = (short)hot_y; | 80 cursor->ph_cursor->offset1.y = (short) hot_y; |
80 cursor->ph_cursor->bytesperline1 = (char)w/8; | 81 cursor->ph_cursor->bytesperline1 = (char) w / 8; |
81 cursor->ph_cursor->color1 = Pg_WHITE; | 82 cursor->ph_cursor->color1 = Pg_WHITE; |
82 cursor->ph_cursor->size2.x = (short)w; | 83 cursor->ph_cursor->size2.x = (short) w; |
83 cursor->ph_cursor->size2.y = (short)h; | 84 cursor->ph_cursor->size2.y = (short) h; |
84 cursor->ph_cursor->offset2.x = (short)hot_x; | 85 cursor->ph_cursor->offset2.x = (short) hot_x; |
85 cursor->ph_cursor->offset2.y = (short)hot_y; | 86 cursor->ph_cursor->offset2.y = (short) hot_y; |
86 cursor->ph_cursor->bytesperline2 = (char)w/8; | 87 cursor->ph_cursor->bytesperline2 = (char) w / 8; |
87 cursor->ph_cursor->color2 = Pg_BLACK; | 88 cursor->ph_cursor->color2 = Pg_BLACK; |
88 | 89 |
89 clen = (w/8)*h; | 90 clen = (w / 8) * h; |
90 | 91 |
91 /* Copy the mask and the data to different bitmap planes */ | 92 /* Copy the mask and the data to different bitmap planes */ |
92 for (i=0; i<clen; ++i) | 93 for (i = 0; i < clen; ++i) { |
93 { | 94 for (bit = 0; bit < 8; bit++) { |
94 for (bit = 0; bit < 8; bit++) | |
95 { | |
96 databit = data[i] & (1 << bit); | 95 databit = data[i] & (1 << bit); |
97 maskbit = mask[i] & (1 << bit); | 96 maskbit = mask[i] & (1 << bit); |
98 | 97 |
99 cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0; | 98 cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0; |
100 /* If the databit != 0, treat it as a black pixel and | 99 /* If the databit != 0, treat it as a black pixel and |
101 * ignore the maskbit (can't do an inverted color) */ | 100 * ignore the maskbit (can't do an inverted color) */ |
102 cursor->ph_cursor->images[i+clen] |= databit; | 101 cursor->ph_cursor->images[i + clen] |= databit; |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 /* #bytes following the hdr struct */ | 105 /* #bytes following the hdr struct */ |
107 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); | 106 cursor->ph_cursor->hdr.len = |
107 sizeof (PhCursorDef_t) + clen * 2 - sizeof (PhRegionDataHdr_t); | |
108 | 108 |
109 return (cursor); | 109 return (cursor); |
110 } | 110 } |
111 | 111 |
112 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) | 112 PhCursorDef_t |
113 ph_GetWMPhCursor (WMcursor * cursor) | |
113 { | 114 { |
114 return (*cursor->ph_cursor); | 115 return (*cursor->ph_cursor); |
115 } | 116 } |
116 | 117 |
117 int ph_ShowWMCursor(_THIS, WMcursor* cursor) | 118 int |
119 ph_ShowWMCursor (_THIS, WMcursor * cursor) | |
118 { | 120 { |
119 PtArg_t args[3]; | 121 PtArg_t args[3]; |
120 int nargs = 0; | 122 int nargs = 0; |
121 | 123 |
122 /* Don't do anything if the display is gone */ | 124 /* Don't do anything if the display is gone */ |
123 if (window == NULL) | 125 if (window == NULL) { |
124 { | |
125 return (0); | 126 return (0); |
126 } | 127 } |
127 | 128 |
128 /* looks like photon can't draw mouse cursor in direct mode */ | 129 /* looks like photon can't draw mouse cursor in direct mode */ |
129 if (this->screen->flags & SDL_FULLSCREEN) | 130 if (this->screen->flags & SDL_FULLSCREEN) { |
130 { | 131 /* disable the fake mouse in the fullscreen OpenGL mode */ |
131 /* disable the fake mouse in the fullscreen OpenGL mode */ | 132 if (this->screen->flags & SDL_INTERNALOPENGL) { |
132 if (this->screen->flags & SDL_INTERNALOPENGL) | 133 cursor = NULL; |
133 { | 134 } else { |
134 cursor=NULL; | 135 return (0); |
135 } | 136 } |
136 else | |
137 { | |
138 return (0); | |
139 } | |
140 } | 137 } |
141 | 138 |
142 /* Set the photon cursor, or blank if cursor is NULL */ | 139 /* Set the photon cursor, or blank if cursor is NULL */ |
143 if (cursor!=NULL) | 140 if (cursor != NULL) { |
144 { | 141 PtSetArg (&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0); |
145 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0); | |
146 /* Could set next to any PgColor_t value */ | 142 /* Could set next to any PgColor_t value */ |
147 PtSetArg(&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR , 0); | 143 PtSetArg (&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0); |
148 PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t))); | 144 PtSetArg (&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, |
145 (cursor->ph_cursor->hdr.len + sizeof (PhRegionDataHdr_t))); | |
149 nargs = 3; | 146 nargs = 3; |
150 } | 147 } else { /* Ph_CURSOR_NONE */ |
151 else /* Ph_CURSOR_NONE */ | 148 |
152 { | 149 PtSetArg (&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0); |
153 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0); | |
154 nargs = 1; | 150 nargs = 1; |
155 } | 151 } |
156 | 152 |
157 SDL_Lock_EventThread(); | 153 SDL_Lock_EventThread (); |
158 | 154 |
159 if (PtSetResources(window, nargs, args) < 0 ) | 155 if (PtSetResources (window, nargs, args) < 0) { |
160 { | |
161 return (0); | 156 return (0); |
162 } | 157 } |
163 | 158 |
164 SDL_Unlock_EventThread(); | 159 SDL_Unlock_EventThread (); |
165 | 160 |
166 return (1); | 161 return (1); |
167 } | 162 } |
168 | 163 |
169 | 164 |
170 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | 165 void |
166 ph_WarpWMCursor (_THIS, Uint16 x, Uint16 y) | |
171 { | 167 { |
172 short abs_x, abs_y; | 168 short abs_x, abs_y; |
173 | 169 |
174 SDL_Lock_EventThread(); | 170 SDL_Lock_EventThread (); |
175 PtGetAbsPosition( window, &abs_x, &abs_y ); | 171 PtGetAbsPosition (window, &abs_x, &abs_y); |
176 PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y ); | 172 PhMoveCursorAbs (PhInputGroup (NULL), x + abs_x, y + abs_y); |
177 SDL_Unlock_EventThread(); | 173 SDL_Unlock_EventThread (); |
178 } | 174 } |
179 | 175 |
180 | 176 |
181 void ph_CheckMouseMode(_THIS) | 177 void |
178 ph_CheckMouseMode (_THIS) | |
182 { | 179 { |
183 /* If the mouse is hidden and input is grabbed, we use relative mode */ | 180 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
184 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF)) | 181 if (!(SDL_cursorstate & CURSOR_VISIBLE) |
185 { | 182 && (this->input_grab != SDL_GRAB_OFF)) { |
186 mouse_relative = 1; | 183 mouse_relative = 1; |
187 } | 184 } else { |
188 else | |
189 { | |
190 mouse_relative = 0; | 185 mouse_relative = 0; |
191 } | 186 } |
192 } | 187 } |
193 | 188 |
194 | 189 |
195 void ph_UpdateMouse(_THIS) | 190 void |
191 ph_UpdateMouse (_THIS) | |
196 { | 192 { |
197 PhCursorInfo_t phcursor; | 193 PhCursorInfo_t phcursor; |
198 short abs_x; | 194 short abs_x; |
199 short abs_y; | 195 short abs_y; |
200 | 196 |
201 /* Lock the event thread, in multi-threading environments */ | 197 /* Lock the event thread, in multi-threading environments */ |
202 SDL_Lock_EventThread(); | 198 SDL_Lock_EventThread (); |
203 | 199 |
204 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */ | 200 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */ |
205 PtGetAbsPosition(window, &abs_x, &abs_y); | 201 PtGetAbsPosition (window, &abs_x, &abs_y); |
206 PhQueryCursor(PhInputGroup(NULL), &phcursor); | 202 PhQueryCursor (PhInputGroup (NULL), &phcursor); |
207 if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) && | 203 if (((phcursor.pos.x >= abs_x) |
208 ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h))) | 204 && (phcursor.pos.x <= abs_x + this->screen->w)) |
209 { | 205 && ((phcursor.pos.y >= abs_y) |
210 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | 206 && (phcursor.pos.y <= abs_y + this->screen->h))) { |
211 SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y); | 207 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); |
212 } | 208 SDL_PrivateMouseMotion (0, 0, phcursor.pos.x - abs_x, |
213 else | 209 phcursor.pos.y - abs_y); |
214 { | 210 } else { |
215 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | 211 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); |
216 } | 212 } |
217 | 213 |
218 /* Unlock the event thread, in multi-threading environments */ | 214 /* Unlock the event thread, in multi-threading environments */ |
219 SDL_Unlock_EventThread(); | 215 SDL_Unlock_EventThread (); |
220 } | 216 } |
217 | |
218 /* vi: set ts=4 sw=4 expandtab: */ |