Completely reworked mouse handling - should now be smoother due to there no longer being a multi-layered game of telephone going on with all the various interim coordinate counters, also rewritten the serial mouse emulation ground ground up.
This commit is contained in:
@@ -21,17 +21,16 @@
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <86box/86box.h>
|
||||
#include <86box/mouse.h>
|
||||
#include <86box/pic.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/win.h>
|
||||
|
||||
int mouse_capture;
|
||||
double mouse_sensitivity = 1.0; /* Unused. */
|
||||
double mouse_x_error = 0.0; /* Unused. */
|
||||
double mouse_y_error = 0.0; /* Unused. */
|
||||
|
||||
typedef struct {
|
||||
int buttons;
|
||||
@@ -65,53 +64,62 @@ void
|
||||
win_mouse_handle(PRAWINPUT raw)
|
||||
{
|
||||
RAWMOUSE state = raw->data.mouse;
|
||||
static int x;
|
||||
static int y;
|
||||
static int x, delta_x;
|
||||
static int y, delta_y;
|
||||
static int b, delta_z;
|
||||
|
||||
b = mouse_get_buttons_ex();
|
||||
|
||||
/* read mouse buttons and wheel */
|
||||
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
|
||||
mousestate.buttons |= 1;
|
||||
b |= 1;
|
||||
else if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP)
|
||||
mousestate.buttons &= ~1;
|
||||
b &= ~1;
|
||||
|
||||
if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)
|
||||
mousestate.buttons |= 4;
|
||||
b |= 4;
|
||||
else if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP)
|
||||
mousestate.buttons &= ~4;
|
||||
b &= ~4;
|
||||
|
||||
if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN)
|
||||
mousestate.buttons |= 2;
|
||||
b |= 2;
|
||||
else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
|
||||
mousestate.buttons &= ~2;
|
||||
b &= ~2;
|
||||
|
||||
if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
|
||||
mousestate.buttons |= 8;
|
||||
b |= 8;
|
||||
else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP)
|
||||
mousestate.buttons &= ~8;
|
||||
b &= ~8;
|
||||
|
||||
if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
|
||||
mousestate.buttons |= 16;
|
||||
b |= 16;
|
||||
else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP)
|
||||
mousestate.buttons &= ~16;
|
||||
b &= ~16;
|
||||
|
||||
mouse_set_buttons_ex(b);
|
||||
|
||||
if (state.usButtonFlags & RI_MOUSE_WHEEL) {
|
||||
mousestate.dwheel += (SHORT) state.usButtonData / 120;
|
||||
}
|
||||
delta_z = (SHORT) state.usButtonData / 120;
|
||||
mouse_set_z(delta_z);
|
||||
} else
|
||||
delta_z = 0;
|
||||
|
||||
if (state.usFlags & MOUSE_MOVE_ABSOLUTE) {
|
||||
/* absolute mouse, i.e. RDP or VNC
|
||||
* seems to work fine for RDP on Windows 10
|
||||
* Not sure about other environments.
|
||||
*/
|
||||
mousestate.dx += (state.lLastX - x) / 25;
|
||||
mousestate.dy += (state.lLastY - y) / 25;
|
||||
delta_x = (state.lLastX - x) / 25;
|
||||
delta_y = (state.lLastY - y) / 25;
|
||||
x = state.lLastX;
|
||||
y = state.lLastY;
|
||||
} else {
|
||||
/* relative mouse, i.e. regular mouse */
|
||||
mousestate.dx += state.lLastX;
|
||||
mousestate.dy += state.lLastY;
|
||||
delta_x = state.lLastX;
|
||||
delta_y = state.lLastY;
|
||||
}
|
||||
|
||||
mouse_scale(delta_x, delta_y);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -124,27 +132,3 @@ win_mouse_close(void)
|
||||
ridev.usUsage = 0x02;
|
||||
RegisterRawInputDevices(&ridev, 1, sizeof(ridev));
|
||||
}
|
||||
|
||||
void
|
||||
mouse_poll(void)
|
||||
{
|
||||
static int b = 0;
|
||||
if (mouse_capture || video_fullscreen) {
|
||||
if (mousestate.dx != 0 || mousestate.dy != 0 || mousestate.dwheel != 0) {
|
||||
mouse_x += mousestate.dx;
|
||||
mouse_y += mousestate.dy;
|
||||
mouse_z = mousestate.dwheel;
|
||||
|
||||
mousestate.dx = 0;
|
||||
mousestate.dy = 0;
|
||||
mousestate.dwheel = 0;
|
||||
|
||||
// pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z);
|
||||
}
|
||||
|
||||
if (b != mousestate.buttons) {
|
||||
mouse_buttons = mousestate.buttons;
|
||||
b = mousestate.buttons;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user