mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #10381 from tupaschoal/cursorsate-store-coords
Make CursorState store a ScreenCoordsXY object
This commit is contained in:
commit
099404b505
|
@ -367,8 +367,8 @@ public:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
_cursorState.x = (int32_t)(e.motion.x / gConfigGeneral.window_scale);
|
_cursorState.position = { static_cast<int32_t>(e.motion.x / gConfigGeneral.window_scale),
|
||||||
_cursorState.y = (int32_t)(e.motion.y / gConfigGeneral.window_scale);
|
static_cast<int32_t>(e.motion.y / gConfigGeneral.window_scale) };
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
if (_inGameConsole.IsOpen())
|
if (_inGameConsole.IsOpen())
|
||||||
|
@ -435,8 +435,8 @@ public:
|
||||||
// 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:
|
||||||
_cursorState.x = (int32_t)(e.tfinger.x * _width);
|
_cursorState.position = { static_cast<int32_t>(e.tfinger.x * _width),
|
||||||
_cursorState.y = (int32_t)(e.tfinger.y * _height);
|
static_cast<int32_t>(e.tfinger.y * _height) };
|
||||||
break;
|
break;
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,8 +144,7 @@ static int32_t game_get_next_input(ScreenCoordsXY& screenCoords)
|
||||||
if (input == nullptr)
|
if (input == nullptr)
|
||||||
{
|
{
|
||||||
const CursorState* cursorState = context_get_cursor_state();
|
const CursorState* cursorState = context_get_cursor_state();
|
||||||
screenCoords.x = cursorState->x;
|
screenCoords = cursorState->position;
|
||||||
screenCoords.y = cursorState->y;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1569,15 +1568,15 @@ void game_handle_edge_scroll()
|
||||||
|
|
||||||
// Scroll left / right
|
// Scroll left / right
|
||||||
const CursorState* cursorState = context_get_cursor_state();
|
const CursorState* cursorState = context_get_cursor_state();
|
||||||
if (cursorState->x == 0)
|
if (cursorState->position.x == 0)
|
||||||
scrollX = -1;
|
scrollX = -1;
|
||||||
else if (cursorState->x >= context_get_width() - 1)
|
else if (cursorState->position.x >= context_get_width() - 1)
|
||||||
scrollX = 1;
|
scrollX = 1;
|
||||||
|
|
||||||
// Scroll up / down
|
// Scroll up / down
|
||||||
if (cursorState->y == 0)
|
if (cursorState->position.y == 0)
|
||||||
scrollY = -1;
|
scrollY = -1;
|
||||||
else if (cursorState->y >= context_get_height() - 1)
|
else if (cursorState->position.y >= context_get_height() - 1)
|
||||||
scrollY = 1;
|
scrollY = 1;
|
||||||
|
|
||||||
input_scroll_viewport(ScreenCoordsXY(scrollX, scrollY));
|
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()
|
void window_all_wheel_input()
|
||||||
{
|
{
|
||||||
// Get wheel value
|
// Get wheel value
|
||||||
CursorState* cursorState = (CursorState*)context_get_cursor_state();
|
auto cursorState = context_get_cursor_state();
|
||||||
int32_t absolute_wheel = cursorState->wheel;
|
int32_t absolute_wheel = cursorState->wheel;
|
||||||
int32_t relative_wheel = absolute_wheel - _previousAbsoluteWheel;
|
int32_t relative_wheel = absolute_wheel - _previousAbsoluteWheel;
|
||||||
int32_t pixel_scroll = relative_wheel * WINDOW_SCROLL_PIXELS;
|
int32_t pixel_scroll = relative_wheel * WINDOW_SCROLL_PIXELS;
|
||||||
|
@ -545,7 +545,7 @@ void window_all_wheel_input()
|
||||||
// Check window cursor is over
|
// Check window cursor is over
|
||||||
if (!(input_test_flag(INPUT_FLAG_5)))
|
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)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
// Check if main window
|
// Check if main window
|
||||||
|
@ -556,7 +556,7 @@ void window_all_wheel_input()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check scroll view, cursor is over
|
// 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)
|
if (widgetIndex != -1)
|
||||||
{
|
{
|
||||||
rct_widget* widget = &w->widgets[widgetIndex];
|
rct_widget* widget = &w->widgets[widgetIndex];
|
||||||
|
|
|
@ -698,7 +698,7 @@ static void window_editor_object_selection_scroll_mousedown(rct_window* w, int32
|
||||||
w->Invalidate();
|
w->Invalidate();
|
||||||
|
|
||||||
const CursorState* state = context_get_cursor_state();
|
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)
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,7 +75,7 @@ static uint16_t _window_error_num_lines;
|
||||||
rct_window* window_error_open(rct_string_id title, rct_string_id message)
|
rct_window* window_error_open(rct_string_id title, rct_string_id message)
|
||||||
{
|
{
|
||||||
utf8* dst;
|
utf8* dst;
|
||||||
int32_t numLines, fontHeight, x, y, width, height, maxY;
|
int32_t numLines, fontHeight, width, height, maxY;
|
||||||
rct_window* w;
|
rct_window* w;
|
||||||
|
|
||||||
window_close_by_class(WC_ERROR);
|
window_close_by_class(WC_ERROR);
|
||||||
|
@ -126,20 +126,17 @@ rct_window* window_error_open(rct_string_id title, rct_string_id message)
|
||||||
int32_t screenWidth = context_get_width();
|
int32_t screenWidth = context_get_width();
|
||||||
int32_t screenHeight = context_get_height();
|
int32_t screenHeight = context_get_height();
|
||||||
const CursorState* state = context_get_cursor_state();
|
const CursorState* state = context_get_cursor_state();
|
||||||
x = state->x - (width / 2);
|
ScreenCoordsXY windowPosition = state->position - ScreenCoordsXY(width / 2, -26);
|
||||||
x = std::clamp(x, 0, screenWidth);
|
windowPosition.x = std::clamp(windowPosition.x, 0, screenWidth);
|
||||||
|
windowPosition.y = std::max(22, windowPosition.y);
|
||||||
y = state->y + 26;
|
|
||||||
y = std::max(22, y);
|
|
||||||
maxY = screenHeight - height;
|
maxY = screenHeight - height;
|
||||||
if (y > maxY)
|
if (windowPosition.y > maxY)
|
||||||
{
|
{
|
||||||
y = y - height - 40;
|
windowPosition.y = std::min(windowPosition.y - height - 40, maxY);
|
||||||
y = std::min(y, maxY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w = window_create(
|
w = window_create(
|
||||||
ScreenCoordsXY(x, y), width, height, &window_error_events, WC_ERROR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_RESIZABLE);
|
windowPosition, width, height, &window_error_events, WC_ERROR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_RESIZABLE);
|
||||||
w->widgets = window_error_widgets;
|
w->widgets = window_error_widgets;
|
||||||
w->error.var_480 = 0;
|
w->error.var_480 = 0;
|
||||||
if (!gDisableErrorWindowSound)
|
if (!gDisableErrorWindowSound)
|
||||||
|
|
|
@ -59,8 +59,7 @@ static rct_window_event_list window_map_tooltip_events = {
|
||||||
|
|
||||||
#define MAP_TOOLTIP_ARGS
|
#define MAP_TOOLTIP_ARGS
|
||||||
|
|
||||||
static int32_t _lastCursorX;
|
static ScreenCoordsXY _lastCursor;
|
||||||
static int32_t _lastCursorY;
|
|
||||||
static int32_t _cursorHoldDuration;
|
static int32_t _cursorHoldDuration;
|
||||||
|
|
||||||
static void window_map_tooltip_open();
|
static void window_map_tooltip_open();
|
||||||
|
@ -78,19 +77,16 @@ void window_map_tooltip_update_visibility()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cursorX, cursorY;
|
|
||||||
|
|
||||||
const CursorState* state = context_get_cursor_state();
|
const CursorState* state = context_get_cursor_state();
|
||||||
cursorX = state->x;
|
auto cursor = state->position;
|
||||||
cursorY = state->y;
|
auto cursorChange = cursor - _lastCursor;
|
||||||
|
|
||||||
// Check for cursor movement
|
// Check for cursor movement
|
||||||
_cursorHoldDuration++;
|
_cursorHoldDuration++;
|
||||||
if (abs(cursorX - _lastCursorX) > 5 || abs(cursorY - _lastCursorY) > 5 || (input_test_flag(INPUT_FLAG_5)))
|
if (abs(cursorChange.x) > 5 || abs(cursorChange.y) > 5 || (input_test_flag(INPUT_FLAG_5)))
|
||||||
_cursorHoldDuration = 0;
|
_cursorHoldDuration = 0;
|
||||||
|
|
||||||
_lastCursorX = cursorX;
|
_lastCursor = cursor;
|
||||||
_lastCursorY = cursorY;
|
|
||||||
|
|
||||||
// Show or hide tooltip
|
// Show or hide tooltip
|
||||||
rct_string_id stringId;
|
rct_string_id stringId;
|
||||||
|
@ -116,27 +112,25 @@ void window_map_tooltip_update_visibility()
|
||||||
static void window_map_tooltip_open()
|
static void window_map_tooltip_open()
|
||||||
{
|
{
|
||||||
rct_window* w;
|
rct_window* w;
|
||||||
int32_t x, y, width, height;
|
|
||||||
|
|
||||||
width = 200;
|
constexpr int32_t width = 200;
|
||||||
height = 44;
|
constexpr int32_t height = 44;
|
||||||
const CursorState* state = context_get_cursor_state();
|
const CursorState* state = context_get_cursor_state();
|
||||||
x = state->x - (width / 2);
|
ScreenCoordsXY pos = { state->position.x - (width / 2), state->position.y + 15 };
|
||||||
y = state->y + 15;
|
|
||||||
|
|
||||||
w = window_find_by_class(WC_MAP_TOOLTIP);
|
w = window_find_by_class(WC_MAP_TOOLTIP);
|
||||||
if (w == nullptr)
|
if (w == nullptr)
|
||||||
{
|
{
|
||||||
w = window_create(
|
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);
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
|
||||||
w->widgets = window_map_tooltip_widgets;
|
w->widgets = window_map_tooltip_widgets;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w->Invalidate();
|
w->Invalidate();
|
||||||
w->x = x;
|
w->x = pos.x;
|
||||||
w->y = y;
|
w->y = pos.y;
|
||||||
w->width = width;
|
w->width = width;
|
||||||
w->height = height;
|
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
|
|| errorText == STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND || errorText == STR_TOO_HIGH_FOR_SUPPORTS
|
||||||
|| zAttempts == 0 || z < 0)
|
|| 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);
|
w = window_find_by_class(WC_RIDE_CONSTRUCTION);
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -3914,7 +3914,7 @@ void ride_construction_tooldown_construct(ScreenCoordsXY screenCoords)
|
||||||
_currentTrackAlternative = saveCurrentTrackAlternative;
|
_currentTrackAlternative = saveCurrentTrackAlternative;
|
||||||
_currentTrackLiftHill = saveCurrentTrackLiftHill;
|
_currentTrackLiftHill = saveCurrentTrackLiftHill;
|
||||||
|
|
||||||
audio_play_sound(SoundId::Error, 0, state->x);
|
audio_play_sound(SoundId::Error, 0, state->position.x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (zAttempts >= 0)
|
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)
|
static void window_scenery_update(rct_window* w)
|
||||||
{
|
{
|
||||||
const CursorState* state = context_get_cursor_state();
|
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)
|
if (other == w)
|
||||||
{
|
{
|
||||||
int32_t window_x = state->x - w->x + 26;
|
ScreenCoordsXY window = state->position - ScreenCoordsXY{ w->x - 26, w->y };
|
||||||
int32_t window_y = state->y - 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)
|
if (widgetIndex >= WIDX_SCENERY_TAB_CONTENT_PANEL)
|
||||||
{
|
{
|
||||||
w->scenery.hover_counter++;
|
w->scenery.hover_counter++;
|
||||||
|
|
|
@ -28,7 +28,7 @@ using rct_windowclass = uint8_t;
|
||||||
|
|
||||||
struct CursorState
|
struct CursorState
|
||||||
{
|
{
|
||||||
int32_t x, y;
|
ScreenCoordsXY position;
|
||||||
uint8_t left, middle, right, any;
|
uint8_t left, middle, right, any;
|
||||||
int32_t wheel;
|
int32_t wheel;
|
||||||
int32_t old;
|
int32_t old;
|
||||||
|
|
Loading…
Reference in New Issue