comparison src/events/SDL_mouse.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children eef792d31de8
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
37 static Uint8 SDL_ButtonState = 0; 37 static Uint8 SDL_ButtonState = 0;
38 38
39 39
40 /* Public functions */ 40 /* Public functions */
41 int 41 int
42 SDL_MouseInit (void) 42 SDL_MouseInit(void)
43 { 43 {
44 /* The mouse is at (0,0) */ 44 /* The mouse is at (0,0) */
45 SDL_MouseX = 0; 45 SDL_MouseX = 0;
46 SDL_MouseY = 0; 46 SDL_MouseY = 0;
47 SDL_DeltaX = 0; 47 SDL_DeltaX = 0;
51 /* That's it! */ 51 /* That's it! */
52 return (0); 52 return (0);
53 } 53 }
54 54
55 void 55 void
56 SDL_MouseQuit (void) 56 SDL_MouseQuit(void)
57 { 57 {
58 } 58 }
59 59
60 /* We lost the mouse, so post button up messages for all pressed buttons */ 60 /* We lost the mouse, so post button up messages for all pressed buttons */
61 void 61 void
62 SDL_ResetMouse (void) 62 SDL_ResetMouse(void)
63 { 63 {
64 Uint8 i; 64 Uint8 i;
65 for (i = 0; i < sizeof (SDL_ButtonState) * 8; ++i) { 65 for (i = 0; i < sizeof(SDL_ButtonState) * 8; ++i) {
66 if (SDL_ButtonState & SDL_BUTTON (i)) { 66 if (SDL_ButtonState & SDL_BUTTON(i)) {
67 SDL_PrivateMouseButton (SDL_RELEASED, i, 0, 0); 67 SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
68 } 68 }
69 } 69 }
70 } 70 }
71 71
72 Uint8 72 Uint8
73 SDL_GetMouseState (int *x, int *y) 73 SDL_GetMouseState(int *x, int *y)
74 { 74 {
75 if (x) { 75 if (x) {
76 *x = SDL_MouseX; 76 *x = SDL_MouseX;
77 } 77 }
78 if (y) { 78 if (y) {
80 } 80 }
81 return (SDL_ButtonState); 81 return (SDL_ButtonState);
82 } 82 }
83 83
84 Uint8 84 Uint8
85 SDL_GetRelativeMouseState (int *x, int *y) 85 SDL_GetRelativeMouseState(int *x, int *y)
86 { 86 {
87 if (x) 87 if (x)
88 *x = SDL_DeltaX; 88 *x = SDL_DeltaX;
89 if (y) 89 if (y)
90 *y = SDL_DeltaY; 90 *y = SDL_DeltaY;
92 SDL_DeltaY = 0; 92 SDL_DeltaY = 0;
93 return (SDL_ButtonState); 93 return (SDL_ButtonState);
94 } 94 }
95 95
96 static void 96 static void
97 ClipOffset (Sint16 * x, Sint16 * y) 97 ClipOffset(Sint16 * x, Sint16 * y)
98 { 98 {
99 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 99 SDL_VideoDevice *_this = SDL_GetVideoDevice();
100 100
101 /* This clips absolute mouse coordinates when the apparent 101 /* This clips absolute mouse coordinates when the apparent
102 display surface is smaller than the real display surface. 102 display surface is smaller than the real display surface.
103 */ 103 */
104 if (SDL_VideoSurface->offset) { 104 if (SDL_VideoSurface->offset) {
108 } 108 }
109 } 109 }
110 110
111 /* These are global for SDL_eventloop.c */ 111 /* These are global for SDL_eventloop.c */
112 int 112 int
113 SDL_PrivateMouseMotion (Uint8 buttonstate, int relative, Sint16 x, Sint16 y) 113 SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
114 { 114 {
115 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 115 SDL_VideoDevice *_this = SDL_GetVideoDevice();
116 int posted; 116 int posted;
117 Uint16 X, Y; 117 Uint16 X, Y;
118 Sint16 Xrel; 118 Sint16 Xrel;
119 Sint16 Yrel; 119 Sint16 Yrel;
120 120
134 /* Push the cursor around */ 134 /* Push the cursor around */
135 x = (SDL_MouseX + x); 135 x = (SDL_MouseX + x);
136 y = (SDL_MouseY + y); 136 y = (SDL_MouseY + y);
137 } else { 137 } else {
138 /* Do we need to clip {x,y} ? */ 138 /* Do we need to clip {x,y} ? */
139 ClipOffset (&x, &y); 139 ClipOffset(&x, &y);
140 } 140 }
141 141
142 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ 142 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
143 if (x < 0) 143 if (x < 0)
144 X = 0; 144 X = 0;
164 } 164 }
165 165
166 /* Drop events that don't change state */ 166 /* Drop events that don't change state */
167 if (!Xrel && !Yrel) { 167 if (!Xrel && !Yrel) {
168 #if 0 168 #if 0
169 printf ("Mouse event didn't change state - dropped!\n"); 169 printf("Mouse event didn't change state - dropped!\n");
170 #endif 170 #endif
171 return (0); 171 return (0);
172 } 172 }
173 173
174 /* Update internal mouse state */ 174 /* Update internal mouse state */
175 SDL_ButtonState = buttonstate; 175 SDL_ButtonState = buttonstate;
176 SDL_MouseX = X; 176 SDL_MouseX = X;
177 SDL_MouseY = Y; 177 SDL_MouseY = Y;
178 SDL_DeltaX += Xrel; 178 SDL_DeltaX += Xrel;
179 SDL_DeltaY += Yrel; 179 SDL_DeltaY += Yrel;
180 SDL_MoveCursor (SDL_MouseX, SDL_MouseY); 180 SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
181 181
182 /* Post the event, if desired */ 182 /* Post the event, if desired */
183 posted = 0; 183 posted = 0;
184 if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) { 184 if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
185 SDL_Event event; 185 SDL_Event event;
186 SDL_memset (&event, 0, sizeof (event)); 186 SDL_memset(&event, 0, sizeof(event));
187 event.type = SDL_MOUSEMOTION; 187 event.type = SDL_MOUSEMOTION;
188 event.motion.state = buttonstate; 188 event.motion.state = buttonstate;
189 event.motion.x = X; 189 event.motion.x = X;
190 event.motion.y = Y; 190 event.motion.y = Y;
191 event.motion.xrel = Xrel; 191 event.motion.xrel = Xrel;
192 event.motion.yrel = Yrel; 192 event.motion.yrel = Yrel;
193 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { 193 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
194 posted = 1; 194 posted = 1;
195 SDL_PushEvent (&event); 195 SDL_PushEvent(&event);
196 } 196 }
197 } 197 }
198 return (posted); 198 return (posted);
199 } 199 }
200 200
201 int 201 int
202 SDL_PrivateMouseButton (Uint8 state, Uint8 button, Sint16 x, Sint16 y) 202 SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
203 { 203 {
204 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 204 SDL_VideoDevice *_this = SDL_GetVideoDevice();
205 SDL_Event event; 205 SDL_Event event;
206 int posted; 206 int posted;
207 int move_mouse; 207 int move_mouse;
208 Uint8 buttonstate; 208 Uint8 buttonstate;
209 209
210 SDL_memset (&event, 0, sizeof (event)); 210 SDL_memset(&event, 0, sizeof(event));
211 211
212 /* Check parameters */ 212 /* Check parameters */
213 if (x || y) { 213 if (x || y) {
214 ClipOffset (&x, &y); 214 ClipOffset(&x, &y);
215 move_mouse = 1; 215 move_mouse = 1;
216 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ 216 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
217 if (x < 0) 217 if (x < 0)
218 x = 0; 218 x = 0;
219 else if (x >= SDL_VideoSurface->w) 219 else if (x >= SDL_VideoSurface->w)
234 /* Figure out which event to perform */ 234 /* Figure out which event to perform */
235 buttonstate = SDL_ButtonState; 235 buttonstate = SDL_ButtonState;
236 switch (state) { 236 switch (state) {
237 case SDL_PRESSED: 237 case SDL_PRESSED:
238 event.type = SDL_MOUSEBUTTONDOWN; 238 event.type = SDL_MOUSEBUTTONDOWN;
239 buttonstate |= SDL_BUTTON (button); 239 buttonstate |= SDL_BUTTON(button);
240 break; 240 break;
241 case SDL_RELEASED: 241 case SDL_RELEASED:
242 event.type = SDL_MOUSEBUTTONUP; 242 event.type = SDL_MOUSEBUTTONUP;
243 buttonstate &= ~SDL_BUTTON (button); 243 buttonstate &= ~SDL_BUTTON(button);
244 break; 244 break;
245 default: 245 default:
246 /* Invalid state -- bail */ 246 /* Invalid state -- bail */
247 return (0); 247 return (0);
248 } 248 }
250 /* Update internal mouse state */ 250 /* Update internal mouse state */
251 SDL_ButtonState = buttonstate; 251 SDL_ButtonState = buttonstate;
252 if (move_mouse) { 252 if (move_mouse) {
253 SDL_MouseX = x; 253 SDL_MouseX = x;
254 SDL_MouseY = y; 254 SDL_MouseY = y;
255 SDL_MoveCursor (SDL_MouseX, SDL_MouseY); 255 SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
256 } 256 }
257 257
258 /* Post the event, if desired */ 258 /* Post the event, if desired */
259 posted = 0; 259 posted = 0;
260 if (SDL_ProcessEvents[event.type] == SDL_ENABLE) { 260 if (SDL_ProcessEvents[event.type] == SDL_ENABLE) {
262 event.button.button = button; 262 event.button.button = button;
263 event.button.x = x; 263 event.button.x = x;
264 event.button.y = y; 264 event.button.y = y;
265 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { 265 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
266 posted = 1; 266 posted = 1;
267 SDL_PushEvent (&event); 267 SDL_PushEvent(&event);
268 } 268 }
269 } 269 }
270 return (posted); 270 return (posted);
271 } 271 }
272 272