mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remember and apply cursor position relative to tile.
This commit is contained in:
parent
1755fa433f
commit
8ac1b79799
|
@ -1445,7 +1445,7 @@ void window_rotate_camera(rct_window *w, int direction)
|
|||
reset_all_sprite_quadrant_placements();
|
||||
}
|
||||
|
||||
void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y)
|
||||
void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y, sint16 *offset_x, sint16 *offset_y)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
platform_get_cursor_position(&mouse_x, &mouse_y);
|
||||
|
@ -1455,9 +1455,29 @@ void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint
|
|||
mouse_y = (int) ceilf(mouse_y / gConfigGeneral.window_scale);
|
||||
|
||||
get_map_coordinates_from_pos(mouse_x, mouse_y, VIEWPORT_INTERACTION_MASK_NONE, map_x, map_y, NULL, NULL, NULL);
|
||||
|
||||
// Get viewport coordinates centring around the tile.
|
||||
int base_height = map_element_height(*map_x, *map_y);
|
||||
int dest_x, dest_y;
|
||||
center_2d_coordinates(*map_x, *map_y, base_height, &dest_x, &dest_y, w->viewport);
|
||||
|
||||
// Rebase mouse position onto centre of window.
|
||||
int rebased_x = (w->width >> 1) - mouse_x,
|
||||
rebased_y = (w->height >> 1) - mouse_y;
|
||||
|
||||
// Compensate for zoom level.
|
||||
rebased_x <<= w->viewport->zoom;
|
||||
rebased_y <<= w->viewport->zoom;
|
||||
|
||||
// Apply offset to the viewport.
|
||||
int new_x = dest_x + rebased_x,
|
||||
new_y = dest_y + rebased_y;
|
||||
|
||||
*offset_x = (w->saved_view_x - new_x) << w->viewport->zoom,
|
||||
*offset_y = (w->saved_view_y - new_y) << w->viewport->zoom;
|
||||
}
|
||||
|
||||
void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_y)
|
||||
void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_y, sint16 offset_x, sint16 offset_y)
|
||||
{
|
||||
// Get viewport coordinates centring around the tile.
|
||||
int dest_x, dest_y;
|
||||
|
@ -1481,8 +1501,8 @@ void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint
|
|||
rebased_y <<= w->viewport->zoom;
|
||||
|
||||
// Apply offset to the viewport.
|
||||
w->saved_view_x = dest_x + rebased_x;
|
||||
w->saved_view_y = dest_y + rebased_y;
|
||||
w->saved_view_x = dest_x + rebased_x + (offset_x >> w->viewport->zoom);
|
||||
w->saved_view_y = dest_y + rebased_y + (offset_y >> w->viewport->zoom);
|
||||
}
|
||||
|
||||
void window_zoom_set(rct_window *w, int zoomLevel)
|
||||
|
@ -1494,9 +1514,9 @@ void window_zoom_set(rct_window *w, int zoomLevel)
|
|||
return;
|
||||
|
||||
// Zooming to cursor? Remember where we're pointing at the moment.
|
||||
sint16 saved_map_x, saved_map_y;
|
||||
sint16 saved_map_x, saved_map_y, offset_x, offset_y;
|
||||
if (gConfigGeneral.zoom_to_cursor) {
|
||||
window_viewport_get_map_coords_by_cursor(w, &saved_map_x, &saved_map_y);
|
||||
window_viewport_get_map_coords_by_cursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y);
|
||||
}
|
||||
|
||||
// Zoom in
|
||||
|
@ -1519,7 +1539,7 @@ void window_zoom_set(rct_window *w, int zoomLevel)
|
|||
|
||||
// Zooming to cursor? Centre around the tile we were hovering over just now.
|
||||
if (gConfigGeneral.zoom_to_cursor) {
|
||||
window_viewport_centre_tile_around_cursor(w, saved_map_x, saved_map_y);
|
||||
window_viewport_centre_tile_around_cursor(w, saved_map_x, saved_map_y, offset_x, offset_y);
|
||||
}
|
||||
|
||||
// HACK: Prevents the redraw from failing when there is
|
||||
|
|
|
@ -574,8 +574,8 @@ rct_window *window_get_main();
|
|||
void window_scroll_to_viewport(rct_window *w);
|
||||
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_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y);
|
||||
void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_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_zoom_set(rct_window *w, int zoomLevel);
|
||||
void window_zoom_in(rct_window *w);
|
||||
void window_zoom_out(rct_window *w);
|
||||
|
|
Loading…
Reference in New Issue