2016-12-28 21:45:52 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-12-28 21:45:52 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-12-28 21:45:52 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-12-28 21:45:52 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-03-14 15:25:34 +01:00
|
|
|
#include <cmath>
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Viewport.h>
|
2018-05-08 01:25:05 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
|
|
|
#include <openrct2/Input.h>
|
|
|
|
#include <openrct2/config/Config.h>
|
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/paint/Paint.h>
|
2018-05-12 13:41:45 +02:00
|
|
|
#include <openrct2/sprites.h>
|
2018-05-08 01:25:05 +02:00
|
|
|
#include <openrct2/world/Location.hpp>
|
2016-12-28 21:45:52 +01:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2016-12-28 21:45:52 +01:00
|
|
|
enum WINDOW_VIEW_CLIPPING_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
2018-05-12 13:41:45 +02:00
|
|
|
WIDX_CLIP_CHECKBOX_ENABLE,
|
|
|
|
WIDX_GROUPBOX_VERTICAL,
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_CLIP_HEIGHT_VALUE,
|
|
|
|
WIDX_CLIP_HEIGHT_INCREASE,
|
|
|
|
WIDX_CLIP_HEIGHT_DECREASE,
|
2018-05-08 01:25:05 +02:00
|
|
|
WIDX_CLIP_HEIGHT_SLIDER,
|
2018-05-12 13:41:45 +02:00
|
|
|
WIDX_GROUPBOX_HORIZONTAL,
|
2018-05-08 01:25:05 +02:00
|
|
|
WIDX_CLIP_SELECTOR,
|
2018-05-12 13:41:45 +02:00
|
|
|
WIDX_CLIP_CLEAR,
|
2016-12-28 21:45:52 +01:00
|
|
|
};
|
|
|
|
|
2017-08-02 00:20:32 +02:00
|
|
|
enum class DISPLAY_TYPE {
|
2017-06-06 23:24:18 +02:00
|
|
|
DISPLAY_RAW,
|
|
|
|
DISPLAY_UNITS
|
2017-08-02 00:20:32 +02:00
|
|
|
};
|
2017-01-09 22:23:05 +01:00
|
|
|
|
2017-10-09 17:13:14 +02:00
|
|
|
static DISPLAY_TYPE gClipHeightDisplayType = DISPLAY_TYPE::DISPLAY_UNITS;
|
2017-01-09 22:23:05 +01:00
|
|
|
|
2016-12-28 21:45:52 +01:00
|
|
|
#pragma region Widgets
|
|
|
|
|
2020-05-09 17:05:01 +02:00
|
|
|
static constexpr const int32_t WW = 180;
|
|
|
|
static constexpr const int32_t WH = 155;
|
2017-01-07 13:24:55 +01:00
|
|
|
|
2017-08-06 14:41:13 +02:00
|
|
|
static rct_widget window_view_clipping_widgets[] = {
|
2018-05-12 13:41:45 +02:00
|
|
|
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, // panel / background
|
|
|
|
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_VIEW_CLIPPING_TITLE, STR_WINDOW_TITLE_TIP }, // title bar
|
|
|
|
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
|
|
|
|
{ WWT_CHECKBOX, 0, 11, WW - 11, 19, 29, STR_VIEW_CLIPPING_HEIGHT_ENABLE, STR_VIEW_CLIPPING_HEIGHT_ENABLE_TIP }, // clip enable/disable check box
|
|
|
|
{ WWT_GROUPBOX, 0, 5, WW - 6, 36, 83, STR_VIEW_CLIPPING_VERTICAL_CLIPPING, STR_NONE },
|
2018-06-10 21:31:08 +02:00
|
|
|
SPINNER_WIDGETS (0, 90, WW - 12, 51, 62, STR_NONE, STR_VIEW_CLIPPING_HEIGHT_VALUE_TOGGLE), // clip height (3 widgets)
|
2018-05-12 13:41:45 +02:00
|
|
|
{ WWT_SCROLL, 0, 11, WW - 12, 66, 78, SCROLL_HORIZONTAL, STR_VIEW_CLIPPING_HEIGHT_SCROLL_TIP }, // clip height scrollbar
|
|
|
|
{ WWT_GROUPBOX, 0, 5, WW - 6, 90, WH - 6, STR_VIEW_CLIPPING_HORIZONTAL_CLIPPING, STR_NONE },
|
|
|
|
{ WWT_BUTTON, 0, 11, WW - 12, 105, 121, STR_VIEW_CLIPPING_SELECT_AREA, STR_NONE }, // selector
|
|
|
|
{ WWT_BUTTON, 0, 11, WW - 12, 126, 143, STR_VIEW_CLIPPING_CLEAR_SELECTION, STR_NONE }, // clear
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2016-12-28 21:45:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2018-05-08 01:25:05 +02:00
|
|
|
#pragma region Members
|
|
|
|
|
2019-12-24 21:21:26 +01:00
|
|
|
static CoordsXY _selectionStart;
|
2020-03-07 21:07:18 +01:00
|
|
|
static CoordsXY _previousClipSelectionA;
|
|
|
|
static CoordsXY _previousClipSelectionB;
|
2018-05-09 01:18:03 +02:00
|
|
|
static bool _toolActive;
|
|
|
|
static bool _dragging;
|
2018-05-08 01:25:05 +02:00
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2016-12-28 21:45:52 +01:00
|
|
|
#pragma region Events
|
|
|
|
|
2018-05-09 00:32:04 +02:00
|
|
|
static void window_view_clipping_close_button(rct_window* w);
|
|
|
|
static void window_view_clipping_mouseup(rct_window* w, rct_widgetindex widgetIndex);
|
2018-06-04 13:41:27 +02:00
|
|
|
static void window_view_clipping_mousedown(rct_window*w, rct_widgetindex widgetIndex, rct_widget *widget);
|
2018-05-09 00:32:04 +02:00
|
|
|
static void window_view_clipping_update(rct_window* w);
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_view_clipping_tool_update(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords);
|
|
|
|
static void window_view_clipping_tool_down(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords);
|
|
|
|
static void window_view_clipping_tool_drag(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords);
|
|
|
|
static void window_view_clipping_tool_up(rct_window* w, rct_widgetindex, const ScreenCoordsXY&);
|
2018-05-09 00:32:04 +02:00
|
|
|
static void window_view_clipping_invalidate(rct_window* w);
|
|
|
|
static void window_view_clipping_paint(rct_window* w, rct_drawpixelinfo* dpi);
|
|
|
|
static void window_view_clipping_scrollgetsize(rct_window* w, int scrollIndex, int* width, int* height);
|
2017-08-06 14:41:13 +02:00
|
|
|
static void window_view_clipping_close();
|
2016-12-28 21:45:52 +01:00
|
|
|
|
|
|
|
static rct_window_event_list window_view_clipping_events = {
|
2017-06-06 23:24:18 +02:00
|
|
|
window_view_clipping_close_button,
|
|
|
|
window_view_clipping_mouseup,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2018-06-04 13:41:27 +02:00
|
|
|
window_view_clipping_mousedown,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_view_clipping_update,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2018-05-09 00:32:04 +02:00
|
|
|
window_view_clipping_tool_update,
|
2018-05-08 01:25:05 +02:00
|
|
|
window_view_clipping_tool_down,
|
|
|
|
window_view_clipping_tool_drag,
|
|
|
|
window_view_clipping_tool_up,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_view_clipping_scrollgetsize,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_view_clipping_invalidate,
|
|
|
|
window_view_clipping_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2016-12-28 21:45:52 +01:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2016-12-28 21:45:52 +01:00
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_set_clipheight(rct_window* w, const uint8_t clipheight)
|
2017-01-07 14:51:29 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gClipHeight = clipheight;
|
|
|
|
rct_widget* widget = &window_view_clipping_widgets[WIDX_CLIP_HEIGHT_SLIDER];
|
2020-04-18 13:32:48 +02:00
|
|
|
const float clip_height_ratio = static_cast<float>(gClipHeight) / 255;
|
2020-06-25 03:44:00 +02:00
|
|
|
w->scrolls[0].h_left = static_cast<int16_t>(std::ceil(clip_height_ratio * (w->scrolls[0].h_right - (widget->width() - 1))));
|
2017-01-07 14:51:29 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_view_clipping_open()
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* window;
|
|
|
|
|
|
|
|
// Get the main viewport to set the view clipping flag.
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* mainWindow = window_get_main();
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Check if window is already open
|
2017-08-12 23:06:12 +02:00
|
|
|
window = window_find_by_class(WC_VIEW_CLIPPING);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (window != nullptr)
|
|
|
|
{
|
2017-08-12 23:06:12 +02:00
|
|
|
return window;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Window is not open - create it.
|
2019-10-19 13:07:03 +02:00
|
|
|
window = window_create(ScreenCoordsXY(32, 32), WW, WH, &window_view_clipping_events, WC_VIEW_CLIPPING, 0);
|
2017-06-06 23:24:18 +02:00
|
|
|
window->widgets = window_view_clipping_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
window->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CLIP_CHECKBOX_ENABLE) | (1ULL << WIDX_CLIP_HEIGHT_VALUE)
|
|
|
|
| (1ULL << WIDX_CLIP_HEIGHT_INCREASE) | (1ULL << WIDX_CLIP_HEIGHT_DECREASE) | (1ULL << WIDX_CLIP_HEIGHT_SLIDER)
|
|
|
|
| (1ULL << WIDX_CLIP_SELECTOR) | (1ULL << WIDX_CLIP_CLEAR);
|
2018-06-04 13:41:27 +02:00
|
|
|
window->hold_down_widgets = (1ULL << WIDX_CLIP_HEIGHT_INCREASE) | (1UL << WIDX_CLIP_HEIGHT_DECREASE);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
|
|
|
|
// Initialise the clip height slider from the current clip height value.
|
|
|
|
window_view_clipping_set_clipheight(window, gClipHeight);
|
|
|
|
|
|
|
|
window_push_others_below(window);
|
|
|
|
|
|
|
|
// Turn on view clipping when the window is opened.
|
2018-06-22 23:21:44 +02:00
|
|
|
if (mainWindow != nullptr)
|
|
|
|
{
|
2018-05-08 01:25:05 +02:00
|
|
|
mainWindow->viewport->flags |= VIEWPORT_FLAG_CLIP_VIEW;
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 01:18:03 +02:00
|
|
|
_toolActive = false;
|
|
|
|
_dragging = false;
|
|
|
|
|
2017-08-12 23:06:12 +02:00
|
|
|
return window;
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2017-08-06 14:41:13 +02:00
|
|
|
static void window_view_clipping_close()
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Turn off view clipping when the window is closed.
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
|
|
|
{
|
2018-05-08 01:25:05 +02:00
|
|
|
mainWindow->viewport->flags &= ~VIEWPORT_FLAG_CLIP_VIEW;
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_close_button(rct_window* w)
|
2017-01-06 22:43:32 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_view_clipping_close();
|
2017-01-06 22:43:32 +01:00
|
|
|
}
|
|
|
|
|
2018-05-12 13:41:45 +02:00
|
|
|
// Returns true when the tool is active
|
|
|
|
static bool window_view_clipping_tool_is_active()
|
|
|
|
{
|
|
|
|
if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE)))
|
|
|
|
return false;
|
|
|
|
if (gCurrentToolWidget.window_classification != WC_VIEW_CLIPPING)
|
|
|
|
return false;
|
|
|
|
return _toolActive;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* mainWindow;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// mouseup appears to be used for buttons, checkboxes
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_CLIP_CHECKBOX_ENABLE:
|
|
|
|
// Toggle height clipping.
|
|
|
|
mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
|
|
|
{
|
|
|
|
mainWindow->viewport->flags ^= VIEWPORT_FLAG_CLIP_VIEW;
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_CLIP_HEIGHT_VALUE:
|
|
|
|
// Toggle display of the cut height value in RAW vs UNITS
|
|
|
|
if (gClipHeightDisplayType == DISPLAY_TYPE::DISPLAY_RAW)
|
|
|
|
{
|
|
|
|
gClipHeightDisplayType = DISPLAY_TYPE::DISPLAY_UNITS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gClipHeightDisplayType = DISPLAY_TYPE::DISPLAY_RAW;
|
|
|
|
}
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_CLIP_SELECTOR:
|
|
|
|
// Activate the selection tool
|
|
|
|
tool_set(w, WIDX_BACKGROUND, TOOL_CROSSHAIR);
|
|
|
|
_toolActive = true;
|
|
|
|
_dragging = false;
|
|
|
|
|
|
|
|
// Reset clip selection to show all tiles
|
2019-12-30 20:03:34 +01:00
|
|
|
_previousClipSelectionA = gClipSelectionA;
|
|
|
|
_previousClipSelectionB = gClipSelectionB;
|
2018-06-22 23:21:44 +02:00
|
|
|
gClipSelectionA = { 0, 0 };
|
2020-03-16 21:47:38 +01:00
|
|
|
gClipSelectionB = { MAXIMUM_MAP_SIZE_BIG - 1, MAXIMUM_MAP_SIZE_BIG - 1 };
|
2018-06-22 23:21:44 +02:00
|
|
|
gfx_invalidate_screen();
|
|
|
|
break;
|
|
|
|
case WIDX_CLIP_CLEAR:
|
|
|
|
if (window_view_clipping_tool_is_active())
|
|
|
|
{
|
|
|
|
_toolActive = false;
|
|
|
|
tool_cancel();
|
|
|
|
}
|
|
|
|
gClipSelectionA = { 0, 0 };
|
2020-03-16 21:47:38 +01:00
|
|
|
gClipSelectionB = { MAXIMUM_MAP_SIZE_BIG - 1, MAXIMUM_MAP_SIZE_BIG - 1 };
|
2018-06-22 23:21:44 +02:00
|
|
|
gfx_invalidate_screen();
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-04 13:41:27 +02:00
|
|
|
static void window_view_clipping_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
|
|
|
|
{
|
|
|
|
rct_window* mainWindow = window_get_main();
|
|
|
|
|
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLIP_HEIGHT_INCREASE:
|
|
|
|
if (gClipHeight < 255)
|
|
|
|
window_view_clipping_set_clipheight(w, gClipHeight + 1);
|
|
|
|
mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2018-06-04 13:41:27 +02:00
|
|
|
break;
|
|
|
|
case WIDX_CLIP_HEIGHT_DECREASE:
|
|
|
|
if (gClipHeight > 0)
|
|
|
|
window_view_clipping_set_clipheight(w, gClipHeight - 1);
|
|
|
|
mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2018-06-04 13:41:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_update(rct_window* w)
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
const rct_widget* const widget = &window_view_clipping_widgets[WIDX_CLIP_HEIGHT_SLIDER];
|
|
|
|
const rct_scroll* const scroll = &w->scrolls[0];
|
2020-06-25 03:44:00 +02:00
|
|
|
const int16_t scroll_width = widget->width() - 1;
|
2020-04-18 13:32:48 +02:00
|
|
|
const uint8_t clip_height = static_cast<uint8_t>(
|
|
|
|
(static_cast<float>(scroll->h_left) / (scroll->h_right - scroll_width)) * 255);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (clip_height != gClipHeight)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gClipHeight = clip_height;
|
|
|
|
|
|
|
|
// Update the main window accordingly.
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
|
|
|
{
|
2019-06-15 17:20:16 +02:00
|
|
|
mainWindow->Invalidate();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-08 01:25:05 +02:00
|
|
|
|
2018-05-09 01:18:03 +02:00
|
|
|
// Restore previous selection if the tool has been interrupted
|
|
|
|
if (_toolActive && !window_view_clipping_tool_is_active())
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
2018-05-09 01:18:03 +02:00
|
|
|
_toolActive = false;
|
2019-12-30 20:03:34 +01:00
|
|
|
gClipSelectionA = _previousClipSelectionA;
|
|
|
|
gClipSelectionB = _previousClipSelectionB;
|
2018-05-08 01:25:05 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
widget_invalidate(w, WIDX_CLIP_HEIGHT_SLIDER);
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_view_clipping_tool_update(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords)
|
2018-05-09 00:32:04 +02:00
|
|
|
{
|
|
|
|
if (_dragging)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t direction;
|
2019-12-22 13:59:24 +01:00
|
|
|
auto mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
|
|
|
|
if (mapCoords)
|
2018-05-09 00:32:04 +02:00
|
|
|
{
|
|
|
|
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
|
2019-12-28 09:44:33 +01:00
|
|
|
map_invalidate_tile_full(gMapSelectPositionA);
|
2019-12-22 13:59:24 +01:00
|
|
|
gMapSelectPositionA = gMapSelectPositionB = *mapCoords;
|
2019-12-28 09:44:33 +01:00
|
|
|
map_invalidate_tile_full(*mapCoords);
|
2018-05-09 00:32:04 +02:00
|
|
|
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_view_clipping_tool_down(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords)
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t direction;
|
2019-12-22 13:59:24 +01:00
|
|
|
auto mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
|
|
|
|
if (mapCoords)
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
2018-05-09 00:32:04 +02:00
|
|
|
_dragging = true;
|
2019-12-24 21:21:26 +01:00
|
|
|
_selectionStart = *mapCoords;
|
2018-05-08 01:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_view_clipping_tool_drag(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords)
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
2018-05-09 00:32:04 +02:00
|
|
|
if (!_dragging)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t direction;
|
2019-12-22 13:59:24 +01:00
|
|
|
auto mapCoords = screen_pos_to_map_pos(screenCoords, &direction);
|
|
|
|
if (mapCoords)
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
|
|
|
map_invalidate_selection_rect();
|
|
|
|
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
|
2019-12-24 21:21:26 +01:00
|
|
|
gMapSelectPositionA.x = std::min(_selectionStart.x, mapCoords->x);
|
|
|
|
gMapSelectPositionB.x = std::max(_selectionStart.x, mapCoords->x);
|
|
|
|
gMapSelectPositionA.y = std::min(_selectionStart.y, mapCoords->y);
|
|
|
|
gMapSelectPositionB.y = std::max(_selectionStart.y, mapCoords->y);
|
2018-05-08 01:25:05 +02:00
|
|
|
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
|
|
|
map_invalidate_selection_rect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_view_clipping_tool_up(struct rct_window*, rct_widgetindex, const ScreenCoordsXY&)
|
2018-05-08 01:25:05 +02:00
|
|
|
{
|
2020-03-07 21:07:18 +01:00
|
|
|
gClipSelectionA = gMapSelectPositionA;
|
|
|
|
gClipSelectionB = gMapSelectPositionB;
|
2018-05-09 01:18:03 +02:00
|
|
|
_toolActive = false;
|
2018-05-08 01:25:05 +02:00
|
|
|
tool_cancel();
|
|
|
|
gfx_invalidate_screen();
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_invalidate(rct_window* w)
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
widget_scroll_update_thumbs(w, WIDX_CLIP_HEIGHT_SLIDER);
|
2016-12-28 21:45:52 +01:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* mainWindow = window_get_main();
|
|
|
|
if (mainWindow != nullptr)
|
|
|
|
{
|
2018-05-12 13:41:45 +02:00
|
|
|
widget_set_checkbox_value(w, WIDX_CLIP_CHECKBOX_ENABLE, mainWindow->viewport->flags & VIEWPORT_FLAG_CLIP_VIEW);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2018-05-12 14:47:45 +02:00
|
|
|
|
|
|
|
if (window_view_clipping_tool_is_active())
|
|
|
|
{
|
|
|
|
w->pressed_widgets |= 1ULL << WIDX_CLIP_SELECTOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w->pressed_widgets &= ~(1ULL << WIDX_CLIP_SELECTOR);
|
|
|
|
}
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
|
|
|
|
// Clip height value
|
2020-06-20 21:09:45 +02:00
|
|
|
auto screenCoords = w->windowPos + ScreenCoordsXY{ 8, w->widgets[WIDX_CLIP_HEIGHT_VALUE].top };
|
|
|
|
gfx_draw_string_left(dpi, STR_VIEW_CLIPPING_HEIGHT_VALUE, nullptr, w->colours[0], screenCoords);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-06-20 21:09:45 +02:00
|
|
|
screenCoords = w->windowPos
|
|
|
|
+ ScreenCoordsXY{ w->widgets[WIDX_CLIP_HEIGHT_VALUE].left + 1, w->widgets[WIDX_CLIP_HEIGHT_VALUE].top };
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
fixed16_1dp clipHeightValueInUnits;
|
|
|
|
fixed32_2dp clipHeightValueInMeters;
|
|
|
|
fixed16_1dp clipHeightValueInFeet;
|
2020-04-18 13:32:48 +02:00
|
|
|
int32_t clipHeightRawValue = static_cast<int32_t>(gClipHeight);
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (gClipHeightDisplayType)
|
|
|
|
{
|
|
|
|
case DISPLAY_TYPE::DISPLAY_RAW:
|
|
|
|
default:
|
2020-06-20 21:09:45 +02:00
|
|
|
gfx_draw_string_left(
|
|
|
|
dpi, STR_FORMAT_INTEGER, &clipHeightRawValue, w->colours[0], screenCoords); // Printing the raw value.
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DISPLAY_TYPE::DISPLAY_UNITS:
|
|
|
|
// Print the value in the configured height label type:
|
|
|
|
if (gConfigGeneral.show_height_as_units == 1)
|
|
|
|
{
|
|
|
|
// Height label is Units.
|
2020-04-18 13:32:48 +02:00
|
|
|
clipHeightValueInUnits = static_cast<fixed16_1dp>(FIXED_1DP(gClipHeight, 0) / 2 - FIXED_1DP(7, 0));
|
2018-06-22 23:21:44 +02:00
|
|
|
gfx_draw_string_left(
|
2020-06-20 21:09:45 +02:00
|
|
|
dpi, STR_UNIT1DP_NO_SUFFIX, &clipHeightValueInUnits, w->colours[0],
|
|
|
|
screenCoords); // Printing the value in Height Units.
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Height label is Real Values.
|
|
|
|
// Print the value in the configured measurement units.
|
|
|
|
switch (gConfigGeneral.measurement_format)
|
|
|
|
{
|
|
|
|
case MEASUREMENT_FORMAT_METRIC:
|
|
|
|
case MEASUREMENT_FORMAT_SI:
|
2020-04-18 13:32:48 +02:00
|
|
|
clipHeightValueInMeters = static_cast<fixed32_2dp>(
|
|
|
|
FIXED_2DP(gClipHeight, 0) / 2 * 1.5f - FIXED_2DP(10, 50));
|
2020-06-20 21:09:45 +02:00
|
|
|
gfx_draw_string_left(
|
|
|
|
dpi, STR_UNIT2DP_SUFFIX_METRES, &clipHeightValueInMeters, w->colours[0], screenCoords);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case MEASUREMENT_FORMAT_IMPERIAL:
|
|
|
|
default:
|
2020-04-18 13:32:48 +02:00
|
|
|
clipHeightValueInFeet = static_cast<fixed16_1dp>(
|
|
|
|
FIXED_1DP(gClipHeight, 0) / 2.0f * 5 - FIXED_1DP(35, 0));
|
2020-06-20 21:09:45 +02:00
|
|
|
gfx_draw_string_left(dpi, STR_UNIT1DP_SUFFIX_FEET, &clipHeightValueInFeet, w->colours[0], screenCoords);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_view_clipping_scrollgetsize(rct_window* w, int scrollIndex, int* width, int* height)
|
2016-12-28 21:45:52 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*width = 1000;
|
2016-12-28 21:45:52 +01:00
|
|
|
}
|