refactor drag widget in input.c

This commit is contained in:
IntelOrca 2016-01-05 00:10:28 +00:00
parent 88c391120a
commit d842708f90
1 changed files with 28 additions and 30 deletions

View File

@ -43,11 +43,12 @@
#include "world/scenery.h" #include "world/scenery.h"
#include "openrct2.h" #include "openrct2.h"
static int _dragX, _dragY; static sint32 _dragX;
static rct_windowclass _dragWindowClass; static sint32 _dragY;
static rct_windownumber _dragWindowNumber; static widget_ref _dragWidget;
static int _dragWidgetIndex, _dragScrollIndex; static uint8 _dragScrollIndex;
static int _originalWindowWidth, _originalWindowHeight; static sint32 _originalWindowWidth;
static sint32 _originalWindowHeight;
uint8 gInputState; uint8 gInputState;
uint8 gInputFlags; uint8 gInputFlags;
@ -191,9 +192,9 @@ static void input_scroll_drag_begin(int x, int y, rct_window* w, rct_widget* wid
gInputState = INPUT_STATE_SCROLL_RIGHT; gInputState = INPUT_STATE_SCROLL_RIGHT;
_dragX = x; _dragX = x;
_dragY = y; _dragY = y;
_dragWindowClass = w->classification; _dragWidget.window_classification = w->classification;
_dragWindowNumber = w->number; _dragWidget.window_number = w->number;
_dragWidgetIndex = widgetIndex; _dragWidget.widget_index = widgetIndex;
RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) = 0;
_dragScrollIndex = window_get_scroll_data_index(w, widgetIndex); _dragScrollIndex = window_get_scroll_data_index(w, widgetIndex);
@ -204,8 +205,9 @@ static void input_scroll_drag_begin(int x, int y, rct_window* w, rct_widget* wid
* Based on (heavily changed) * Based on (heavily changed)
* rct2: 0x006E9E0E, 0x006E9ED0 * rct2: 0x006E9E0E, 0x006E9ED0
*/ */
static void input_scroll_drag_continue(int x, int y, rct_window* w) { static void input_scroll_drag_continue(int x, int y, rct_window* w)
uint8 widgetIndex = _dragWidgetIndex; {
uint8 widgetIndex = _dragWidget.widget_index;
uint8 scrollIndex = _dragScrollIndex; uint8 scrollIndex = _dragScrollIndex;
rct_widget* widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
@ -242,8 +244,8 @@ static void input_scroll_drag_continue(int x, int y, rct_window* w) {
*/ */
static void input_scroll_right(int x, int y, int state) { static void input_scroll_right(int x, int y, int state) {
rct_window* w = window_find_by_number( rct_window* w = window_find_by_number(
_dragWindowClass, _dragWidget.window_classification,
_dragWindowNumber _dragWidget.window_number
); );
if (w == NULL) { if (w == NULL) {
@ -319,7 +321,7 @@ static void game_handle_input_mouse(int x, int y, int state)
input_state_widget_pressed(x, y, state, widgetIndex, w, widget); input_state_widget_pressed(x, y, state, widgetIndex, w, widget);
break; break;
case INPUT_STATE_POSITIONING_WINDOW: case INPUT_STATE_POSITIONING_WINDOW:
w = window_find_by_number(_dragWindowClass, _dragWindowNumber); w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number);
if (w == NULL) { if (w == NULL) {
gInputState = INPUT_STATE_RESET; gInputState = INPUT_STATE_RESET;
} }
@ -401,7 +403,7 @@ static void game_handle_input_mouse(int x, int y, int state)
input_scroll_end(); input_scroll_end();
break; break;
case INPUT_STATE_RESIZING: case INPUT_STATE_RESIZING:
w = window_find_by_number(_dragWindowClass, _dragWindowNumber); w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number);
if (w == NULL) { if (w == NULL) {
gInputState = INPUT_STATE_RESET; gInputState = INPUT_STATE_RESET;
} }
@ -426,9 +428,9 @@ void input_window_position_begin(rct_window *w, int widgetIndex, int x, int y)
gInputState = INPUT_STATE_POSITIONING_WINDOW; gInputState = INPUT_STATE_POSITIONING_WINDOW;
_dragX = x - w->x; _dragX = x - w->x;
_dragY = y - w->y; _dragY = y - w->y;
_dragWindowClass = w->classification; _dragWidget.window_classification = w->classification;
_dragWindowNumber = w->number; _dragWidget.window_number = w->number;
_dragWidgetIndex = widgetIndex; _dragWidget.widget_index = widgetIndex;
} }
static void input_window_position_continue(rct_window *w, int wdx, int wdy, int x, int y) static void input_window_position_continue(rct_window *w, int wdx, int wdy, int x, int y)
@ -443,9 +445,7 @@ static void input_window_position_end(rct_window *w, int x, int y)
{ {
gInputState = INPUT_STATE_NORMAL; gInputState = INPUT_STATE_NORMAL;
gTooltipTimeout = 0; gTooltipTimeout = 0;
gTooltipWidget.window_classification = _dragWindowClass; gTooltipWidget = _dragWidget;
gTooltipWidget.window_number = _dragWindowNumber;
gTooltipWidget.widget_index = _dragWidgetIndex;
window_event_moved_call(w, x, y); window_event_moved_call(w, x, y);
} }
@ -454,9 +454,9 @@ static void input_window_resize_begin(rct_window *w, int widgetIndex, int x, int
gInputState = INPUT_STATE_RESIZING; gInputState = INPUT_STATE_RESIZING;
_dragX = x; _dragX = x;
_dragY = y; _dragY = y;
_dragWindowClass = w->classification; _dragWidget.window_classification = w->classification;
_dragWindowNumber = w->number; _dragWidget.window_number = w->number;
_dragWidgetIndex = widgetIndex; _dragWidget.widget_index = widgetIndex;
_originalWindowWidth = w->width; _originalWindowWidth = w->width;
_originalWindowHeight = w->height; _originalWindowHeight = w->height;
} }
@ -483,9 +483,7 @@ static void input_window_resize_end()
{ {
gInputState = INPUT_STATE_NORMAL; gInputState = INPUT_STATE_NORMAL;
gTooltipTimeout = 0; gTooltipTimeout = 0;
gTooltipWidget.window_classification = _dragWindowClass; gTooltipWidget = _dragWidget;
gTooltipWidget.window_number = _dragWindowNumber;
gTooltipWidget.widget_index = _dragWidgetIndex;
} }
#pragma endregion #pragma endregion
@ -496,8 +494,8 @@ static void input_viewport_drag_begin(rct_window *w, int x, int y)
{ {
w->flags &= ~WF_SCROLLING_TO_LOCATION; w->flags &= ~WF_SCROLLING_TO_LOCATION;
gInputState = INPUT_STATE_VIEWPORT_RIGHT; gInputState = INPUT_STATE_VIEWPORT_RIGHT;
_dragWindowClass = w->classification; _dragWidget.window_classification = w->classification;
_dragWindowNumber = w->number; _dragWidget.window_number = w->number;
RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) = 0;
platform_get_cursor_position(&_dragX, &_dragY); platform_get_cursor_position(&_dragX, &_dragY);
platform_hide_cursor(); platform_hide_cursor();
@ -515,7 +513,7 @@ static void input_viewport_drag_continue()
dx = newDragX - _dragX; dx = newDragX - _dragX;
dy = newDragY - _dragY; dy = newDragY - _dragY;
w = window_find_by_number(_dragWindowClass, _dragWindowNumber); w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number);
assert(w != NULL); assert(w != NULL);
viewport = w->viewport; viewport = w->viewport;