32 /* These are static for our mouse handling code */ |
32 /* These are static for our mouse handling code */ |
33 static Sint16 SDL_MouseX = 0; |
33 static Sint16 SDL_MouseX = 0; |
34 static Sint16 SDL_MouseY = 0; |
34 static Sint16 SDL_MouseY = 0; |
35 static Sint16 SDL_DeltaX = 0; |
35 static Sint16 SDL_DeltaX = 0; |
36 static Sint16 SDL_DeltaY = 0; |
36 static Sint16 SDL_DeltaY = 0; |
|
37 static Sint16 SDL_MouseMaxX = 0; |
|
38 static Sint16 SDL_MouseMaxY = 0; |
37 static Uint8 SDL_ButtonState = 0; |
39 static Uint8 SDL_ButtonState = 0; |
38 |
40 |
39 |
41 |
40 /* Public functions */ |
42 /* Public functions */ |
41 int SDL_MouseInit(void) |
43 int SDL_MouseInit(void) |
90 static void ClipOffset(Sint16 *x, Sint16 *y) |
94 static void ClipOffset(Sint16 *x, Sint16 *y) |
91 { |
95 { |
92 /* This clips absolute mouse coordinates when the apparent |
96 /* This clips absolute mouse coordinates when the apparent |
93 display surface is smaller than the real display surface. |
97 display surface is smaller than the real display surface. |
94 */ |
98 */ |
95 if ( SDL_VideoSurface->offset ) { |
99 if ( SDL_VideoSurface && SDL_VideoSurface->offset ) { |
96 *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; |
100 *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; |
97 *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ |
101 *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ |
98 SDL_VideoSurface->format->BytesPerPixel; |
102 SDL_VideoSurface->format->BytesPerPixel; |
99 } |
103 } |
|
104 } |
|
105 |
|
106 void SDL_SetMouseRange(int maxX, int maxY) |
|
107 { |
|
108 SDL_MouseMaxX = (Sint16)maxX; |
|
109 SDL_MouseMaxY = (Sint16)maxY; |
100 } |
110 } |
101 |
111 |
102 /* These are global for SDL_eventloop.c */ |
112 /* These are global for SDL_eventloop.c */ |
103 int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) |
113 int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) |
104 { |
114 { |
105 int posted; |
115 int posted; |
106 Uint16 X, Y; |
116 Uint16 X, Y; |
107 Sint16 Xrel; |
117 Sint16 Xrel; |
108 Sint16 Yrel; |
118 Sint16 Yrel; |
109 |
|
110 /* Don't handle mouse motion if there's no cursor surface */ |
|
111 if ( SDL_VideoSurface == NULL ) { |
|
112 return(0); |
|
113 } |
|
114 |
119 |
115 /* Default buttonstate is the current one */ |
120 /* Default buttonstate is the current one */ |
116 if ( ! buttonstate ) { |
121 if ( ! buttonstate ) { |
117 buttonstate = SDL_ButtonState; |
122 buttonstate = SDL_ButtonState; |
118 } |
123 } |
130 |
135 |
131 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ |
136 /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ |
132 if ( x < 0 ) |
137 if ( x < 0 ) |
133 X = 0; |
138 X = 0; |
134 else |
139 else |
135 if ( x >= SDL_VideoSurface->w ) |
140 if ( x >= SDL_MouseMaxX ) |
136 X = SDL_VideoSurface->w-1; |
141 X = SDL_MouseMaxX-1; |
137 else |
142 else |
138 X = (Uint16)x; |
143 X = (Uint16)x; |
139 |
144 |
140 if ( y < 0 ) |
145 if ( y < 0 ) |
141 Y = 0; |
146 Y = 0; |
142 else |
147 else |
143 if ( y >= SDL_VideoSurface->h ) |
148 if ( y >= SDL_MouseMaxY ) |
144 Y = SDL_VideoSurface->h-1; |
149 Y = SDL_MouseMaxY-1; |
145 else |
150 else |
146 Y = (Uint16)y; |
151 Y = (Uint16)y; |
147 |
152 |
148 /* If not relative mode, generate relative motion from clamped X/Y. |
153 /* If not relative mode, generate relative motion from clamped X/Y. |
149 This prevents lots of extraneous large delta relative motion when |
154 This prevents lots of extraneous large delta relative motion when |