1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

clang-format UI interface

This commit is contained in:
clang-format
2018-06-22 23:20:47 +02:00
committed by Hielke Morsink
parent 2151b8d75a
commit 949a34646e
12 changed files with 1136 additions and 860 deletions

View File

@@ -9,8 +9,8 @@
#pragma once
#include <openrct2/common.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/common.h>
#define DROPDOWN_SEPARATOR 0
#define DROPDOWN_FORMAT_COLOUR_PICKER 0xFFFE
@@ -39,9 +39,27 @@ void dropdown_set_checked(int32_t index, bool value);
void dropdown_set_disabled(int32_t index, bool value);
void window_dropdown_show_text(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t flags, size_t num_items);
void window_dropdown_show_text_custom_width(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t custom_height, uint8_t flags, size_t num_items, int32_t width);
void window_dropdown_show_image(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t flags, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns);
void window_dropdown_show_text_custom_width(
int32_t x,
int32_t y,
int32_t extray,
uint8_t colour,
uint8_t custom_height,
uint8_t flags,
size_t num_items,
int32_t width);
void window_dropdown_show_image(
int32_t x,
int32_t y,
int32_t extray,
uint8_t colour,
uint8_t flags,
int32_t numItems,
int32_t itemWidth,
int32_t itemHeight,
int32_t numColumns);
void window_dropdown_close();
int32_t dropdown_index_from_point(int32_t x, int32_t y, rct_window* w);
void window_dropdown_show_colour(rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour);
void window_dropdown_show_colour_available(rct_window *w, rct_widget *widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours);
void window_dropdown_show_colour_available(
rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours);

View File

@@ -7,11 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <openrct2-ui/interface/Graph.h>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2-ui/interface/Graph.h>
static void graph_draw_months_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * history, int32_t count, int32_t baseX, int32_t baseY)
static void
graph_draw_months_uint8_t(rct_drawpixelinfo* dpi, const uint8_t* history, int32_t count, int32_t baseX, int32_t baseY)
{
int32_t i, x, y, yearOver32, currentMonth, currentDay;
@@ -37,7 +38,8 @@ static void graph_draw_months_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * h
}
}
static void graph_draw_line_a_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * history, int32_t count, int32_t baseX, int32_t baseY)
static void
graph_draw_line_a_uint8_t(rct_drawpixelinfo* dpi, const uint8_t* history, int32_t count, int32_t baseX, int32_t baseY)
{
int32_t i, x, y, lastX, lastY;
lastX = -1;
@@ -64,7 +66,8 @@ static void graph_draw_line_a_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * h
}
}
static void graph_draw_line_b_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * history, int32_t count, int32_t baseX, int32_t baseY)
static void
graph_draw_line_b_uint8_t(rct_drawpixelinfo* dpi, const uint8_t* history, int32_t count, int32_t baseX, int32_t baseY)
{
int32_t i, x, y, lastX, lastY;
@@ -96,7 +99,8 @@ void graph_draw_uint8_t(rct_drawpixelinfo * dpi, uint8_t * history, int32_t coun
graph_draw_line_b_uint8_t(dpi, history, count, baseX, baseY);
}
static void graph_draw_months_money32(rct_drawpixelinfo *dpi, const money32 *history, int32_t count, int32_t baseX, int32_t baseY)
static void
graph_draw_months_money32(rct_drawpixelinfo* dpi, const money32* history, int32_t count, int32_t baseX, int32_t baseY)
{
int32_t i, x, y, yearOver32, currentMonth, currentDay;
@@ -105,8 +109,10 @@ static void graph_draw_months_money32(rct_drawpixelinfo *dpi, const money32 *his
yearOver32 = (currentMonth * 4) + (currentDay >> 14) - 31;
x = baseX;
y = baseY;
for (i = count - 1; i >= 0; i--) {
if (history[i] != MONEY32_UNDEFINED && yearOver32 % 4 == 0) {
for (i = count - 1; i >= 0; i--)
{
if (history[i] != MONEY32_UNDEFINED && yearOver32 % 4 == 0)
{
// Draw month text
int32_t monthFormat = DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)];
gfx_draw_string_centred(dpi, STR_GRAPH_LABEL, x, y - 10, COLOUR_BLACK, &monthFormat);
@@ -120,17 +126,27 @@ static void graph_draw_months_money32(rct_drawpixelinfo *dpi, const money32 *his
}
}
static void graph_draw_line_a_money32(rct_drawpixelinfo *dpi, const money32 *history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset)
static void graph_draw_line_a_money32(
rct_drawpixelinfo* dpi,
const money32* history,
int32_t count,
int32_t baseX,
int32_t baseY,
int32_t modifier,
int32_t offset)
{
int32_t i, x, y, lastX, lastY;
lastX = -1;
lastY = -1;
x = baseX;
for (i = count - 1; i >= 0; i--) {
if (history[i] != MONEY32_UNDEFINED) {
for (i = count - 1; i >= 0; i--)
{
if (history[i] != MONEY32_UNDEFINED)
{
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256);
if (lastX != -1) {
if (lastX != -1)
{
gfx_draw_line(dpi, lastX + 1, lastY + 1, x + 1, y + 1, PALETTE_INDEX_10);
gfx_draw_line(dpi, lastX, lastY + 1, x, y + 1, PALETTE_INDEX_10);
}
@@ -144,15 +160,24 @@ static void graph_draw_line_a_money32(rct_drawpixelinfo *dpi, const money32 *his
}
}
static void graph_draw_line_b_money32(rct_drawpixelinfo *dpi, const money32 *history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset)
static void graph_draw_line_b_money32(
rct_drawpixelinfo* dpi,
const money32* history,
int32_t count,
int32_t baseX,
int32_t baseY,
int32_t modifier,
int32_t offset)
{
int32_t i, x, y, lastX, lastY;
lastX = -1;
lastY = -1;
x = baseX;
for (i = count - 1; i >= 0; i--) {
if (history[i] != MONEY32_UNDEFINED) {
for (i = count - 1; i >= 0; i--)
{
if (history[i] != MONEY32_UNDEFINED)
{
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256);
if (lastX != -1)
@@ -167,7 +192,8 @@ static void graph_draw_line_b_money32(rct_drawpixelinfo *dpi, const money32 *his
}
}
void graph_draw_money32(rct_drawpixelinfo *dpi, money32 *history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset)
void graph_draw_money32(
rct_drawpixelinfo* dpi, money32* history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset)
{
graph_draw_months_money32(dpi, history, count, baseX, baseY);
graph_draw_line_a_money32(dpi, history, count, baseX, baseY, modifier, offset);

View File

@@ -14,6 +14,7 @@
#include <openrct2/drawing/Drawing.h>
void graph_draw_uint8_t(rct_drawpixelinfo* dpi, uint8_t* history, int32_t count, int32_t baseX, int32_t baseY);
void graph_draw_money32(rct_drawpixelinfo *dpi, money32 *history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset);
void graph_draw_money32(
rct_drawpixelinfo* dpi, money32* history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset);
#endif

View File

@@ -7,19 +7,21 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "InGameConsole.h"
#include "Theme.h"
#include <algorithm>
#include <cstring>
#include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/Version.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/interface/Window.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/localisation/LocalisationService.h>
#include <openrct2/Version.h>
#include "InGameConsole.h"
#include "Theme.h"
using namespace OpenRCT2::Ui;
@@ -40,13 +42,15 @@ void InGameConsole::WritePrompt()
void InGameConsole::Input(CONSOLE_INPUT input)
{
switch (input) {
switch (input)
{
case CONSOLE_INPUT_LINE_CLEAR:
ClearInput();
RefreshCaret();
break;
case CONSOLE_INPUT_LINE_EXECUTE:
if (_consoleCurrentLine[0] != '\0') {
if (_consoleCurrentLine[0] != '\0')
{
HistoryAdd(_consoleCurrentLine);
// Append text we are executing to prompt line
@@ -60,7 +64,8 @@ void InGameConsole::Input(CONSOLE_INPUT input)
ScrollToEnd();
break;
case CONSOLE_INPUT_HISTORY_PREVIOUS:
if (_consoleHistoryIndex > 0) {
if (_consoleHistoryIndex > 0)
{
_consoleHistoryIndex--;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE);
}
@@ -69,13 +74,16 @@ void InGameConsole::Input(CONSOLE_INPUT input)
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
break;
case CONSOLE_INPUT_HISTORY_NEXT:
if (_consoleHistoryIndex < _consoleHistoryCount - 1) {
if (_consoleHistoryIndex < _consoleHistoryCount - 1)
{
_consoleHistoryIndex++;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE);
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer);
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
} else {
}
else
{
_consoleHistoryIndex = _consoleHistoryCount;
ClearInput();
}
@@ -100,14 +108,16 @@ void InGameConsole::Input(CONSOLE_INPUT input)
void InGameConsole::ClearInput()
{
_consoleCurrentLine[0] = 0;
if (_isOpen) {
if (_isOpen)
{
context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
}
}
void InGameConsole::HistoryAdd(const utf8* src)
{
if (_consoleHistoryCount >= CONSOLE_HISTORY_SIZE) {
if (_consoleHistoryCount >= CONSOLE_HISTORY_SIZE)
{
for (int32_t i = 0; i < _consoleHistoryCount - 1; i++)
memcpy(_consoleHistory[i], _consoleHistory[i + 1], CONSOLE_INPUT_SIZE);
_consoleHistoryCount--;
@@ -220,13 +230,17 @@ void InGameConsole::Update()
_consoleRight = context_get_width();
_consoleBottom = 322;
if (_isOpen) {
if (_isOpen)
{
// When scrolling the map, the console pixels get copied... therefore invalidate the screen
rct_window* mainWindow = window_get_main();
if (mainWindow != nullptr) {
if (mainWindow != nullptr)
{
rct_viewport* mainViewport = window_get_viewport(mainWindow);
if (mainViewport != nullptr) {
if (_lastMainViewportX != mainViewport->view_x || _lastMainViewportY != mainViewport->view_y) {
if (mainViewport != nullptr)
{
if (_lastMainViewportX != mainViewport->view_x || _lastMainViewportY != mainViewport->view_y)
{
_lastMainViewportX = mainViewport->view_x;
_lastMainViewportY = mainViewport->view_y;
@@ -281,15 +295,24 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
// Paint background colour.
uint8_t backgroundColour = theme_get_colour(WC_CONSOLE, 0);
gfx_fill_rect_inset(dpi, _consoleLeft, _consoleTop, _consoleRight, _consoleBottom, backgroundColour, INSET_RECT_FLAG_FILL_NONE);
gfx_fill_rect_inset(dpi, _consoleLeft + 1, _consoleTop + 1, _consoleRight - 1, _consoleBottom - 1, backgroundColour, INSET_RECT_FLAG_BORDER_INSET);
gfx_fill_rect_inset(
dpi, _consoleLeft, _consoleTop, _consoleRight, _consoleBottom, backgroundColour, INSET_RECT_FLAG_FILL_NONE);
gfx_fill_rect_inset(
dpi,
_consoleLeft + 1,
_consoleTop + 1,
_consoleRight - 1,
_consoleBottom - 1,
backgroundColour,
INSET_RECT_FLAG_BORDER_INSET);
std::string lineBuffer;
int32_t x = _consoleLeft + CONSOLE_EDGE_PADDING;
int32_t y = _consoleTop + CONSOLE_EDGE_PADDING;
// Draw text inside console
for (std::size_t i = 0; i < _consoleLines.size() && i < (size_t)maxLines; i++) {
for (std::size_t i = 0; i < _consoleLines.size() && i < (size_t)maxLines; i++)
{
const size_t index = i + _consoleScrollPos;
lineBuffer = colourFormatStr + _consoleLines[index];
gfx_draw_string(dpi, lineBuffer.c_str(), textColour, x, y);
@@ -303,7 +326,8 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
gfx_draw_string(dpi, lineBuffer.c_str(), TEXT_COLOUR_255, x, y);
// Draw caret
if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD) {
if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD)
{
int32_t caretX = x + gfx_get_string_width(_consoleCurrentLine);
int32_t caretY = y + lineHeight;
@@ -316,8 +340,10 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
uint8_t borderColour2 = ColourMapA[BASE_COLOUR(backgroundColour)].mid_dark;
// Input area top border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 11, _consoleRight, _consoleBottom - lineHeight - 11, borderColour1);
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 10, _consoleRight, _consoleBottom - lineHeight - 10, borderColour2);
gfx_fill_rect(
dpi, _consoleLeft, _consoleBottom - lineHeight - 11, _consoleRight, _consoleBottom - lineHeight - 11, borderColour1);
gfx_fill_rect(
dpi, _consoleLeft, _consoleBottom - lineHeight - 10, _consoleRight, _consoleBottom - lineHeight - 10, borderColour2);
// Input area bottom border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - 1, _consoleRight, _consoleBottom - 1, borderColour1);

View File

@@ -39,7 +39,10 @@ namespace OpenRCT2::Ui
InGameConsole();
InGameConsole(const InGameConsole& src) = delete;
bool IsOpen() const { return _isOpen; }
bool IsOpen() const
{
return _isOpen;
}
void Clear() override;
void Open();

View File

@@ -8,13 +8,13 @@
*****************************************************************************/
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Surface.h>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/Input.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Surface.h>
// clang-format off
static uint16_t toolSizeSpriteIndices[] =
@@ -99,14 +99,15 @@ void land_tool_show_surface_style_dropdown(rct_window * w, rct_widget * widget,
}
window_dropdown_show_image(
w->x + widget->left, w->y + widget->top,
w->x + widget->left,
w->y + widget->top,
widget->bottom - widget->top,
w->colours[2],
0,
TERRAIN_COUNT_REGULAR,
47, 36,
gAppropriateImageDropdownItemsPerRow[TERRAIN_COUNT_REGULAR]
);
47,
36,
gAppropriateImageDropdownItemsPerRow[TERRAIN_COUNT_REGULAR]);
gDropdownDefaultIndex = defaultIndex;
}
@@ -117,7 +118,8 @@ void land_tool_show_edge_style_dropdown(rct_window * w, rct_widget * widget, uin
// Do not show RCT1 edge styles if the player does not have RCT1.
const uint8_t edgeCount = is_csg_loaded() ? TERRAIN_EDGE_COUNT : TERRAIN_EDGE_RCT2_COUNT;
for (uint8_t i = 0; i < edgeCount; i++) {
for (uint8_t i = 0; i < edgeCount; i++)
{
gDropdownItemsFormat[i] = DROPDOWN_FORMAT_LAND_PICKER;
gDropdownItemsArgs[i] = WallTexturePreviews[WallTextureOrder[i]];
if (WallTextureOrder[i] == currentEdgeType)
@@ -125,14 +127,15 @@ void land_tool_show_edge_style_dropdown(rct_window * w, rct_widget * widget, uin
}
window_dropdown_show_image(
w->x + widget->left, w->y + widget->top,
w->x + widget->left,
w->y + widget->top,
widget->bottom - widget->top,
w->colours[2],
0,
edgeCount,
47, 36,
gAppropriateImageDropdownItemsPerRow[edgeCount]
);
47,
36,
gAppropriateImageDropdownItemsPerRow[edgeCount]);
gDropdownDefaultIndex = defaultIndex;
}

View File

@@ -9,9 +9,9 @@
#pragma once
#include <openrct2-ui/interface/Window.h>
#include <openrct2/common.h>
#include <openrct2/sprites.h>
#include <openrct2-ui/interface/Window.h>
#define MINIMUM_TOOL_SIZE 1
#define MAXIMUM_TOOL_SIZE 64

View File

@@ -9,14 +9,16 @@
#pragma warning(disable : 4706) // assignment within conditional expression
#include <memory>
#include <stdexcept>
#include <vector>
#include <jansson.h>
#include "Theme.h"
#include "Window.h"
#include <jansson.h>
#include <memory>
#include <openrct2/Context.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/common.h>
#include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/core/File.h>
#include <openrct2/core/FileScanner.h>
#include <openrct2/core/Guard.hpp>
@@ -25,12 +27,11 @@
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/localisation/StringIds.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/interface/Colour.h>
#include "Theme.h"
#include "Window.h"
#include <stdexcept>
#include <vector>
using namespace OpenRCT2;
@@ -52,7 +53,6 @@ struct UIThemeWindowEntry
rct_windowclass WindowClass;
WindowTheme Theme;
json_t* ToJson() const;
static UIThemeWindowEntry FromJson(const WindowThemeDesc* wtDesc, const json_t* json);
};
@@ -274,7 +274,8 @@ json_t * UIThemeWindowEntry::ToJson() const
}
json_t* jsonColours = json_array();
for (uint8_t i = 0; i < wtDesc->NumColours; i++) {
for (uint8_t i = 0; i < wtDesc->NumColours; i++)
{
colour_t colour = Theme.Colours[i];
json_array_append_new(jsonColours, json_integer(colour));
}
@@ -374,9 +375,8 @@ json_t * UITheme::ToJson() const
json_object_set_new(jsonTheme, "useLightsRide", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_RIDE));
json_object_set_new(jsonTheme, "useLightsPark", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_PARK));
json_object_set_new(jsonTheme,
"useAltScenarioSelectFont",
json_boolean(Flags & UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT));
json_object_set_new(
jsonTheme, "useAltScenarioSelectFont", json_boolean(Flags & UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT));
json_object_set_new(jsonTheme, "useFullBottomToolbar", json_boolean(Flags & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR));
return jsonTheme;
@@ -438,7 +438,8 @@ UITheme * UITheme::FromJson(const json_t * json)
json_object_foreach(jsonEntries, jkey, jvalue)
{
const WindowThemeDesc* wtDesc = GetWindowThemeDescriptor(jkey);
if (wtDesc == nullptr) continue;
if (wtDesc == nullptr)
continue;
UIThemeWindowEntry entry = UIThemeWindowEntry::FromJson(wtDesc, jvalue);
result->SetEntry(&entry);
@@ -897,11 +898,11 @@ void colour_scheme_update_by_class(rct_window * window, rct_windowclass classifi
windowTheme = &desc->DefaultTheme;
}
for (int32_t i = 0; i < 6; i++) {
for (int32_t i = 0; i < 6; i++)
{
window->colours[i] = windowTheme->Colours[i];
}
// Some windows need to be transparent even if the colours aren't.
// There doesn't seem to be any side-effects for all windows being transparent
window->flags |= WF_TRANSPARENT;
}

View File

@@ -12,7 +12,8 @@
#include <openrct2/common.h>
#include <openrct2/interface/Window.h>
enum {
enum
{
UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,

View File

@@ -7,12 +7,17 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <openrct2/core/Math.hpp>
#include "Viewport.h"
#include "Window.h"
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/WallRemoveAction.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
@@ -20,17 +25,13 @@
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Banner.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/LargeScenery.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/Sprite.h>
#include <openrct2/world/Surface.h>
#include <openrct2/world/Wall.h>
#include <openrct2/Context.h>
#include <openrct2/actions/WallRemoveAction.hpp>
#include "Viewport.h"
#include "Window.h"
static void viewport_interaction_remove_scenery(rct_tile_element* tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_footpath(rct_tile_element* tileElement, int32_t x, int32_t y);
@@ -59,15 +60,25 @@ int32_t viewport_interaction_get_item_left(int32_t x, int32_t y, viewport_intera
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
LocationXY16 mapCoord = {};
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK, &mapCoord.x, &mapCoord.y, &info->type, &info->tileElement, nullptr);
get_map_coordinates_from_pos(
x,
y,
VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK,
&mapCoord.x,
&mapCoord.y,
&info->type,
&info->tileElement,
nullptr);
info->x = mapCoord.x;
info->y = mapCoord.y;
tileElement = info->tileElement;
sprite = (rct_sprite*)tileElement;
switch (info->type) {
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (sprite->unknown.sprite_identifier) {
switch (sprite->unknown.sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
vehicle = &(sprite->vehicle);
if (vehicle->ride_subtype != 255)
@@ -93,7 +104,8 @@ int32_t viewport_interaction_get_item_left(int32_t x, int32_t y, viewport_intera
}
// If nothing is under cursor, find a close by peep
if (info->type == VIEWPORT_INTERACTION_ITEM_NONE) {
if (info->type == VIEWPORT_INTERACTION_ITEM_NONE)
{
info->peep = viewport_interaction_get_closest_peep(x, y, 32);
if (info->peep == nullptr)
return VIEWPORT_INTERACTION_ITEM_NONE;
@@ -111,7 +123,8 @@ int32_t viewport_interaction_left_over(int32_t x, int32_t y)
{
viewport_interaction_info info;
switch (viewport_interaction_get_item_left(x, y, &info)) {
switch (viewport_interaction_get_item_left(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
case VIEWPORT_INTERACTION_ITEM_RIDE:
case VIEWPORT_INTERACTION_ITEM_PARK:
@@ -125,9 +138,11 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y)
{
viewport_interaction_info info;
switch (viewport_interaction_get_item_left(x, y, &info)) {
switch (viewport_interaction_get_item_left(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (info.sprite->unknown.sprite_identifier) {
switch (info.sprite->unknown.sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
{
auto intent = Intent(WD_VEHICLE);
@@ -143,10 +158,19 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y)
break;
}
case SPRITE_IDENTIFIER_MISC:
if (game_is_not_paused()) {
switch (info.sprite->unknown.misc_identifier) {
if (game_is_not_paused())
{
switch (info.sprite->unknown.misc_identifier)
{
case SPRITE_MISC_BALLOON:
game_do_command(info.sprite->balloon.sprite_index, GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_BALLOON_PRESS, 0, 0);
game_do_command(
info.sprite->balloon.sprite_index,
GAME_COMMAND_FLAG_APPLY,
0,
0,
GAME_COMMAND_BALLOON_PRESS,
0,
0);
break;
case SPRITE_MISC_DUCK:
duck_press(&info.sprite->duck);
@@ -192,19 +216,29 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
LocationXY16 mapCoord = {};
get_map_coordinates_from_pos(x, y, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), &mapCoord.x, &mapCoord.y, &info->type, &info->tileElement, nullptr);
get_map_coordinates_from_pos(
x,
y,
~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER),
&mapCoord.x,
&mapCoord.y,
&info->type,
&info->tileElement,
nullptr);
info->x = mapCoord.x;
info->y = mapCoord.y;
tileElement = info->tileElement;
switch (info->type) {
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
tileElement += 6;
ride = get_ride(tileElement->type);
if (ride->status == RIDE_STATUS_CLOSED) {
if (ride->status == RIDE_STATUS_CLOSED)
{
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
set_map_tooltip_format_arg(2, rct_string_id, ride->name);
set_map_tooltip_format_arg(4, uint32_t, ride->name_arguments);
@@ -223,32 +257,50 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) {
if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)
{
rct_string_id stringId;
if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) {
if (ride->num_stations > 1) {
if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_ENTRANCE;
} else {
}
else
{
stringId = STR_RIDE_ENTRANCE;
}
} else {
if (ride->num_stations > 1) {
}
else
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_EXIT;
} else {
}
else
{
stringId = STR_RIDE_EXIT;
}
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
} else if (track_element_is_station(tileElement)) {
}
else if (track_element_is_station(tileElement))
{
rct_string_id stringId;
if (ride->num_stations > 1) {
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X;
} else {
}
else
{
stringId = STR_RIDE_STATION;
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
} else {
if (!gCheatsSandboxMode && !map_is_location_owned(info->x, info->y, tileElement->base_height << 4)) {
}
else
{
if (!gCheatsSandboxMode && !map_is_location_owned(info->x, info->y, tileElement->base_height << 4))
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
@@ -259,7 +311,8 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
set_map_tooltip_format_arg(4, rct_string_id, ride->name);
set_map_tooltip_format_arg(6, uint32_t, ride->name_arguments);
set_map_tooltip_format_arg(10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);
set_map_tooltip_format_arg(
10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);
stationIndex = tile_element_get_station(tileElement);
for (i = stationIndex; i >= 0; i--)
@@ -271,7 +324,8 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
case VIEWPORT_INTERACTION_ITEM_WALL:
sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
if (sceneryEntry->wall.scrolling_mode != 255) {
if (sceneryEntry->wall.scrolling_mode != 255)
{
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
@@ -280,7 +334,8 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement));
if (sceneryEntry->large_scenery.scrolling_mode != 255) {
if (sceneryEntry->large_scenery.scrolling_mode != 255)
{
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
@@ -296,13 +351,16 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
return info->type;
}
if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) {
if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr) {
if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE)))
{
if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr)
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
}
switch (info->type) {
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SCENERY:
sceneryEntry = get_small_scenery_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
@@ -319,10 +377,13 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement));
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) {
if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN)
{
set_map_tooltip_format_arg(2, rct_string_id, STR_BROKEN);
set_map_tooltip_format_arg(4, rct_string_id, sceneryEntry->name);
} else {
}
else
{
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
}
return info->type;
@@ -370,7 +431,8 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
CoordsXYE tileElement;
viewport_interaction_info info;
switch (viewport_interaction_get_item_right(x, y, &info)) {
switch (viewport_interaction_get_item_right(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_NONE:
return 0;
@@ -424,8 +486,7 @@ static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, i
(tileElement->properties.scenery.type << 8) | tileElement->base_height,
GAME_COMMAND_REMOVE_SCENERY,
0,
0
);
0);
}
/**
@@ -445,8 +506,10 @@ static void viewport_interaction_remove_footpath(rct_tile_element *tileElement,
footpath_provisional_update();
tileElement2 = map_get_first_element_at(x / 32, y / 32);
do {
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z) {
do
{
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z)
{
gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE;
footpath_remove(x, y, z, GAME_COMMAND_FLAG_APPLY);
break;
@@ -474,8 +537,7 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElem
(type << 8) | tileElement->base_height,
GAME_COMMAND_PLACE_PATH,
0,
0
);
0);
}
/**
@@ -485,7 +547,8 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElem
void viewport_interaction_remove_park_entrance(rct_tile_element* tileElement, int32_t x, int32_t y)
{
int32_t rotation = tile_element_get_direction_with_offset(tileElement, 1);
switch (tileElement->properties.entrance.index & 0x0F) {
switch (tileElement->properties.entrance.index & 0x0F)
{
case 1:
x += CoordsDirectionDelta[rotation].x;
y += CoordsDirectionDelta[rotation].y;
@@ -530,7 +593,9 @@ static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElem
{
BannerIndex bannerIndex = scenery_large_get_banner_id(tileElement);
context_open_detail_window(WD_SIGN, bannerIndex);
} else {
}
else
{
gGameCommandErrorTitle = STR_CANT_REMOVE_THIS;
game_do_command(
x,
@@ -539,8 +604,7 @@ static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElem
tileElement->base_height | (scenery_large_get_sequence(tileElement) << 8),
GAME_COMMAND_REMOVE_LARGE_SCENERY,
0,
0
);
0);
}
}
@@ -565,17 +629,18 @@ static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int
closestPeep = nullptr;
closestDistance = 0xFFFF;
FOR_ALL_PEEPS(spriteIndex, peep) {
FOR_ALL_PEEPS (spriteIndex, peep)
{
if (peep->sprite_left == LOCATION_NULL)
continue;
distance =
abs(((peep->sprite_left + peep->sprite_right) / 2) - x) +
abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
distance
= abs(((peep->sprite_left + peep->sprite_right) / 2) - x) + abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
if (distance > maxDistance)
continue;
if (distance < closestDistance) {
if (distance < closestDistance)
{
closestPeep = peep;
closestDistance = distance;
}
@@ -594,24 +659,36 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t *x, int16_t *y, int32_
int32_t interactionType;
rct_tile_element* myTileElement;
rct_viewport* viewport;
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, &my_x, &my_y, &interactionType, &myTileElement, &viewport);
get_map_coordinates_from_pos(
screenX,
screenY,
VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER,
&my_x,
&my_y,
&interactionType,
&myTileElement,
&viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{
*x = LOCATION_NULL;
return;
}
int16_t originalZ = 0;
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER)
{
originalZ = surface_get_water_height(myTileElement) << 4;
}
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(viewport, screenX, screenY);
LocationXY16 map_pos = { (int16_t)(my_x + 16), (int16_t)(my_y + 16) };
for (int32_t i = 0; i < 5; i++) {
for (int32_t i = 0; i < 5; i++)
{
int16_t z = originalZ;
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER) {
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER)
{
z = tile_element_height(map_pos.x, map_pos.y);
}
map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
@@ -623,22 +700,33 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t *x, int16_t *y, int32_
int32_t myDirection;
int32_t mod_x = map_pos.x & 0x1F;
int32_t mod_y = map_pos.y & 0x1F;
if (mod_x < mod_y) {
if (mod_x + mod_y < 32) {
if (mod_x < mod_y)
{
if (mod_x + mod_y < 32)
{
myDirection = 0;
} else {
}
else
{
myDirection = 1;
}
} else {
if (mod_x + mod_y < 32) {
}
else
{
if (mod_x + mod_y < 32)
{
myDirection = 3;
} else {
}
else
{
myDirection = 2;
}
}
*x = map_pos.x & ~0x1F;
*y = map_pos.y & ~0x1F;
if (direction != nullptr) *direction = myDirection;
if (tileElement != nullptr) *tileElement = myTileElement;
if (direction != nullptr)
*direction = myDirection;
if (tileElement != nullptr)
*tileElement = myTileElement;
}

View File

@@ -7,16 +7,18 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "Widget.h"
#include "Window.h"
#include <algorithm>
#include <cmath>
#include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include "Widget.h"
#include "Window.h"
static void widget_frame_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_resize_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
@@ -33,8 +35,10 @@ static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
static void widget_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_closebox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_scroll_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_hscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_vscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_draw_image(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
/**
@@ -43,7 +47,8 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
*/
void widget_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{
switch (w->widgets[widgetIndex].type) {
switch (w->widgets[widgetIndex].type)
{
case WWT_EMPTY:
break;
case WWT_FRAME:
@@ -186,12 +191,14 @@ static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
int32_t b = w->y + widget->bottom;
// Check if the button is pressed down
uint8_t press = widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press
= widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
// Get the colour
uint8_t colour = w->colours[widget->colour];
if ((int32_t)widget->image == -2) {
if ((int32_t)widget->image == -2)
{
// Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE);
return;
@@ -216,7 +223,8 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
return;
// Draw widgets that aren't explicitly disabled.
if (!widget_is_disabled(w, widgetIndex)) {
if (!widget_is_disabled(w, widgetIndex))
{
widget_draw_image(dpi, w, widgetIndex);
return;
}
@@ -225,7 +233,8 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
if (widget->type == WWT_TAB && widget->image != (IMAGE_TYPE_REMAP | SPR_G2_TAB_DISABLED))
return;
if (widget->type != WWT_TRNBTN) {
if (widget->type != WWT_TRNBTN)
{
widget_draw_image(dpi, w, widgetIndex);
return;
}
@@ -248,7 +257,8 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
*/
static void widget_flat_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{
if (!widget_is_disabled(w, widgetIndex) && widget_is_highlighted(w, widgetIndex)) {
if (!widget_is_disabled(w, widgetIndex) && widget_is_highlighted(w, widgetIndex))
{
widget_button_draw(dpi, w, widgetIndex);
return;
}
@@ -266,8 +276,10 @@ static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_w
uint8_t colour = w->colours[widget->colour];
// Check if the button is pressed down
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) {
if ((int32_t)widget->image == -2) {
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
{
if ((int32_t)widget->image == -2)
{
// Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE);
return;
@@ -300,7 +312,8 @@ static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
uint8_t colour = w->colours[widget->colour];
// Border
uint8_t press = widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press
= widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press);
// Button caption
@@ -349,14 +362,7 @@ static void widget_text_centred(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
t = w->y + widget->top;
gfx_draw_string_centred_clipped(
dpi,
widget->text,
gCommonFormatArgs,
colour,
(l + r + 1) / 2 - 1,
t,
widget->right - widget->left - 2
);
dpi, widget->text, gCommonFormatArgs, colour, (l + r + 1) / 2 - 1, t, widget->right - widget->left - 2);
}
/**
@@ -434,7 +440,8 @@ static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
int32_t textRight = l;
// Text
if (widget->text != STR_NONE) {
if (widget->text != STR_NONE)
{
uint8_t colour = w->colours[widget->colour] & 0x7F;
if (widget_is_disabled(w, widgetIndex))
colour |= COLOUR_FLAG_INSET;
@@ -515,7 +522,8 @@ static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
l = widget->left + w->x + 2;
t = widget->top + w->y + 1;
int32_t width = widget->right - widget->left - 4;
if ((widget + 1)->type == WWT_CLOSEBOX) {
if ((widget + 1)->type == WWT_CLOSEBOX)
{
width -= 10;
if ((widget + 2)->type == WWT_CLOSEBOX)
width -= 10;
@@ -586,7 +594,8 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
gfx_fill_rect_inset(dpi, l, yMid - 5, l + 9, yMid + 4, colour, INSET_RECT_F_60);
// fill it when checkbox is pressed
if (widget_is_pressed(w, widgetIndex)) {
if (widget_is_pressed(w, widgetIndex))
{
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, NOT_TRANSLUCENT(colour), l, yMid - 5);
}
@@ -595,7 +604,8 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
if (widget->text == STR_NONE)
return;
if (widget_is_disabled(w, widgetIndex)) {
if (widget_is_disabled(w, widgetIndex))
{
colour |= COLOUR_FLAG_INSET;
}
@@ -673,7 +683,8 @@ static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
window_event_scroll_paint_call(w, &scroll_dpi, scrollIndex);
}
static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
static void widget_hscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
{
colour &= 0x7F;
// Trough
@@ -685,21 +696,28 @@ static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
gfx_fill_rect(dpi, l + 10, t + 8, r - 10, t + 8, ColourMapA[colour].lighter);
// Left button
gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, ((scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, t, l + 9, b, colour, ((scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t);
// Thumb
gfx_fill_rect_inset(dpi,
std::max(l + 10, l + scroll->h_thumb_left - 1), t,
std::min(r - 10, l + scroll->h_thumb_right - 1), b,
colour, ((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi,
std::max(l + 10, l + scroll->h_thumb_left - 1),
t,
std::min(r - 10, l + scroll->h_thumb_right - 1),
b,
colour,
((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
// Right button
gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, ((scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, r - 9, t, r, b, colour, ((scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackRightArrowString, COLOUR_BLACK, r - 6, t);
}
static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
static void widget_vscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
{
colour &= 0x7F;
// Trough
@@ -711,17 +729,23 @@ static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
gfx_fill_rect(dpi, l + 8, t + 10, l + 8, b - 10, ColourMapA[colour].lighter);
// Up button
gfx_fill_rect_inset(dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1);
// Thumb
gfx_fill_rect_inset(dpi,
l, std::max(t + 10, t + scroll->v_thumb_top - 1),
r, std::min(b - 10, t + scroll->v_thumb_bottom - 1),
colour, ((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi,
l,
std::max(t + 10, t + scroll->v_thumb_top - 1),
r,
std::min(b - 10, t + scroll->v_thumb_bottom - 1),
colour,
((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
// Down button
gfx_fill_rect_inset(dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9);
}
@@ -750,7 +774,8 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
image++;
if (widget_is_disabled(w, widgetIndex)) {
if (widget_is_disabled(w, widgetIndex))
{
// Draw greyed out (light border bottom right shadow)
colour = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].lighter;
@@ -760,8 +785,11 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
colour = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].mid_light;
gfx_draw_sprite_solid(dpi, image, l, t, colour);
} else {
if (image & IMAGE_TYPE_REMAP_2_PLUS) {
}
else
{
if (image & IMAGE_TYPE_REMAP_2_PLUS)
{
// ?
}
@@ -786,14 +814,20 @@ bool widget_is_disabled(rct_window *w, rct_widgetindex widgetIndex)
bool widget_is_pressed(rct_window* w, rct_widgetindex widgetIndex)
{
if (w->pressed_widgets & (1LL << widgetIndex)) {
if (w->pressed_widgets & (1LL << widgetIndex))
{
return true;
}
if (input_get_state() == INPUT_STATE_WIDGET_PRESSED || input_get_state() == INPUT_STATE_DROPDOWN_ACTIVE) {
if (!(input_test_flag(INPUT_FLAG_WIDGET_PRESSED))) return false;
if (gPressedWidget.window_classification != w->classification) return false;
if (gPressedWidget.window_number != w->number) return false;
if (gPressedWidget.widget_index != widgetIndex) return false;
if (input_get_state() == INPUT_STATE_WIDGET_PRESSED || input_get_state() == INPUT_STATE_DROPDOWN_ACTIVE)
{
if (!(input_test_flag(INPUT_FLAG_WIDGET_PRESSED)))
return false;
if (gPressedWidget.window_classification != w->classification)
return false;
if (gPressedWidget.window_number != w->number)
return false;
if (gPressedWidget.widget_index != widgetIndex)
return false;
return true;
}
return false;
@@ -801,9 +835,12 @@ bool widget_is_pressed(rct_window *w, rct_widgetindex widgetIndex)
bool widget_is_highlighted(rct_window* w, rct_widgetindex widgetIndex)
{
if (gHoverWidget.window_classification != w->classification) return false;
if (gHoverWidget.window_number != w->number) return false;
if (gHoverWidget.widget_index != widgetIndex) return false;
if (gHoverWidget.window_classification != w->classification)
return false;
if (gHoverWidget.window_number != w->number)
return false;
if (gHoverWidget.widget_index != widgetIndex)
return false;
return true;
}
@@ -831,7 +868,15 @@ bool widget_is_active_tool(rct_window *w, rct_widgetindex widgetIndex)
* esi: w
* edi: widget
*/
void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_t y, int32_t *output_x, int32_t *output_y, int32_t *output_scroll_area, int32_t *scroll_id)
void widget_scroll_get_part(
rct_window* w,
rct_widget* widget,
int32_t x,
int32_t y,
int32_t* output_x,
int32_t* output_y,
int32_t* output_scroll_area,
int32_t* scroll_id)
{
rct_widget* iterator = w->widgets;
*scroll_id = 0;
@@ -938,11 +983,13 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_
void widget_set_enabled(rct_window* w, rct_widgetindex widgetIndex, bool enabled)
{
if (enabled) {
if (enabled)
{
w->enabled_widgets |= (1ULL << widgetIndex);
w->disabled_widgets &= ~(1ULL << widgetIndex);
}
else {
else
{
w->enabled_widgets &= ~(1ULL << widgetIndex);
w->disabled_widgets |= (1ULL << widgetIndex);
}
@@ -974,9 +1021,8 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
// Get the colour
uint8_t colour = w->colours[widget->colour];
bool active = w->classification == gCurrentTextBox.window.classification &&
w->number == gCurrentTextBox.window.number &&
widgetIndex == gCurrentTextBox.widget_index;
bool active = w->classification == gCurrentTextBox.window.classification && w->number == gCurrentTextBox.window.number
&& widgetIndex == gCurrentTextBox.widget_index;
// gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00));
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_F_60);
@@ -984,9 +1030,10 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gCurrentFontFlags = 0;
if (!active || gTextInput == nullptr) {
if (w->widgets[widgetIndex].text != 0) {
if (!active || gTextInput == nullptr)
{
if (w->widgets[widgetIndex].text != 0)
{
safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512);
gfx_wrap_string(wrapped_string, r - l - 5, &no_lines, &font_height);
gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
@@ -994,17 +1041,14 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
return;
}
safe_strcpy(wrapped_string, gTextBoxInput, TEXT_INPUT_SIZE);
// String length needs to add 12 either side of box
// +13 for cursor when max length.
gfx_wrap_string(wrapped_string, r - l - 5 - 6, &no_lines, &font_height);
gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
size_t string_length = get_string_size(wrapped_string) - 1;
// Make a copy of the string for measuring the width.
@@ -1013,7 +1057,8 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
int32_t cur_x = l + gfx_get_string_width(temp_string) + 3;
int32_t width = 6;
if ((uint32_t)gTextInput->SelectionStart < strlen(gTextBoxInput)){
if ((uint32_t)gTextInput->SelectionStart < strlen(gTextBoxInput))
{
// Make a new 1 character wide string for measuring the width
// of the character that the cursor is under.
temp_string[1] = '\0';
@@ -1021,7 +1066,8 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
width = std::max(gfx_get_string_width(temp_string) - 2, 4);
}
if (gTextBoxFrameNo <= 15){
if (gTextBoxFrameNo <= 15)
{
colour = ColourMapA[w->colours[1]].mid_light;
gfx_fill_rect(dpi, cur_x, t + 9, cur_x + width, t + 9, colour + 5);
}

View File

@@ -7,19 +7,21 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "Window.h"
#include "Theme.h"
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h>
#include <openrct2/interface/Widget.h>
#include <openrct2/localisation/StringIds.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/sprites.h>
#include <openrct2/world/Sprite.h>
#include <openrct2/ui/UiContext.h>
#include "Theme.h"
#include "Window.h"
#include <openrct2/world/Sprite.h>
using namespace OpenRCT2;
@@ -35,10 +37,14 @@ static bool window_fits_between_others(int32_t x, int32_t y, int32_t width, int3
if (w->flags & WF_STICK_TO_BACK)
continue;
if (x + width <= w->x) continue;
if (x >= w->x + w->width) continue;
if (y + height <= w->y) continue;
if (y >= w->y + w->height) continue;
if (x + width <= w->x)
continue;
if (x >= w->x + w->width)
continue;
if (y + height <= w->y)
continue;
if (y >= w->y + w->height)
continue;
return false;
}
@@ -47,10 +53,14 @@ static bool window_fits_between_others(int32_t x, int32_t y, int32_t width, int3
static bool window_fits_within_space(int32_t x, int32_t y, int32_t width, int32_t height)
{
if (x < 0) return false;
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false;
if (x + width > context_get_width()) return false;
if (y + height > context_get_height()) return false;
if (x < 0)
return false;
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
return false;
if (x + width > context_get_width())
return false;
if (y + height > context_get_height())
return false;
return window_fits_between_others(x, y, width, height);
}
@@ -61,16 +71,27 @@ static bool window_fits_on_screen(int32_t x, int32_t y, int32_t width, int32_t h
int32_t unk;
unk = -(width / 4);
if (x < unk) return false;
if (x < unk)
return false;
unk = screenWidth + (unk * 2);
if (x > unk) return false;
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false;
if (x > unk)
return false;
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
return false;
unk = screenHeight - (height / 4);
if (y > unk) return false;
if (y > unk)
return false;
return window_fits_between_others(x, y, width, height);
}
rct_window *window_create(int32_t x, int32_t y, int32_t width, int32_t height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16_t flags)
rct_window* window_create(
int32_t x,
int32_t y,
int32_t width,
int32_t height,
rct_window_event_list* event_handlers,
rct_windowclass cls,
uint16_t flags)
{
// Check if there are any window slots left
// include WINDOW_LIMIT_RESERVED for items such as the main viewport and toolbars to not appear to be counted.
@@ -121,7 +142,8 @@ rct_window *window_create(int32_t x, int32_t y, int32_t width, int32_t height, r
w->flags = flags;
// Play sounds and flash the window
if (!(flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) {
if (!(flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)))
{
w->flags |= WF_WHITE_BORDER_MASK;
audio_play_sound(SOUND_WINDOW_OPEN, 0, x + (width / 2));
}
@@ -156,7 +178,8 @@ rct_window *window_create(int32_t x, int32_t y, int32_t width, int32_t height, r
return w;
}
rct_window *window_create_auto_pos(int32_t width, int32_t height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16_t flags)
rct_window* window_create_auto_pos(
int32_t width, int32_t height, rct_window_event_list* event_handlers, rct_windowclass cls, uint16_t flags)
{
auto uiContext = GetContext()->GetUiContext();
auto screenWidth = uiContext->GetWidth();
@@ -184,19 +207,23 @@ rct_window *window_create_auto_pos(int32_t width, int32_t height, rct_window_eve
// Place window in an empty corner of the screen
int32_t x = 0;
int32_t y = 30;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = screenWidth - width;
y = 30;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = 0;
y = screenHeight - 34 - height;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = screenWidth - width;
y = screenHeight - 34 - height;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
// Place window next to another
for (auto& w : g_window_list)
@@ -206,35 +233,43 @@ rct_window *window_create_auto_pos(int32_t width, int32_t height, rct_window_eve
x = w->x + w->width + 2;
y = w->y;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x - w->width - 2;
y = w->y;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x;
y = w->y + w->height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x;
y = w->y - w->height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x + w->width + 2;
y = w->y - w->height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x - w->width - 2;
y = w->y - w->height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x + w->width + 2;
y = w->y + w->height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
x = w->x - w->width - 2;
y = w->y + w->height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
if (window_fits_within_space(x, y, width, height))
goto foundSpace;
}
// Overlap
@@ -245,19 +280,23 @@ rct_window *window_create_auto_pos(int32_t width, int32_t height, rct_window_eve
x = w->x + w->width + 2;
y = w->y;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
if (window_fits_on_screen(x, y, width, height))
goto foundSpace;
x = w->x - w->width - 2;
y = w->y;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
if (window_fits_on_screen(x, y, width, height))
goto foundSpace;
x = w->x;
y = w->y + w->height + 2;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
if (window_fits_on_screen(x, y, width, height))
goto foundSpace;
x = w->x;
y = w->y - w->height - 2;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
if (window_fits_on_screen(x, y, width, height))
goto foundSpace;
}
// Cascade
@@ -282,7 +321,8 @@ foundSpace:
return window_create(x, y, width, height, event_handlers, cls, flags);
}
rct_window * window_create_centred(int32_t width, int32_t height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16_t flags)
rct_window* window_create_centred(
int32_t width, int32_t height, rct_window_event_list* event_handlers, rct_windowclass cls, uint16_t flags)
{
auto uiContext = GetContext()->GetUiContext();
auto screenWidth = uiContext->GetWidth();
@@ -309,7 +349,8 @@ static int32_t window_get_scroll_index(rct_window *w, int32_t targetWidgetIndex)
int32_t scrollIndex = 0;
rct_widgetindex widgetIndex = 0;
for (rct_widget *widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
for (rct_widget* widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++)
{
if (widgetIndex == targetWidgetIndex)
break;
if (widget->type == WWT_SCROLL)
@@ -321,7 +362,8 @@ static int32_t window_get_scroll_index(rct_window *w, int32_t targetWidgetIndex)
static rct_widget* window_get_scroll_widget(rct_window* w, int32_t scrollIndex)
{
for (rct_widget *widget = w->widgets; widget->type != WWT_LAST; widget++) {
for (rct_widget* widget = w->widgets; widget->type != WWT_LAST; widget++)
{
if (widget->type != WWT_SCROLL)
continue;
@@ -343,13 +385,16 @@ static void window_scroll_wheel_input(rct_window *w, int32_t scrollIndex, int32_
rct_widget* widget = window_get_scroll_widget(w, scrollIndex);
rct_widgetindex widgetIndex = window_get_widget_index(w, widget);
if (scroll->flags & VSCROLLBAR_VISIBLE) {
if (scroll->flags & VSCROLLBAR_VISIBLE)
{
int32_t size = widget->bottom - widget->top - 1;
if (scroll->flags & HSCROLLBAR_VISIBLE)
size -= 11;
size = std::max(0, scroll->v_bottom - size);
scroll->v_top = std::min(std::max(0, scroll->v_top + wheel), size);
} else {
}
else
{
int32_t size = widget->right - widget->left - 1;
if (scroll->flags & VSCROLLBAR_VISIBLE)
size -= 11;
@@ -368,13 +413,15 @@ static void window_scroll_wheel_input(rct_window *w, int32_t scrollIndex, int32_
static int32_t window_wheel_input(rct_window* w, int32_t wheel)
{
int32_t i = 0;
for (rct_widget *widget = w->widgets; widget->type != WWT_LAST; widget++) {
for (rct_widget* widget = w->widgets; widget->type != WWT_LAST; widget++)
{
if (widget->type != WWT_SCROLL)
continue;
// Originally always checked first scroll view, bug maybe?
rct_scroll* scroll = &w->scrolls[i];
if (scroll->flags & (HSCROLLBAR_VISIBLE | VSCROLLBAR_VISIBLE)) {
if (scroll->flags & (HSCROLLBAR_VISIBLE | VSCROLLBAR_VISIBLE))
{
window_scroll_wheel_input(w, i, wheel);
return 1;
}
@@ -460,7 +507,8 @@ static bool window_other_wheel_input(rct_window* w, rct_widgetindex widgetIndex,
expectedContent[0] = STR_NUMERIC_UP;
expectedContent[1] = STR_NUMERIC_DOWN;
break;
default: return false;
default:
return false;
}
if (widget_is_disabled(w, buttonWidgetIndex))
@@ -499,28 +547,37 @@ void window_all_wheel_input()
return;
// Check window cursor is over
if (!(input_test_flag(INPUT_FLAG_5))) {
if (!(input_test_flag(INPUT_FLAG_5)))
{
rct_window* w = window_find_from_point(cursorState->x, cursorState->y);
if (w != nullptr) {
if (w != nullptr)
{
// Check if main window
if (w->classification == WC_MAIN_WINDOW || w->classification == WC_VIEWPORT) {
if (w->classification == WC_MAIN_WINDOW || w->classification == WC_VIEWPORT)
{
window_viewport_wheel_input(w, relative_wheel);
return;
}
// Check scroll view, cursor is over
rct_widgetindex widgetIndex = window_find_widget_from_point(w, cursorState->x, cursorState->y);
if (widgetIndex != -1) {
if (widgetIndex != -1)
{
rct_widget* widget = &w->widgets[widgetIndex];
if (widget->type == WWT_SCROLL) {
if (widget->type == WWT_SCROLL)
{
int32_t scrollIndex = window_get_scroll_index(w, widgetIndex);
rct_scroll* scroll = &w->scrolls[scrollIndex];
if (scroll->flags & (HSCROLLBAR_VISIBLE | VSCROLLBAR_VISIBLE)) {
if (scroll->flags & (HSCROLLBAR_VISIBLE | VSCROLLBAR_VISIBLE))
{
window_scroll_wheel_input(w, window_get_scroll_index(w, widgetIndex), pixel_scroll);
return;
}
} else {
if (window_other_wheel_input(w, widgetIndex, pixel_scroll)) {
}
else
{
if (window_other_wheel_input(w, widgetIndex, pixel_scroll))
{
return;
}
}
@@ -546,8 +603,10 @@ void window_init_scroll_widgets(rct_window *w)
widget_index = 0;
scroll_index = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
if (widget->type != WWT_SCROLL) {
for (widget = w->widgets; widget->type != WWT_LAST; widget++)
{
if (widget->type != WWT_SCROLL)
{
widget_index++;
continue;
}
@@ -589,7 +648,8 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
// todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
for (widget = w->widgets; widget->type != WWT_LAST; widget++)
{
// Check if widget is outside the draw region
if (w->x + widget->left < dpi->x + dpi->width && w->x + widget->right >= dpi->x)
if (w->y + widget->top < dpi->y + dpi->height && w->y + widget->bottom >= dpi->y)
@@ -600,8 +660,10 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
// todo: something missing here too? Between 006EC32B and 006EC369
if (w->flags & WF_WHITE_BORDER_MASK) {
gfx_fill_rect_inset(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, COLOUR_WHITE, INSET_RECT_FLAG_FILL_NONE);
if (w->flags & WF_WHITE_BORDER_MASK)
{
gfx_fill_rect_inset(
dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, COLOUR_WHITE, INSET_RECT_FLAG_FILL_NONE);
}
}
@@ -615,7 +677,8 @@ static void window_invalidate_pressed_image_buttons(rct_window *w)
rct_widget* widget;
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++)
{
if (widget->type != WWT_IMGBTN)
continue;