1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

fix #2658: fix dragging on land and water tools

This commit is contained in:
IntelOrca
2016-01-06 18:31:25 +00:00
parent b80cb15639
commit 29397ebcc5
3 changed files with 31 additions and 33 deletions

View File

@@ -62,8 +62,6 @@ static uint8 _mouseInputQueueReadIndex = 0;
static uint8 _mouseInputQueueWriteIndex = 0;
static uint32 _ticksSinceDragStart;
static sint32 _dragX;
static sint32 _dragY;
static widget_ref _dragWidget;
static uint8 _dragScrollIndex;
static sint32 _originalWindowWidth;
@@ -73,6 +71,9 @@ uint8 gInputState;
uint8 gInputFlags;
uint8 gInputPlaceObjectModifier;
sint32 gInputDragLastX;
sint32 gInputDragLastY;
widget_ref gHoverWidget;
widget_ref gPressedWidget;
@@ -207,8 +208,8 @@ static rct_mouse_data *get_mouse_input()
static void input_scroll_drag_begin(int x, int y, rct_window* w, rct_widget* widget, int widgetIndex)
{
gInputState = INPUT_STATE_SCROLL_RIGHT;
_dragX = x;
_dragY = y;
gInputDragLastX = x;
gInputDragLastY = y;
_dragWidget.window_classification = w->classification;
_dragWidget.window_number = w->number;
_dragWidget.widget_index = widgetIndex;
@@ -231,8 +232,8 @@ static void input_scroll_drag_continue(int x, int y, rct_window* w)
rct_scroll* scroll = &w->scrolls[scrollIndex];
int dx, dy;
dx = x - _dragX;
dy = y - _dragY;
dx = x - gInputDragLastX;
dy = y - gInputDragLastY;
if (scroll->flags & HSCROLLBAR_VISIBLE) {
sint16 size = widget->right - widget->left - 1;
@@ -252,7 +253,7 @@ static void input_scroll_drag_continue(int x, int y, rct_window* w)
widget_scroll_update_thumbs(w, widgetIndex);
window_invalidate_by_number(w->classification, w->number);
platform_set_cursor_position(_dragX, _dragY);
platform_set_cursor_position(gInputDragLastX, gInputDragLastY);
}
/**
@@ -340,7 +341,7 @@ static void game_handle_input_mouse(int x, int y, int state)
if (w == NULL) {
gInputState = INPUT_STATE_RESET;
} else {
input_window_position_continue(w, _dragX, _dragY, x, y);
input_window_position_continue(w, gInputDragLastX, gInputDragLastY, x, y);
if (state == MOUSE_STATE_LEFT_RELEASE) {
input_window_position_end(w, x, y);
}
@@ -443,8 +444,8 @@ static void game_handle_input_mouse(int x, int y, int state)
void input_window_position_begin(rct_window *w, int widgetIndex, int x, int y)
{
gInputState = INPUT_STATE_POSITIONING_WINDOW;
_dragX = x - w->x;
_dragY = y - w->y;
gInputDragLastX = x - w->x;
gInputDragLastY = y - w->y;
_dragWidget.window_classification = w->classification;
_dragWidget.window_number = w->number;
_dragWidget.widget_index = widgetIndex;
@@ -469,8 +470,8 @@ static void input_window_position_end(rct_window *w, int x, int y)
static void input_window_resize_begin(rct_window *w, int widgetIndex, int x, int y)
{
gInputState = INPUT_STATE_RESIZING;
_dragX = x;
_dragY = y;
gInputDragLastX = x;
gInputDragLastY = y;
_dragWidget.window_classification = w->classification;
_dragWidget.window_number = w->number;
_dragWidget.widget_index = widgetIndex;
@@ -483,8 +484,8 @@ static void input_window_resize_continue(rct_window *w, int x, int y)
int dx, dy, targetWidth, targetHeight;
if (y < RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 2) {
dx = x - _dragX;
dy = y - _dragY;
dx = x - gInputDragLastX;
dy = y - gInputDragLastY;
targetWidth = _originalWindowWidth + dx;
targetHeight = _originalWindowHeight + dy;
@@ -514,7 +515,7 @@ static void input_viewport_drag_begin(rct_window *w, int x, int y)
_dragWidget.window_classification = w->classification;
_dragWidget.window_number = w->number;
_ticksSinceDragStart = 0;
platform_get_cursor_position(&_dragX, &_dragY);
platform_get_cursor_position(&gInputDragLastX, &gInputDragLastY);
platform_hide_cursor();
// gInputFlags |= INPUT_FLAG_5;
@@ -528,8 +529,8 @@ static void input_viewport_drag_continue()
platform_get_cursor_position(&newDragX, &newDragY);
dx = newDragX - _dragX;
dy = newDragY - _dragY;
dx = newDragX - gInputDragLastX;
dy = newDragY - gInputDragLastY;
w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number);
assert(w != NULL);
@@ -558,7 +559,7 @@ static void input_viewport_drag_continue()
}
}
platform_set_cursor_position(_dragX, _dragY);
platform_set_cursor_position(gInputDragLastX, gInputDragLastY);
}
static void input_viewport_drag_end()
@@ -1002,8 +1003,8 @@ static void input_widget_left(int x, int y, rct_window *w, int widgetIndex)
break;
case WWT_VIEWPORT:
gInputState = INPUT_STATE_VIEWPORT_LEFT;
_dragX = x;
_dragY = y;
gInputDragLastX = x;
gInputDragLastY = y;
_dragWidget.window_classification = windowClass;
_dragWidget.window_number = windowNumber;
if (gInputFlags & INPUT_FLAG_TOOL_ACTIVE) {

View File

@@ -76,6 +76,9 @@ extern uint8 gInputState;
extern uint8 gInputFlags;
extern uint8 gInputPlaceObjectModifier;
extern sint32 gInputDragLastX;
extern sint32 gInputDragLastY;
extern widget_ref gHoverWidget;
extern widget_ref gPressedWidget;

View File

@@ -2638,27 +2638,21 @@ void window_top_toolbar_land_tool_drag(short x, short y)
sint16 tile_height = -16 / (1 << viewport->zoom);
int y_diff = y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16);
int y_diff = y - gInputDragLastY;
if (y_diff <= tile_height) {
RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += tile_height;
gInputDragLastY += tile_height;
selection_raise_land(GAME_COMMAND_FLAG_APPLY);
RCT2_GLOBAL(RCT2_ADDRESS_LAND_RAISE_COST, uint32) = MONEY32_UNDEFINED;
RCT2_GLOBAL(RCT2_ADDRESS_LAND_LOWER_COST, uint32) = MONEY32_UNDEFINED;
return;
}
if (y_diff >= -tile_height) {
RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) -= tile_height;
} else if (y_diff >= -tile_height) {
gInputDragLastY -= tile_height;
selection_lower_land(GAME_COMMAND_FLAG_APPLY);
RCT2_GLOBAL(RCT2_ADDRESS_LAND_RAISE_COST, uint32) = MONEY32_UNDEFINED;
RCT2_GLOBAL(RCT2_ADDRESS_LAND_LOWER_COST, uint32) = MONEY32_UNDEFINED;
return;
}
}
@@ -2684,10 +2678,10 @@ void window_top_toolbar_water_tool_drag(short x, short y)
sint16 dx = 0xFFF0;
dx >>= viewport->zoom;
y -= RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16);
y -= gInputDragLastY;
if (y <= dx) {
RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += dx;
gInputDragLastY += dx;
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, rct_string_id) = STR_CANT_RAISE_WATER_LEVEL_HERE;
@@ -2709,7 +2703,7 @@ void window_top_toolbar_water_tool_drag(short x, short y)
dx = -dx;
if (y >= dx) {
RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += dx;
gInputDragLastY += dx;
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, rct_string_id) = STR_CANT_LOWER_WATER_LEVEL_HERE;