mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Use ScreenCoordsXY on context cursor operations (#10364)
This commit is contained in:
committed by
Michael Steenbeek
parent
af7b364946
commit
9d09f1b95c
@@ -239,14 +239,16 @@ public:
|
||||
SDL_ShowCursor(value ? SDL_ENABLE : SDL_DISABLE);
|
||||
}
|
||||
|
||||
void GetCursorPosition(int32_t* x, int32_t* y) override
|
||||
ScreenCoordsXY GetCursorPosition() override
|
||||
{
|
||||
SDL_GetMouseState(x, y);
|
||||
ScreenCoordsXY cursorPosition;
|
||||
SDL_GetMouseState(&cursorPosition.x, &cursorPosition.y);
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
void SetCursorPosition(int32_t x, int32_t y) override
|
||||
void SetCursorPosition(ScreenCoordsXY cursorPosition) override
|
||||
{
|
||||
SDL_WarpMouseInWindow(nullptr, x, y);
|
||||
SDL_WarpMouseInWindow(nullptr, cursorPosition.x, cursorPosition.y);
|
||||
}
|
||||
|
||||
void SetCursorTrap(bool value) override
|
||||
|
||||
@@ -231,10 +231,10 @@ static void input_scroll_drag_continue(ScreenCoordsXY screenCoords, rct_window*
|
||||
widget_scroll_update_thumbs(w, widgetIndex);
|
||||
window_invalidate_by_number(w->classification, w->number);
|
||||
|
||||
int32_t fixedCursorPositionX = (int32_t)std::ceil(gInputDragLastX * gConfigGeneral.window_scale);
|
||||
int32_t fixedCursorPositionY = (int32_t)std::ceil(gInputDragLastY * gConfigGeneral.window_scale);
|
||||
ScreenCoordsXY fixedCursorPosition = { static_cast<int32_t>(std::ceil(gInputDragLastX * gConfigGeneral.window_scale)),
|
||||
static_cast<int32_t>(std::ceil(gInputDragLastY * gConfigGeneral.window_scale)) };
|
||||
|
||||
context_set_cursor_position(fixedCursorPositionX, fixedCursorPositionY);
|
||||
context_set_cursor_position(fixedCursorPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -518,7 +518,9 @@ static void input_viewport_drag_begin(rct_window* w)
|
||||
_dragWidget.window_classification = w->classification;
|
||||
_dragWidget.window_number = w->number;
|
||||
_ticksSinceDragStart = 0;
|
||||
context_get_cursor_position(&gInputDragLastX, &gInputDragLastY);
|
||||
auto cursorPosition = context_get_cursor_position();
|
||||
gInputDragLastX = cursorPosition.x;
|
||||
gInputDragLastY = cursorPosition.y;
|
||||
context_hide_cursor();
|
||||
|
||||
window_unfollow_sprite(w);
|
||||
@@ -527,15 +529,15 @@ static void input_viewport_drag_begin(rct_window* w)
|
||||
|
||||
static void input_viewport_drag_continue()
|
||||
{
|
||||
int32_t dx, dy, newDragX, newDragY;
|
||||
int32_t dx, dy;
|
||||
rct_window* w;
|
||||
rct_viewport* viewport;
|
||||
|
||||
context_get_cursor_position(&newDragX, &newDragY);
|
||||
auto newDragCoords = context_get_cursor_position();
|
||||
const CursorState* cursorState = context_get_cursor_state();
|
||||
|
||||
dx = newDragX - gInputDragLastX;
|
||||
dy = newDragY - gInputDragLastY;
|
||||
dx = newDragCoords.x - gInputDragLastX;
|
||||
dy = newDragCoords.y - gInputDragLastY;
|
||||
w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number);
|
||||
|
||||
// #3294: Window can be closed during a drag session, so just finish
|
||||
@@ -580,12 +582,12 @@ static void input_viewport_drag_continue()
|
||||
|
||||
if (cursorState->touch)
|
||||
{
|
||||
gInputDragLastX = newDragX;
|
||||
gInputDragLastY = newDragY;
|
||||
gInputDragLastX = newDragCoords.x;
|
||||
gInputDragLastY = newDragCoords.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
context_set_cursor_position(gInputDragLastX, gInputDragLastY);
|
||||
context_set_cursor_position({ gInputDragLastX, gInputDragLastY });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1149,23 +1149,22 @@ void context_show_cursor()
|
||||
GetContext()->GetUiContext()->SetCursorVisible(true);
|
||||
}
|
||||
|
||||
void context_get_cursor_position(int32_t* x, int32_t* y)
|
||||
ScreenCoordsXY context_get_cursor_position()
|
||||
{
|
||||
GetContext()->GetUiContext()->GetCursorPosition(x, y);
|
||||
return GetContext()->GetUiContext()->GetCursorPosition();
|
||||
}
|
||||
|
||||
void context_get_cursor_position_scaled(int32_t* x, int32_t* y)
|
||||
ScreenCoordsXY context_get_cursor_position_scaled()
|
||||
{
|
||||
context_get_cursor_position(x, y);
|
||||
|
||||
auto cursorCoords = context_get_cursor_position();
|
||||
// Compensate for window scaling.
|
||||
*x = (int32_t)std::ceil(*x / gConfigGeneral.window_scale);
|
||||
*y = (int32_t)std::ceil(*y / gConfigGeneral.window_scale);
|
||||
return { static_cast<int32_t>(std::ceil(cursorCoords.x / gConfigGeneral.window_scale)),
|
||||
static_cast<int32_t>(std::ceil(cursorCoords.y / gConfigGeneral.window_scale)) };
|
||||
}
|
||||
|
||||
void context_set_cursor_position(int32_t x, int32_t y)
|
||||
void context_set_cursor_position(ScreenCoordsXY cursorPosition)
|
||||
{
|
||||
GetContext()->GetUiContext()->SetCursorPosition(x, y);
|
||||
GetContext()->GetUiContext()->SetCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
const CursorState* context_get_cursor_state()
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "world/Location.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -218,9 +219,9 @@ void context_setcurrentcursor(int32_t cursor);
|
||||
void context_update_cursor_scale();
|
||||
void context_hide_cursor();
|
||||
void context_show_cursor();
|
||||
void context_get_cursor_position(int32_t* x, int32_t* y);
|
||||
void context_get_cursor_position_scaled(int32_t* x, int32_t* y);
|
||||
void context_set_cursor_position(int32_t x, int32_t y);
|
||||
ScreenCoordsXY context_get_cursor_position();
|
||||
ScreenCoordsXY context_get_cursor_position_scaled();
|
||||
void context_set_cursor_position(ScreenCoordsXY cursorPosition);
|
||||
const CursorState* context_get_cursor_state();
|
||||
const uint8_t* context_get_keys_state();
|
||||
const uint8_t* context_get_keys_pressed();
|
||||
|
||||
@@ -956,12 +956,11 @@ void window_viewport_get_map_coords_by_cursor(
|
||||
rct_window* w, int16_t* map_x, int16_t* map_y, int16_t* offset_x, int16_t* offset_y)
|
||||
{
|
||||
// Get mouse position to offset against.
|
||||
int32_t mouse_x, mouse_y;
|
||||
context_get_cursor_position_scaled(&mouse_x, &mouse_y);
|
||||
auto mouseCoords = context_get_cursor_position_scaled();
|
||||
|
||||
// Compute map coordinate by mouse position.
|
||||
CoordsXY mapCoords;
|
||||
get_map_coordinates_from_pos({ mouse_x, mouse_y }, VIEWPORT_INTERACTION_MASK_NONE, mapCoords, nullptr, nullptr, nullptr);
|
||||
get_map_coordinates_from_pos(mouseCoords, VIEWPORT_INTERACTION_MASK_NONE, mapCoords, nullptr, nullptr, nullptr);
|
||||
*map_x = mapCoords.x;
|
||||
*map_y = mapCoords.y;
|
||||
|
||||
@@ -976,8 +975,8 @@ void window_viewport_get_map_coords_by_cursor(
|
||||
}
|
||||
|
||||
// Rebase mouse position onto centre of window, and compensate for zoom level.
|
||||
int32_t rebased_x = ((w->width >> 1) - mouse_x) * (1 << w->viewport->zoom),
|
||||
rebased_y = ((w->height >> 1) - mouse_y) * (1 << w->viewport->zoom);
|
||||
int32_t rebased_x = ((w->width >> 1) - mouseCoords.x) * (1 << w->viewport->zoom),
|
||||
rebased_y = ((w->height >> 1) - mouseCoords.y) * (1 << w->viewport->zoom);
|
||||
|
||||
// Compute cursor offset relative to tile.
|
||||
*offset_x = (w->saved_view_x - (centreLoc->x + rebased_x)) * (1 << w->viewport->zoom);
|
||||
@@ -997,12 +996,11 @@ void window_viewport_centre_tile_around_cursor(rct_window* w, int16_t map_x, int
|
||||
}
|
||||
|
||||
// Get mouse position to offset against.
|
||||
int32_t mouse_x, mouse_y;
|
||||
context_get_cursor_position_scaled(&mouse_x, &mouse_y);
|
||||
auto mouseCoords = context_get_cursor_position_scaled();
|
||||
|
||||
// Rebase mouse position onto centre of window, and compensate for zoom level.
|
||||
int32_t rebased_x = ((w->width >> 1) - mouse_x) * (1 << w->viewport->zoom),
|
||||
rebased_y = ((w->height >> 1) - mouse_y) * (1 << w->viewport->zoom);
|
||||
int32_t rebased_x = ((w->width >> 1) - mouseCoords.x) * (1 << w->viewport->zoom),
|
||||
rebased_y = ((w->height >> 1) - mouseCoords.y) * (1 << w->viewport->zoom);
|
||||
|
||||
// Apply offset to the viewport.
|
||||
w->saved_view_x = centreLoc->x + rebased_x + (offset_x / (1 << w->viewport->zoom));
|
||||
|
||||
@@ -116,10 +116,11 @@ namespace OpenRCT2::Ui
|
||||
void SetCursorVisible(bool /*value*/) override
|
||||
{
|
||||
}
|
||||
void GetCursorPosition(int32_t* /*x*/, int32_t* /*y*/) override
|
||||
ScreenCoordsXY GetCursorPosition() override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
void SetCursorPosition(int32_t /*x*/, int32_t /*y*/) override
|
||||
void SetCursorPosition(ScreenCoordsXY /*cursorPosition*/) override
|
||||
{
|
||||
}
|
||||
void SetCursorTrap(bool /*value*/) override
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../Context.h"
|
||||
#include "../common.h"
|
||||
#include "../interface/Cursors.h"
|
||||
#include "../world/Location.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -120,8 +121,8 @@ namespace OpenRCT2
|
||||
virtual void SetCursor(CURSOR_ID cursor) abstract;
|
||||
virtual void SetCursorScale(uint8_t scale) abstract;
|
||||
virtual void SetCursorVisible(bool value) abstract;
|
||||
virtual void GetCursorPosition(int32_t * x, int32_t * y) abstract;
|
||||
virtual void SetCursorPosition(int32_t x, int32_t y) abstract;
|
||||
virtual ScreenCoordsXY GetCursorPosition() abstract;
|
||||
virtual void SetCursorPosition(ScreenCoordsXY cursorPosition) abstract;
|
||||
virtual void SetCursorTrap(bool value) abstract;
|
||||
virtual const uint8_t* GetKeysState() abstract;
|
||||
virtual const uint8_t* GetKeysPressed() abstract;
|
||||
|
||||
Reference in New Issue
Block a user