Remove mouse state globals, use parameters instead

This commit is contained in:
Ted John 2016-09-05 20:50:33 +01:00
parent 029da58459
commit 1338f7cedd
3 changed files with 40 additions and 32 deletions

View File

@ -39,14 +39,6 @@
#include "world/scenery.h" #include "world/scenery.h"
#include "openrct2.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 { typedef struct rct_mouse_data {
uint32 x; uint32 x;
uint32 y; uint32 y;
@ -138,7 +130,7 @@ void game_handle_input()
sub_6EA73F(); sub_6EA73F();
int x, y, state; 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); game_handle_input_mouse(x, y, state & 0xFF);
} }
@ -1111,8 +1103,7 @@ void process_mouse_over(int x, int y)
break; break;
case WWT_SCROLL: case WWT_SCROLL:
RCT2_GLOBAL(0x9DE558, uint16) = x; {
RCT2_GLOBAL(0x9DE55A, uint16) = y;
int output_scroll_area, scroll_id; int output_scroll_area, scroll_id;
int scroll_x, scroll_y; int scroll_x, scroll_y;
widget_scroll_get_part(window, &window->widgets[widgetId], x, y, &scroll_x, &scroll_y, &output_scroll_area, &scroll_id); 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) if (cursorId == -1)
cursorId = CURSOR_ARROW; cursorId = CURSOR_ARROW;
break; break;
}
default: default:
cursorId = window_event_cursor_call(window, widgetId, x, y); cursorId = window_event_cursor_call(window, widgetId, x, y);
if (cursorId == -1) if (cursorId == -1)
@ -1598,7 +1590,7 @@ void invalidate_scroll()
/** /**
* rct2: 0x00406C96 * rct2: 0x00406C96
*/ */
void store_mouse_input(int state) void store_mouse_input(int state, int x, int y)
{ {
uint32 writeIndex = _mouseInputQueueWriteIndex; uint32 writeIndex = _mouseInputQueueWriteIndex;
uint32 nextWriteIndex = (writeIndex + 1) % countof(_mouseInputQueue); uint32 nextWriteIndex = (writeIndex + 1) % countof(_mouseInputQueue);
@ -1606,8 +1598,8 @@ void store_mouse_input(int state)
// Check if the queue is full // Check if the queue is full
if (nextWriteIndex != _mouseInputQueueReadIndex) { if (nextWriteIndex != _mouseInputQueueReadIndex) {
rct_mouse_data *item = &_mouseInputQueue[writeIndex]; rct_mouse_data *item = &_mouseInputQueue[writeIndex];
item->x = RCT2_GLOBAL(0x01424318, uint32); item->x = x;
item->y = RCT2_GLOBAL(0x0142431C, uint32); item->y = y;
item->state = state; item->state = state;
_mouseInputQueueWriteIndex = nextWriteIndex; _mouseInputQueueWriteIndex = nextWriteIndex;

View File

@ -62,6 +62,14 @@ enum {
PLACE_OBJECT_MODIFIER_COPY_Z = (1 << 1), 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 { typedef struct widget_ref {
rct_windowclass window_classification; rct_windowclass window_classification;
rct_windownumber window_number; rct_windownumber window_number;
@ -91,7 +99,7 @@ void title_handle_keyboard_input();
void game_handle_input(); void game_handle_input();
void game_handle_keyboard_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); void input_window_position_begin(rct_window *w, int widgetIndex, int x, int y);

View File

@ -340,11 +340,12 @@ void platform_process_messages()
gCursorState.wheel += e.wheel.y * 128; gCursorState.wheel += e.wheel.y * 128;
break; break;
case SDL_MOUSEBUTTONDOWN: 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) { switch (e.button.button) {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
store_mouse_input(1); store_mouse_input(MOUSE_STATE_LEFT_PRESS, x, y);
gCursorState.left = CURSOR_PRESSED; gCursorState.left = CURSOR_PRESSED;
gCursorState.old = 1; gCursorState.old = 1;
break; break;
@ -352,18 +353,20 @@ void platform_process_messages()
gCursorState.middle = CURSOR_PRESSED; gCursorState.middle = CURSOR_PRESSED;
break; break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
store_mouse_input(3); store_mouse_input(MOUSE_STATE_RIGHT_PRESS, x, y);
gCursorState.right = CURSOR_PRESSED; gCursorState.right = CURSOR_PRESSED;
gCursorState.old = 2; gCursorState.old = 2;
break; break;
} }
break; break;
}
case SDL_MOUSEBUTTONUP: 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) { switch (e.button.button) {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
store_mouse_input(2); store_mouse_input(MOUSE_STATE_LEFT_RELEASE, x, y);
gCursorState.left = CURSOR_RELEASED; gCursorState.left = CURSOR_RELEASED;
gCursorState.old = 3; gCursorState.old = 3;
break; break;
@ -371,12 +374,13 @@ void platform_process_messages()
gCursorState.middle = CURSOR_RELEASED; gCursorState.middle = CURSOR_RELEASED;
break; break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
store_mouse_input(4); store_mouse_input(MOUSE_STATE_RIGHT_RELEASE, x, y);
gCursorState.right = CURSOR_RELEASED; gCursorState.right = CURSOR_RELEASED;
gCursorState.old = 4; gCursorState.old = 4;
break; break;
} }
break; break;
}
// Apple sends touchscreen events for trackpads, so ignore these events on macOS // Apple sends touchscreen events for trackpads, so ignore these events on macOS
#ifndef __MACOSX__ #ifndef __MACOSX__
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
@ -387,39 +391,43 @@ void platform_process_messages()
gCursorState.y = (int)(e.tfinger.y * gScreenHeight); gCursorState.y = (int)(e.tfinger.y * gScreenHeight);
break; break;
case SDL_FINGERDOWN: 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 gCursorState.touchIsDouble = (!gCursorState.touchIsDouble
&& e.tfinger.timestamp - gCursorState.touchDownTimestamp < TOUCH_DOUBLE_TIMEOUT); && e.tfinger.timestamp - gCursorState.touchDownTimestamp < TOUCH_DOUBLE_TIMEOUT);
if (gCursorState.touchIsDouble) { if (gCursorState.touchIsDouble) {
store_mouse_input(3); store_mouse_input(MOUSE_STATE_RIGHT_PRESS, x, y);
gCursorState.right = CURSOR_PRESSED; gCursorState.right = CURSOR_PRESSED;
gCursorState.old = 2; gCursorState.old = 2;
} else { } else {
store_mouse_input(1); store_mouse_input(MOUSE_STATE_LEFT_PRESS, x, y);
gCursorState.left = CURSOR_PRESSED; gCursorState.left = CURSOR_PRESSED;
gCursorState.old = 1; gCursorState.old = 1;
} }
gCursorState.touch = true; gCursorState.touch = true;
gCursorState.touchDownTimestamp = e.tfinger.timestamp; gCursorState.touchDownTimestamp = e.tfinger.timestamp;
break; break;
}
case SDL_FINGERUP: 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) { if (gCursorState.touchIsDouble) {
store_mouse_input(4); store_mouse_input(MOUSE_STATE_RIGHT_RELEASE, x, y);
gCursorState.left = CURSOR_RELEASED; gCursorState.left = CURSOR_RELEASED;
gCursorState.old = 4; gCursorState.old = 4;
} else { } else {
store_mouse_input(2); store_mouse_input(MOUSE_STATE_LEFT_RELEASE, x, y);
gCursorState.left = CURSOR_RELEASED; gCursorState.left = CURSOR_RELEASED;
gCursorState.old = 3; gCursorState.old = 3;
} }
gCursorState.touch = true; gCursorState.touch = true;
break; break;
}
#endif #endif
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (gTextInputCompositionActive) break; if (gTextInputCompositionActive) break;