Files
OpenRCT2-Web/src/openrct2/interface/Window.cpp
T

2185 lines
61 KiB
C++
Raw Normal View History

2017-06-01 21:55:10 +02:00
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
2018-01-06 00:05:16 +00:00
#include <algorithm>
2014-10-06 17:36:58 +01:00
#include "../audio/audio.h"
#include "../config/Config.h"
2017-03-25 17:42:14 +00:00
#include "../Context.h"
2017-02-17 09:07:05 +01:00
#include "../core/Guard.hpp"
2018-01-06 00:05:16 +00:00
#include "../core/Math.hpp"
#include "../core/Util.hpp"
2018-01-05 21:17:33 +00:00
#include "../drawing/Drawing.h"
#include "../Editor.h"
2017-11-30 18:17:06 +01:00
#include "../Game.h"
2017-12-12 14:52:57 +01:00
#include "../Input.h"
#include "../interface/Cursors.h"
2018-01-06 18:32:25 +01:00
#include "../localisation/Localisation.h"
#include "../localisation/StringIds.h"
2017-07-28 19:44:13 +01:00
#include "../OpenRCT2.h"
2015-02-12 20:51:40 +00:00
#include "../platform/platform.h"
2018-03-19 23:28:40 +01:00
#include "../scenario/Scenario.h"
#include "../sprites.h"
2018-01-03 14:56:08 +01:00
#include "../world/Map.h"
2018-01-11 10:59:26 +01:00
#include "../world/Sprite.h"
#include "../ui/UiContext.h"
#include "../ui/WindowManager.h"
2018-01-05 23:45:53 +00:00
#include "Viewport.h"
2018-01-05 23:56:37 +00:00
#include "Widget.h"
2018-01-06 00:05:16 +00:00
#include "Window.h"
2018-01-05 23:31:19 +01:00
#include "Window_internal.h"
2018-01-06 00:05:16 +00:00
2017-06-06 23:24:18 +02:00
#define RCT2_FIRST_WINDOW (g_window_list)
#define RCT2_LAST_WINDOW (gWindowNextSlot - 1)
#define RCT2_NEW_WINDOW (gWindowNextSlot)
2016-07-26 03:45:26 -04:00
rct_window g_window_list[WINDOW_LIMIT_MAX + WINDOW_LIMIT_RESERVED];
rct_window * gWindowFirst;
2018-01-07 21:43:07 +01:00
rct_window * gWindowNextSlot = nullptr;
2016-09-10 22:18:51 +01:00
rct_window * gWindowAudioExclusive;
2015-12-31 09:16:44 +01:00
uint16 TextInputDescriptionArgs[4];
2015-06-06 17:04:53 -04:00
widget_identifier gCurrentTextBox = { { 255, 0 }, 0 };
2017-04-14 19:17:38 +02:00
char gTextBoxInput[TEXT_INPUT_SIZE] = { 0 };
2017-01-04 22:17:08 +01:00
sint32 gMaxTextBoxInputLength = 0;
sint32 gTextBoxFrameNo = 0;
bool gUsingWidgetTextBox = false;
2017-03-26 03:36:22 +01:00
TextInputSession * gTextInput;
2015-05-13 11:38:44 -04:00
2016-08-06 01:35:46 +01:00
uint16 gWindowUpdateTicks;
2016-05-13 22:51:16 +01:00
uint16 gWindowMapFlashingFlags;
2016-08-06 01:32:40 +01:00
colour_t gCurrentWindowColours[4];
2014-09-22 02:04:10 -06:00
// converted from uint16 values at 0x009A41EC - 0x009A4230
2017-07-01 00:11:28 +02:00
// these are percentage coordinates of the viewport to centre to, if a window is obscuring a location, the next is tried
2018-01-11 23:14:31 +01:00
static constexpr const float window_scroll_locations[][2] = {
2017-06-06 23:24:18 +02:00
{0.5f, 0.5f},
{0.75f, 0.5f},
{0.25f, 0.5f},
{0.5f, 0.75f},
{0.5f, 0.25f},
{0.75f, 0.75f},
{0.75f, 0.25f},
{0.25f, 0.75f},
{0.25f, 0.25f},
{0.125f, 0.5f},
{0.875f, 0.5f},
{0.5f, 0.125f},
{0.5f, 0.875f},
{0.875f, 0.125f},
{0.875f, 0.875f},
{0.125f, 0.875f},
{0.125f, 0.125f},
2014-09-22 02:04:10 -06:00
};
2017-06-01 22:03:14 +02:00
static bool window_fits_between_others(sint32 x, sint32 y, sint32 width, sint32 height);
2017-01-04 22:17:08 +01:00
static sint32 window_draw_split(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom);
static void window_draw_single(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom);
2014-04-08 19:49:04 +01:00
2014-04-08 17:52:39 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-08 17:52:39 +01:00
* rct2: 0x006ED7B0
*/
void window_dispatch_update_all()
{
2017-06-06 23:24:18 +02:00
// gTooltipNotShownTicks++;
for (rct_window *w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
window_event_update_call(w);
}
void window_update_all_viewports()
{
2017-06-06 23:24:18 +02:00
for (rct_window *w = g_window_list; w < RCT2_NEW_WINDOW; w++)
2018-01-07 21:43:07 +01:00
if (w->viewport != nullptr && window_is_visible(w))
2017-06-06 23:24:18 +02:00
viewport_update_position(w);
}
2014-04-08 17:52:39 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-08 17:52:39 +01:00
* rct2: 0x006E77A1
*/
void window_update_all()
{
2017-06-06 23:24:18 +02:00
// gfx_draw_all_dirty_blocks();
// window_update_all_viewports();
// gfx_draw_all_dirty_blocks();
2014-04-08 17:52:39 +01:00
2017-06-06 23:24:18 +02:00
// 1000 tick update
gWindowUpdateTicks += gTicksSinceLastUpdate;
if (gWindowUpdateTicks >= 1000) {
gWindowUpdateTicks = 0;
for (rct_window* w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
window_event_unknown_07_call(w);
}
2014-04-08 17:52:39 +01:00
2017-06-06 23:24:18 +02:00
// Border flash invalidation
for (rct_window* w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
if (w->flags & WF_WHITE_BORDER_MASK) {
w->flags -= WF_WHITE_BORDER_ONE;
if (!(w->flags & WF_WHITE_BORDER_MASK))
window_invalidate(w);
}
}
2014-04-08 17:52:39 +01:00
auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager();
windowManager->UpdateMouseWheel();
2014-04-08 17:52:39 +01:00
}
2017-01-04 22:17:08 +01:00
static void window_close_surplus(sint32 cap, sint8 avoid_classification)
{
2017-06-06 23:24:18 +02:00
sint32 count, i, diff;
//find the amount of windows that are currently open
count = WINDOW_LIMIT_MAX;
for (i = 0; i < WINDOW_LIMIT_MAX; i++) {
if (&g_window_list[i] == RCT2_NEW_WINDOW) {
count = i;
break;
}
}
//difference between amount open and cap = amount to close
diff = count - WINDOW_LIMIT_RESERVED - cap;
for (i = 0; i < diff; i++) {
2018-01-07 21:43:07 +01:00
rct_window *w = nullptr;
2017-06-06 23:24:18 +02:00
//iterates through the list until it finds the newest window, or a window that can be closed
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) {
if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT | WF_NO_AUTO_CLOSE)))
break;
}
//skip window if window matches specified rct_windowclass (as user may be modifying via options)
2018-01-07 21:43:07 +01:00
if (avoid_classification != -1 && w != nullptr && w->classification == avoid_classification) {
2017-06-06 23:24:18 +02:00
continue;
}
window_close(w);
}
}
/*
* Changes the maximum amount of windows allowed
*/
2017-01-04 22:17:08 +01:00
void window_set_window_limit(sint32 value)
{
2017-06-06 23:24:18 +02:00
sint32 prev = gConfigGeneral.window_limit;
2018-01-06 00:05:16 +00:00
sint32 val = Math::Clamp(WINDOW_LIMIT_MIN, value, WINDOW_LIMIT_MAX);
2017-06-06 23:24:18 +02:00
gConfigGeneral.window_limit = val;
config_save_default();
// Checks if value decreases and then closes surplus
// windows if one sets a limit lower than the number of windows open
if (val < prev) {
window_close_surplus(val, WC_OPTIONS);
}
}
/**
* Closes the specified window.
* rct2: 0x006ECD4C
*
* @param window The window to close (esi).
*/
void window_close(rct_window* window)
{
2017-06-06 23:24:18 +02:00
sint32 num_windows;
2018-01-07 21:43:07 +01:00
if (window == nullptr)
2017-06-06 23:24:18 +02:00
return;
2017-06-06 23:24:18 +02:00
// Make a copy of the window class and number in case
// the window order is changed by the close event.
rct_windowclass cls = window->classification;
rct_windownumber number = window->number;
2017-06-06 23:24:18 +02:00
window_event_close_call(window);
2017-06-06 23:24:18 +02:00
window = window_find_by_number(cls, number);
2018-01-07 21:43:07 +01:00
if (window == nullptr)
2017-06-06 23:24:18 +02:00
return;
2017-06-06 23:24:18 +02:00
// Remove viewport
2018-01-07 21:43:07 +01:00
if (window->viewport != nullptr) {
2017-06-06 23:24:18 +02:00
window->viewport->width = 0;
2018-01-07 21:43:07 +01:00
window->viewport = nullptr;
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
// Invalidate the window (area)
window_invalidate(window);
2017-06-06 23:24:18 +02:00
// Remove window from list and reshift all windows
RCT2_NEW_WINDOW--;
num_windows = (sint32)(RCT2_NEW_WINDOW - window);
if (num_windows > 0)
memmove(window, window + 1, num_windows * sizeof(rct_window));
2017-06-06 23:24:18 +02:00
viewport_update_pointers();
}
2014-04-09 14:43:27 +01:00
/**
2014-10-16 02:02:43 +01:00
* Closes all windows with the specified window class.
2014-04-09 14:43:27 +01:00
* rct2: 0x006ECCF4
2014-10-16 02:02:43 +01:00
* @param cls (cl) with bit 15 set
2014-04-09 14:43:27 +01:00
*/
2014-10-16 02:02:43 +01:00
void window_close_by_class(rct_windowclass cls)
2014-04-09 14:43:27 +01:00
{
2017-06-06 23:24:18 +02:00
for (rct_window *w = g_window_list; w < RCT2_NEW_WINDOW;) {
if (w->classification == cls) {
window_close(w);
w = g_window_list;
} else {
w++;
}
}
2014-04-09 14:43:27 +01:00
}
/**
2014-10-16 02:02:43 +01:00
* Closes all windows with specified window class and number.
* rct2: 0x006ECCF4
* @param cls (cl) without bit 15 set
* @param number (dx)
*/
2014-10-16 02:02:43 +01:00
void window_close_by_number(rct_windowclass cls, rct_windownumber number)
{
2017-06-06 23:24:18 +02:00
for (rct_window* w = g_window_list; w < RCT2_NEW_WINDOW;) {
if (w->classification == cls && w->number == number) {
window_close(w);
w = g_window_list;
} else {
w++;
}
}
2014-10-16 02:02:43 +01:00
}
/**
* Finds the first window with the specified window class.
* rct2: 0x006EA8A0
* @param cls (cl) with bit 15 set
* @returns the window or NULL if no window was found.
*/
rct_window *window_find_by_class(rct_windowclass cls)
{
2017-06-06 23:24:18 +02:00
for (rct_window *w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls)
return w;
2014-10-16 02:02:43 +01:00
2018-01-07 21:43:07 +01:00
return nullptr;
2014-10-16 02:02:43 +01:00
}
/**
* Finds the first window with the specified window class and number.
* rct2: 0x006EA8A0
* @param cls (cl) without bit 15 set
* @param number (dx)
* @returns the window or NULL if no window was found.
*/
rct_window *window_find_by_number(rct_windowclass cls, rct_windownumber number)
{
2017-06-06 23:24:18 +02:00
rct_window *w;
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls && w->number == number)
return w;
2018-01-07 21:43:07 +01:00
return nullptr;
}
2014-05-09 12:54:11 +02:00
/**
2015-12-11 09:38:37 -06:00
* Closes the top-most window
2014-05-09 12:54:11 +02:00
*
* rct2: 0x006E403C
*/
2014-05-12 01:45:45 +01:00
void window_close_top()
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2014-05-09 12:54:11 +02:00
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_DROPDOWN);
2014-05-09 12:54:11 +02:00
2017-06-06 23:24:18 +02:00
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
if (gS6Info.editor_step != EDITOR_STEP_LANDSCAPE_EDITOR)
return;
2014-05-12 01:45:45 +01:00
2017-06-06 23:24:18 +02:00
for (w = RCT2_NEW_WINDOW - 1; w >= g_window_list; w--) {
if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) {
window_close(w);
return;
}
}
2014-05-09 12:54:11 +02:00
}
/**
2015-12-11 09:38:37 -06:00
* Closes all open windows
2014-05-09 12:54:11 +02:00
*
* rct2: 0x006EE927
*/
void window_close_all()
{
2018-02-10 21:37:25 +00:00
if (gWindowNextSlot == nullptr)
{
return;
}
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_DROPDOWN);
2014-05-09 12:54:11 +02:00
2017-12-20 02:14:29 +01:00
for (rct_window * w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
{
if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)))
{
2017-06-06 23:24:18 +02:00
window_close(w);
}
}
2014-05-09 12:54:11 +02:00
}
void window_close_all_except_class(rct_windowclass cls)
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2015-05-23 14:56:54 -04:00
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_DROPDOWN);
2015-05-23 14:56:54 -04:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w <= RCT2_LAST_WINDOW; w++){
if (w->classification != cls && !(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) {
window_close(w);
w = g_window_list;
}
}
2015-05-23 14:56:54 -04:00
}
2017-12-25 09:40:53 +01:00
/**
* Closes all windows, save for those having any of the passed flags.
*/
2017-12-20 02:14:29 +01:00
void window_close_all_except_flags(uint16 flags)
{
for (rct_window * w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
{
if (!(w->flags & flags))
{
window_close(w);
}
}
}
2014-04-14 03:09:51 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-14 03:09:51 +01:00
* rct2: 0x006EA845
*/
2017-01-04 22:17:08 +01:00
rct_window *window_find_from_point(sint32 x, sint32 y)
2014-04-14 03:09:51 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window *w;
sint32 widget_index;
2014-04-14 03:09:51 +01:00
2017-06-06 23:24:18 +02:00
for (w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
if (x < w->x || x >= w->x + w->width || y < w->y || y >= w->y + w->height)
continue;
2014-04-14 03:09:51 +01:00
2017-06-06 23:24:18 +02:00
if (w->flags & WF_NO_BACKGROUND) {
widget_index = window_find_widget_from_point(w, x, y);
if (widget_index == -1)
continue;
}
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
return w;
}
2014-04-14 03:09:51 +01:00
2018-01-07 21:43:07 +01:00
return nullptr;
2014-04-14 03:09:51 +01:00
}
/**
2015-09-22 19:18:57 +02:00
*
2014-04-14 03:09:51 +01:00
* rct2: 0x006EA594
* x (ax)
* y (bx)
* returns widget_index (edx)
* EDI NEEDS TO BE SET TO w->widgets[widget_index] AFTER
*/
2017-05-01 15:41:45 +02:00
rct_widgetindex window_find_widget_from_point(rct_window *w, sint32 x, sint32 y)
2014-04-14 03:09:51 +01:00
{
2017-06-06 23:24:18 +02:00
// Invalidate the window
window_event_invalidate_call(w);
2014-04-14 03:09:51 +01:00
2017-06-06 23:24:18 +02:00
// Find the widget at point x, y
rct_widgetindex widget_index = -1;
for (sint32 i = 0;; i++) {
rct_widget *widget = &w->widgets[i];
if (widget->type == WWT_LAST) {
break;
} else if (widget->type != WWT_EMPTY) {
if (x >= w->x + widget->left && x <= w->x + widget->right &&
y >= w->y + widget->top && y <= w->y + widget->bottom
) {
widget_index = i;
}
}
}
2014-04-14 03:09:51 +01:00
2017-06-06 23:24:18 +02:00
// Return next widget if a dropdown
if (widget_index != -1)
if (w->widgets[widget_index].type == WWT_DROPDOWN)
widget_index++;
2014-04-14 03:09:51 +01:00
2017-06-06 23:24:18 +02:00
// Return the widget index
return widget_index;
2014-04-14 03:09:51 +01:00
}
/**
* Invalidates the specified window.
* rct2: 0x006EB13A
*
* @param window The window to invalidate (esi).
*/
void window_invalidate(rct_window *window)
{
2018-01-07 21:43:07 +01:00
if (window != nullptr)
2017-06-06 23:24:18 +02:00
gfx_set_dirty_blocks(window->x, window->y, window->x + window->width, window->y + window->height);
2014-04-04 21:46:26 +01:00
}
2014-04-04 21:46:26 +01:00
/**
2014-10-16 02:02:43 +01:00
* Invalidates all windows with the specified window class.
2014-04-04 21:46:26 +01:00
* rct2: 0x006EC3AC
2014-10-16 02:02:43 +01:00
* @param cls (al) with bit 14 set
2014-04-04 21:46:26 +01:00
*/
2014-10-16 02:02:43 +01:00
void window_invalidate_by_class(rct_windowclass cls)
2014-04-04 21:46:26 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2014-04-04 21:46:26 +01:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls)
window_invalidate(w);
}
2014-10-16 02:02:43 +01:00
/**
* Invalidates all windows with the specified window class and number.
* rct2: 0x006EC3AC
* @param (ah) widget index
* @param cls (al) without bit 14 set
* @param number (bx)
*/
void window_invalidate_by_number(rct_windowclass cls, rct_windownumber number)
2014-04-14 21:25:20 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls && w->number == number)
window_invalidate(w);
2014-10-16 02:02:43 +01:00
}
/**
2015-12-11 09:38:37 -06:00
* Invalidates all windows.
*/
void window_invalidate_all()
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
window_invalidate(w);
}
2014-10-16 02:02:43 +01:00
/**
* Invalidates the specified widget of a window.
* rct2: 0x006EC402
*/
2017-05-01 15:41:45 +02:00
void widget_invalidate(rct_window *w, rct_widgetindex widgetIndex)
2014-10-16 02:02:43 +01:00
{
2017-06-06 23:24:18 +02:00
rct_widget* widget;
2014-10-16 02:02:43 +01:00
2018-01-29 17:06:01 +01:00
assert(w != nullptr);
2017-02-07 21:01:07 +01:00
#ifdef DEBUG
2017-06-06 23:24:18 +02:00
for (sint32 i = 0; i <= widgetIndex; i++) {
assert(w->widgets[i].type != WWT_LAST);
}
2016-08-21 15:20:30 +01:00
#endif
2017-06-06 23:24:18 +02:00
widget = &w->widgets[widgetIndex];
if (widget->left == -2)
return;
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
gfx_set_dirty_blocks(w->x + widget->left, w->y + widget->top, w->x + widget->right + 1, w->y + widget->bottom + 1);
2014-10-16 02:02:43 +01:00
}
/**
* Invalidates the specified widget of all windows that match the specified window class.
*/
2017-05-01 15:41:45 +02:00
void widget_invalidate_by_class(rct_windowclass cls, rct_widgetindex widgetIndex)
2014-10-16 02:02:43 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls)
widget_invalidate(w, widgetIndex);
2014-10-16 02:02:43 +01:00
}
/**
* Invalidates the specified widget of all windows that match the specified window class and number.
* rct2: 0x006EC3AC
* @param (ah) widget index
* @param cls (al) with bit 15 set
* @param number (bx)
*/
2017-05-01 15:41:45 +02:00
void widget_invalidate_by_number(rct_windowclass cls, rct_windownumber number, rct_widgetindex widgetIndex)
2014-10-16 02:02:43 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == cls && w->number == number)
widget_invalidate(w, widgetIndex);
2014-04-14 21:25:20 +01:00
}
2014-04-25 03:02:06 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-25 03:02:06 +01:00
* rct2: 0x006EAE4E
*
* @param w The window (esi).
*/
void window_update_scroll_widgets(rct_window *w)
{
2017-06-06 23:24:18 +02:00
sint32 scrollIndex, width, height, scrollPositionChanged;
rct_widgetindex widgetIndex;
rct_scroll *scroll;
rct_widget *widget;
2017-06-06 23:24:18 +02:00
widgetIndex = 0;
scrollIndex = 0;
2018-01-29 17:06:01 +01:00
assert(w != nullptr);
2017-06-06 23:24:18 +02:00
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
if (widget->type != WWT_SCROLL)
continue;
2017-06-06 23:24:18 +02:00
scroll = &w->scrolls[scrollIndex];
width = 0;
height = 0;
window_get_scroll_size(w, scrollIndex, &width, &height);
if (height == 0){
scroll->v_top = 0;
}
else if (width == 0){
scroll->h_left = 0;
}
width++;
height++;
2017-06-06 23:24:18 +02:00
scrollPositionChanged = 0;
if ((widget->content & SCROLL_HORIZONTAL) && width != scroll->h_right) {
scrollPositionChanged = 1;
scroll->h_right = width;
}
2017-06-06 23:24:18 +02:00
if ((widget->content & SCROLL_VERTICAL) && height != scroll->v_bottom) {
scrollPositionChanged = 1;
scroll->v_bottom = height;
}
2017-06-06 23:24:18 +02:00
if (scrollPositionChanged) {
widget_scroll_update_thumbs(w, widgetIndex);
window_invalidate(w);
}
scrollIndex++;
}
2014-04-25 03:02:06 +01:00
}
2017-05-01 15:41:45 +02:00
sint32 window_get_scroll_data_index(rct_window *w, rct_widgetindex widget_index)
2014-04-03 19:49:00 +01:00
{
2017-06-06 23:24:18 +02:00
sint32 i, result;
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
result = 0;
2018-01-29 17:06:01 +01:00
assert(w != nullptr);
2017-06-06 23:24:18 +02:00
for (i = 0; i < widget_index; i++) {
if (w->widgets[i].type == WWT_SCROLL)
result++;
}
return result;
2014-04-03 19:49:00 +01:00
}
/**
2015-09-22 19:18:57 +02:00
*
2014-04-03 19:49:00 +01:00
* rct2: 0x006ECDA4
*/
rct_window *window_bring_to_front(rct_window *w)
{
2017-06-06 23:24:18 +02:00
if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))
return w;
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
rct_window *v;
for (v = RCT2_LAST_WINDOW; v >= g_window_list; v--)
if (!(v->flags & WF_STICK_TO_FRONT))
break;
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
if (v >= g_window_list && w != v) {
do {
rct_window t = *w;
*w = *(w + 1);
*(w + 1) = t;
w++;
} while (w != v);
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
window_invalidate(w);
}
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
if (w->x + w->width < 20) {
sint32 i = 20 - w->x;
w->x += i;
2018-01-07 21:43:07 +01:00
if (w->viewport != nullptr)
2017-06-06 23:24:18 +02:00
w->viewport->x += i;
window_invalidate(w);
}
2014-04-03 19:49:00 +01:00
2017-06-06 23:24:18 +02:00
return w;
2014-04-08 17:52:39 +01:00
}
rct_window *window_bring_to_front_by_class_with_flags(rct_windowclass cls, uint16 flags)
2014-10-16 02:02:43 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
w = window_find_by_class(cls);
2018-01-07 21:43:07 +01:00
if (w != nullptr) {
2017-06-06 23:24:18 +02:00
w->flags |= flags;
window_invalidate(w);
w = window_bring_to_front(w);
}
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
return w;
2014-10-16 02:02:43 +01:00
}
rct_window *window_bring_to_front_by_class(rct_windowclass cls)
{
2017-06-06 23:24:18 +02:00
return window_bring_to_front_by_class_with_flags(cls, WF_WHITE_BORDER_MASK);
}
2014-10-16 02:02:43 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-10-16 02:02:43 +01:00
* rct2: 0x006ED78A
* cls (cl)
* number (dx)
*/
rct_window *window_bring_to_front_by_number(rct_windowclass cls, rct_windownumber number)
{
2017-06-06 23:24:18 +02:00
rct_window* w;
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
w = window_find_by_number(cls, number);
2018-01-07 21:43:07 +01:00
if (w != nullptr) {
2017-06-06 23:24:18 +02:00
w->flags |= WF_WHITE_BORDER_MASK;
window_invalidate(w);
w = window_bring_to_front(w);
}
2014-10-16 02:02:43 +01:00
2017-06-06 23:24:18 +02:00
return w;
2014-10-16 02:02:43 +01:00
}
/**
*
2015-12-11 09:38:37 -06:00
* rct2: 0x006EE65A
*/
void window_push_others_right(rct_window* window)
{
2017-06-06 23:24:18 +02:00
for (rct_window* w = g_window_list; w < gWindowNextSlot; w++) {
if (w == window)
continue;
if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))
continue;
if (w->x >= window->x + window->width)
continue;
if (w->x + w->width <= window->x)
continue;
if (w->y >= window->y + window->height)
continue;
if (w->y + w->height <= window->y)
continue;
2017-06-06 23:24:18 +02:00
window_invalidate(w);
if (window->x + window->width + 13 >= context_get_width())
continue;
uint16 push_amount = window->x + window->width - w->x + 3;
w->x += push_amount;
window_invalidate(w);
2018-01-07 21:43:07 +01:00
if (w->viewport != nullptr)
2017-06-06 23:24:18 +02:00
w->viewport->x += push_amount;
}
}
2014-04-13 22:23:56 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-13 22:23:56 +01:00
* rct2: 0x006EE6EA
*/
void window_push_others_below(rct_window *w1)
{
2017-06-06 23:24:18 +02:00
sint32 push_amount;
rct_window* w2;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Enumerate through all other windows
for (w2 = g_window_list; w2 < RCT2_NEW_WINDOW; w2++) {
if (w1 == w2)
continue;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// ?
if (w2->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))
continue;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Check if w2 intersects with w1
if (w2->x > (w1->x + w1->width) || w2->x + w2->width < w1->x)
continue;
if (w2->y > (w1->y + w1->height) || w2->y + w2->height < w1->y)
continue;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Check if there is room to push it down
if (w1->y + w1->height + 80 >= context_get_height())
continue;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate the window's current area
window_invalidate(w2);
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
push_amount = w1->y + w1->height - w2->y + 3;
w2->y += push_amount;
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate the window's new area
window_invalidate(w2);
2014-04-13 22:23:56 +01:00
2017-06-06 23:24:18 +02:00
// Update viewport position if necessary
2018-01-07 21:43:07 +01:00
if (w2->viewport != nullptr)
2017-06-06 23:24:18 +02:00
w2->viewport->y += push_amount;
}
2014-04-13 22:23:56 +01:00
}
2014-04-09 17:06:47 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-09 17:06:47 +01:00
* rct2: 0x006EE2E4
*/
rct_window *window_get_main()
{
2018-01-07 21:43:07 +01:00
rct_window* w = nullptr;
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (w->classification == WC_MAIN_WINDOW)
return w;
2014-04-09 17:06:47 +01:00
2018-01-07 21:43:07 +01:00
openrct2_assert(w != nullptr, "Failed to get main window");
return nullptr;
}
/**
2015-09-22 19:18:57 +02:00
* Based on
2015-12-11 09:38:37 -06:00
* rct2: 0x696ee9, 0x66842F, 0x006AF3B3
*/
void window_scroll_to_viewport(rct_window *w)
{
2017-06-06 23:24:18 +02:00
sint32 x, y, z;
rct_window *mainWindow;
2018-01-29 17:06:01 +01:00
assert(w != nullptr);
2017-06-06 23:24:18 +02:00
// In original checked to make sure x and y were not -1 as well.
2018-01-07 21:43:07 +01:00
if (w->viewport == nullptr || w->viewport_focus_coordinates.y == -1)
2017-06-06 23:24:18 +02:00
return;
2017-06-06 23:24:18 +02:00
if (w->viewport_focus_sprite.type & VIEWPORT_FOCUS_TYPE_SPRITE) {
rct_sprite *sprite = get_sprite(w->viewport_focus_sprite.sprite_id);
x = sprite->unknown.x;
y = sprite->unknown.y;
z = sprite->unknown.z;
} else {
x = w->viewport_focus_coordinates.x;
y = w->viewport_focus_coordinates.y & VIEWPORT_FOCUS_Y_MASK;
z = w->viewport_focus_coordinates.z;
}
2017-06-06 23:24:18 +02:00
mainWindow = window_get_main();
2018-01-07 21:43:07 +01:00
if (mainWindow != nullptr)
2017-06-06 23:24:18 +02:00
window_scroll_to_location(mainWindow, x, y, z);
2014-04-09 17:06:47 +01:00
}
void window_set_location(rct_window *w, sint32 x, sint32 y, sint32 z)
{
2017-06-06 23:24:18 +02:00
window_scroll_to_location(w, x, y, z);
w->flags &= ~WF_SCROLLING_TO_LOCATION;
}
2014-04-11 17:38:15 +01:00
/**
2014-09-22 02:04:10 -06:00
*
* rct2: 0x006E7C9C
* @param w (esi)
* @param x (eax)
* @param y (ecx)
* @param z (edx)
*/
2017-01-04 22:17:08 +01:00
void window_scroll_to_location(rct_window *w, sint32 x, sint32 y, sint32 z)
2014-04-11 17:38:15 +01:00
{
LocationXYZ16 location_3d = {
2018-01-06 00:05:16 +00:00
/* .x = */ (sint16)x,
/* .y = */ (sint16)y,
/* .z = */ (sint16)z
2017-06-06 23:24:18 +02:00
};
2018-01-29 17:06:01 +01:00
assert(w != nullptr);
2017-11-02 20:16:30 -04:00
window_unfollow_sprite(w);
2017-06-06 23:24:18 +02:00
if (w->viewport) {
2017-10-31 12:57:40 +01:00
sint16 height = tile_element_height(x, y);
2017-06-06 23:24:18 +02:00
if (z < height - 16) {
if (!(w->viewport->flags & 1 << 0)) {
w->viewport->flags |= 1 << 0;
window_invalidate(w);
}
} else {
if (w->viewport->flags & 1 << 0) {
w->viewport->flags &= ~(1 << 0);
window_invalidate(w);
}
}
LocationXY16 map_coordinate = coordinate_3d_to_2d(&location_3d, get_current_rotation());
2017-06-06 23:24:18 +02:00
sint32 i = 0;
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) {
sint32 found = 0;
while (!found) {
sint16 x2 = w->viewport->x + (sint16)(w->viewport->width * window_scroll_locations[i][0]);
sint16 y2 = w->viewport->y + (sint16)(w->viewport->height * window_scroll_locations[i][1]);
rct_window* w2 = w;
while (true) {
2017-06-06 23:24:18 +02:00
w2++;
if (w2 >= gWindowNextSlot) {
found = 1;
break;
}
sint16 x1 = w2->x - 10;
sint16 y1 = w2->y - 10;
if (x2 >= x1 && x2 <= w2->width + x1 + 20) {
if (y2 >= y1 && y2 <= w2->height + y1 + 20) {
// window is covering this area, try the next one
i++;
found = 0;
break;
}
}
}
2018-01-06 00:05:16 +00:00
if (i >= (sint32)Util::CountOf(window_scroll_locations)) {
2017-06-06 23:24:18 +02:00
i = 0;
found = 1;
}
}
}
// rct2: 0x006E7C76
if (w->viewport_target_sprite == SPRITE_INDEX_NULL) {
2017-06-06 23:24:18 +02:00
if (!(w->flags & WF_NO_SCROLLING)) {
w->saved_view_x = map_coordinate.x - (sint16)(w->viewport->view_width * window_scroll_locations[i][0]);
w->saved_view_y = map_coordinate.y - (sint16)(w->viewport->view_height * window_scroll_locations[i][1]);
w->flags |= WF_SCROLLING_TO_LOCATION;
}
}
}
2014-04-11 17:38:15 +01:00
}
/**
2015-09-22 19:18:57 +02:00
*
* rct2: 0x00688956
*/
2017-06-26 03:56:41 -04:00
static void call_event_viewport_rotate_on_all_windows()
{
2017-06-06 23:24:18 +02:00
rct_window *w;
2017-06-06 23:24:18 +02:00
for (w = RCT2_NEW_WINDOW - 1; w >= g_window_list; w--)
2017-06-26 03:56:41 -04:00
window_event_viewport_rotate_call(w);
}
2014-04-10 15:14:47 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-10 15:14:47 +01:00
* rct2: 0x0068881A
2015-12-11 09:38:37 -06:00
* direction can be used to alter the camera rotation:
2017-06-06 23:24:18 +02:00
* 1: clockwise
* -1: anti-clockwise
2014-04-10 15:14:47 +01:00
*/
2017-01-04 22:17:08 +01:00
void window_rotate_camera(rct_window *w, sint32 direction)
2014-04-10 15:14:47 +01:00
{
2017-06-06 23:24:18 +02:00
rct_viewport *viewport = w->viewport;
2018-01-07 21:43:07 +01:00
if (viewport == nullptr)
2017-06-06 23:24:18 +02:00
return;
2017-06-06 23:24:18 +02:00
sint16 x = (viewport->width >> 1) + viewport->x;
sint16 y = (viewport->height >> 1) + viewport->y;
sint16 z;
2017-06-06 23:24:18 +02:00
//has something to do with checking if middle of the viewport is obstructed
rct_viewport *other;
screen_get_map_xy(x, y, &x, &y, &other);
2017-06-06 23:24:18 +02:00
// other != viewport probably triggers on viewports in ride or guest window?
// x is LOCATION_NULL if middle of viewport is obstructed by another window?
if (x == LOCATION_NULL || other != viewport) {
2017-06-06 23:24:18 +02:00
x = (viewport->view_width >> 1) + viewport->view_x;
y = (viewport->view_height >> 1) + viewport->view_y;
2017-06-06 23:24:18 +02:00
viewport_adjust_for_map_height(&x, &y, &z);
}
else {
2017-10-31 12:57:40 +01:00
z = tile_element_height(x, y);
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
gCurrentRotation = (get_current_rotation() + direction) & 3;
2017-06-06 23:24:18 +02:00
sint32 new_x, new_y;
2017-07-01 00:11:28 +02:00
centre_2d_coordinates(x, y, z, &new_x, &new_y, viewport);
2017-06-06 23:24:18 +02:00
w->saved_view_x = new_x;
w->saved_view_y = new_y;
viewport->view_x = new_x;
viewport->view_y = new_y;
2017-06-06 23:24:18 +02:00
window_invalidate(w);
2017-06-26 03:56:41 -04:00
call_event_viewport_rotate_on_all_windows();
2017-06-06 23:24:18 +02:00
reset_all_sprite_quadrant_placements();
2014-04-10 15:14:47 +01:00
}
void window_viewport_get_map_coords_by_cursor(rct_window *w, sint16 *map_x, sint16 *map_y, sint16 *offset_x, sint16 *offset_y)
{
2017-06-06 23:24:18 +02:00
// Get mouse position to offset against.
sint32 mouse_x, mouse_y;
context_get_cursor_position_scaled(&mouse_x, &mouse_y);
2017-06-06 23:24:18 +02:00
// Compute map coordinate by mouse position.
2018-01-07 21:43:07 +01:00
get_map_coordinates_from_pos(mouse_x, mouse_y, VIEWPORT_INTERACTION_MASK_NONE, map_x, map_y, nullptr, nullptr, nullptr);
2017-06-06 23:24:18 +02:00
// Get viewport coordinates centring around the tile.
2017-10-31 12:57:40 +01:00
sint32 base_height = tile_element_height(*map_x, *map_y);
2017-06-06 23:24:18 +02:00
sint32 dest_x, dest_y;
2017-07-01 00:11:28 +02:00
centre_2d_coordinates(*map_x, *map_y, base_height, &dest_x, &dest_y, w->viewport);
2017-06-06 23:24:18 +02:00
// Rebase mouse position onto centre of window, and compensate for zoom level.
sint32 rebased_x = ((w->width >> 1) - mouse_x) * (1 << w->viewport->zoom),
rebased_y = ((w->height >> 1) - mouse_y) * (1 << w->viewport->zoom);
2017-06-06 23:24:18 +02:00
// Compute cursor offset relative to tile.
*offset_x = (w->saved_view_x - (dest_x + rebased_x)) * (1 << w->viewport->zoom);
*offset_y = (w->saved_view_y - (dest_y + rebased_y)) * (1 << w->viewport->zoom);
}
void window_viewport_centre_tile_around_cursor(rct_window *w, sint16 map_x, sint16 map_y, sint16 offset_x, sint16 offset_y)
{
2017-06-06 23:24:18 +02:00
// Get viewport coordinates centring around the tile.
sint32 dest_x, dest_y;
2017-10-31 12:57:40 +01:00
sint32 base_height = tile_element_height(map_x, map_y);
2017-07-01 00:11:28 +02:00
centre_2d_coordinates(map_x, map_y, base_height, &dest_x, &dest_y, w->viewport);
2017-06-06 23:24:18 +02:00
// Get mouse position to offset against.
sint32 mouse_x, mouse_y;
context_get_cursor_position_scaled(&mouse_x, &mouse_y);
2017-06-06 23:24:18 +02:00
// Rebase mouse position onto centre of window, and compensate for zoom level.
sint32 rebased_x = ((w->width >> 1) - mouse_x) * (1 << w->viewport->zoom),
rebased_y = ((w->height >> 1) - mouse_y) * (1 << w->viewport->zoom);
2016-07-22 10:47:07 +02:00
2017-06-06 23:24:18 +02:00
// Apply offset to the viewport.
w->saved_view_x = dest_x + rebased_x + (offset_x / (1 << w->viewport->zoom));
w->saved_view_y = dest_y + rebased_y + (offset_y / (1 << w->viewport->zoom));
}
2017-01-04 22:17:08 +01:00
void window_zoom_set(rct_window *w, sint32 zoomLevel, bool atCursor)
2014-04-26 15:50:01 +01:00
{
2017-06-06 23:24:18 +02:00
rct_viewport* v = w->viewport;
2018-01-06 00:05:16 +00:00
zoomLevel = Math::Clamp(0, zoomLevel, MAX_ZOOM_LEVEL);
2017-06-06 23:24:18 +02:00
if (v->zoom == zoomLevel)
return;
2017-06-06 23:24:18 +02:00
// Zooming to cursor? Remember where we're pointing at the moment.
sint16 saved_map_x = 0;
sint16 saved_map_y = 0;
sint16 offset_x = 0;
sint16 offset_y = 0;
if (gConfigGeneral.zoom_to_cursor && atCursor) {
window_viewport_get_map_coords_by_cursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y);
}
2017-06-06 23:24:18 +02:00
// Zoom in
while (v->zoom > zoomLevel) {
v->zoom--;
w->saved_view_x += v->view_width / 4;
w->saved_view_y += v->view_height / 4;
v->view_width /= 2;
v->view_height /= 2;
}
2017-06-06 23:24:18 +02:00
// Zoom out
while (v->zoom < zoomLevel) {
v->zoom++;
w->saved_view_x -= v->view_width / 2;
w->saved_view_y -= v->view_height / 2;
v->view_width *= 2;
v->view_height *= 2;
}
2017-06-06 23:24:18 +02:00
// Zooming to cursor? Centre around the tile we were hovering over just now.
if (gConfigGeneral.zoom_to_cursor && atCursor) {
window_viewport_centre_tile_around_cursor(w, saved_map_x, saved_map_y, offset_x, offset_y);
}
2017-06-06 23:24:18 +02:00
// HACK: Prevents the redraw from failing when there is
// a window on top of the viewport.
window_bring_to_front(w);
window_invalidate(w);
2014-04-26 15:50:01 +01:00
}
/**
2015-09-22 19:18:57 +02:00
*
* rct2: 0x006887A6
*/
void window_zoom_in(rct_window *w, bool atCursor)
{
2017-06-06 23:24:18 +02:00
window_zoom_set(w, w->viewport->zoom - 1, atCursor);
}
2014-04-26 15:50:01 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-26 15:50:01 +01:00
* rct2: 0x006887E0
*/
void window_zoom_out(rct_window *w, bool atCursor)
2014-04-26 15:50:01 +01:00
{
2017-06-06 23:24:18 +02:00
window_zoom_set(w, w->viewport->zoom + 1, atCursor);
}
void main_window_zoom(bool zoomIn, bool atCursor) {
2017-06-06 23:24:18 +02:00
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();
2018-01-07 21:43:07 +01:00
if (mainWindow != nullptr)
2017-06-06 23:24:18 +02:00
window_zoom_set(mainWindow, mainWindow->viewport->zoom + (zoomIn ? -1 : 1), atCursor);
}
}
2014-04-26 15:50:01 +01:00
}
2014-04-08 17:52:39 +01:00
/**
* Draws a window that is in the specified region.
* rct2: 0x006E756C
* left (ax)
* top (bx)
* right (dx)
* bottom (bp)
*/
2017-01-04 22:17:08 +01:00
void window_draw(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom)
2014-04-08 17:52:39 +01:00
{
2017-06-06 23:24:18 +02:00
if (!window_is_visible(w)) return;
2017-06-06 23:24:18 +02:00
// Split window into only the regions that require drawing
if (window_draw_split(dpi, w, left, top, right, bottom))
return;
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// Clamp region
2018-01-06 00:05:16 +00:00
left = std::max<sint32>(left, w->x);
top = std::max<sint32>(top, w->y);
right = std::min<sint32>(right, w->x + w->width);
bottom = std::min<sint32>(bottom, w->y + w->height);
2017-06-06 23:24:18 +02:00
if (left >= right) return;
if (top >= bottom) return;
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// Draw the window in this region
for (rct_window *v = w; v < RCT2_NEW_WINDOW; v++) {
// Don't draw overlapping opaque windows, they won't have changed
if ((w == v || (v->flags & WF_TRANSPARENT)) && window_is_visible(v)) {
window_draw_single(dpi, v, left, top, right, bottom);
}
}
2014-04-08 19:49:04 +01:00
}
/**
* Splits a drawing of a window into regions that can be seen and are not hidden
* by other opaque overlapping windows.
*/
2017-01-04 22:17:08 +01:00
static sint32 window_draw_split(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom)
2014-04-08 19:49:04 +01:00
{
2017-06-06 23:24:18 +02:00
rct_window* topwindow;
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// Divide the draws up for only the visible regions of the window recursively
for (topwindow = w + 1; topwindow < RCT2_NEW_WINDOW; topwindow++) {
// Check if this window overlaps w
if (topwindow->x >= right || topwindow->y >= bottom)
continue;
if (topwindow->x + topwindow->width <= left || topwindow->y + topwindow->height <= top)
continue;
if (topwindow->flags & WF_TRANSPARENT)
continue;
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// A window overlaps w, split up the draw into two regions where the window starts to overlap
if (topwindow->x > left) {
// Split draw at topwindow.left
window_draw(dpi, w, left, top, topwindow->x, bottom);
window_draw(dpi, w, topwindow->x, top, right, bottom);
} else if (topwindow->x + topwindow->width < right) {
// Split draw at topwindow.right
window_draw(dpi, w, left, top, topwindow->x + topwindow->width, bottom);
window_draw(dpi, w, topwindow->x + topwindow->width, top, right, bottom);
} else if (topwindow->y > top) {
// Split draw at topwindow.top
window_draw(dpi, w, left, top, right, topwindow->y);
window_draw(dpi, w, left, topwindow->y, right, bottom);
} else if (topwindow->y + topwindow->height < bottom) {
// Split draw at topwindow.bottom
window_draw(dpi, w, left, top, right, topwindow->y + topwindow->height);
window_draw(dpi, w, left, topwindow->y + topwindow->height, right, bottom);
}
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// Drawing for this region should be done now, exit
return 1;
}
2014-04-08 19:49:04 +01:00
2017-06-06 23:24:18 +02:00
// No windows overlap
return 0;
2014-04-09 14:43:27 +01:00
}
2017-01-04 22:17:08 +01:00
static void window_draw_single(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom)
2016-06-05 15:11:12 +01:00
{
2017-06-06 23:24:18 +02:00
// Copy dpi so we can crop it
rct_drawpixelinfo copy = *dpi;
dpi = &copy;
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Clamp left to 0
sint32 overflow = left - dpi->x;
if (overflow > 0) {
dpi->x += overflow;
dpi->width -= overflow;
if (dpi->width <= 0)
return;
dpi->pitch += overflow;
dpi->bits += overflow;
}
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Clamp width to right
overflow = dpi->x + dpi->width - right;
if (overflow > 0) {
dpi->width -= overflow;
if (dpi->width <= 0)
return;
dpi->pitch += overflow;
}
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Clamp top to 0
overflow = top - dpi->y;
if (overflow > 0) {
dpi->y += overflow;
dpi->height -= overflow;
if (dpi->height <= 0)
return;
dpi->bits += (dpi->width + dpi->pitch) * overflow;
}
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Clamp height to bottom
overflow = dpi->y + dpi->height - bottom;
if (overflow > 0) {
dpi->height -= overflow;
if (dpi->height <= 0)
return;
}
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate modifies the window colours so first get the correct
// colour before setting the global variables for the string painting
window_event_invalidate_call(w);
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
// Text colouring
gCurrentWindowColours[0] = NOT_TRANSLUCENT(w->colours[0]);
gCurrentWindowColours[1] = NOT_TRANSLUCENT(w->colours[1]);
gCurrentWindowColours[2] = NOT_TRANSLUCENT(w->colours[2]);
gCurrentWindowColours[3] = NOT_TRANSLUCENT(w->colours[3]);
2016-06-05 15:11:12 +01:00
2017-06-06 23:24:18 +02:00
window_event_paint_call(w, dpi);
2016-06-05 15:11:12 +01:00
}
2014-04-17 03:19:30 +01:00
/**
2015-09-22 19:18:57 +02:00
*
2014-04-17 03:19:30 +01:00
* rct2: 0x00685BE1
*
* @param dpi (edi)
* @param w (esi)
*/
void window_draw_viewport(rct_drawpixelinfo *dpi, rct_window *w)
{
2017-06-06 23:24:18 +02:00
viewport_render(dpi, w->viewport, dpi->x, dpi->y, dpi->x + dpi->width, dpi->y + dpi->height);
2014-04-18 00:07:06 +01:00
}
2017-01-04 22:17:08 +01:00
void window_set_position(rct_window *w, sint32 x, sint32 y)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
window_move_position(w, x - w->x, y - w->y);
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
void window_move_position(rct_window *w, sint32 dx, sint32 dy)
2014-04-25 03:02:06 +01:00
{
2017-06-06 23:24:18 +02:00
if (dx == 0 && dy == 0)
return;
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate old region
window_invalidate(w);
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Translate window and viewport
w->x += dx;
w->y += dy;
2018-01-07 21:43:07 +01:00
if (w->viewport != nullptr) {
2017-06-06 23:24:18 +02:00
w->viewport->x += dx;
w->viewport->y += dy;
}
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate new region
window_invalidate(w);
2014-04-25 03:02:06 +01:00
}
2017-01-04 22:17:08 +01:00
void window_resize(rct_window *w, sint32 dw, sint32 dh)
2014-04-25 03:02:06 +01:00
{
2017-06-06 23:24:18 +02:00
sint32 i;
if (dw == 0 && dh == 0)
return;
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate old region
window_invalidate(w);
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Clamp new size to minimum and maximum
2018-01-06 00:05:16 +00:00
w->width = Math::Clamp<sint16>(w->min_width, w->width + dw, w->max_width);
w->height = Math::Clamp<sint16>(w->min_height, w->height + dh, w->max_height);
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
window_event_resize_call(w);
window_event_invalidate_call(w);
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Update scroll widgets
for (i = 0; i < 3; i++) {
w->scrolls[i].h_right = WINDOW_SCROLL_UNDEFINED;
w->scrolls[i].v_bottom = WINDOW_SCROLL_UNDEFINED;
2017-06-06 23:24:18 +02:00
}
window_update_scroll_widgets(w);
2014-04-25 03:02:06 +01:00
2017-06-06 23:24:18 +02:00
// Invalidate new region
window_invalidate(w);
2014-04-25 03:02:06 +01:00
}
2017-01-04 22:17:08 +01:00
void window_set_resize(rct_window *w, sint32 minWidth, sint32 minHeight, sint32 maxWidth, sint32 maxHeight)
2014-04-18 00:07:06 +01:00
{
2017-06-06 23:24:18 +02:00
w->min_width = minWidth;
w->min_height = minHeight;
w->max_width = maxWidth;
w->max_height = maxHeight;
2014-04-18 00:07:06 +01:00
2017-06-06 23:24:18 +02:00
// Clamp width and height to minimum and maximum
2018-01-06 00:05:16 +00:00
sint32 width = Math::Clamp<sint32>(minWidth, w->width, maxWidth);
sint32 height = Math::Clamp<sint32>(minHeight, w->height, maxHeight);
2017-06-06 23:24:18 +02:00
// Resize window if size has changed
if (w->width != width || w->height != height) {
window_invalidate(w);
w->width = width;
w->height = height;
window_invalidate(w);
}
}
/**
2015-09-22 19:18:57 +02:00
*
* rct2: 0x006EE212
*
* @param tool (al)
* @param widgetIndex (dx)
* @param w (esi)
*/
2017-05-03 15:57:17 +02:00
bool tool_set(rct_window *w, rct_widgetindex widgetIndex, TOOL_IDX tool)
{
2017-06-06 23:24:18 +02:00
if (input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) {
if (
w->classification == gCurrentToolWidget.window_classification &&
w->number == gCurrentToolWidget.window_number &&
widgetIndex == gCurrentToolWidget.widget_index
) {
tool_cancel();
return true;
} else {
tool_cancel();
}
}
2017-06-06 23:24:18 +02:00
input_set_flag(INPUT_FLAG_TOOL_ACTIVE, true);
input_set_flag(INPUT_FLAG_6, false);
gCurrentToolId = tool;
gCurrentToolWidget.window_classification = w->classification;
gCurrentToolWidget.window_number = w->number;
gCurrentToolWidget.widget_index = widgetIndex;
return false;
}
/**
2015-09-22 19:18:57 +02:00
*
* rct2: 0x006EE281
*/
void tool_cancel()
{
2017-06-06 23:24:18 +02:00
if (input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) {
input_set_flag(INPUT_FLAG_TOOL_ACTIVE, false);
2017-06-06 23:24:18 +02:00
map_invalidate_selection_rect();
map_invalidate_map_selection_tiles();
2017-06-06 23:24:18 +02:00
// Reset map selection
gMapSelectFlags = 0;
2017-06-06 23:24:18 +02:00
if (gCurrentToolWidget.widget_index != -1) {
// Invalidate tool widget
widget_invalidate_by_number(
gCurrentToolWidget.window_classification,
gCurrentToolWidget.window_number,
gCurrentToolWidget.widget_index
);
2017-06-06 23:24:18 +02:00
// Abort tool event
rct_window *w = window_find_by_number(
gCurrentToolWidget.window_classification,
gCurrentToolWidget.window_number
);
2018-01-07 21:43:07 +01:00
if (w != nullptr)
2017-06-06 23:24:18 +02:00
window_event_tool_abort_call(w, gCurrentToolWidget.widget_index);
}
}
2014-05-06 22:04:09 +01:00
}
void window_event_close_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->close != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->close(w);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_mouse_up_call(rct_window *w, rct_widgetindex widgetIndex)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->mouse_up != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->mouse_up(w, widgetIndex);
2015-06-09 18:29:02 +01:00
}
void window_event_resize_call(rct_window *w)
2014-05-12 01:45:45 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->resize != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->resize(w);
2014-11-11 20:51:25 +00:00
}
2017-05-01 15:41:45 +02:00
void window_event_mouse_down_call(rct_window *w, rct_widgetindex widgetIndex)
2014-11-11 20:51:25 +00:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->mouse_down != nullptr)
w->event_handlers->mouse_down(w, widgetIndex, &w->widgets[widgetIndex]);
2014-11-11 20:51:25 +00:00
}
2017-05-01 15:41:45 +02:00
void window_event_dropdown_call(rct_window *w, rct_widgetindex widgetIndex, sint32 dropdownIndex)
2014-11-11 20:51:25 +00:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->dropdown != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->dropdown(w, widgetIndex, dropdownIndex);
}
void window_event_unknown_05_call(rct_window *w)
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->unknown_05 != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->unknown_05(w);
}
void window_event_update_call(rct_window *w)
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->update != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->update(w);
}
void window_event_unknown_07_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->unknown_07 != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->unknown_07(w);
2015-06-09 18:29:02 +01:00
}
void window_event_unknown_08_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->unknown_08 != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->unknown_08(w);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_tool_update_call(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tool_update != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tool_update(w, widgetIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_tool_down_call(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tool_down != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tool_down(w, widgetIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_tool_drag_call(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tool_drag != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tool_drag(w, widgetIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_tool_up_call(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tool_up != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tool_up(w, widgetIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_tool_abort_call(rct_window *w, rct_widgetindex widgetIndex)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tool_abort != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tool_abort(w, widgetIndex);
2015-06-09 18:29:02 +01:00
}
void window_event_unknown_0E_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->unknown_0E != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->unknown_0E(w);
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_get_scroll_size(rct_window *w, sint32 scrollIndex, sint32 *width, sint32 *height)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->get_scroll_size != nullptr) {
2017-06-06 23:24:18 +02:00
w->event_handlers->get_scroll_size(w, scrollIndex, width, height);
}
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_scroll_mousedown_call(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->scroll_mousedown != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->scroll_mousedown(w, scrollIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_scroll_mousedrag_call(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->scroll_mousedrag != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->scroll_mousedrag(w, scrollIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_scroll_mouseover_call(rct_window *w, sint32 scrollIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->scroll_mouseover != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->scroll_mouseover(w, scrollIndex, x, y);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
void window_event_textinput_call(rct_window *w, rct_widgetindex widgetIndex, char *text)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->text_input != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->text_input(w, widgetIndex, text);
2015-06-09 18:29:02 +01:00
}
2017-06-26 03:56:41 -04:00
void window_event_viewport_rotate_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->viewport_rotate != nullptr)
2017-06-26 03:56:41 -04:00
w->event_handlers->viewport_rotate(w);
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_unknown_15_call(rct_window *w, sint32 scrollIndex, sint32 scrollAreaType)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->unknown_15 != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->unknown_15(w, scrollIndex, scrollAreaType);
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
rct_string_id window_event_tooltip_call(rct_window *w, rct_widgetindex widgetIndex)
2015-06-09 18:29:02 +01:00
{
2017-06-06 23:24:18 +02:00
rct_string_id result = 0;
2018-01-07 21:43:07 +01:00
if (w->event_handlers->tooltip != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->tooltip(w, widgetIndex, &result);
return result;
2015-06-09 18:29:02 +01:00
}
2017-05-01 15:41:45 +02:00
sint32 window_event_cursor_call(rct_window *w, rct_widgetindex widgetIndex, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2017-06-06 23:24:18 +02:00
sint32 cursorId = CURSOR_ARROW;
2018-01-07 21:43:07 +01:00
if (w->event_handlers->cursor != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->cursor(w, widgetIndex, x, y, &cursorId);
return cursorId;
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_moved_call(rct_window *w, sint32 x, sint32 y)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->moved != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->moved(w, x, y);
2015-06-09 18:29:02 +01:00
}
void window_event_invalidate_call(rct_window *w)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->invalidate != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->invalidate(w);
2015-06-09 18:29:02 +01:00
}
void window_event_paint_call(rct_window *w, rct_drawpixelinfo *dpi)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->paint != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->paint(w, dpi);
2015-06-09 18:29:02 +01:00
}
2017-01-04 22:17:08 +01:00
void window_event_scroll_paint_call(rct_window *w, rct_drawpixelinfo *dpi, sint32 scrollIndex)
2015-06-09 18:29:02 +01:00
{
2018-01-07 21:43:07 +01:00
if (w->event_handlers->scroll_paint != nullptr)
2017-06-06 23:24:18 +02:00
w->event_handlers->scroll_paint(w, dpi, scrollIndex);
2015-06-09 18:29:02 +01:00
}
/**
2015-12-11 09:38:37 -06:00
* Bubbles an item one position up in the window list. This is done by swapping
* the two locations.
* rct2: New function not from rct2
*/
2017-01-04 22:17:08 +01:00
void window_bubble_list_item(rct_window* w, sint32 item_position){
2017-06-06 23:24:18 +02:00
char swap = w->list_item_positions[item_position];
w->list_item_positions[item_position] = w->list_item_positions[item_position + 1];
w->list_item_positions[item_position + 1] = swap;
}
2014-07-29 19:40:06 +01:00
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x006ED710
* Called after a window resize to move windows if they
* are going to be out of sight.
*/
2017-01-04 22:17:08 +01:00
void window_relocate_windows(sint32 width, sint32 height){
2017-06-06 23:24:18 +02:00
sint32 new_location = 8;
for (rct_window* w = g_window_list; w < RCT2_NEW_WINDOW; w++){
2017-06-06 23:24:18 +02:00
// Work out if the window requires moving
if (w->x + 10 < width){
if (w->flags&(WF_STICK_TO_BACK | WF_STICK_TO_FRONT)){
if (w->y -22 < height)continue;
}
if (w->y + 10 < height)continue;
}
2017-06-06 23:24:18 +02:00
// Calculate the new locations
sint32 x = w->x;
sint32 y = w->y;
w->x = new_location;
w->y = new_location + TOP_TOOLBAR_HEIGHT + 1;
2017-06-06 23:24:18 +02:00
// Move the next new location so windows are not directly on top
new_location += 8;
2017-06-06 23:24:18 +02:00
// Adjust the viewport if required.
if (w->viewport != nullptr){
2017-06-06 23:24:18 +02:00
w->viewport->x -= x - w->x;
w->viewport->y -= y - w->y;
}
}
}
2014-07-29 19:40:06 +01:00
/**
* rct2: 0x0066B905
*/
2017-01-04 22:17:08 +01:00
void window_resize_gui(sint32 width, sint32 height)
2014-07-29 19:40:06 +01:00
{
2017-06-06 23:24:18 +02:00
if (gScreenFlags & (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)){
window_resize_gui_scenario_editor(width, height);
return;
}
rct_window *mainWind = window_get_main();
2018-01-07 21:43:07 +01:00
if (mainWind != nullptr) {
2017-06-06 23:24:18 +02:00
rct_viewport* viewport = mainWind->viewport;
mainWind->width = width;
mainWind->height = height;
viewport->width = width;
viewport->height = height;
viewport->view_width = width << viewport->zoom;
viewport->view_height = height << viewport->zoom;
2018-01-07 21:43:07 +01:00
if (mainWind->widgets != nullptr && mainWind->widgets[WC_MAIN_WINDOW__0].type == WWT_VIEWPORT){
2017-06-06 23:24:18 +02:00
mainWind->widgets[WC_MAIN_WINDOW__0].right = width;
mainWind->widgets[WC_MAIN_WINDOW__0].bottom = height;
}
}
2014-07-29 19:40:06 +01:00
2017-06-06 23:24:18 +02:00
rct_window *topWind = window_find_by_class(WC_TOP_TOOLBAR);
2018-01-07 21:43:07 +01:00
if (topWind != nullptr) {
2018-01-06 00:05:16 +00:00
topWind->width = std::max(640, width);
2017-06-06 23:24:18 +02:00
}
2014-07-29 19:40:06 +01:00
2017-06-06 23:24:18 +02:00
rct_window *bottomWind = window_find_by_class(WC_BOTTOM_TOOLBAR);
2018-01-07 21:43:07 +01:00
if (bottomWind != nullptr) {
2017-06-06 23:24:18 +02:00
bottomWind->y = height - 32;
2018-01-06 00:05:16 +00:00
bottomWind->width = std::max(640, width);
2017-06-06 23:24:18 +02:00
}
2014-07-29 19:40:06 +01:00
2017-06-06 23:24:18 +02:00
rct_window *titleWind = window_find_by_class(WC_TITLE_MENU);
2018-01-07 21:43:07 +01:00
if (titleWind != nullptr) {
2017-06-06 23:24:18 +02:00
titleWind->x = (width - titleWind->width) / 2;
titleWind->y = height - 142;
}
2014-07-29 19:40:06 +01:00
2017-06-06 23:24:18 +02:00
rct_window *exitWind = window_find_by_class(WC_TITLE_EXIT);
2018-01-07 21:43:07 +01:00
if (exitWind != nullptr) {
2017-06-06 23:24:18 +02:00
exitWind->x = width - 40;
exitWind->y = height - 64;
}
2017-06-06 23:24:18 +02:00
rct_window *optionsWind = window_find_by_class(WC_TITLE_OPTIONS);
2018-01-07 21:43:07 +01:00
if (optionsWind != nullptr) {
2017-06-06 23:24:18 +02:00
optionsWind->x = width - 80;
}
2017-06-06 23:24:18 +02:00
gfx_invalidate_screen();
}
/**
* rct2: 0x0066F0DD
*/
2017-01-04 22:17:08 +01:00
void window_resize_gui_scenario_editor(sint32 width, sint32 height)
{
2017-06-06 23:24:18 +02:00
rct_window* mainWind = window_get_main();
if (mainWind != nullptr) {
2017-06-06 23:24:18 +02:00
rct_viewport* viewport = mainWind->viewport;
mainWind->width = width;
mainWind->height = height;
viewport->width = width;
viewport->height = height;
viewport->view_width = width << viewport->zoom;
viewport->view_height = height << viewport->zoom;
2018-01-07 21:43:07 +01:00
if (mainWind->widgets != nullptr && mainWind->widgets[WC_MAIN_WINDOW__0].type == WWT_VIEWPORT){
2017-06-06 23:24:18 +02:00
mainWind->widgets[WC_MAIN_WINDOW__0].right = width;
mainWind->widgets[WC_MAIN_WINDOW__0].bottom = height;
}
}
2017-06-06 23:24:18 +02:00
rct_window *topWind = window_find_by_class(WC_TOP_TOOLBAR);
2018-01-07 21:43:07 +01:00
if (topWind != nullptr) {
2018-01-06 00:05:16 +00:00
topWind->width = std::max(640, width);
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
rct_window *bottomWind = window_find_by_class(WC_BOTTOM_TOOLBAR);
2018-01-07 21:43:07 +01:00
if (bottomWind != nullptr) {
2017-06-06 23:24:18 +02:00
bottomWind->y = height - 32;
2018-01-06 00:05:16 +00:00
bottomWind->width = std::max(640, width);
2017-06-06 23:24:18 +02:00
}
2015-09-22 19:18:57 +02:00
}
2014-08-24 18:45:47 +01:00
2014-08-27 12:34:47 +01:00
/* Based on rct2: 0x6987ED and another version from window_park */
2017-05-01 15:41:45 +02:00
void window_align_tabs(rct_window *w, rct_widgetindex start_tab_id, rct_widgetindex end_tab_id)
2014-08-28 06:58:57 +01:00
{
2017-06-06 23:24:18 +02:00
sint32 i, x = w->widgets[start_tab_id].left;
sint32 tab_width = w->widgets[start_tab_id].right - w->widgets[start_tab_id].left;
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
for (i = start_tab_id; i <= end_tab_id; i++) {
if (!(w->disabled_widgets & (1LL << i))) {
w->widgets[i].left = x;
w->widgets[i].right = x + tab_width;
x += tab_width + 1;
}
}
2014-08-27 12:34:47 +01:00
}
2014-09-01 17:10:15 +01:00
2014-09-27 00:41:24 +01:00
/**
*
* rct2: 0x006CBCC3
*/
void window_close_construction_windows()
{
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_RIDE_CONSTRUCTION);
window_close_by_class(WC_FOOTPATH);
window_close_by_class(WC_TRACK_DESIGN_LIST);
window_close_by_class(WC_TRACK_DESIGN_PLACE);
}
2014-11-02 14:03:28 +00:00
/**
* Update zoom based volume attenuation for ride music and clear music list.
* rct2: 0x006BC348
*/
void window_update_viewport_ride_music()
{
2017-06-06 23:24:18 +02:00
rct_viewport *viewport;
rct_window *w;
2014-11-02 14:03:28 +00:00
2017-06-06 23:24:18 +02:00
gRideMusicParamsListEnd = &gRideMusicParamsList[0];
2018-01-07 21:43:07 +01:00
g_music_tracking_viewport = nullptr;
2014-11-02 14:03:28 +00:00
2017-06-06 23:24:18 +02:00
for (w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
viewport = w->viewport;
2018-01-07 21:43:07 +01:00
if (viewport == nullptr || !(viewport->flags & VIEWPORT_FLAG_SOUND_ON))
2017-06-06 23:24:18 +02:00
continue;
2014-11-02 14:03:28 +00:00
2017-06-06 23:24:18 +02:00
g_music_tracking_viewport = viewport;
gWindowAudioExclusive = w;
2014-11-02 14:03:28 +00:00
2017-06-06 23:24:18 +02:00
switch (viewport->zoom) {
case 0:
gVolumeAdjustZoom = 0;
break;
case 1:
gVolumeAdjustZoom = 30;
break;
default:
gVolumeAdjustZoom = 60;
break;
}
break;
}
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
static void window_snap_left(rct_window *w, sint32 proximity)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
sint32 right, rightMost, wLeftProximity, wRightProximity, wBottom;
rct_window *mainWindow, *w2;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
mainWindow = window_get_main();
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
wBottom = w->y + w->height;
wLeftProximity = w->x - (proximity * 2);
wRightProximity = w->x + (proximity * 2);
rightMost = INT32_MIN;
for (w2 = g_window_list; w2 < RCT2_NEW_WINDOW; w2++) {
if (w2 == w || w2 == mainWindow)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
right = w2->x + w2->width;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (wBottom < w2->y || w->y > w2->y + w2->height)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (right < wLeftProximity || right > wRightProximity)
continue;
2014-11-09 17:18:51 +00:00
2018-01-06 00:05:16 +00:00
rightMost = std::max(rightMost, right);
2017-06-06 23:24:18 +02:00
}
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (0 >= wLeftProximity && 0 <= wRightProximity)
2018-01-06 00:05:16 +00:00
rightMost = std::max(rightMost, 0);
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (rightMost != INT32_MIN)
w->x = rightMost;
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
static void window_snap_top(rct_window *w, sint32 proximity)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
sint32 bottom, bottomMost, wTopProximity, wBottomProximity, wRight;
rct_window *mainWindow, *w2;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
mainWindow = window_get_main();
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
wRight = w->x + w->width;
wTopProximity = w->y - (proximity * 2);
wBottomProximity = w->y + (proximity * 2);
bottomMost = INT32_MIN;
for (w2 = g_window_list; w2 < RCT2_NEW_WINDOW; w2++) {
if (w2 == w || w2 == mainWindow)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
bottom = w2->y + w2->height;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (wRight < w2->x || w->x > w2->x + w2->width)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (bottom < wTopProximity || bottom > wBottomProximity)
continue;
2014-11-09 17:18:51 +00:00
2018-01-06 00:05:16 +00:00
bottomMost = std::max(bottomMost, bottom);
2017-06-06 23:24:18 +02:00
}
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (0 >= wTopProximity && 0 <= wBottomProximity)
2018-01-06 00:05:16 +00:00
bottomMost = std::max(bottomMost, 0);
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (bottomMost != INT32_MIN)
w->y = bottomMost;
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
static void window_snap_right(rct_window *w, sint32 proximity)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
sint32 leftMost, wLeftProximity, wRightProximity, wRight, wBottom, screenWidth;
rct_window *mainWindow, *w2;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
mainWindow = window_get_main();
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
wRight = w->x + w->width;
wBottom = w->y + w->height;
wLeftProximity = wRight - (proximity * 2);
wRightProximity = wRight + (proximity * 2);
leftMost = INT32_MAX;
for (w2 = g_window_list; w2 < RCT2_NEW_WINDOW; w2++) {
if (w2 == w || w2 == mainWindow)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (wBottom < w2->y || w->y > w2->y + w2->height)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (w2->x < wLeftProximity || w2->x > wRightProximity)
continue;
2014-11-09 17:18:51 +00:00
2018-01-06 00:05:16 +00:00
leftMost = std::min<sint32>(leftMost, w2->x);
2017-06-06 23:24:18 +02:00
}
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
screenWidth = context_get_width();
if (screenWidth >= wLeftProximity && screenWidth <= wRightProximity)
2018-01-06 00:05:16 +00:00
leftMost = std::min(leftMost, screenWidth);
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (leftMost != INT32_MAX)
w->x = leftMost - w->width;
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
static void window_snap_bottom(rct_window *w, sint32 proximity)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
sint32 topMost, wTopProximity, wBottomProximity, wRight, wBottom, screenHeight;
rct_window *mainWindow, *w2;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
mainWindow = window_get_main();
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
wRight = w->x + w->width;
wBottom = w->y + w->height;
wTopProximity = wBottom - (proximity * 2);
wBottomProximity = wBottom + (proximity * 2);
topMost = INT32_MAX;
for (w2 = g_window_list; w2 < RCT2_NEW_WINDOW; w2++) {
if (w2 == w || w2 == mainWindow)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (wRight < w2->x || w->x > w2->x + w2->width)
continue;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (w2->y < wTopProximity || w2->y > wBottomProximity)
continue;
2014-11-09 17:18:51 +00:00
2018-01-06 00:05:16 +00:00
topMost = std::min<sint32>(topMost, w2->y);
2017-06-06 23:24:18 +02:00
}
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
screenHeight = context_get_height();
if (screenHeight >= wTopProximity && screenHeight <= wBottomProximity)
2018-01-06 00:05:16 +00:00
topMost = std::min(topMost, screenHeight);
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (topMost != INT32_MAX)
w->y = topMost - w->height;
2014-11-09 17:18:51 +00:00
}
2017-01-04 22:17:08 +01:00
void window_move_and_snap(rct_window *w, sint32 newWindowX, sint32 newWindowY, sint32 snapProximity)
2014-11-09 17:18:51 +00:00
{
2017-06-06 23:24:18 +02:00
sint32 originalX = w->x;
sint32 originalY = w->y;
sint32 minY = (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) ? 1 : TOP_TOOLBAR_HEIGHT + 2;
2014-11-09 17:18:51 +00:00
2018-01-06 00:05:16 +00:00
newWindowY = Math::Clamp(minY, newWindowY, context_get_height() - 34);
2015-09-22 19:18:57 +02:00
2017-06-06 23:24:18 +02:00
if (snapProximity > 0) {
w->x = newWindowX;
w->y = newWindowY;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
window_snap_right(w, snapProximity);
window_snap_bottom(w, snapProximity);
window_snap_left(w, snapProximity);
window_snap_top(w, snapProximity);
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
if (w->x == originalX && w->y == originalY)
return;
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
newWindowX = w->x;
newWindowY = w->y;
w->x = originalX;
w->y = originalY;
}
2014-11-09 17:18:51 +00:00
2017-06-06 23:24:18 +02:00
window_set_position(w, newWindowX, newWindowY);
2014-11-11 00:20:06 +00:00
}
2017-01-04 22:17:08 +01:00
sint32 window_can_resize(rct_window *w)
2014-11-11 00:20:06 +00:00
{
2017-06-06 23:24:18 +02:00
return (w->flags & WF_RESIZABLE) && (w->min_width != w->max_width || w->min_height != w->max_height);
}
/**
*
* rct2: 0x006EE3C3
*/
void textinput_cancel()
{
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_TEXTINPUT);
2015-06-06 17:04:53 -04:00
}
2017-05-01 15:41:45 +02:00
void window_start_textbox(rct_window *call_w, rct_widgetindex call_widget, rct_string_id existing_text, char * existing_args, sint32 maxLength)
2015-06-06 17:04:53 -04:00
{
2017-06-06 23:24:18 +02:00
if (gUsingWidgetTextBox)
window_cancel_textbox();
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
gUsingWidgetTextBox = true;
gCurrentTextBox.window.classification = call_w->classification;
gCurrentTextBox.window.number = call_w->number;
gCurrentTextBox.widget_index = call_widget;
gTextBoxFrameNo = 0;
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
gMaxTextBoxInputLength = maxLength;
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
window_close_by_class(WC_TEXTINPUT);
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
// Clear the text input buffer
memset(gTextBoxInput, 0, maxLength);
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
// Enter in the text input buffer any existing
// text.
if (existing_text != STR_NONE)
format_string(gTextBoxInput, TEXT_INPUT_SIZE, existing_text, &existing_args);
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
// In order to prevent strings that exceed the maxLength
// from crashing the game.
gTextBoxInput[maxLength - 1] = '\0';
2015-06-06 17:04:53 -04:00
2017-06-06 23:24:18 +02:00
gTextInput = context_start_text_input(gTextBoxInput, maxLength);
2015-06-06 17:04:53 -04:00
}
void window_cancel_textbox()
{
2017-06-06 23:24:18 +02:00
if (gUsingWidgetTextBox) {
rct_window *w = window_find_by_number(
gCurrentTextBox.window.classification,
gCurrentTextBox.window.number
);
2018-01-07 21:43:07 +01:00
window_event_textinput_call(w, gCurrentTextBox.widget_index, nullptr);
2017-06-06 23:24:18 +02:00
gCurrentTextBox.window.classification = WC_NULL;
gCurrentTextBox.window.number = 0;
context_stop_text_input();
gUsingWidgetTextBox = false;
widget_invalidate(w, gCurrentTextBox.widget_index);
gCurrentTextBox.widget_index = WWT_LAST;
}
2015-06-06 17:04:53 -04:00
}
void window_update_textbox_caret()
{
2017-06-06 23:24:18 +02:00
gTextBoxFrameNo++;
if (gTextBoxFrameNo > 30)
gTextBoxFrameNo = 0;
2015-06-06 17:04:53 -04:00
}
void window_update_textbox()
{
2017-06-06 23:24:18 +02:00
if (gUsingWidgetTextBox) {
gTextBoxFrameNo = 0;
rct_window *w = window_find_by_number(
gCurrentTextBox.window.classification,
gCurrentTextBox.window.number
);
widget_invalidate(w, gCurrentTextBox.widget_index);
window_event_textinput_call(w, gCurrentTextBox.widget_index, gTextBoxInput);
}
2015-09-22 19:18:57 +02:00
}
2016-07-05 12:54:28 -04:00
bool window_is_visible(rct_window* w)
{
2017-06-06 23:24:18 +02:00
// w->visibility is used to prevent repeat calculations within an iteration by caching the result
2018-01-07 21:43:07 +01:00
if (w == nullptr)
2017-06-06 23:24:18 +02:00
return false;
2017-06-06 23:24:18 +02:00
if (w->visibility == VC_VISIBLE) return true;
if (w->visibility == VC_COVERED) return false;
2017-06-06 23:24:18 +02:00
// only consider viewports, consider the main window always visible
2018-01-07 21:43:07 +01:00
if (w->viewport == nullptr || w->classification == WC_MAIN_WINDOW)
2017-06-06 23:24:18 +02:00
{
// default to previous behaviour
w->visibility = VC_VISIBLE;
return true;
}
2016-07-05 12:54:28 -04:00
2017-06-06 23:24:18 +02:00
// start from the window above the current
for (rct_window *w_other = (w+1); w_other < RCT2_NEW_WINDOW; w_other++)
{
// if covered by a higher window, no rendering needed
if (w_other->x <= w->x
&& w_other->y <= w->y
&& w_other->x + w_other->width >= w->x + w->width
&& w_other->y + w_other->height >= w->y + w->height)
{
w->visibility = VC_COVERED;
w->viewport->visibility = VC_COVERED;
return false;
}
}
2016-07-05 12:54:28 -04:00
2017-06-06 23:24:18 +02:00
// default to previous behaviour
w->visibility = VC_VISIBLE;
w->viewport->visibility = VC_VISIBLE;
return true;
2016-07-05 12:54:28 -04:00
}
2017-12-20 02:14:29 +01:00
/**
*
* rct2: 0x006E7499
* left (ax)
* top (bx)
* right (dx)
* bottom (bp)
*/
void window_draw_all(rct_drawpixelinfo *dpi, sint16 left, sint16 top, sint16 right, sint16 bottom)
{
rct_drawpixelinfo windowDPI;
windowDPI.bits = dpi->bits + left + ((dpi->width + dpi->pitch) * top);
windowDPI.x = left;
windowDPI.y = top;
windowDPI.width = right - left;
windowDPI.height = bottom - top;
windowDPI.pitch = dpi->width + dpi->pitch + left - right;
windowDPI.zoom_level = 0;
for (rct_window *w = g_window_list; w < gWindowNextSlot; w++) {
if (w->flags & WF_TRANSPARENT) continue;
if (right <= w->x || bottom <= w->y) continue;
if (left >= w->x + w->width || top >= w->y + w->height) continue;
window_draw(&windowDPI, w, left, top, right, bottom);
}
}
rct_viewport * window_get_previous_viewport(rct_viewport * current)
{
2018-01-07 21:43:07 +01:00
bool foundPrevious = (current == nullptr);
2017-12-20 02:14:29 +01:00
rct_window * window = gWindowNextSlot;
2018-01-07 21:43:07 +01:00
if (window == nullptr)
2017-12-20 02:14:29 +01:00
{
2018-01-07 21:43:07 +01:00
return nullptr;
2017-12-20 02:14:29 +01:00
}
while (true)
{
window--;
if (window < g_window_list)
{
break;
}
2018-01-07 21:43:07 +01:00
if (window->viewport == nullptr)
2017-12-20 02:14:29 +01:00
{
continue;
}
if (foundPrevious)
{
return window->viewport;
}
if (window->viewport == current)
{
foundPrevious = true;
}
}
2018-01-07 21:43:07 +01:00
return nullptr;
2017-12-20 02:14:29 +01:00
}
2017-12-20 12:20:17 +01:00
void window_reset_visibilities()
{
// reset window visibility status to unknown
for (rct_window * w = g_window_list; w < gWindowNextSlot; w++)
{
w->visibility = VC_UNKNOWN;
2018-01-07 21:43:07 +01:00
if (w->viewport != nullptr)
2017-12-20 12:20:17 +01:00
{
w->viewport->visibility = VC_UNKNOWN;
}
}
}
void window_init_all()
{
2018-02-10 21:37:25 +00:00
window_close_all();
2017-12-20 12:20:17 +01:00
gWindowNextSlot = g_window_list;
}
2017-11-02 20:16:30 -04:00
void window_follow_sprite(rct_window * w, size_t spriteIndex)
{
if (spriteIndex < MAX_SPRITES || spriteIndex == SPRITE_INDEX_NULL)
{
w->viewport_smart_follow_sprite = (uint16)spriteIndex;
}
}
void window_unfollow_sprite(rct_window * w)
{
w->viewport_smart_follow_sprite = SPRITE_INDEX_NULL;
w->viewport_target_sprite = SPRITE_INDEX_NULL;
}
2018-01-06 00:05:16 +00:00
2018-01-05 23:31:56 +01:00
rct_viewport * window_get_viewport(rct_window * w)
{
if (w == nullptr)
{
return nullptr;
}
return w->viewport;
}
2018-01-15 06:34:56 +01:00
rct_window * window_get_listening()
{
for (rct_window * w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
{
if (w->viewport == nullptr)
{
continue;
}
if (w->viewport->flags & VIEWPORT_FLAG_SOUND_ON)
{
return w;
}
}
return nullptr;
}
rct_windowclass window_get_classification(rct_window * window)
{
return window->classification;
}
2018-06-11 00:04:41 +01:00
/**
*
* rct2: 0x006EAF26
*/
void widget_scroll_update_thumbs(rct_window *w, rct_widgetindex widget_index)
{
rct_widget *widget = &w->widgets[widget_index];
rct_scroll* scroll = &w->scrolls[window_get_scroll_data_index(w, widget_index)];
if (scroll->flags & HSCROLLBAR_VISIBLE) {
sint32 view_size = widget->right - widget->left - 21;
if (scroll->flags & VSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 x = scroll->h_left * view_size;
if (scroll->h_right != 0)
x /= scroll->h_right;
scroll->h_thumb_left = x + 11;
x = widget->right - widget->left - 2;
if (scroll->flags & VSCROLLBAR_VISIBLE)
x -= 11;
x += scroll->h_left;
if (scroll->h_right != 0)
x = (x * view_size) / scroll->h_right;
x += 11;
view_size += 10;
scroll->h_thumb_right = std::min(x, view_size);
if(scroll->h_thumb_right - scroll->h_thumb_left < 20) {
double barPosition = (scroll->h_thumb_right * 1.0) / view_size;
scroll->h_thumb_left = (uint16)std::lround(scroll->h_thumb_left - (20 * barPosition));
scroll->h_thumb_right = (uint16)std::lround(scroll->h_thumb_right + (20 * (1 - barPosition)));
}
}
if (scroll->flags & VSCROLLBAR_VISIBLE) {
sint32 view_size = widget->bottom - widget->top - 21;
if (scroll->flags & HSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 y = scroll->v_top * view_size;
if (scroll->v_bottom != 0)
y /= scroll->v_bottom;
scroll->v_thumb_top = y + 11;
y = widget->bottom - widget->top - 2;
if (scroll->flags & HSCROLLBAR_VISIBLE)
y -= 11;
y += scroll->v_top;
if (scroll->v_bottom != 0)
y = (y * view_size) / scroll->v_bottom;
y += 11;
view_size += 10;
scroll->v_thumb_bottom = std::min(y, view_size);
if(scroll->v_thumb_bottom - scroll->v_thumb_top < 20) {
double barPosition = (scroll->v_thumb_bottom * 1.0) / view_size;
scroll->v_thumb_top = (uint16)std::lround(scroll->v_thumb_top - (20 * barPosition));
scroll->v_thumb_bottom = (uint16)std::lround(scroll->v_thumb_bottom + (20 * (1 - barPosition)));
}
}
}