1.1 --- a/src/video/windx5/SDL_dx5events.c Fri Dec 11 15:31:37 2009 +0000
1.2 +++ b/src/video/windx5/SDL_dx5events.c Mon Dec 14 22:41:31 2009 +0000
1.3 @@ -374,179 +374,179 @@
1.4 if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
1.5 mouse_lost = 1;
1.6 ClipCursor(NULL);
1.7 - }
1.8 + } else {
1.9 + /* If the mouse was lost, regain some sense of mouse state */
1.10 + if ( mouse_lost ) {
1.11 + POINT mouse_pos;
1.12 + Uint8 old_state;
1.13 + Uint8 new_state;
1.14
1.15 - /* If the mouse was lost, regain some sense of mouse state */
1.16 - if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
1.17 - POINT mouse_pos;
1.18 - Uint8 old_state;
1.19 - Uint8 new_state;
1.20 + /* Set ourselves up with the current cursor position */
1.21 + GetCursorPos(&mouse_pos);
1.22 + ScreenToClient(SDL_Window, &mouse_pos);
1.23 + post_mouse_motion( 0, (Sint16)mouse_pos.x, (Sint16)mouse_pos.y);
1.24
1.25 - /* Set ourselves up with the current cursor position */
1.26 - GetCursorPos(&mouse_pos);
1.27 - ScreenToClient(SDL_Window, &mouse_pos);
1.28 - post_mouse_motion( 0, (Sint16)mouse_pos.x, (Sint16)mouse_pos.y);
1.29 + /* Check for mouse button changes */
1.30 + old_state = SDL_GetMouseState(NULL, NULL);
1.31 + new_state = 0;
1.32 + { /* Get the new DirectInput button state for the mouse */
1.33 + #if DIRECTINPUT_VERSION >= 0x700
1.34 + DIMOUSESTATE2 distate;
1.35 + #else
1.36 + DIMOUSESTATE distate;
1.37 + #endif
1.38 + HRESULT result;
1.39
1.40 - /* Check for mouse button changes */
1.41 - old_state = SDL_GetMouseState(NULL, NULL);
1.42 - new_state = 0;
1.43 - { /* Get the new DirectInput button state for the mouse */
1.44 -#if DIRECTINPUT_VERSION >= 0x700
1.45 - DIMOUSESTATE2 distate;
1.46 -#else
1.47 - DIMOUSESTATE distate;
1.48 -#endif
1.49 - HRESULT result;
1.50 -
1.51 - result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1],
1.52 - sizeof(distate), &distate);
1.53 - if ( result != DI_OK ) {
1.54 - /* Try again next time */
1.55 - SetDIerror(
1.56 - "IDirectInputDevice2::GetDeviceState", result);
1.57 - return;
1.58 + result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1],
1.59 + sizeof(distate), &distate);
1.60 + if ( result != DI_OK ) {
1.61 + /* Try again next time */
1.62 + SetDIerror(
1.63 + "IDirectInputDevice2::GetDeviceState", result);
1.64 + return;
1.65 + }
1.66 + for ( i=3; i>=0; --i ) {
1.67 + if ( (distate.rgbButtons[i]&0x80) == 0x80 ) {
1.68 + new_state |= 0x01;
1.69 + }
1.70 + new_state <<= 1;
1.71 + }
1.72 }
1.73 - for ( i=3; i>=0; --i ) {
1.74 - if ( (distate.rgbButtons[i]&0x80) == 0x80 ) {
1.75 - new_state |= 0x01;
1.76 + for ( i=0; i<8; ++i ) {
1.77 + if ( (old_state&0x01) != (new_state&0x01) ) {
1.78 + button = (Uint8)(i+1);
1.79 + /* Map DI button numbers to SDL */
1.80 + switch ( button ) {
1.81 + case 2: button = SDL_BUTTON_RIGHT; break;
1.82 + case 3: button = SDL_BUTTON_MIDDLE; break;
1.83 + case 4: button = SDL_BUTTON_X1; break;
1.84 + case 5: button = SDL_BUTTON_X2; break;
1.85 + default: break;
1.86 + }
1.87 + if ( new_state & 0x01 ) {
1.88 + /* Grab mouse so we get mouse-up */
1.89 + if ( ++mouse_pressed > 0 ) {
1.90 + SetCapture(SDL_Window);
1.91 + }
1.92 + state = SDL_PRESSED;
1.93 + } else {
1.94 + /* Release mouse after all mouse-ups */
1.95 + if ( --mouse_pressed <= 0 ) {
1.96 + ReleaseCapture();
1.97 + mouse_pressed = 0;
1.98 + }
1.99 + state = SDL_RELEASED;
1.100 + }
1.101 + if ( mouse_buttons_swapped ) {
1.102 + if ( button == 1 ) button = 3;
1.103 + else
1.104 + if ( button == 3 ) button = 1;
1.105 + }
1.106 + posted = SDL_PrivateMouseButton(state, button,
1.107 + 0, 0);
1.108 }
1.109 - new_state <<= 1;
1.110 + old_state >>= 1;
1.111 + new_state >>= 1;
1.112 }
1.113 + mouse_lost = 0;
1.114 + return;
1.115 }
1.116 - for ( i=0; i<8; ++i ) {
1.117 - if ( (old_state&0x01) != (new_state&0x01) ) {
1.118 - button = (Uint8)(i+1);
1.119 - /* Map DI button numbers to SDL */
1.120 - switch ( button ) {
1.121 - case 2: button = SDL_BUTTON_RIGHT; break;
1.122 - case 3: button = SDL_BUTTON_MIDDLE; break;
1.123 - case 4: button = SDL_BUTTON_X1; break;
1.124 - case 5: button = SDL_BUTTON_X2; break;
1.125 - default: break;
1.126 - }
1.127 - if ( new_state & 0x01 ) {
1.128 - /* Grab mouse so we get mouse-up */
1.129 - if ( ++mouse_pressed > 0 ) {
1.130 - SetCapture(SDL_Window);
1.131 - }
1.132 - state = SDL_PRESSED;
1.133 - } else {
1.134 - /* Release mouse after all mouse-ups */
1.135 - if ( --mouse_pressed <= 0 ) {
1.136 - ReleaseCapture();
1.137 - mouse_pressed = 0;
1.138 +
1.139 + /* Translate mouse messages */
1.140 + xrel = 0;
1.141 + yrel = 0;
1.142 + for ( i=0; i<(int)numevents; ++i ) {
1.143 + switch (ptrbuf[i].dwOfs) {
1.144 + case DIMOFS_X:
1.145 + if ( timestamp != ptrbuf[i].dwTimeStamp ) {
1.146 + if ( xrel || yrel ) {
1.147 + post_mouse_motion(1, xrel, yrel);
1.148 + xrel = 0;
1.149 + yrel = 0;
1.150 + }
1.151 + timestamp = ptrbuf[i].dwTimeStamp;
1.152 }
1.153 - state = SDL_RELEASED;
1.154 - }
1.155 - if ( mouse_buttons_swapped ) {
1.156 - if ( button == 1 ) button = 3;
1.157 - else
1.158 - if ( button == 3 ) button = 1;
1.159 - }
1.160 - posted = SDL_PrivateMouseButton(state, button,
1.161 - 0, 0);
1.162 - }
1.163 - old_state >>= 1;
1.164 - new_state >>= 1;
1.165 - }
1.166 - mouse_lost = 0;
1.167 - return;
1.168 - }
1.169 -
1.170 - /* Translate mouse messages */
1.171 - xrel = 0;
1.172 - yrel = 0;
1.173 - for ( i=0; i<(int)numevents; ++i ) {
1.174 - switch (ptrbuf[i].dwOfs) {
1.175 - case DIMOFS_X:
1.176 - if ( timestamp != ptrbuf[i].dwTimeStamp ) {
1.177 + xrel += (Sint16)ptrbuf[i].dwData;
1.178 + break;
1.179 + case DIMOFS_Y:
1.180 + if ( timestamp != ptrbuf[i].dwTimeStamp ) {
1.181 + if ( xrel || yrel ) {
1.182 + post_mouse_motion(1, xrel, yrel);
1.183 + xrel = 0;
1.184 + yrel = 0;
1.185 + }
1.186 + timestamp = ptrbuf[i].dwTimeStamp;
1.187 + }
1.188 + yrel += (Sint16)ptrbuf[i].dwData;
1.189 + break;
1.190 + case DIMOFS_Z:
1.191 if ( xrel || yrel ) {
1.192 post_mouse_motion(1, xrel, yrel);
1.193 xrel = 0;
1.194 yrel = 0;
1.195 }
1.196 - timestamp = ptrbuf[i].dwTimeStamp;
1.197 - }
1.198 - xrel += (Sint16)ptrbuf[i].dwData;
1.199 - break;
1.200 - case DIMOFS_Y:
1.201 - if ( timestamp != ptrbuf[i].dwTimeStamp ) {
1.202 + timestamp = 0;
1.203 + if((int)ptrbuf[i].dwData > 0)
1.204 + button = SDL_BUTTON_WHEELUP;
1.205 + else
1.206 + button = SDL_BUTTON_WHEELDOWN;
1.207 + posted = SDL_PrivateMouseButton(
1.208 + SDL_PRESSED, button, 0, 0);
1.209 + posted |= SDL_PrivateMouseButton(
1.210 + SDL_RELEASED, button, 0, 0);
1.211 + break;
1.212 + case DIMOFS_BUTTON0:
1.213 + case DIMOFS_BUTTON1:
1.214 + case DIMOFS_BUTTON2:
1.215 + case DIMOFS_BUTTON3:
1.216 + #if DIRECTINPUT_VERSION >= 0x700
1.217 + case DIMOFS_BUTTON4:
1.218 + case DIMOFS_BUTTON5:
1.219 + case DIMOFS_BUTTON6:
1.220 + case DIMOFS_BUTTON7:
1.221 + #endif
1.222 if ( xrel || yrel ) {
1.223 post_mouse_motion(1, xrel, yrel);
1.224 xrel = 0;
1.225 yrel = 0;
1.226 }
1.227 - timestamp = ptrbuf[i].dwTimeStamp;
1.228 - }
1.229 - yrel += (Sint16)ptrbuf[i].dwData;
1.230 - break;
1.231 - case DIMOFS_Z:
1.232 - if ( xrel || yrel ) {
1.233 - post_mouse_motion(1, xrel, yrel);
1.234 - xrel = 0;
1.235 - yrel = 0;
1.236 - }
1.237 - timestamp = 0;
1.238 - if((int)ptrbuf[i].dwData > 0)
1.239 - button = SDL_BUTTON_WHEELUP;
1.240 - else
1.241 - button = SDL_BUTTON_WHEELDOWN;
1.242 - posted = SDL_PrivateMouseButton(
1.243 - SDL_PRESSED, button, 0, 0);
1.244 - posted |= SDL_PrivateMouseButton(
1.245 - SDL_RELEASED, button, 0, 0);
1.246 - break;
1.247 - case DIMOFS_BUTTON0:
1.248 - case DIMOFS_BUTTON1:
1.249 - case DIMOFS_BUTTON2:
1.250 - case DIMOFS_BUTTON3:
1.251 -#if DIRECTINPUT_VERSION >= 0x700
1.252 - case DIMOFS_BUTTON4:
1.253 - case DIMOFS_BUTTON5:
1.254 - case DIMOFS_BUTTON6:
1.255 - case DIMOFS_BUTTON7:
1.256 -#endif
1.257 - if ( xrel || yrel ) {
1.258 - post_mouse_motion(1, xrel, yrel);
1.259 - xrel = 0;
1.260 - yrel = 0;
1.261 - }
1.262 - timestamp = 0;
1.263 - button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1;
1.264 - /* Map DI button numbers to SDL */
1.265 - switch ( button ) {
1.266 - case 2: button = SDL_BUTTON_RIGHT; break;
1.267 - case 3: button = SDL_BUTTON_MIDDLE; break;
1.268 - case 4: button = SDL_BUTTON_X1; break;
1.269 - case 5: button = SDL_BUTTON_X2; break;
1.270 - default: break;
1.271 - }
1.272 - if ( ptrbuf[i].dwData & 0x80 ) {
1.273 - /* Grab mouse so we get mouse-up */
1.274 - if ( ++mouse_pressed > 0 ) {
1.275 - SetCapture(SDL_Window);
1.276 + timestamp = 0;
1.277 + button = (Uint8)(ptrbuf[i].dwOfs-DIMOFS_BUTTON0)+1;
1.278 + /* Map DI button numbers to SDL */
1.279 + switch ( button ) {
1.280 + case 2: button = SDL_BUTTON_RIGHT; break;
1.281 + case 3: button = SDL_BUTTON_MIDDLE; break;
1.282 + case 4: button = SDL_BUTTON_X1; break;
1.283 + case 5: button = SDL_BUTTON_X2; break;
1.284 + default: break;
1.285 }
1.286 - state = SDL_PRESSED;
1.287 - } else {
1.288 - /* Release mouse after all mouse-ups */
1.289 - if ( --mouse_pressed <= 0 ) {
1.290 - ReleaseCapture();
1.291 - mouse_pressed = 0;
1.292 + if ( ptrbuf[i].dwData & 0x80 ) {
1.293 + /* Grab mouse so we get mouse-up */
1.294 + if ( ++mouse_pressed > 0 ) {
1.295 + SetCapture(SDL_Window);
1.296 + }
1.297 + state = SDL_PRESSED;
1.298 + } else {
1.299 + /* Release mouse after all mouse-ups */
1.300 + if ( --mouse_pressed <= 0 ) {
1.301 + ReleaseCapture();
1.302 + mouse_pressed = 0;
1.303 + }
1.304 + state = SDL_RELEASED;
1.305 }
1.306 - state = SDL_RELEASED;
1.307 - }
1.308 - if ( mouse_buttons_swapped ) {
1.309 - if ( button == 1 ) button = 3;
1.310 - else
1.311 - if ( button == 3 ) button = 1;
1.312 - }
1.313 - posted = SDL_PrivateMouseButton(state, button,
1.314 - 0, 0);
1.315 - break;
1.316 + if ( mouse_buttons_swapped ) {
1.317 + if ( button == 1 ) button = 3;
1.318 + else
1.319 + if ( button == 3 ) button = 1;
1.320 + }
1.321 + posted = SDL_PrivateMouseButton(state, button,
1.322 + 0, 0);
1.323 + break;
1.324 + }
1.325 }
1.326 - }
1.327 - if ( xrel || yrel ) {
1.328 - post_mouse_motion(1, xrel, yrel);
1.329 + if ( xrel || yrel ) {
1.330 + post_mouse_motion(1, xrel, yrel);
1.331 + }
1.332 }
1.333 }
1.334