mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove mouse state globals, use parameters instead
This commit is contained in:
parent
029da58459
commit
1338f7cedd
20
src/input.c
20
src/input.c
|
@ -39,14 +39,6 @@
|
|||
#include "world/scenery.h"
|
||||
#include "openrct2.h"
|
||||
|
||||
enum {
|
||||
MOUSE_STATE_RELEASED,
|
||||
MOUSE_STATE_LEFT_PRESS,
|
||||
MOUSE_STATE_LEFT_RELEASE,
|
||||
MOUSE_STATE_RIGHT_PRESS,
|
||||
MOUSE_STATE_RIGHT_RELEASE
|
||||
};
|
||||
|
||||
typedef struct rct_mouse_data {
|
||||
uint32 x;
|
||||
uint32 y;
|
||||
|
@ -138,7 +130,7 @@ void game_handle_input()
|
|||
sub_6EA73F();
|
||||
|
||||
int x, y, state;
|
||||
while ((state = game_get_next_input(&x, &y)) != 0) {
|
||||
while ((state = game_get_next_input(&x, &y)) != MOUSE_STATE_RELEASED) {
|
||||
game_handle_input_mouse(x, y, state & 0xFF);
|
||||
}
|
||||
|
||||
|
@ -1111,8 +1103,7 @@ void process_mouse_over(int x, int y)
|
|||
break;
|
||||
|
||||
case WWT_SCROLL:
|
||||
RCT2_GLOBAL(0x9DE558, uint16) = x;
|
||||
RCT2_GLOBAL(0x9DE55A, uint16) = y;
|
||||
{
|
||||
int output_scroll_area, scroll_id;
|
||||
int scroll_x, scroll_y;
|
||||
widget_scroll_get_part(window, &window->widgets[widgetId], x, y, &scroll_x, &scroll_y, &output_scroll_area, &scroll_id);
|
||||
|
@ -1127,6 +1118,7 @@ void process_mouse_over(int x, int y)
|
|||
if (cursorId == -1)
|
||||
cursorId = CURSOR_ARROW;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cursorId = window_event_cursor_call(window, widgetId, x, y);
|
||||
if (cursorId == -1)
|
||||
|
@ -1598,7 +1590,7 @@ void invalidate_scroll()
|
|||
/**
|
||||
* rct2: 0x00406C96
|
||||
*/
|
||||
void store_mouse_input(int state)
|
||||
void store_mouse_input(int state, int x, int y)
|
||||
{
|
||||
uint32 writeIndex = _mouseInputQueueWriteIndex;
|
||||
uint32 nextWriteIndex = (writeIndex + 1) % countof(_mouseInputQueue);
|
||||
|
@ -1606,8 +1598,8 @@ void store_mouse_input(int state)
|
|||
// Check if the queue is full
|
||||
if (nextWriteIndex != _mouseInputQueueReadIndex) {
|
||||
rct_mouse_data *item = &_mouseInputQueue[writeIndex];
|
||||
item->x = RCT2_GLOBAL(0x01424318, uint32);
|
||||
item->y = RCT2_GLOBAL(0x0142431C, uint32);
|
||||
item->x = x;
|
||||
item->y = y;
|
||||
item->state = state;
|
||||
|
||||
_mouseInputQueueWriteIndex = nextWriteIndex;
|
||||
|
|
10
src/input.h
10
src/input.h
|
@ -62,6 +62,14 @@ enum {
|
|||
PLACE_OBJECT_MODIFIER_COPY_Z = (1 << 1),
|
||||
};
|
||||
|
||||
enum MOUSE_STATE {
|
||||
MOUSE_STATE_RELEASED,
|
||||
MOUSE_STATE_LEFT_PRESS,
|
||||
MOUSE_STATE_LEFT_RELEASE,
|
||||
MOUSE_STATE_RIGHT_PRESS,
|
||||
MOUSE_STATE_RIGHT_RELEASE
|
||||
};
|
||||
|
||||
typedef struct widget_ref {
|
||||
rct_windowclass window_classification;
|
||||
rct_windownumber window_number;
|
||||
|
@ -91,7 +99,7 @@ void title_handle_keyboard_input();
|
|||
void game_handle_input();
|
||||
void game_handle_keyboard_input();
|
||||
|
||||
void store_mouse_input(int state);
|
||||
void store_mouse_input(int state, int x, int y);
|
||||
|
||||
void input_window_position_begin(rct_window *w, int widgetIndex, int x, int y);
|
||||
|
||||
|
|
|
@ -340,11 +340,12 @@ void platform_process_messages()
|
|||
gCursorState.wheel += e.wheel.y * 128;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
RCT2_GLOBAL(0x01424318, int) = (int)(e.button.x / gConfigGeneral.window_scale);
|
||||
RCT2_GLOBAL(0x0142431C, int) = (int)(e.button.y / gConfigGeneral.window_scale);
|
||||
{
|
||||
int x = (int)(e.button.x / gConfigGeneral.window_scale);
|
||||
int y = (int)(e.button.y / gConfigGeneral.window_scale);
|
||||
switch (e.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
store_mouse_input(1);
|
||||
store_mouse_input(MOUSE_STATE_LEFT_PRESS, x, y);
|
||||
gCursorState.left = CURSOR_PRESSED;
|
||||
gCursorState.old = 1;
|
||||
break;
|
||||
|
@ -352,18 +353,20 @@ void platform_process_messages()
|
|||
gCursorState.middle = CURSOR_PRESSED;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
store_mouse_input(3);
|
||||
store_mouse_input(MOUSE_STATE_RIGHT_PRESS, x, y);
|
||||
gCursorState.right = CURSOR_PRESSED;
|
||||
gCursorState.old = 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
RCT2_GLOBAL(0x01424318, int) = (int)(e.button.x / gConfigGeneral.window_scale);
|
||||
RCT2_GLOBAL(0x0142431C, int) = (int)(e.button.y / gConfigGeneral.window_scale);
|
||||
{
|
||||
int x = (int)(e.button.x / gConfigGeneral.window_scale);
|
||||
int y = (int)(e.button.y / gConfigGeneral.window_scale);
|
||||
switch (e.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
store_mouse_input(2);
|
||||
store_mouse_input(MOUSE_STATE_LEFT_RELEASE, x, y);
|
||||
gCursorState.left = CURSOR_RELEASED;
|
||||
gCursorState.old = 3;
|
||||
break;
|
||||
|
@ -371,12 +374,13 @@ void platform_process_messages()
|
|||
gCursorState.middle = CURSOR_RELEASED;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
store_mouse_input(4);
|
||||
store_mouse_input(MOUSE_STATE_RIGHT_RELEASE, x, y);
|
||||
gCursorState.right = CURSOR_RELEASED;
|
||||
gCursorState.old = 4;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Apple sends touchscreen events for trackpads, so ignore these events on macOS
|
||||
#ifndef __MACOSX__
|
||||
case SDL_FINGERMOTION:
|
||||
|
@ -387,39 +391,43 @@ void platform_process_messages()
|
|||
gCursorState.y = (int)(e.tfinger.y * gScreenHeight);
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
RCT2_GLOBAL(0x01424318, int) = (int)(e.tfinger.x * gScreenWidth);
|
||||
RCT2_GLOBAL(0x0142431C, int) = (int)(e.tfinger.y * gScreenHeight);
|
||||
{
|
||||
int x = (int)(e.tfinger.x * gScreenWidth);
|
||||
int y = (int)(e.tfinger.y * gScreenHeight);
|
||||
|
||||
gCursorState.touchIsDouble = (!gCursorState.touchIsDouble
|
||||
&& e.tfinger.timestamp - gCursorState.touchDownTimestamp < TOUCH_DOUBLE_TIMEOUT);
|
||||
|
||||
if (gCursorState.touchIsDouble) {
|
||||
store_mouse_input(3);
|
||||
store_mouse_input(MOUSE_STATE_RIGHT_PRESS, x, y);
|
||||
gCursorState.right = CURSOR_PRESSED;
|
||||
gCursorState.old = 2;
|
||||
} else {
|
||||
store_mouse_input(1);
|
||||
store_mouse_input(MOUSE_STATE_LEFT_PRESS, x, y);
|
||||
gCursorState.left = CURSOR_PRESSED;
|
||||
gCursorState.old = 1;
|
||||
}
|
||||
gCursorState.touch = true;
|
||||
gCursorState.touchDownTimestamp = e.tfinger.timestamp;
|
||||
break;
|
||||
}
|
||||
case SDL_FINGERUP:
|
||||
RCT2_GLOBAL(0x01424318, int) = (int)(e.tfinger.x * gScreenWidth);
|
||||
RCT2_GLOBAL(0x0142431C, int) = (int)(e.tfinger.y * gScreenHeight);
|
||||
{
|
||||
int x = (int)(e.tfinger.x * gScreenWidth);
|
||||
int y = (int)(e.tfinger.y * gScreenHeight);
|
||||
|
||||
if (gCursorState.touchIsDouble) {
|
||||
store_mouse_input(4);
|
||||
store_mouse_input(MOUSE_STATE_RIGHT_RELEASE, x, y);
|
||||
gCursorState.left = CURSOR_RELEASED;
|
||||
gCursorState.old = 4;
|
||||
} else {
|
||||
store_mouse_input(2);
|
||||
store_mouse_input(MOUSE_STATE_LEFT_RELEASE, x, y);
|
||||
gCursorState.left = CURSOR_RELEASED;
|
||||
gCursorState.old = 3;
|
||||
}
|
||||
gCursorState.touch = true;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case SDL_KEYDOWN:
|
||||
if (gTextInputCompositionActive) break;
|
||||
|
|
Loading…
Reference in New Issue