Add op_get_mouse_buttons

This commit is contained in:
Alexander Batalov 2023-04-20 10:31:32 +03:00
parent cf4921de1e
commit 129361836f
3 changed files with 21 additions and 6 deletions

View File

@ -54,7 +54,7 @@ static unsigned char* _mouse_fptr = NULL;
static double gMouseSensitivity = 1.0;
// 0x51E2AC
static int gMouseButtonsState = 0;
static int last_buttons = 0;
// 0x6AC790
static bool gCursorIsHidden;
@ -415,7 +415,7 @@ void _mouse_info()
}
x = 0;
y = 0;
buttons = gMouseButtonsState;
buttons = last_buttons;
}
_mouse_simulate_input(x, y, buttons);
@ -447,7 +447,7 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons)
return;
}
if (delta_x || delta_y || buttons != gMouseButtonsState) {
if (delta_x || delta_y || buttons != last_buttons) {
if (gVcrState == 0) {
if (_vcr_buffer_index == VCR_BUFFER_CAPACITY - 1) {
vcrDump();
@ -464,13 +464,13 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons)
_vcr_buffer_index++;
}
} else {
if (gMouseButtonsState == 0) {
if (last_buttons == 0) {
if (!_mouse_idling) {
_mouse_idle_start_time = getTicks();
_mouse_idling = 1;
}
gMouseButtonsState = 0;
last_buttons = 0;
_raw_buttons = 0;
gMouseEvent = 0;
@ -479,7 +479,7 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons)
}
_mouse_idling = 0;
gMouseButtonsState = buttons;
last_buttons = buttons;
previousEvent = gMouseEvent;
gMouseEvent = 0;
@ -703,4 +703,9 @@ void convertMouseWheelToArrowKey(int* keyCodePtr)
}
}
int mouse_get_last_buttons()
{
return last_buttons;
}
} // namespace fallout

View File

@ -52,6 +52,7 @@ void mouseGetPositionInWindow(int win, int* x, int* y);
bool mouseHitTestInWindow(int win, int left, int top, int right, int bottom);
void mouseGetWheel(int* x, int* y);
void convertMouseWheelToArrowKey(int* keyCodePtr);
int mouse_get_last_buttons();
} // namespace fallout

View File

@ -396,6 +396,14 @@ static void opGetMouseY(Program* program)
programStackPushInteger(program, y);
}
// get_mouse_buttons
static void op_get_mouse_buttons(Program* program)
{
// CE: Implementation is slightly different - it does not handle middle
// mouse button.
programStackPushInteger(program, mouse_get_last_buttons());
}
// get_screen_width
static void opGetScreenWidth(Program* program)
{
@ -540,6 +548,7 @@ void sfallOpcodesInit()
interpreterRegisterOpcode(0x821A, opSetWeaponAmmoCount);
interpreterRegisterOpcode(0x821C, opGetMouseX);
interpreterRegisterOpcode(0x821D, opGetMouseY);
interpreterRegisterOpcode(0x821E, op_get_mouse_buttons);
interpreterRegisterOpcode(0x8220, opGetScreenWidth);
interpreterRegisterOpcode(0x8221, opGetScreenHeight);
interpreterRegisterOpcode(0x8237, opParseInt);