mirror of https://github.com/OpenRCT2/OpenRCT2.git
Make CursorState store a ScreenCoordsXY object
This commit is contained in:
parent
9d09f1b95c
commit
2cd3add373
|
@ -367,8 +367,8 @@ public:
|
|||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
_cursorState.x = (int32_t)(e.motion.x / gConfigGeneral.window_scale);
|
||||
_cursorState.y = (int32_t)(e.motion.y / gConfigGeneral.window_scale);
|
||||
_cursorState.position = { static_cast<int32_t>(e.motion.x / gConfigGeneral.window_scale),
|
||||
static_cast<int32_t>(e.motion.y / gConfigGeneral.window_scale) };
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (_inGameConsole.IsOpen())
|
||||
|
@ -435,8 +435,8 @@ public:
|
|||
// Apple sends touchscreen events for trackpads, so ignore these events on macOS
|
||||
#ifndef __MACOSX__
|
||||
case SDL_FINGERMOTION:
|
||||
_cursorState.x = (int32_t)(e.tfinger.x * _width);
|
||||
_cursorState.y = (int32_t)(e.tfinger.y * _height);
|
||||
_cursorState.position = { static_cast<int32_t>(e.tfinger.x * _width),
|
||||
static_cast<int32_t>(e.tfinger.y * _height) };
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
{
|
||||
|
|
|
@ -145,8 +145,7 @@ static int32_t game_get_next_input(ScreenCoordsXY& screenCoords)
|
|||
if (input == nullptr)
|
||||
{
|
||||
const CursorState* cursorState = context_get_cursor_state();
|
||||
screenCoords.x = cursorState->x;
|
||||
screenCoords.y = cursorState->y;
|
||||
screenCoords = cursorState->position;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -1578,15 +1577,15 @@ void game_handle_edge_scroll()
|
|||
|
||||
// Scroll left / right
|
||||
const CursorState* cursorState = context_get_cursor_state();
|
||||
if (cursorState->x == 0)
|
||||
if (cursorState->position.x == 0)
|
||||
scrollX = -1;
|
||||
else if (cursorState->x >= context_get_width() - 1)
|
||||
else if (cursorState->position.x >= context_get_width() - 1)
|
||||
scrollX = 1;
|
||||
|
||||
// Scroll up / down
|
||||
if (cursorState->y == 0)
|
||||
if (cursorState->position.y == 0)
|
||||
scrollY = -1;
|
||||
else if (cursorState->y >= context_get_height() - 1)
|
||||
else if (cursorState->position.y >= context_get_height() - 1)
|
||||
scrollY = 1;
|
||||
|
||||
input_scroll_viewport(ScreenCoordsXY(scrollX, scrollY));
|
||||
|
|
|
@ -533,7 +533,7 @@ static bool window_other_wheel_input(rct_window* w, rct_widgetindex widgetIndex,
|
|||
void window_all_wheel_input()
|
||||
{
|
||||
// Get wheel value
|
||||
CursorState* cursorState = (CursorState*)context_get_cursor_state();
|
||||
auto cursorState = context_get_cursor_state();
|
||||
int32_t absolute_wheel = cursorState->wheel;
|
||||
int32_t relative_wheel = absolute_wheel - _previousAbsoluteWheel;
|
||||
int32_t pixel_scroll = relative_wheel * WINDOW_SCROLL_PIXELS;
|
||||
|
@ -545,7 +545,7 @@ void window_all_wheel_input()
|
|||
// Check window cursor is over
|
||||
if (!(input_test_flag(INPUT_FLAG_5)))
|
||||
{
|
||||
rct_window* w = window_find_from_point(ScreenCoordsXY(cursorState->x, cursorState->y));
|
||||
rct_window* w = window_find_from_point(cursorState->position);
|
||||
if (w != nullptr)
|
||||
{
|
||||
// Check if main window
|
||||
|
@ -556,7 +556,7 @@ void window_all_wheel_input()
|
|||
}
|
||||
|
||||
// Check scroll view, cursor is over
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, ScreenCoordsXY(cursorState->x, cursorState->y));
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, cursorState->position);
|
||||
if (widgetIndex != -1)
|
||||
{
|
||||
rct_widget* widget = &w->widgets[widgetIndex];
|
||||
|
|
|
@ -698,7 +698,7 @@ static void window_editor_object_selection_scroll_mousedown(rct_window* w, int32
|
|||
w->Invalidate();
|
||||
|
||||
const CursorState* state = context_get_cursor_state();
|
||||
audio_play_sound(SoundId::Click1, 0, state->x);
|
||||
audio_play_sound(SoundId::Click1, 0, state->position.x);
|
||||
|
||||
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
||||
{
|
||||
|
|
|
@ -126,10 +126,10 @@ rct_window* window_error_open(rct_string_id title, rct_string_id message)
|
|||
int32_t screenWidth = context_get_width();
|
||||
int32_t screenHeight = context_get_height();
|
||||
const CursorState* state = context_get_cursor_state();
|
||||
x = state->x - (width / 2);
|
||||
x = state->position.x - (width / 2);
|
||||
x = std::clamp(x, 0, screenWidth);
|
||||
|
||||
y = state->y + 26;
|
||||
y = state->position.y + 26;
|
||||
y = std::max(22, y);
|
||||
maxY = screenHeight - height;
|
||||
if (y > maxY)
|
||||
|
|
|
@ -59,8 +59,7 @@ static rct_window_event_list window_map_tooltip_events = {
|
|||
|
||||
#define MAP_TOOLTIP_ARGS
|
||||
|
||||
static int32_t _lastCursorX;
|
||||
static int32_t _lastCursorY;
|
||||
static ScreenCoordsXY _lastCursor;
|
||||
static int32_t _cursorHoldDuration;
|
||||
|
||||
static void window_map_tooltip_open();
|
||||
|
@ -78,19 +77,15 @@ void window_map_tooltip_update_visibility()
|
|||
return;
|
||||
}
|
||||
|
||||
int32_t cursorX, cursorY;
|
||||
|
||||
const CursorState* state = context_get_cursor_state();
|
||||
cursorX = state->x;
|
||||
cursorY = state->y;
|
||||
auto cursor = state->position;
|
||||
|
||||
// Check for cursor movement
|
||||
_cursorHoldDuration++;
|
||||
if (abs(cursorX - _lastCursorX) > 5 || abs(cursorY - _lastCursorY) > 5 || (input_test_flag(INPUT_FLAG_5)))
|
||||
if (abs(cursor.x - _lastCursor.x) > 5 || abs(cursor.y - _lastCursor.y) > 5 || (input_test_flag(INPUT_FLAG_5)))
|
||||
_cursorHoldDuration = 0;
|
||||
|
||||
_lastCursorX = cursorX;
|
||||
_lastCursorY = cursorY;
|
||||
_lastCursor = cursor;
|
||||
|
||||
// Show or hide tooltip
|
||||
rct_string_id stringId;
|
||||
|
@ -116,27 +111,25 @@ void window_map_tooltip_update_visibility()
|
|||
static void window_map_tooltip_open()
|
||||
{
|
||||
rct_window* w;
|
||||
int32_t x, y, width, height;
|
||||
|
||||
width = 200;
|
||||
height = 44;
|
||||
constexpr int32_t width = 200;
|
||||
constexpr int32_t height = 44;
|
||||
const CursorState* state = context_get_cursor_state();
|
||||
x = state->x - (width / 2);
|
||||
y = state->y + 15;
|
||||
ScreenCoordsXY pos = { state->position.x - (width / 2), state->position.y + 15 };
|
||||
|
||||
w = window_find_by_class(WC_MAP_TOOLTIP);
|
||||
if (w == nullptr)
|
||||
{
|
||||
w = window_create(
|
||||
ScreenCoordsXY(x, y), width, height, &window_map_tooltip_events, WC_MAP_TOOLTIP,
|
||||
pos, width, height, &window_map_tooltip_events, WC_MAP_TOOLTIP,
|
||||
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
|
||||
w->widgets = window_map_tooltip_widgets;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->Invalidate();
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
w->x = pos.x;
|
||||
w->y = pos.y;
|
||||
w->width = width;
|
||||
w->height = height;
|
||||
}
|
||||
|
|
|
@ -3841,7 +3841,7 @@ void ride_construction_tooldown_construct(ScreenCoordsXY screenCoords)
|
|||
|| errorText == STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND || errorText == STR_TOO_HIGH_FOR_SUPPORTS
|
||||
|| zAttempts == 0 || z < 0)
|
||||
{
|
||||
audio_play_sound(SoundId::Error, 0, state->x);
|
||||
audio_play_sound(SoundId::Error, 0, state->position.x);
|
||||
w = window_find_by_class(WC_RIDE_CONSTRUCTION);
|
||||
if (w != nullptr)
|
||||
{
|
||||
|
@ -3914,7 +3914,7 @@ void ride_construction_tooldown_construct(ScreenCoordsXY screenCoords)
|
|||
_currentTrackAlternative = saveCurrentTrackAlternative;
|
||||
_currentTrackLiftHill = saveCurrentTrackLiftHill;
|
||||
|
||||
audio_play_sound(SoundId::Error, 0, state->x);
|
||||
audio_play_sound(SoundId::Error, 0, state->position.x);
|
||||
break;
|
||||
}
|
||||
else if (zAttempts >= 0)
|
||||
|
|
|
@ -748,15 +748,14 @@ static void window_scenery_periodic_update(rct_window* w)
|
|||
static void window_scenery_update(rct_window* w)
|
||||
{
|
||||
const CursorState* state = context_get_cursor_state();
|
||||
rct_window* other = window_find_from_point(ScreenCoordsXY(state->x, state->y));
|
||||
rct_window* other = window_find_from_point(state->position);
|
||||
if (other == w)
|
||||
{
|
||||
int32_t window_x = state->x - w->x + 26;
|
||||
int32_t window_y = state->y - w->y;
|
||||
ScreenCoordsXY window = state->position - ScreenCoordsXY{ w->x + 26, w->y };
|
||||
|
||||
if (window_y < 44 || window_x <= w->width)
|
||||
if (window.y < 44 || window.x <= w->width)
|
||||
{
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, ScreenCoordsXY(state->x, state->y));
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, state->position);
|
||||
if (widgetIndex >= WIDX_SCENERY_TAB_CONTENT_PANEL)
|
||||
{
|
||||
w->scenery.hover_counter++;
|
||||
|
|
|
@ -28,7 +28,7 @@ using rct_windowclass = uint8_t;
|
|||
|
||||
struct CursorState
|
||||
{
|
||||
int32_t x, y;
|
||||
ScreenCoordsXY position;
|
||||
uint8_t left, middle, right, any;
|
||||
int32_t wheel;
|
||||
int32_t old;
|
||||
|
|
Loading…
Reference in New Issue