Don't zoom to cursor for keyboard or toolbar inputs (#5028)

This commit is contained in:
LRFLEW 2017-01-11 17:43:11 -06:00 committed by GitHub
parent e3cf32342b
commit 47c532d020
6 changed files with 33 additions and 44 deletions

View File

@ -174,34 +174,12 @@ static void shortcut_pause_game()
static void shortcut_zoom_view_out() static void shortcut_zoom_view_out()
{ {
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) main_window_zoom(false, false);
return;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gS6Info.editor_step == EDITOR_STEP_LANDSCAPE_EDITOR) {
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)) {
rct_window *window = window_find_by_class(WC_TOP_TOOLBAR);
if (window != NULL) {
window_invalidate(window);
window_event_mouse_up_call(window, 2);
}
}
}
} }
static void shortcut_zoom_view_in() static void shortcut_zoom_view_in()
{ {
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) main_window_zoom(true, false);
return;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gS6Info.editor_step == EDITOR_STEP_LANDSCAPE_EDITOR) {
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)) {
rct_window *window = window_find_by_class(WC_TOP_TOOLBAR);
if (window != NULL) {
window_invalidate(window);
window_event_mouse_up_call(window, 3);
}
}
}
} }
static void shortcut_rotate_view_clockwise() static void shortcut_rotate_view_clockwise()

View File

@ -244,9 +244,9 @@ static void window_viewport_wheel_input(rct_window *w, int wheel)
return; return;
if (wheel < 0) if (wheel < 0)
window_zoom_in(w); window_zoom_in(w, true);
else if (wheel > 0) else if (wheel > 0)
window_zoom_out(w); window_zoom_out(w, true);
} }
static bool window_other_wheel_input(rct_window *w, int widgetIndex, int wheel) static bool window_other_wheel_input(rct_window *w, int widgetIndex, int wheel)
@ -1490,7 +1490,7 @@ void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint
w->saved_view_y = dest_y + rebased_y + (offset_y / (1 << w->viewport->zoom)); w->saved_view_y = dest_y + rebased_y + (offset_y / (1 << w->viewport->zoom));
} }
void window_zoom_set(rct_window *w, int zoomLevel) void window_zoom_set(rct_window *w, int zoomLevel, bool atCursor)
{ {
rct_viewport* v = w->viewport; rct_viewport* v = w->viewport;
@ -1500,7 +1500,7 @@ void window_zoom_set(rct_window *w, int zoomLevel)
// Zooming to cursor? Remember where we're pointing at the moment. // Zooming to cursor? Remember where we're pointing at the moment.
sint16 saved_map_x, saved_map_y, offset_x, offset_y; sint16 saved_map_x, saved_map_y, offset_x, offset_y;
if (gConfigGeneral.zoom_to_cursor) { if (gConfigGeneral.zoom_to_cursor && atCursor) {
window_viewport_get_map_coords_by_cursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y); window_viewport_get_map_coords_by_cursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y);
} }
@ -1523,7 +1523,7 @@ void window_zoom_set(rct_window *w, int zoomLevel)
} }
// Zooming to cursor? Centre around the tile we were hovering over just now. // Zooming to cursor? Centre around the tile we were hovering over just now.
if (gConfigGeneral.zoom_to_cursor) { if (gConfigGeneral.zoom_to_cursor && atCursor) {
window_viewport_centre_tile_around_cursor(w, saved_map_x, saved_map_y, offset_x, offset_y); window_viewport_centre_tile_around_cursor(w, saved_map_x, saved_map_y, offset_x, offset_y);
} }
@ -1537,18 +1537,30 @@ void window_zoom_set(rct_window *w, int zoomLevel)
* *
* rct2: 0x006887A6 * rct2: 0x006887A6
*/ */
void window_zoom_in(rct_window *w) void window_zoom_in(rct_window *w, bool atCursor)
{ {
window_zoom_set(w, w->viewport->zoom - 1); window_zoom_set(w, w->viewport->zoom - 1, atCursor);
} }
/** /**
* *
* rct2: 0x006887E0 * rct2: 0x006887E0
*/ */
void window_zoom_out(rct_window *w) void window_zoom_out(rct_window *w, bool atCursor)
{ {
window_zoom_set(w, w->viewport->zoom + 1); window_zoom_set(w, w->viewport->zoom + 1, atCursor);
}
void main_window_zoom(bool zoomIn, bool atCursor) {
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
return;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gS6Info.editor_step == EDITOR_STEP_LANDSCAPE_EDITOR) {
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)) {
rct_window *mainWindow = window_get_main();
if (mainWindow != NULL)
window_zoom_set(mainWindow, mainWindow->viewport->zoom + (zoomIn ? -1 : 1), atCursor);
}
}
} }
/** /**

View File

@ -600,9 +600,10 @@ void window_scroll_to_location(rct_window *w, int x, int y, int z);
void window_rotate_camera(rct_window *w, int direction); void window_rotate_camera(rct_window *w, int direction);
void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y, sint16 *offset_x, sint16 *offset_y); void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y, sint16 *offset_x, sint16 *offset_y);
void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_y, sint16 offset_x, sint16 offset_y); void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_y, sint16 offset_x, sint16 offset_y);
void window_zoom_set(rct_window *w, int zoomLevel); void window_zoom_set(rct_window *w, int zoomLevel, bool atCursor);
void window_zoom_in(rct_window *w); void window_zoom_in(rct_window *w, bool atCursor);
void window_zoom_out(rct_window *w); void window_zoom_out(rct_window *w, bool atCursor);
void main_window_zoom(bool zoomIn, bool atCursor);
void window_show_textinput(rct_window *w, int widgetIndex, uint16 title, uint16 text, int value); void window_show_textinput(rct_window *w, int widgetIndex, uint16 title, uint16 text, int value);
void window_text_input_key(rct_window* w, int key); void window_text_input_key(rct_window* w, int key);

View File

@ -19,6 +19,7 @@
#include "../config.h" #include "../config.h"
#include "../drawing/drawing.h" #include "../drawing/drawing.h"
#include "../drawing/lightfx.h" #include "../drawing/lightfx.h"
#include "../editor.h"
#include "../game.h" #include "../game.h"
#include "../input.h" #include "../input.h"
#include "../interface/console.h" #include "../interface/console.h"
@ -507,12 +508,9 @@ void platform_process_messages()
// Zoom gesture // Zoom gesture
const int tolerance = 128; const int tolerance = 128;
int gesturePixels = (int)(_gestureRadius * gScreenWidth); int gesturePixels = (int)(_gestureRadius * gScreenWidth);
if (gesturePixels > tolerance) { if (abs(gesturePixels) > tolerance) {
_gestureRadius = 0; _gestureRadius = 0;
keyboard_shortcut_handle_command(SHORTCUT_ZOOM_VIEW_IN); main_window_zoom(gesturePixels > 0, true);
} else if (gesturePixels < -tolerance) {
_gestureRadius = 0;
keyboard_shortcut_handle_command(SHORTCUT_ZOOM_VIEW_OUT);
} }
} }
break; break;

View File

@ -314,7 +314,7 @@ private:
rct_window * w = window_get_main(); rct_window * w = window_get_main();
if (w != nullptr && w->viewport != nullptr) if (w != nullptr && w->viewport != nullptr)
{ {
window_zoom_set(w, zoom); window_zoom_set(w, zoom, false);
} }
} }

View File

@ -308,11 +308,11 @@ static void window_top_toolbar_mouseup(rct_window *w, int widgetIndex)
break; break;
case WIDX_ZOOM_OUT: case WIDX_ZOOM_OUT:
if ((mainWindow = window_get_main()) != NULL) if ((mainWindow = window_get_main()) != NULL)
window_zoom_out(mainWindow); window_zoom_out(mainWindow, false);
break; break;
case WIDX_ZOOM_IN: case WIDX_ZOOM_IN:
if ((mainWindow = window_get_main()) != NULL) if ((mainWindow = window_get_main()) != NULL)
window_zoom_in(mainWindow); window_zoom_in(mainWindow, false);
break; break;
case WIDX_CLEAR_SCENERY: case WIDX_CLEAR_SCENERY:
toggle_clear_scenery_window(w, WIDX_CLEAR_SCENERY); toggle_clear_scenery_window(w, WIDX_CLEAR_SCENERY);