From d8844513a1d272c2bb10697bc47f0cf0d6ba4de1 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 10 Nov 2014 22:37:55 +0000 Subject: [PATCH] remove windows.h from input.c and improve window resize --- src/input.c | 39 ++++++++++++++++++++++----------------- src/platform/platform.h | 4 ++++ src/platform/windows.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/input.c b/src/input.c index 3aa3c1e9a2..763943bafa 100644 --- a/src/input.c +++ b/src/input.c @@ -19,7 +19,6 @@ *****************************************************************************/ #include -#include #include "addresses.h" #include "audio/audio.h" #include "config.h" @@ -41,7 +40,8 @@ #include "world/sprite.h" #include "world/scenery.h" -POINT _dragPosition; +static int _dragX, _dragY; +static int _originalWindowWidth, _originalWindowHeight; typedef struct { uint32 x, y; @@ -348,6 +348,7 @@ static void game_handle_input_mouse(int x, int y, int state) if (state != 0 && state != 2) break; + if (state == 2) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0; @@ -357,14 +358,17 @@ static void game_handle_input_mouse(int x, int y, int state) } if (y < RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 2) { + int dx = x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16); + int dy = y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16); + int ww = _originalWindowWidth + dx; + int wh = _originalWindowHeight + dy; + window_resize( w, - x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16), - y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) + ww -w->width, + wh - w->height ); } - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16) = x; - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) = y; break; case 9: RCT2_CALLPROC_X(0x006E8ACB, x, y, state, widgetIndex, (int)w, (int)widget, 0); @@ -385,21 +389,20 @@ static void input_viewport_drag_begin(rct_window *w, int x, int y) // RCT2_CALLPROC_X(0x00407045, 0, 0, 0, 0, 0, 0, 0); // RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) |= INPUT_FLAG_5; - GetCursorPos(&_dragPosition); - ShowCursor(FALSE); + platform_get_cursor_position(&_dragX, &_dragY); + platform_hide_cursor(); } static void input_viewport_drag_continue() { - int dx, dy; + int dx, dy, newDragX, newDragY; rct_window *w; rct_viewport *viewport; - POINT newDragPosition; - GetCursorPos(&newDragPosition); - - dx = newDragPosition.x - _dragPosition.x; - dy = newDragPosition.y - _dragPosition.y; + platform_get_cursor_position(&newDragX, &newDragY); + + dx = newDragX - _dragX; + dy = newDragY - _dragY; w = window_find_by_number( RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWCLASS, rct_windowclass), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWNUMBER, rct_windownumber) @@ -408,7 +411,7 @@ static void input_viewport_drag_continue() viewport = w->viewport; RCT2_GLOBAL(0x009DE540, sint16) += RCT2_GLOBAL(0x009DE588, sint16); if (viewport == NULL) { - ShowCursor(TRUE); + platform_show_cursor(); RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; } else if (dx != 0 || dy != 0) { if (!(w->flags & (1 << 2))) { @@ -420,13 +423,13 @@ static void input_viewport_drag_continue() } } - SetCursorPos(_dragPosition.x, _dragPosition.y); + platform_set_cursor_position(_dragX, _dragY); } static void input_viewport_drag_end() { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; - ShowCursor(TRUE); + platform_show_cursor(); } static void input_window_drag(rct_window *w, int wdx, int wdy, int x, int y) @@ -754,6 +757,8 @@ static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex) RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) = y; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWCLASS, rct_windowclass) = windowClass; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWNUMBER, rct_windownumber) = windowNumber; + _originalWindowWidth = w->width; + _originalWindowHeight = w->height; break; case WWT_VIEWPORT: RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_VIEWPORT_LEFT; diff --git a/src/platform/platform.h b/src/platform/platform.h index 543f764ca5..4c29800160 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -34,5 +34,9 @@ int platform_lock_single_instance(); int platform_enumerate_files_begin(const char *pattern); int platform_enumerate_files_next(int handle, char **outFileName); void platform_enumerate_files_end(int handle); +void platform_hide_cursor(); +void platform_show_cursor(); +void platform_get_cursor_position(int *x, int *y); +void platform_set_cursor_position(int x, int y); #endif \ No newline at end of file diff --git a/src/platform/windows.c b/src/platform/windows.c index c13a81862d..a6647bce99 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -187,6 +187,34 @@ void platform_enumerate_files_end(int handle) enumFileInfo->active = 0; } +void platform_hide_cursor() +{ + ShowCursor(FALSE); +} + +void platform_show_cursor() +{ + ShowCursor(TRUE); +} + +void platform_get_cursor_position(int *x, int *y) +{ + POINT point; + + if (GetCursorPos(&point)) { + *x = point.x; + *y = point.y; + } else { + *x = INT32_MIN; + *y = INT32_MIN; + } +} + +void platform_set_cursor_position(int x, int y) +{ + SetCursorPos(x, y); +} + /** * http://alter.org.ua/en/docs/win/args/ */