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,13 +9,13 @@
#pragma once #pragma once
#include <openrct2/common.h>
#include <openrct2-ui/interface/Window.h> #include <openrct2-ui/interface/Window.h>
#include <openrct2/common.h>
#define DROPDOWN_SEPARATOR 0 #define DROPDOWN_SEPARATOR 0
#define DROPDOWN_FORMAT_COLOUR_PICKER 0xFFFE #define DROPDOWN_FORMAT_COLOUR_PICKER 0xFFFE
#define DROPDOWN_FORMAT_LAND_PICKER 0xFFFF #define DROPDOWN_FORMAT_LAND_PICKER 0xFFFF
#define DROPDOWN_ITEMS_MAX_SIZE 128 #define DROPDOWN_ITEMS_MAX_SIZE 128
enum enum
{ {
@@ -39,9 +39,27 @@ void dropdown_set_checked(int32_t index, bool value);
void dropdown_set_disabled(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(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_text_custom_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); 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(); void window_dropdown_close();
int32_t dropdown_index_from_point(int32_t x, int32_t y, rct_window* w); 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(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. * 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/Date.h>
#include <openrct2/localisation/Localisation.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; 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; int32_t i, x, y, lastX, lastY;
lastX = -1; 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; int32_t i, x, y, lastX, lastY;
@@ -89,14 +92,15 @@ static void graph_draw_line_b_uint8_t(rct_drawpixelinfo * dpi, const uint8_t * h
} }
} }
void graph_draw_uint8_t(rct_drawpixelinfo * dpi, uint8_t * history, int32_t count, int32_t baseX, int32_t baseY) void graph_draw_uint8_t(rct_drawpixelinfo* dpi, uint8_t* history, int32_t count, int32_t baseX, int32_t baseY)
{ {
graph_draw_months_uint8_t(dpi, history, count, baseX, baseY); graph_draw_months_uint8_t(dpi, history, count, baseX, baseY);
graph_draw_line_a_uint8_t(dpi, history, count, baseX, baseY); graph_draw_line_a_uint8_t(dpi, history, count, baseX, baseY);
graph_draw_line_b_uint8_t(dpi, history, count, baseX, baseY); 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; 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; yearOver32 = (currentMonth * 4) + (currentDay >> 14) - 31;
x = baseX; x = baseX;
y = baseY; y = baseY;
for (i = count - 1; i >= 0; i--) { for (i = count - 1; i >= 0; i--)
if (history[i] != MONEY32_UNDEFINED && yearOver32 % 4 == 0) { {
if (history[i] != MONEY32_UNDEFINED && yearOver32 % 4 == 0)
{
// Draw month text // Draw month text
int32_t monthFormat = DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)]; 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); 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; int32_t i, x, y, lastX, lastY;
lastX = -1; lastX = -1;
lastY = -1; lastY = -1;
x = baseX; x = baseX;
for (i = count - 1; i >= 0; i--) { for (i = count - 1; i >= 0; i--)
if (history[i] != MONEY32_UNDEFINED) { {
if (history[i] != MONEY32_UNDEFINED)
{
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256); 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 + 1, lastY + 1, x + 1, y + 1, PALETTE_INDEX_10);
gfx_draw_line(dpi, lastX, lastY + 1, x, 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; int32_t i, x, y, lastX, lastY;
lastX = -1; lastX = -1;
lastY = -1; lastY = -1;
x = baseX; x = baseX;
for (i = count - 1; i >= 0; i--) { for (i = count - 1; i >= 0; i--)
if (history[i] != MONEY32_UNDEFINED) { {
if (history[i] != MONEY32_UNDEFINED)
{
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256); y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256);
if (lastX != -1) 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_months_money32(dpi, history, count, baseX, baseY);
graph_draw_line_a_money32(dpi, history, count, baseX, baseY, modifier, offset); graph_draw_line_a_money32(dpi, history, count, baseX, baseY, modifier, offset);

View File

@@ -13,7 +13,8 @@
#include <openrct2/common.h> #include <openrct2/common.h>
#include <openrct2/drawing/Drawing.h> #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_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 #endif

View File

@@ -7,19 +7,21 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "InGameConsole.h"
#include "Theme.h"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <openrct2/config/Config.h>
#include <openrct2/Context.h> #include <openrct2/Context.h>
#include <openrct2/Version.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp> #include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h> #include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h> #include <openrct2/interface/Colour.h>
#include <openrct2/interface/Window.h> #include <openrct2/interface/Window.h>
#include <openrct2/localisation/Language.h> #include <openrct2/localisation/Language.h>
#include <openrct2/localisation/LocalisationService.h> #include <openrct2/localisation/LocalisationService.h>
#include <openrct2/Version.h>
#include "InGameConsole.h"
#include "Theme.h"
using namespace OpenRCT2::Ui; using namespace OpenRCT2::Ui;
@@ -40,74 +42,82 @@ void InGameConsole::WritePrompt()
void InGameConsole::Input(CONSOLE_INPUT input) void InGameConsole::Input(CONSOLE_INPUT input)
{ {
switch (input) { switch (input)
case CONSOLE_INPUT_LINE_CLEAR: {
ClearInput(); case CONSOLE_INPUT_LINE_CLEAR:
RefreshCaret();
break;
case CONSOLE_INPUT_LINE_EXECUTE:
if (_consoleCurrentLine[0] != '\0') {
HistoryAdd(_consoleCurrentLine);
// Append text we are executing to prompt line
_consoleLines.back().append(_consoleCurrentLine);
Execute(_consoleCurrentLine);
WritePrompt();
ClearInput(); ClearInput();
RefreshCaret(); RefreshCaret();
} break;
ScrollToEnd(); case CONSOLE_INPUT_LINE_EXECUTE:
break; if (_consoleCurrentLine[0] != '\0')
case CONSOLE_INPUT_HISTORY_PREVIOUS: {
if (_consoleHistoryIndex > 0) { HistoryAdd(_consoleCurrentLine);
_consoleHistoryIndex--;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE); // Append text we are executing to prompt line
} _consoleLines.back().append(_consoleCurrentLine);
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer); Execute(_consoleCurrentLine);
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine); WritePrompt();
break; ClearInput();
case CONSOLE_INPUT_HISTORY_NEXT: RefreshCaret();
if (_consoleHistoryIndex < _consoleHistoryCount - 1) { }
_consoleHistoryIndex++; ScrollToEnd();
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE); break;
case CONSOLE_INPUT_HISTORY_PREVIOUS:
if (_consoleHistoryIndex > 0)
{
_consoleHistoryIndex--;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE);
}
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer); _consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer); _consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer);
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine); _consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
} else { break;
_consoleHistoryIndex = _consoleHistoryCount; case CONSOLE_INPUT_HISTORY_NEXT:
ClearInput(); 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
{
_consoleHistoryIndex = _consoleHistoryCount;
ClearInput();
}
break;
case CONSOLE_INPUT_SCROLL_PREVIOUS:
{
int32_t scrollAmt = GetNumVisibleLines() - 1;
Scroll(scrollAmt);
break;
} }
break; case CONSOLE_INPUT_SCROLL_NEXT:
case CONSOLE_INPUT_SCROLL_PREVIOUS: {
{ int32_t scrollAmt = GetNumVisibleLines() - 1;
int32_t scrollAmt = GetNumVisibleLines() - 1; Scroll(-scrollAmt);
Scroll(scrollAmt); break;
break; }
} default:
case CONSOLE_INPUT_SCROLL_NEXT: break;
{
int32_t scrollAmt = GetNumVisibleLines() - 1;
Scroll(-scrollAmt);
break;
}
default:
break;
} }
} }
void InGameConsole::ClearInput() void InGameConsole::ClearInput()
{ {
_consoleCurrentLine[0] = 0; _consoleCurrentLine[0] = 0;
if (_isOpen) { if (_isOpen)
{
context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine)); context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
} }
} }
void InGameConsole::HistoryAdd(const utf8 * src) 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++) for (int32_t i = 0; i < _consoleHistoryCount - 1; i++)
memcpy(_consoleHistory[i], _consoleHistory[i + 1], CONSOLE_INPUT_SIZE); memcpy(_consoleHistory[i], _consoleHistory[i + 1], CONSOLE_INPUT_SIZE);
_consoleHistoryCount--; _consoleHistoryCount--;
@@ -133,7 +143,7 @@ void InGameConsole::Scroll(int32_t linesToScroll)
if (numLines > maxVisibleLines) if (numLines > maxVisibleLines)
{ {
int32_t maxScrollValue = numLines - maxVisibleLines; int32_t maxScrollValue = numLines - maxVisibleLines;
_consoleScrollPos = Math::Clamp<int32_t>(0, _consoleScrollPos - linesToScroll, maxScrollValue); _consoleScrollPos = Math::Clamp<int32_t>(0, _consoleScrollPos - linesToScroll, maxScrollValue);
} }
} }
@@ -182,7 +192,7 @@ void InGameConsole::Toggle()
} }
} }
void InGameConsole::WriteLine(const std::string &input, uint32_t colourFormat) void InGameConsole::WriteLine(const std::string& input, uint32_t colourFormat)
{ {
// Include text colour format only for special cases // Include text colour format only for special cases
// The draw function handles the default text colour differently // The draw function handles the default text colour differently
@@ -191,12 +201,12 @@ void InGameConsole::WriteLine(const std::string &input, uint32_t colourFormat)
utf8_write_codepoint(colourCodepoint, colourFormat); utf8_write_codepoint(colourCodepoint, colourFormat);
std::string line; std::string line;
std::size_t splitPos = 0; std::size_t splitPos = 0;
std::size_t stringOffset = 0; std::size_t stringOffset = 0;
while (splitPos != std::string::npos) while (splitPos != std::string::npos)
{ {
splitPos = input.find('\n', stringOffset); splitPos = input.find('\n', stringOffset);
line = input.substr(stringOffset, splitPos - stringOffset); line = input.substr(stringOffset, splitPos - stringOffset);
_consoleLines.push_back(colourCodepoint + line); _consoleLines.push_back(colourCodepoint + line);
stringOffset = splitPos + 1; stringOffset = splitPos + 1;
} }
@@ -220,13 +230,17 @@ void InGameConsole::Update()
_consoleRight = context_get_width(); _consoleRight = context_get_width();
_consoleBottom = 322; _consoleBottom = 322;
if (_isOpen) { if (_isOpen)
{
// When scrolling the map, the console pixels get copied... therefore invalidate the screen // When scrolling the map, the console pixels get copied... therefore invalidate the screen
rct_window *mainWindow = window_get_main(); rct_window* mainWindow = window_get_main();
if (mainWindow != nullptr) { if (mainWindow != nullptr)
rct_viewport *mainViewport = window_get_viewport(mainWindow); {
if (mainViewport != nullptr) { rct_viewport* mainViewport = window_get_viewport(mainWindow);
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; _lastMainViewportX = mainViewport->view_x;
_lastMainViewportY = mainViewport->view_y; _lastMainViewportY = mainViewport->view_y;
@@ -243,17 +257,17 @@ void InGameConsole::Update()
_consoleCaretTicks = (_consoleCaretTicks + 1) % 30; _consoleCaretTicks = (_consoleCaretTicks + 1) % 30;
} }
void InGameConsole::Draw(rct_drawpixelinfo * dpi) const void InGameConsole::Draw(rct_drawpixelinfo* dpi) const
{ {
if (!_isOpen) if (!_isOpen)
return; return;
// Set font // Set font
gCurrentFontSpriteBase = (gConfigInterface.console_small_font ? FONT_SPRITE_BASE_SMALL : FONT_SPRITE_BASE_MEDIUM); gCurrentFontSpriteBase = (gConfigInterface.console_small_font ? FONT_SPRITE_BASE_SMALL : FONT_SPRITE_BASE_MEDIUM);
gCurrentFontFlags = 0; gCurrentFontFlags = 0;
uint8_t textColour = NOT_TRANSLUCENT(theme_get_colour(WC_CONSOLE, 1)); uint8_t textColour = NOT_TRANSLUCENT(theme_get_colour(WC_CONSOLE, 1));
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase); const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t maxLines = GetNumVisibleLines(); const int32_t maxLines = GetNumVisibleLines();
// This is something of a hack to ensure the text is actually black // This is something of a hack to ensure the text is actually black
// as opposed to a desaturated grey // as opposed to a desaturated grey
@@ -281,17 +295,26 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
// Paint background colour. // Paint background colour.
uint8_t backgroundColour = theme_get_colour(WC_CONSOLE, 0); 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(
gfx_fill_rect_inset(dpi, _consoleLeft + 1, _consoleTop + 1, _consoleRight - 1, _consoleBottom - 1, backgroundColour, INSET_RECT_FLAG_BORDER_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; std::string lineBuffer;
int32_t x = _consoleLeft + CONSOLE_EDGE_PADDING; int32_t x = _consoleLeft + CONSOLE_EDGE_PADDING;
int32_t y = _consoleTop + CONSOLE_EDGE_PADDING; int32_t y = _consoleTop + CONSOLE_EDGE_PADDING;
// Draw text inside console // 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; const size_t index = i + _consoleScrollPos;
lineBuffer = colourFormatStr + _consoleLines[index]; lineBuffer = colourFormatStr + _consoleLines[index];
gfx_draw_string(dpi, lineBuffer.c_str(), textColour, x, y); gfx_draw_string(dpi, lineBuffer.c_str(), textColour, x, y);
y += lineHeight; y += lineHeight;
} }
@@ -303,7 +326,8 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
gfx_draw_string(dpi, lineBuffer.c_str(), TEXT_COLOUR_255, x, y); gfx_draw_string(dpi, lineBuffer.c_str(), TEXT_COLOUR_255, x, y);
// Draw caret // 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 caretX = x + gfx_get_string_width(_consoleCurrentLine);
int32_t caretY = y + lineHeight; 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; uint8_t borderColour2 = ColourMapA[BASE_COLOUR(backgroundColour)].mid_dark;
// Input area top border // Input area top border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 11, _consoleRight, _consoleBottom - lineHeight - 11, borderColour1); gfx_fill_rect(
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 10, _consoleRight, _consoleBottom - lineHeight - 10, borderColour2); 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 // Input area bottom border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - 1, _consoleRight, _consoleBottom - 1, borderColour1); gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - 1, _consoleRight, _consoleBottom - 1, borderColour1);
@@ -327,8 +353,8 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
// Calculates the amount of visible lines, based on the console size, excluding the input line. // Calculates the amount of visible lines, based on the console size, excluding the input line.
int32_t InGameConsole::GetNumVisibleLines() const int32_t InGameConsole::GetNumVisibleLines() const
{ {
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase); const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t consoleHeight = _consoleBottom - _consoleTop; const int32_t consoleHeight = _consoleBottom - _consoleTop;
const int32_t drawableHeight = consoleHeight - 2 * lineHeight - 4; // input line, separator - padding const int32_t drawableHeight = consoleHeight - 2 * lineHeight - 4; // input line, separator - padding
return drawableHeight / lineHeight; return drawableHeight / lineHeight;
} }

View File

@@ -23,42 +23,45 @@ namespace OpenRCT2::Ui
static constexpr int32_t CONSOLE_EDGE_PADDING = 4; static constexpr int32_t CONSOLE_EDGE_PADDING = 4;
static constexpr int32_t CONSOLE_CARET_WIDTH = 6; static constexpr int32_t CONSOLE_CARET_WIDTH = 6;
bool _isOpen = false; bool _isOpen = false;
int32_t _consoleLeft, _consoleTop, _consoleRight, _consoleBottom; int32_t _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
int32_t _lastMainViewportX, _lastMainViewportY; int32_t _lastMainViewportX, _lastMainViewportY;
std::deque<std::string> _consoleLines; std::deque<std::string> _consoleLines;
utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE] = {}; utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE] = {};
int32_t _consoleCaretTicks; int32_t _consoleCaretTicks;
int32_t _consoleScrollPos = 0; int32_t _consoleScrollPos = 0;
TextInputSession * _consoleTextInputSession; TextInputSession* _consoleTextInputSession;
utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE]; utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
int32_t _consoleHistoryIndex = 0; int32_t _consoleHistoryIndex = 0;
int32_t _consoleHistoryCount = 0; int32_t _consoleHistoryCount = 0;
public: public:
InGameConsole(); InGameConsole();
InGameConsole(const InGameConsole& src) = delete; InGameConsole(const InGameConsole& src) = delete;
bool IsOpen() const { return _isOpen; } bool IsOpen() const
{
return _isOpen;
}
void Clear() override; void Clear() override;
void Open(); void Open();
void Close() override; void Close() override;
void Hide() override; void Hide() override;
void Toggle(); void Toggle();
void WriteLine(const std::string &s, uint32_t colourFormat) override; void WriteLine(const std::string& s, uint32_t colourFormat) override;
void Input(CONSOLE_INPUT input); void Input(CONSOLE_INPUT input);
void RefreshCaret(); void RefreshCaret();
void Scroll(int32_t linesToScroll); void Scroll(int32_t linesToScroll);
void Update(); void Update();
void Draw(rct_drawpixelinfo * dpi) const; void Draw(rct_drawpixelinfo* dpi) const;
private: private:
void ClearInput(); void ClearInput();
void ClearLine(); void ClearLine();
void HistoryAdd(const utf8 * src); void HistoryAdd(const utf8* src);
void WritePrompt(); void WritePrompt();
void ScrollToEnd(); void ScrollToEnd();
void Invalidate() const; void Invalidate() const;

View File

@@ -8,13 +8,13 @@
*****************************************************************************/ *****************************************************************************/
#include <openrct2-ui/interface/Dropdown.h> #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/LandTool.h>
#include <openrct2-ui/interface/Widget.h> #include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h> #include <openrct2-ui/interface/Window.h>
#include <openrct2/Input.h> #include <openrct2/Input.h>
#include <openrct2/drawing/Drawing.h> #include <openrct2/drawing/Drawing.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Surface.h>
// clang-format off // clang-format off
static uint16_t toolSizeSpriteIndices[] = static uint16_t toolSizeSpriteIndices[] =
@@ -84,7 +84,7 @@ uint32_t land_tool_size_to_sprite_index(uint16_t size)
} }
} }
void land_tool_show_surface_style_dropdown(rct_window * w, rct_widget * widget, uint8_t currentSurfaceType) void land_tool_show_surface_style_dropdown(rct_window* w, rct_widget* widget, uint8_t currentSurfaceType)
{ {
uint8_t defaultIndex = 0; uint8_t defaultIndex = 0;
@@ -99,25 +99,27 @@ void land_tool_show_surface_style_dropdown(rct_window * w, rct_widget * widget,
} }
window_dropdown_show_image( window_dropdown_show_image(
w->x + widget->left, w->y + widget->top, w->x + widget->left,
widget->bottom - widget->top, w->y + widget->top,
w->colours[2], widget->bottom - widget->top,
0, w->colours[2],
TERRAIN_COUNT_REGULAR, 0,
47, 36, TERRAIN_COUNT_REGULAR,
gAppropriateImageDropdownItemsPerRow[TERRAIN_COUNT_REGULAR] 47,
); 36,
gAppropriateImageDropdownItemsPerRow[TERRAIN_COUNT_REGULAR]);
gDropdownDefaultIndex = defaultIndex; gDropdownDefaultIndex = defaultIndex;
} }
void land_tool_show_edge_style_dropdown(rct_window * w, rct_widget * widget, uint8_t currentEdgeType) void land_tool_show_edge_style_dropdown(rct_window* w, rct_widget* widget, uint8_t currentEdgeType)
{ {
uint8_t defaultIndex = 0; uint8_t defaultIndex = 0;
// Do not show RCT1 edge styles if the player does not have RCT1. // 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; 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; gDropdownItemsFormat[i] = DROPDOWN_FORMAT_LAND_PICKER;
gDropdownItemsArgs[i] = WallTexturePreviews[WallTextureOrder[i]]; gDropdownItemsArgs[i] = WallTexturePreviews[WallTextureOrder[i]];
if (WallTextureOrder[i] == currentEdgeType) 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( window_dropdown_show_image(
w->x + widget->left, w->y + widget->top, w->x + widget->left,
widget->bottom - widget->top, w->y + widget->top,
w->colours[2], widget->bottom - widget->top,
0, w->colours[2],
edgeCount, 0,
47, 36, edgeCount,
gAppropriateImageDropdownItemsPerRow[edgeCount] 47,
); 36,
gAppropriateImageDropdownItemsPerRow[edgeCount]);
gDropdownDefaultIndex = defaultIndex; gDropdownDefaultIndex = defaultIndex;
} }

View File

@@ -9,12 +9,12 @@
#pragma once #pragma once
#include <openrct2-ui/interface/Window.h>
#include <openrct2/common.h> #include <openrct2/common.h>
#include <openrct2/sprites.h> #include <openrct2/sprites.h>
#include <openrct2-ui/interface/Window.h>
#define MINIMUM_TOOL_SIZE 1 #define MINIMUM_TOOL_SIZE 1
#define MAXIMUM_TOOL_SIZE 64 #define MAXIMUM_TOOL_SIZE 64
// The highest tool size to have a sprite. Bigger tool sizes simply display a number. // The highest tool size to have a sprite. Bigger tool sizes simply display a number.
#define MAX_TOOL_SIZE_WITH_SPRITE 7 #define MAX_TOOL_SIZE_WITH_SPRITE 7
@@ -30,5 +30,5 @@ extern uint32_t WallTextureOrder[];
extern uint32_t WallTexturePreviews[]; extern uint32_t WallTexturePreviews[];
uint32_t land_tool_size_to_sprite_index(uint16_t size); uint32_t land_tool_size_to_sprite_index(uint16_t size);
void land_tool_show_surface_style_dropdown(rct_window * w, rct_widget * widget, uint8_t currentSurfaceType); void land_tool_show_surface_style_dropdown(rct_window* w, rct_widget* widget, uint8_t currentSurfaceType);
void land_tool_show_edge_style_dropdown(rct_window * w, rct_widget * widget, uint8_t currentEdgeType); void land_tool_show_edge_style_dropdown(rct_window* w, rct_widget* widget, uint8_t currentEdgeType);

View File

@@ -9,14 +9,16 @@
#pragma warning(disable : 4706) // assignment within conditional expression #pragma warning(disable : 4706) // assignment within conditional expression
#include <memory> #include "Theme.h"
#include <stdexcept>
#include <vector>
#include <jansson.h>
#include "Window.h"
#include <jansson.h>
#include <memory>
#include <openrct2/Context.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/common.h> #include <openrct2/common.h>
#include <openrct2/config/Config.h> #include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/core/File.h> #include <openrct2/core/File.h>
#include <openrct2/core/FileScanner.h> #include <openrct2/core/FileScanner.h>
#include <openrct2/core/Guard.hpp> #include <openrct2/core/Guard.hpp>
@@ -25,12 +27,11 @@
#include <openrct2/core/Path.hpp> #include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp> #include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h> #include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/localisation/Language.h> #include <openrct2/localisation/Language.h>
#include <openrct2/localisation/StringIds.h> #include <openrct2/localisation/StringIds.h>
#include <openrct2/PlatformEnvironment.h> #include <stdexcept>
#include <openrct2/interface/Colour.h> #include <vector>
#include "Theme.h"
#include "Window.h"
using namespace OpenRCT2; using namespace OpenRCT2;
@@ -50,11 +51,10 @@ struct WindowTheme
struct UIThemeWindowEntry struct UIThemeWindowEntry
{ {
rct_windowclass WindowClass; rct_windowclass WindowClass;
WindowTheme Theme; WindowTheme Theme;
json_t* ToJson() const;
json_t * ToJson() const; static UIThemeWindowEntry FromJson(const WindowThemeDesc* wtDesc, const json_t* json);
static UIThemeWindowEntry FromJson(const WindowThemeDesc * wtDesc, const json_t * json);
}; };
/** /**
@@ -63,25 +63,25 @@ struct UIThemeWindowEntry
class UITheme class UITheme
{ {
public: public:
std::string Name; std::string Name;
std::vector<UIThemeWindowEntry> Entries; std::vector<UIThemeWindowEntry> Entries;
uint8_t Flags = 0; uint8_t Flags = 0;
explicit UITheme(const std::string &name) explicit UITheme(const std::string& name)
: Name(name) : Name(name)
{ {
} }
const UIThemeWindowEntry * GetEntry(rct_windowclass windowClass) const; const UIThemeWindowEntry* GetEntry(rct_windowclass windowClass) const;
void SetEntry(const UIThemeWindowEntry * entry); void SetEntry(const UIThemeWindowEntry* entry);
void RemoveEntry(rct_windowclass windowClass); void RemoveEntry(rct_windowclass windowClass);
json_t * ToJson() const; json_t* ToJson() const;
bool WriteToFile(const std::string &path) const; bool WriteToFile(const std::string& path) const;
static UITheme * FromJson(const json_t * json); static UITheme* FromJson(const json_t* json);
static UITheme * FromFile(const std::string &path); static UITheme* FromFile(const std::string& path);
static UITheme CreatePredefined(const std::string &name, const UIThemeWindowEntry * entries, uint8_t flags); static UITheme CreatePredefined(const std::string& name, const UIThemeWindowEntry* entries, uint8_t flags);
}; };
/** /**
@@ -90,10 +90,10 @@ public:
struct WindowThemeDesc struct WindowThemeDesc
{ {
rct_windowclass WindowClass; rct_windowclass WindowClass;
const utf8 * WindowClassSZ; const utf8* WindowClassSZ;
rct_string_id WindowName; rct_string_id WindowName;
uint8_t NumColours; uint8_t NumColours;
WindowTheme DefaultTheme; WindowTheme DefaultTheme;
}; };
#pragma region Window Theme Descriptors #pragma region Window Theme Descriptors
@@ -234,9 +234,9 @@ static constexpr const PredefinedTheme PredefinedThemes[] = {
#pragma endregion #pragma endregion
static const WindowThemeDesc * GetWindowThemeDescriptor(rct_windowclass windowClass) static const WindowThemeDesc* GetWindowThemeDescriptor(rct_windowclass windowClass)
{ {
for (const auto &desc : WindowThemeDescriptors) for (const auto& desc : WindowThemeDescriptors)
{ {
if (desc.WindowClass == windowClass) if (desc.WindowClass == windowClass)
{ {
@@ -246,9 +246,9 @@ static const WindowThemeDesc * GetWindowThemeDescriptor(rct_windowclass windowCl
return nullptr; return nullptr;
} }
static const WindowThemeDesc * GetWindowThemeDescriptor(const utf8 * windowClassSZ) static const WindowThemeDesc* GetWindowThemeDescriptor(const utf8* windowClassSZ)
{ {
for (const auto &desc : WindowThemeDescriptors) for (const auto& desc : WindowThemeDescriptors)
{ {
if (String::Equals(desc.WindowClassSZ, windowClassSZ)) if (String::Equals(desc.WindowClassSZ, windowClassSZ))
{ {
@@ -265,29 +265,30 @@ static void ThrowThemeLoadException()
#pragma region UIThemeEntry #pragma region UIThemeEntry
json_t * UIThemeWindowEntry::ToJson() const json_t* UIThemeWindowEntry::ToJson() const
{ {
const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(WindowClass); const WindowThemeDesc* wtDesc = GetWindowThemeDescriptor(WindowClass);
if (wtDesc == nullptr) if (wtDesc == nullptr)
{ {
return nullptr; return nullptr;
} }
json_t * jsonColours = json_array(); 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]; colour_t colour = Theme.Colours[i];
json_array_append_new(jsonColours, json_integer(colour)); json_array_append_new(jsonColours, json_integer(colour));
} }
json_t * jsonEntry = json_object(); json_t* jsonEntry = json_object();
json_object_set_new(jsonEntry, "colours", jsonColours); json_object_set_new(jsonEntry, "colours", jsonColours);
return jsonEntry; return jsonEntry;
} }
UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc * wtDesc, const json_t * json) UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc* wtDesc, const json_t* json)
{ {
json_t * jsonColours = json_object_get(json, "colours"); json_t* jsonColours = json_object_get(json, "colours");
if (jsonColours == nullptr) if (jsonColours == nullptr)
{ {
ThrowThemeLoadException(); ThrowThemeLoadException();
@@ -296,7 +297,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc * wtDesc,
uint8_t numColours = (uint8_t)json_array_size(jsonColours); uint8_t numColours = (uint8_t)json_array_size(jsonColours);
numColours = std::min(numColours, wtDesc->NumColours); numColours = std::min(numColours, wtDesc->NumColours);
UIThemeWindowEntry result { }; UIThemeWindowEntry result{};
result.WindowClass = wtDesc->WindowClass; result.WindowClass = wtDesc->WindowClass;
result.Theme = wtDesc->DefaultTheme; result.Theme = wtDesc->DefaultTheme;
@@ -312,9 +313,9 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc * wtDesc,
#pragma region UITheme #pragma region UITheme
const UIThemeWindowEntry * UITheme::GetEntry(rct_windowclass windowClass) const const UIThemeWindowEntry* UITheme::GetEntry(rct_windowclass windowClass) const
{ {
for (const auto &entry : Entries) for (const auto& entry : Entries)
{ {
if (entry.WindowClass == windowClass) if (entry.WindowClass == windowClass)
{ {
@@ -324,10 +325,10 @@ const UIThemeWindowEntry * UITheme::GetEntry(rct_windowclass windowClass) const
return nullptr; return nullptr;
} }
void UITheme::SetEntry(const UIThemeWindowEntry * newEntry) void UITheme::SetEntry(const UIThemeWindowEntry* newEntry)
{ {
// Try to replace existing entry // Try to replace existing entry
for (auto &entry : Entries) for (auto& entry : Entries)
{ {
if (entry.WindowClass == newEntry->WindowClass) if (entry.WindowClass == newEntry->WindowClass)
{ {
@@ -344,7 +345,7 @@ void UITheme::RemoveEntry(rct_windowclass windowClass)
// Remove existing entry // Remove existing entry
for (size_t i = 0; i < Entries.size(); i++) for (size_t i = 0; i < Entries.size(); i++)
{ {
UIThemeWindowEntry * entry = &Entries[i]; UIThemeWindowEntry* entry = &Entries[i];
if (entry->WindowClass == windowClass) if (entry->WindowClass == windowClass)
{ {
Entries.erase(Entries.begin() + i); Entries.erase(Entries.begin() + i);
@@ -353,13 +354,13 @@ void UITheme::RemoveEntry(rct_windowclass windowClass)
} }
} }
json_t * UITheme::ToJson() const json_t* UITheme::ToJson() const
{ {
// Create entries // Create entries
json_t * jsonEntries = json_object(); json_t* jsonEntries = json_object();
for (const UIThemeWindowEntry & entry : Entries) for (const UIThemeWindowEntry& entry : Entries)
{ {
const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(entry.WindowClass); const WindowThemeDesc* wtDesc = GetWindowThemeDescriptor(entry.WindowClass);
if (wtDesc == nullptr) if (wtDesc == nullptr)
{ {
return nullptr; return nullptr;
@@ -368,30 +369,29 @@ json_t * UITheme::ToJson() const
} }
// Create theme object // Create theme object
json_t * jsonTheme = json_object(); json_t* jsonTheme = json_object();
json_object_set_new(jsonTheme, "name", json_string(Name.c_str())); json_object_set_new(jsonTheme, "name", json_string(Name.c_str()));
json_object_set_new(jsonTheme, "entries", jsonEntries); json_object_set_new(jsonTheme, "entries", jsonEntries);
json_object_set_new(jsonTheme, "useLightsRide", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_RIDE)); 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, "useLightsPark", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_PARK));
json_object_set_new(jsonTheme, json_object_set_new(
"useAltScenarioSelectFont", jsonTheme, "useAltScenarioSelectFont", json_boolean(Flags & UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT));
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)); json_object_set_new(jsonTheme, "useFullBottomToolbar", json_boolean(Flags & UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR));
return jsonTheme; return jsonTheme;
} }
bool UITheme::WriteToFile(const std::string &path) const bool UITheme::WriteToFile(const std::string& path) const
{ {
json_t * jsonTheme = ToJson(); json_t* jsonTheme = ToJson();
bool result; bool result;
try try
{ {
Json::WriteToFile(path.c_str(), jsonTheme, JSON_INDENT(4) | JSON_PRESERVE_ORDER); Json::WriteToFile(path.c_str(), jsonTheme, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
result = true; result = true;
} }
catch (const std::exception &ex) catch (const std::exception& ex)
{ {
log_error("Unable to save %s: %s", path.c_str(), ex.what()); log_error("Unable to save %s: %s", path.c_str(), ex.what());
result = false; result = false;
@@ -401,17 +401,17 @@ bool UITheme::WriteToFile(const std::string &path) const
return result; return result;
} }
UITheme * UITheme::FromJson(const json_t * json) UITheme* UITheme::FromJson(const json_t* json)
{ {
const char * themeName = json_string_value(json_object_get(json, "name")); const char* themeName = json_string_value(json_object_get(json, "name"));
if (themeName == nullptr) if (themeName == nullptr)
{ {
ThrowThemeLoadException(); ThrowThemeLoadException();
} }
json_t * jsonEntries = json_object_get(json, "entries"); json_t* jsonEntries = json_object_get(json, "entries");
UITheme * result = nullptr; UITheme* result = nullptr;
try try
{ {
result = new UITheme(themeName); result = new UITheme(themeName);
@@ -433,12 +433,13 @@ UITheme * UITheme::FromJson(const json_t * json)
result->Flags |= UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR; result->Flags |= UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR;
} }
const char * jkey; const char* jkey;
json_t * jvalue; json_t* jvalue;
json_object_foreach(jsonEntries, jkey, jvalue) json_object_foreach(jsonEntries, jkey, jvalue)
{ {
const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(jkey); const WindowThemeDesc* wtDesc = GetWindowThemeDescriptor(jkey);
if (wtDesc == nullptr) continue; if (wtDesc == nullptr)
continue;
UIThemeWindowEntry entry = UIThemeWindowEntry::FromJson(wtDesc, jvalue); UIThemeWindowEntry entry = UIThemeWindowEntry::FromJson(wtDesc, jvalue);
result->SetEntry(&entry); result->SetEntry(&entry);
@@ -446,23 +447,23 @@ UITheme * UITheme::FromJson(const json_t * json)
return result; return result;
} }
catch (const std::exception &) catch (const std::exception&)
{ {
delete result; delete result;
throw; throw;
} }
} }
UITheme * UITheme::FromFile(const std::string &path) UITheme* UITheme::FromFile(const std::string& path)
{ {
json_t * json = nullptr; json_t* json = nullptr;
UITheme * result = nullptr; UITheme* result = nullptr;
try try
{ {
json = Json::ReadFromFile(path.c_str()); json = Json::ReadFromFile(path.c_str());
result = UITheme::FromJson(json); result = UITheme::FromJson(json);
} }
catch (const std::exception &) catch (const std::exception&)
{ {
log_error("Unable to read theme: %s", path.c_str()); log_error("Unable to read theme: %s", path.c_str());
result = nullptr; result = nullptr;
@@ -472,13 +473,13 @@ UITheme * UITheme::FromFile(const std::string &path)
return result; return result;
} }
UITheme UITheme::CreatePredefined(const std::string &name, const UIThemeWindowEntry * entries, uint8_t flags) UITheme UITheme::CreatePredefined(const std::string& name, const UIThemeWindowEntry* entries, uint8_t flags)
{ {
auto theme = UITheme(name); auto theme = UITheme(name);
theme.Flags = flags | UITHEME_FLAG_PREDEFINED; theme.Flags = flags | UITHEME_FLAG_PREDEFINED;
size_t numEntries = 0; size_t numEntries = 0;
for (const UIThemeWindowEntry * entry = entries; entry->WindowClass != 255; entry++) for (const UIThemeWindowEntry* entry = entries; entry->WindowClass != 255; entry++)
{ {
numEntries++; numEntries++;
} }
@@ -497,17 +498,17 @@ namespace ThemeManager
std::string Name; std::string Name;
}; };
static std::string CurrentThemePath; static std::string CurrentThemePath;
static UITheme * CurrentTheme; static UITheme* CurrentTheme;
static std::vector<AvailableTheme> AvailableThemes; static std::vector<AvailableTheme> AvailableThemes;
static size_t ActiveAvailableThemeIndex = SIZE_MAX; static size_t ActiveAvailableThemeIndex = SIZE_MAX;
static size_t NumPredefinedThemes = 0; static size_t NumPredefinedThemes = 0;
std::string GetThemeFileName(const std::string &name); std::string GetThemeFileName(const std::string& name);
bool EnsureThemeDirectoryExists(); bool EnsureThemeDirectoryExists();
std::string GetThemePath(); std::string GetThemePath();
static void GetAvailableThemes(std::vector<AvailableTheme> * outThemes) static void GetAvailableThemes(std::vector<AvailableTheme>* outThemes)
{ {
Guard::ArgumentNotNull(outThemes, GUARD_LINE); Guard::ArgumentNotNull(outThemes, GUARD_LINE);
@@ -516,7 +517,7 @@ namespace ThemeManager
NumPredefinedThemes = 0; NumPredefinedThemes = 0;
for (auto predefinedTheme : PredefinedThemes) for (auto predefinedTheme : PredefinedThemes)
{ {
AvailableTheme theme {}; AvailableTheme theme{};
theme.Name = predefinedTheme.Theme->Name; theme.Name = predefinedTheme.Theme->Name;
outThemes->push_back(std::move(theme)); outThemes->push_back(std::move(theme));
@@ -530,7 +531,7 @@ namespace ThemeManager
auto fileInfo = scanner->GetFileInfo(); auto fileInfo = scanner->GetFileInfo();
auto name = Path::GetFileNameWithoutExtension(std::string(fileInfo->Name)); auto name = Path::GetFileNameWithoutExtension(std::string(fileInfo->Name));
AvailableTheme theme {}; AvailableTheme theme{};
theme.Name = name; theme.Name = name;
theme.Path = GetThemeFileName(theme.Name); theme.Path = GetThemeFileName(theme.Name);
outThemes->push_back(std::move(theme)); outThemes->push_back(std::move(theme));
@@ -542,7 +543,7 @@ namespace ThemeManager
} }
} }
static void LoadTheme(UITheme * theme) static void LoadTheme(UITheme* theme)
{ {
if (CurrentTheme == theme) if (CurrentTheme == theme)
{ {
@@ -563,13 +564,13 @@ namespace ThemeManager
gfx_invalidate_screen(); gfx_invalidate_screen();
} }
static void LoadTheme(const std::string &path) static void LoadTheme(const std::string& path)
{ {
auto theme = UITheme::FromFile(path); auto theme = UITheme::FromFile(path);
if (theme == nullptr) if (theme == nullptr)
{ {
// Fall-back to default // Fall-back to default
theme = (UITheme *)&PredefinedThemeRCT2; theme = (UITheme*)&PredefinedThemeRCT2;
LoadTheme(theme); LoadTheme(theme);
} }
else else
@@ -579,16 +580,16 @@ namespace ThemeManager
} }
} }
static bool LoadThemeByConfigName(const utf8 * name) static bool LoadThemeByConfigName(const utf8* name)
{ {
for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++) for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++)
{ {
const auto &theme = ThemeManager::AvailableThemes[i]; const auto& theme = ThemeManager::AvailableThemes[i];
if (String::Equals(name, theme.Name)) if (String::Equals(name, theme.Name))
{ {
if (theme.Path.empty()) if (theme.Path.empty())
{ {
LoadTheme((UITheme *)PredefinedThemes[i].Theme); LoadTheme((UITheme*)PredefinedThemes[i].Theme);
} }
else else
{ {
@@ -604,7 +605,7 @@ namespace ThemeManager
static void Initialise() static void Initialise()
{ {
ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes); ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes);
LoadTheme((UITheme *)&PredefinedThemeRCT2); LoadTheme((UITheme*)&PredefinedThemeRCT2);
ActiveAvailableThemeIndex = 1; ActiveAvailableThemeIndex = 1;
bool configValid = false; bool configValid = false;
@@ -622,7 +623,7 @@ namespace ThemeManager
} }
} }
std::string GetThemeFileName(const std::string &name) std::string GetThemeFileName(const std::string& name)
{ {
auto themeDirectory = GetThemePath(); auto themeDirectory = GetThemePath();
auto themePath = Path::Combine(themeDirectory, name + ".json"); auto themePath = Path::Combine(themeDirectory, name + ".json");
@@ -637,7 +638,7 @@ namespace ThemeManager
Path::CreateDirectory(path); Path::CreateDirectory(path);
return true; return true;
} }
catch (const std::exception &) catch (const std::exception&)
{ {
return false; return false;
} }
@@ -661,16 +662,16 @@ size_t theme_manager_get_num_available_themes()
return ThemeManager::AvailableThemes.size(); return ThemeManager::AvailableThemes.size();
} }
const utf8 * theme_manager_get_available_theme_path(size_t index) const utf8* theme_manager_get_available_theme_path(size_t index)
{ {
return ThemeManager::AvailableThemes[index].Path.c_str(); return ThemeManager::AvailableThemes[index].Path.c_str();
} }
const utf8 * theme_manager_get_available_theme_config_name(size_t index) const utf8* theme_manager_get_available_theme_config_name(size_t index)
{ {
return ThemeManager::AvailableThemes[index].Name.c_str(); return ThemeManager::AvailableThemes[index].Name.c_str();
} }
const utf8 * theme_manager_get_available_theme_name(size_t index) const utf8* theme_manager_get_available_theme_name(size_t index)
{ {
if (index < ThemeManager::NumPredefinedThemes) if (index < ThemeManager::NumPredefinedThemes)
return language_get_string(PredefinedThemes[index].Name); return language_get_string(PredefinedThemes[index].Name);
@@ -686,7 +687,7 @@ void theme_manager_set_active_available_theme(size_t index)
{ {
if (index < ThemeManager::NumPredefinedThemes) if (index < ThemeManager::NumPredefinedThemes)
{ {
ThemeManager::LoadTheme((UITheme *)PredefinedThemes[index].Theme); ThemeManager::LoadTheme((UITheme*)PredefinedThemes[index].Theme);
} }
else else
{ {
@@ -705,12 +706,12 @@ void theme_manager_set_active_available_theme(size_t index)
colour_scheme_update_all(); colour_scheme_update_all();
} }
size_t theme_get_index_for_name(const utf8 * name) size_t theme_get_index_for_name(const utf8* name)
{ {
size_t count = ThemeManager::AvailableThemes.size(); size_t count = ThemeManager::AvailableThemes.size();
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
const utf8 * tn = theme_manager_get_available_theme_name(i); const utf8* tn = theme_manager_get_available_theme_name(i);
if (String::Equals(tn, name, true)) if (String::Equals(tn, name, true))
{ {
return i; return i;
@@ -721,10 +722,10 @@ size_t theme_get_index_for_name(const utf8 * name)
uint8_t theme_get_colour(rct_windowclass wc, uint8_t index) uint8_t theme_get_colour(rct_windowclass wc, uint8_t index)
{ {
const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(wc); const UIThemeWindowEntry* entry = ThemeManager::CurrentTheme->GetEntry(wc);
if (entry == nullptr) if (entry == nullptr)
{ {
const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); const WindowThemeDesc* desc = GetWindowThemeDescriptor(wc);
if (desc == nullptr) if (desc == nullptr)
{ {
return 0; return 0;
@@ -739,17 +740,17 @@ uint8_t theme_get_colour(rct_windowclass wc, uint8_t index)
void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour) void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour)
{ {
UIThemeWindowEntry entry { }; UIThemeWindowEntry entry{};
entry.WindowClass = wc; entry.WindowClass = wc;
auto currentEntry = (UIThemeWindowEntry *)ThemeManager::CurrentTheme->GetEntry(wc); auto currentEntry = (UIThemeWindowEntry*)ThemeManager::CurrentTheme->GetEntry(wc);
if (currentEntry != nullptr) if (currentEntry != nullptr)
{ {
entry.Theme = currentEntry->Theme; entry.Theme = currentEntry->Theme;
} }
else else
{ {
const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); const WindowThemeDesc* desc = GetWindowThemeDescriptor(wc);
if (desc == nullptr) if (desc == nullptr)
{ {
return; return;
@@ -780,7 +781,7 @@ void theme_save()
ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath); ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath);
} }
void theme_rename(const utf8 * name) void theme_rename(const utf8* name)
{ {
const auto oldPath = ThemeManager::CurrentThemePath; const auto oldPath = ThemeManager::CurrentThemePath;
@@ -804,13 +805,13 @@ void theme_rename(const utf8 * name)
} }
} }
void theme_duplicate(const utf8 * name) void theme_duplicate(const utf8* name)
{ {
ThemeManager::EnsureThemeDirectoryExists(); ThemeManager::EnsureThemeDirectoryExists();
auto newPath = ThemeManager::GetThemeFileName(name); auto newPath = ThemeManager::GetThemeFileName(name);
// Copy the theme, save it and then load it back in // Copy the theme, save it and then load it back in
UITheme * newTheme = new UITheme(*ThemeManager::CurrentTheme); UITheme* newTheme = new UITheme(*ThemeManager::CurrentTheme);
newTheme->Name = name; newTheme->Name = name;
newTheme->Flags &= ~UITHEME_FLAG_PREDEFINED; newTheme->Flags &= ~UITHEME_FLAG_PREDEFINED;
newTheme->WriteToFile(newPath); newTheme->WriteToFile(newPath);
@@ -833,7 +834,7 @@ void theme_duplicate(const utf8 * name)
void theme_delete() void theme_delete()
{ {
File::Delete(ThemeManager::CurrentThemePath); File::Delete(ThemeManager::CurrentThemePath);
ThemeManager::LoadTheme((UITheme *)&PredefinedThemeRCT2); ThemeManager::LoadTheme((UITheme*)&PredefinedThemeRCT2);
ThemeManager::ActiveAvailableThemeIndex = 1; ThemeManager::ActiveAvailableThemeIndex = 1;
String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1));
} }
@@ -845,7 +846,7 @@ void theme_manager_initialise()
uint8_t theme_desc_get_num_colours(rct_windowclass wc) uint8_t theme_desc_get_num_colours(rct_windowclass wc)
{ {
const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); const WindowThemeDesc* desc = GetWindowThemeDescriptor(wc);
if (desc == nullptr) if (desc == nullptr)
{ {
return 0; return 0;
@@ -855,7 +856,7 @@ uint8_t theme_desc_get_num_colours(rct_windowclass wc)
rct_string_id theme_desc_get_name(rct_windowclass wc) rct_string_id theme_desc_get_name(rct_windowclass wc)
{ {
const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); const WindowThemeDesc* desc = GetWindowThemeDescriptor(wc);
if (desc == nullptr) if (desc == nullptr)
{ {
return STR_EMPTY; return STR_EMPTY;
@@ -871,22 +872,22 @@ void colour_scheme_update_all()
} }
} }
void colour_scheme_update(rct_window * window) void colour_scheme_update(rct_window* window)
{ {
colour_scheme_update_by_class(window, window->classification); colour_scheme_update_by_class(window, window->classification);
} }
void colour_scheme_update_by_class(rct_window * window, rct_windowclass classification) void colour_scheme_update_by_class(rct_window* window, rct_windowclass classification)
{ {
const WindowTheme * windowTheme; const WindowTheme* windowTheme;
const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(classification); const UIThemeWindowEntry* entry = ThemeManager::CurrentTheme->GetEntry(classification);
if (entry != nullptr) if (entry != nullptr)
{ {
windowTheme = &entry->Theme; windowTheme = &entry->Theme;
} }
else else
{ {
const WindowThemeDesc * desc = GetWindowThemeDescriptor(classification); const WindowThemeDesc* desc = GetWindowThemeDescriptor(classification);
// Some windows don't have a theme set (e.g. main window, title screen) // Some windows don't have a theme set (e.g. main window, title screen)
if (desc == nullptr) if (desc == nullptr)
@@ -897,11 +898,11 @@ void colour_scheme_update_by_class(rct_window * window, rct_windowclass classifi
windowTheme = &desc->DefaultTheme; 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]; window->colours[i] = windowTheme->Colours[i];
} }
// Some windows need to be transparent even if the colours aren't. // 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 // There doesn't seem to be any side-effects for all windows being transparent
window->flags |= WF_TRANSPARENT; window->flags |= WF_TRANSPARENT;
} }

View File

@@ -12,36 +12,37 @@
#include <openrct2/common.h> #include <openrct2/common.h>
#include <openrct2/interface/Window.h> #include <openrct2/interface/Window.h>
enum { enum
UITHEME_FLAG_PREDEFINED = 1 << 0, {
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1, UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2, UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT = 1 << 3, UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,
UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR = 1 << 4, UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT = 1 << 3,
UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR = 1 << 4,
}; };
void colour_scheme_update(rct_window *window); void colour_scheme_update(rct_window* window);
void colour_scheme_update_all(); void colour_scheme_update_all();
void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification); void colour_scheme_update_by_class(rct_window* window, rct_windowclass classification);
void theme_manager_initialise(); void theme_manager_initialise();
void theme_manager_load_available_themes(); void theme_manager_load_available_themes();
size_t theme_manager_get_num_available_themes(); size_t theme_manager_get_num_available_themes();
const utf8 * theme_manager_get_available_theme_path(size_t index); const utf8* theme_manager_get_available_theme_path(size_t index);
const utf8 * theme_manager_get_available_theme_config_name(size_t index); const utf8* theme_manager_get_available_theme_config_name(size_t index);
const utf8 * theme_manager_get_available_theme_name(size_t index); const utf8* theme_manager_get_available_theme_name(size_t index);
size_t theme_manager_get_active_available_theme_index(); size_t theme_manager_get_active_available_theme_index();
void theme_manager_set_active_available_theme(size_t index); void theme_manager_set_active_available_theme(size_t index);
size_t theme_get_index_for_name(const utf8 * name); size_t theme_get_index_for_name(const utf8* name);
colour_t theme_get_colour(rct_windowclass wc, uint8_t index); colour_t theme_get_colour(rct_windowclass wc, uint8_t index);
void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour); void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour);
uint8_t theme_get_flags(); uint8_t theme_get_flags();
void theme_set_flags(uint8_t flags); void theme_set_flags(uint8_t flags);
void theme_save(); void theme_save();
void theme_rename(const utf8 * name); void theme_rename(const utf8* name);
void theme_duplicate(const utf8 * name); void theme_duplicate(const utf8* name);
void theme_delete(); void theme_delete();
uint8_t theme_desc_get_num_colours(rct_windowclass wc); uint8_t theme_desc_get_num_colours(rct_windowclass wc);
rct_string_id theme_desc_get_name(rct_windowclass wc); rct_string_id theme_desc_get_name(rct_windowclass wc);

View File

@@ -7,12 +7,17 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * 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/Editor.h>
#include <openrct2/Game.h> #include <openrct2/Game.h>
#include <openrct2/Input.h> #include <openrct2/Input.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/OpenRCT2.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/Ride.h>
#include <openrct2/ride/RideData.h> #include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h> #include <openrct2/ride/Track.h>
@@ -20,35 +25,31 @@
#include <openrct2/windows/Intent.h> #include <openrct2/windows/Intent.h>
#include <openrct2/world/Banner.h> #include <openrct2/world/Banner.h>
#include <openrct2/world/Footpath.h> #include <openrct2/world/Footpath.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/LargeScenery.h> #include <openrct2/world/LargeScenery.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Park.h> #include <openrct2/world/Park.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/Sprite.h> #include <openrct2/world/Sprite.h>
#include <openrct2/world/Surface.h> #include <openrct2/world/Surface.h>
#include <openrct2/world/Wall.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_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); static void viewport_interaction_remove_footpath(rct_tile_element* tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElement, int32_t x, int32_t y); static void viewport_interaction_remove_footpath_item(rct_tile_element* tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_park_wall(rct_tile_element *tileElement, int32_t x, int32_t y); static void viewport_interaction_remove_park_wall(rct_tile_element* tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElement, int32_t x, int32_t y); static void viewport_interaction_remove_large_scenery(rct_tile_element* tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_park_entrance(rct_tile_element *tileElement, int32_t x, int32_t y); static void viewport_interaction_remove_park_entrance(rct_tile_element* tileElement, int32_t x, int32_t y);
static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance); static rct_peep* viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance);
/** /**
* *
* rct2: 0x006ED9D0 * rct2: 0x006ED9D0
*/ */
int32_t viewport_interaction_get_item_left(int32_t x, int32_t y, viewport_interaction_info *info) int32_t viewport_interaction_get_item_left(int32_t x, int32_t y, viewport_interaction_info* info)
{ {
rct_tile_element *tileElement; rct_tile_element* tileElement;
rct_sprite *sprite; rct_sprite* sprite;
rct_vehicle *vehicle; rct_vehicle* vehicle;
// No click input for title screen or scenario editor or track manager // No click input for title screen or scenario editor or track manager
if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER)) if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER))
@@ -59,41 +60,52 @@ int32_t viewport_interaction_get_item_left(int32_t x, int32_t y, viewport_intera
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
LocationXY16 mapCoord = {}; 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->x = mapCoord.x;
info->y = mapCoord.y; info->y = mapCoord.y;
tileElement = info->tileElement; tileElement = info->tileElement;
sprite = (rct_sprite*)tileElement; sprite = (rct_sprite*)tileElement;
switch (info->type) { switch (info->type)
case VIEWPORT_INTERACTION_ITEM_SPRITE: {
switch (sprite->unknown.sprite_identifier) { case VIEWPORT_INTERACTION_ITEM_SPRITE:
case SPRITE_IDENTIFIER_VEHICLE: switch (sprite->unknown.sprite_identifier)
vehicle = &(sprite->vehicle); {
if (vehicle->ride_subtype != 255) case SPRITE_IDENTIFIER_VEHICLE:
vehicle_set_map_toolbar(vehicle); vehicle = &(sprite->vehicle);
else if (vehicle->ride_subtype != 255)
info->type = VIEWPORT_INTERACTION_ITEM_NONE; vehicle_set_map_toolbar(vehicle);
else
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
break;
case SPRITE_IDENTIFIER_PEEP:
peep_set_map_tooltip(&sprite->peep);
break;
}
break; break;
case SPRITE_IDENTIFIER_PEEP: case VIEWPORT_INTERACTION_ITEM_RIDE:
peep_set_map_tooltip(&sprite->peep); ride_set_map_tooltip(tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
set_map_tooltip_format_arg(0, rct_string_id, gParkName);
set_map_tooltip_format_arg(2, uint32_t, gParkNameArgs);
break;
default:
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
break; break;
}
break;
case VIEWPORT_INTERACTION_ITEM_RIDE:
ride_set_map_tooltip(tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
set_map_tooltip_format_arg(0, rct_string_id, gParkName);
set_map_tooltip_format_arg(2, uint32_t, gParkNameArgs);
break;
default:
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
break;
} }
// If nothing is under cursor, find a close by peep // 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); info->peep = viewport_interaction_get_closest_peep(x, y, 32);
if (info->peep == nullptr) if (info->peep == nullptr)
return VIEWPORT_INTERACTION_ITEM_NONE; return VIEWPORT_INTERACTION_ITEM_NONE;
@@ -111,13 +123,14 @@ int32_t viewport_interaction_left_over(int32_t x, int32_t y)
{ {
viewport_interaction_info info; 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_SPRITE:
case VIEWPORT_INTERACTION_ITEM_PARK: case VIEWPORT_INTERACTION_ITEM_RIDE:
return 1; case VIEWPORT_INTERACTION_ITEM_PARK:
default: return 1;
return 0; default:
return 0;
} }
} }
@@ -125,49 +138,60 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y)
{ {
viewport_interaction_info info; 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) { case VIEWPORT_INTERACTION_ITEM_SPRITE:
case SPRITE_IDENTIFIER_VEHICLE: switch (info.sprite->unknown.sprite_identifier)
{ {
auto intent = Intent(WD_VEHICLE); case SPRITE_IDENTIFIER_VEHICLE:
intent.putExtra(INTENT_EXTRA_VEHICLE, info.vehicle); {
context_open_intent(&intent); auto intent = Intent(WD_VEHICLE);
break; intent.putExtra(INTENT_EXTRA_VEHICLE, info.vehicle);
} context_open_intent(&intent);
case SPRITE_IDENTIFIER_PEEP:
{
auto intent = Intent(WC_PEEP);
intent.putExtra(INTENT_EXTRA_PEEP, info.peep);
context_open_intent(&intent);
break;
}
case SPRITE_IDENTIFIER_MISC:
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);
break;
case SPRITE_MISC_DUCK:
duck_press(&info.sprite->duck);
break; break;
} }
case SPRITE_IDENTIFIER_PEEP:
{
auto intent = Intent(WC_PEEP);
intent.putExtra(INTENT_EXTRA_PEEP, info.peep);
context_open_intent(&intent);
break;
}
case SPRITE_IDENTIFIER_MISC:
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);
break;
case SPRITE_MISC_DUCK:
duck_press(&info.sprite->duck);
break;
}
}
break;
} }
break; return 1;
case VIEWPORT_INTERACTION_ITEM_RIDE:
{
auto intent = Intent(WD_TRACK);
intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.tileElement);
context_open_intent(&intent);
return true;
} }
return 1; case VIEWPORT_INTERACTION_ITEM_PARK:
case VIEWPORT_INTERACTION_ITEM_RIDE: context_open_window(WC_PARK_INFORMATION);
{ return 1;
auto intent = Intent(WD_TRACK); default:
intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.tileElement); return 0;
context_open_intent(&intent);
return true;
}
case VIEWPORT_INTERACTION_ITEM_PARK:
context_open_window(WC_PARK_INFORMATION);
return 1;
default:
return 0;
} }
} }
@@ -175,12 +199,12 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y)
* *
* rct2: 0x006EDE88 * rct2: 0x006EDE88
*/ */
int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_interaction_info *info) int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_interaction_info* info)
{ {
rct_tile_element *tileElement; rct_tile_element* tileElement;
rct_scenery_entry *sceneryEntry; rct_scenery_entry* sceneryEntry;
rct_banner *banner; rct_banner* banner;
Ride *ride; Ride* ride;
int32_t i, stationIndex; int32_t i, stationIndex;
// No click input for title screen or track manager // No click input for title screen or track manager
@@ -192,163 +216,200 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
LocationXY16 mapCoord = {}; 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->x = mapCoord.x;
info->y = mapCoord.y; info->y = mapCoord.y;
tileElement = info->tileElement; tileElement = info->tileElement;
switch (info->type) { switch (info->type)
case VIEWPORT_INTERACTION_ITEM_SPRITE: {
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0) case VIEWPORT_INTERACTION_ITEM_SPRITE:
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0)
tileElement += 6;
ride = get_ride(tileElement->type);
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);
}
return info->type;
case VIEWPORT_INTERACTION_ITEM_RIDE:
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
ride = get_ride(tile_element_get_ride_index(tileElement));
if (ride->status != RIDE_STATUS_CLOSED)
return info->type;
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
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) {
stringId = STR_RIDE_STATION_X_ENTRANCE;
} else {
stringId = STR_RIDE_ENTRANCE;
}
} else {
if (ride->num_stations > 1) {
stringId = STR_RIDE_STATION_X_EXIT;
} else {
stringId = STR_RIDE_EXIT;
}
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
} else if (track_element_is_station(tileElement)) {
rct_string_id stringId;
if (ride->num_stations > 1) {
stringId = STR_RIDE_STATION_X;
} 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)) {
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
tileElement += 6;
ride = get_ride(tileElement->type);
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);
}
return info->type;
case VIEWPORT_INTERACTION_ITEM_RIDE:
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
ride = get_ride(tile_element_get_ride_index(tileElement));
if (ride->status != RIDE_STATUS_CLOSED)
return info->type;
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
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)
{
stringId = STR_RIDE_STATION_X_ENTRANCE;
}
else
{
stringId = STR_RIDE_ENTRANCE;
}
}
else
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_EXIT;
}
else
{
stringId = STR_RIDE_EXIT;
}
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
}
else if (track_element_is_station(tileElement))
{
rct_string_id stringId;
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X;
}
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))
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
set_map_tooltip_format_arg(2, rct_string_id, ride->name);
set_map_tooltip_format_arg(4, uint32_t, ride->name_arguments);
return info->type;
} }
set_map_tooltip_format_arg(2, rct_string_id, ride->name); set_map_tooltip_format_arg(4, rct_string_id, ride->name);
set_map_tooltip_format_arg(4, uint32_t, ride->name_arguments); 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);
stationIndex = tile_element_get_station(tileElement);
for (i = stationIndex; i >= 0; i--)
if (ride->station_starts[i].xy == RCT_XY8_UNDEFINED)
stationIndex--;
stationIndex++;
set_map_tooltip_format_arg(12, uint16_t, stationIndex);
return info->type; return info->type;
}
set_map_tooltip_format_arg(4, rct_string_id, ride->name); case VIEWPORT_INTERACTION_ITEM_WALL:
set_map_tooltip_format_arg(6, uint32_t, ride->name_arguments); sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised); 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;
}
break;
stationIndex = tile_element_get_station(tileElement); case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
for (i = stationIndex; i >= 0; i--) sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement));
if (ride->station_starts[i].xy == RCT_XY8_UNDEFINED) if (sceneryEntry->large_scenery.scrolling_mode != 255)
stationIndex--; {
stationIndex++; set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
set_map_tooltip_format_arg(12, uint16_t, stationIndex); set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type; return info->type;
}
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
banner = &gBanners[tileElement->properties.banner.index];
sceneryEntry = get_banner_entry(banner->type);
case VIEWPORT_INTERACTION_ITEM_WALL:
sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
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(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name); set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type; return info->type;
}
break;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement));
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;
}
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
banner = &gBanners[tileElement->properties.banner.index];
sceneryEntry = get_banner_entry(banner->type);
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;
} }
if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) { 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 (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr)
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; 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); case VIEWPORT_INTERACTION_ITEM_SCENERY:
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); sceneryEntry = get_small_scenery_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name); set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
return info->type;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, STR_FOOTPATH_MAP_TIP);
if (footpath_element_is_queue(tileElement))
set_map_tooltip_format_arg(2, rct_string_id, STR_QUEUE_LINE_MAP_TIP);
return info->type;
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) {
set_map_tooltip_format_arg(2, rct_string_id, STR_BROKEN);
set_map_tooltip_format_arg(4, rct_string_id, sceneryEntry->name);
} else {
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name); set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
} return info->type;
return info->type;
case VIEWPORT_INTERACTION_ITEM_PARK: case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode) set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
break; set_map_tooltip_format_arg(2, rct_string_id, STR_FOOTPATH_MAP_TIP);
if (footpath_element_is_queue(tileElement))
set_map_tooltip_format_arg(2, rct_string_id, STR_QUEUE_LINE_MAP_TIP);
return info->type;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
break; 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)
{
set_map_tooltip_format_arg(2, rct_string_id, STR_BROKEN);
set_map_tooltip_format_arg(4, rct_string_id, sceneryEntry->name);
}
else
{
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
}
return info->type;
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); case VIEWPORT_INTERACTION_ITEM_PARK:
set_map_tooltip_format_arg(2, rct_string_id, STR_OBJECT_SELECTION_PARK_ENTRANCE); if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
return info->type; break;
case VIEWPORT_INTERACTION_ITEM_WALL: if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
sceneryEntry = get_wall_entry(tileElement->properties.scenery.type); break;
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
sceneryEntry = get_large_scenery_entry(tileElement->properties.scenery.type & 0x3FF); set_map_tooltip_format_arg(2, rct_string_id, STR_OBJECT_SELECTION_PARK_ENTRANCE);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); return info->type;
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type; case VIEWPORT_INTERACTION_ITEM_WALL:
sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
sceneryEntry = get_large_scenery_entry(tileElement->properties.scenery.type & 0x3FF);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
} }
return info->type = VIEWPORT_INTERACTION_ITEM_NONE; return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
@@ -370,41 +431,42 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
CoordsXYE tileElement; CoordsXYE tileElement;
viewport_interaction_info info; 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; case VIEWPORT_INTERACTION_ITEM_NONE:
return 0;
case VIEWPORT_INTERACTION_ITEM_SPRITE: case VIEWPORT_INTERACTION_ITEM_SPRITE:
if (info.sprite->unknown.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) if (info.sprite->unknown.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE)
ride_construct(info.sprite->vehicle.ride); ride_construct(info.sprite->vehicle.ride);
break; break;
case VIEWPORT_INTERACTION_ITEM_RIDE: case VIEWPORT_INTERACTION_ITEM_RIDE:
tileElement.x = info.x; tileElement.x = info.x;
tileElement.y = info.y; tileElement.y = info.y;
tileElement.element = info.tileElement; tileElement.element = info.tileElement;
ride_modify(&tileElement); ride_modify(&tileElement);
break; break;
case VIEWPORT_INTERACTION_ITEM_SCENERY: case VIEWPORT_INTERACTION_ITEM_SCENERY:
viewport_interaction_remove_scenery(info.tileElement, info.x, info.y); viewport_interaction_remove_scenery(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH: case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
viewport_interaction_remove_footpath(info.tileElement, info.x, info.y); viewport_interaction_remove_footpath(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
viewport_interaction_remove_footpath_item(info.tileElement, info.x, info.y); viewport_interaction_remove_footpath_item(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_PARK: case VIEWPORT_INTERACTION_ITEM_PARK:
viewport_interaction_remove_park_entrance(info.tileElement, info.x, info.y); viewport_interaction_remove_park_entrance(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_WALL: case VIEWPORT_INTERACTION_ITEM_WALL:
viewport_interaction_remove_park_wall(info.tileElement, info.x, info.y); viewport_interaction_remove_park_wall(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
viewport_interaction_remove_large_scenery(info.tileElement, info.x, info.y); viewport_interaction_remove_large_scenery(info.tileElement, info.x, info.y);
break; break;
case VIEWPORT_INTERACTION_ITEM_BANNER: case VIEWPORT_INTERACTION_ITEM_BANNER:
context_open_detail_window(WD_BANNER, info.tileElement->properties.banner.index); context_open_detail_window(WD_BANNER, info.tileElement->properties.banner.index);
break; break;
} }
return 1; return 1;
@@ -414,7 +476,7 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
* *
* rct2: 0x006E08D2 * rct2: 0x006E08D2
*/ */
static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, int32_t x, int32_t y) static void viewport_interaction_remove_scenery(rct_tile_element* tileElement, int32_t x, int32_t y)
{ {
gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; gGameCommandErrorTitle = STR_CANT_REMOVE_THIS;
game_do_command( game_do_command(
@@ -424,19 +486,18 @@ static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, i
(tileElement->properties.scenery.type << 8) | tileElement->base_height, (tileElement->properties.scenery.type << 8) | tileElement->base_height,
GAME_COMMAND_REMOVE_SCENERY, GAME_COMMAND_REMOVE_SCENERY,
0, 0,
0 0);
);
} }
/** /**
* *
* rct2: 0x006A614A * rct2: 0x006A614A
*/ */
static void viewport_interaction_remove_footpath(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)
{ {
int32_t z; int32_t z;
rct_window *w; rct_window* w;
rct_tile_element *tileElement2; rct_tile_element* tileElement2;
z = tileElement->base_height; z = tileElement->base_height;
@@ -445,8 +506,10 @@ static void viewport_interaction_remove_footpath(rct_tile_element *tileElement,
footpath_provisional_update(); footpath_provisional_update();
tileElement2 = map_get_first_element_at(x / 32, y / 32); tileElement2 = map_get_first_element_at(x / 32, y / 32);
do { do
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z) { {
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z)
{
gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE; gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE;
footpath_remove(x, y, z, GAME_COMMAND_FLAG_APPLY); footpath_remove(x, y, z, GAME_COMMAND_FLAG_APPLY);
break; break;
@@ -458,7 +521,7 @@ static void viewport_interaction_remove_footpath(rct_tile_element *tileElement,
* *
* rct2: 0x006A61AB * rct2: 0x006A61AB
*/ */
static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElement, int32_t x, int32_t y) static void viewport_interaction_remove_footpath_item(rct_tile_element* tileElement, int32_t x, int32_t y)
{ {
int32_t type; int32_t type;
@@ -474,26 +537,26 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElem
(type << 8) | tileElement->base_height, (type << 8) | tileElement->base_height,
GAME_COMMAND_PLACE_PATH, GAME_COMMAND_PLACE_PATH,
0, 0,
0 0);
);
} }
/** /**
* *
* rct2: 0x00666C0E * rct2: 0x00666C0E
*/ */
void viewport_interaction_remove_park_entrance(rct_tile_element *tileElement, int32_t x, int32_t y) 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); 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; case 1:
y += CoordsDirectionDelta[rotation].y; x += CoordsDirectionDelta[rotation].x;
break; y += CoordsDirectionDelta[rotation].y;
case 2: break;
x -= CoordsDirectionDelta[rotation].x; case 2:
y -= CoordsDirectionDelta[rotation].y; x -= CoordsDirectionDelta[rotation].x;
break; y -= CoordsDirectionDelta[rotation].y;
break;
} }
gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; gGameCommandErrorTitle = STR_CANT_REMOVE_THIS;
game_do_command(x, GAME_COMMAND_FLAG_APPLY, y, tileElement->base_height / 2, GAME_COMMAND_REMOVE_PARK_ENTRANCE, 0, 0); game_do_command(x, GAME_COMMAND_FLAG_APPLY, y, tileElement->base_height / 2, GAME_COMMAND_REMOVE_PARK_ENTRANCE, 0, 0);
@@ -503,9 +566,9 @@ void viewport_interaction_remove_park_entrance(rct_tile_element *tileElement, in
* *
* rct2: 0x006E57A9 * rct2: 0x006E57A9
*/ */
static void viewport_interaction_remove_park_wall(rct_tile_element *tileElement, int32_t x, int32_t y) static void viewport_interaction_remove_park_wall(rct_tile_element* tileElement, int32_t x, int32_t y)
{ {
rct_scenery_entry *sceneryEntry = get_wall_entry(tileElement->properties.wall.type); rct_scenery_entry* sceneryEntry = get_wall_entry(tileElement->properties.wall.type);
if (sceneryEntry->wall.scrolling_mode != 0xFF) if (sceneryEntry->wall.scrolling_mode != 0xFF)
{ {
context_open_detail_window(WD_SIGN_SMALL, tileElement->properties.wall.banner_index); context_open_detail_window(WD_SIGN_SMALL, tileElement->properties.wall.banner_index);
@@ -522,15 +585,17 @@ static void viewport_interaction_remove_park_wall(rct_tile_element *tileElement,
* *
* rct2: 0x006B88DC * rct2: 0x006B88DC
*/ */
static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElement, int32_t x, int32_t y) static void viewport_interaction_remove_large_scenery(rct_tile_element* tileElement, int32_t x, int32_t y)
{ {
rct_scenery_entry *sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement)); rct_scenery_entry* sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement));
if (sceneryEntry->large_scenery.scrolling_mode != 0xFF) if (sceneryEntry->large_scenery.scrolling_mode != 0xFF)
{ {
BannerIndex bannerIndex = scenery_large_get_banner_id(tileElement); BannerIndex bannerIndex = scenery_large_get_banner_id(tileElement);
context_open_detail_window(WD_SIGN, bannerIndex); context_open_detail_window(WD_SIGN, bannerIndex);
} else { }
else
{
gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; gGameCommandErrorTitle = STR_CANT_REMOVE_THIS;
game_do_command( game_do_command(
x, x,
@@ -539,17 +604,16 @@ static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElem
tileElement->base_height | (scenery_large_get_sequence(tileElement) << 8), tileElement->base_height | (scenery_large_get_sequence(tileElement) << 8),
GAME_COMMAND_REMOVE_LARGE_SCENERY, GAME_COMMAND_REMOVE_LARGE_SCENERY,
0, 0,
0 0);
);
} }
} }
static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance) static rct_peep* viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance)
{ {
int32_t distance, closestDistance; int32_t distance, closestDistance;
uint16_t spriteIndex; uint16_t spriteIndex;
rct_window *w; rct_window* w;
rct_viewport *viewport; rct_viewport* viewport;
rct_peep *peep, *closestPeep; rct_peep *peep, *closestPeep;
w = window_find_from_point(x, y); w = window_find_from_point(x, y);
@@ -565,17 +629,18 @@ static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int
closestPeep = nullptr; closestPeep = nullptr;
closestDistance = 0xFFFF; closestDistance = 0xFFFF;
FOR_ALL_PEEPS(spriteIndex, peep) { FOR_ALL_PEEPS (spriteIndex, peep)
{
if (peep->sprite_left == LOCATION_NULL) if (peep->sprite_left == LOCATION_NULL)
continue; continue;
distance = distance
abs(((peep->sprite_left + peep->sprite_right) / 2) - x) + = abs(((peep->sprite_left + peep->sprite_right) / 2) - x) + abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
if (distance > maxDistance) if (distance > maxDistance)
continue; continue;
if (distance < closestDistance) { if (distance < closestDistance)
{
closestPeep = peep; closestPeep = peep;
closestDistance = distance; closestDistance = distance;
} }
@@ -588,30 +653,42 @@ static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int
* *
* rct2: 0x0068A15E * rct2: 0x0068A15E
*/ */
void sub_68A15E(int32_t screenX, int32_t screenY, int16_t *x, int16_t *y, int32_t *direction, rct_tile_element **tileElement) void sub_68A15E(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, int32_t* direction, rct_tile_element** tileElement)
{ {
int16_t my_x, my_y; int16_t my_x, my_y;
int32_t interactionType; int32_t interactionType;
rct_tile_element *myTileElement; rct_tile_element* myTileElement;
rct_viewport *viewport; 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; *x = LOCATION_NULL;
return; return;
} }
int16_t originalZ = 0; int16_t originalZ = 0;
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER) { if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER)
{
originalZ = surface_get_water_height(myTileElement) << 4; originalZ = surface_get_water_height(myTileElement) << 4;
} }
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(viewport, screenX, screenY); 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) }; 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; 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); 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); 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 myDirection;
int32_t mod_x = map_pos.x & 0x1F; int32_t mod_x = map_pos.x & 0x1F;
int32_t mod_y = map_pos.y & 0x1F; int32_t mod_y = map_pos.y & 0x1F;
if (mod_x < mod_y) { if (mod_x < mod_y)
if (mod_x + mod_y < 32) { {
if (mod_x + mod_y < 32)
{
myDirection = 0; myDirection = 0;
} else { }
else
{
myDirection = 1; myDirection = 1;
} }
} else { }
if (mod_x + mod_y < 32) { else
{
if (mod_x + mod_y < 32)
{
myDirection = 3; myDirection = 3;
} else { }
else
{
myDirection = 2; myDirection = 2;
} }
} }
*x = map_pos.x & ~0x1F; *x = map_pos.x & ~0x1F;
*y = map_pos.y & ~0x1F; *y = map_pos.y & ~0x1F;
if (direction != nullptr) *direction = myDirection; if (direction != nullptr)
if (tileElement != nullptr) *tileElement = myTileElement; *direction = myDirection;
if (tileElement != nullptr)
*tileElement = myTileElement;
} }

View File

@@ -7,97 +7,102 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "Widget.h"
#include "Window.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <openrct2/Context.h> #include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h> #include <openrct2/Input.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h> #include <openrct2/localisation/Localisation.h>
#include <openrct2/sprites.h> #include <openrct2/sprites.h>
#include <openrct2/util/Util.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_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); static void widget_resize_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_tab_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_flat_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_text_button(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_text_centred(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_text_centred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_text(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_text(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_text_inset(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_text_inset(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_groupbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); static void widget_caption_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); 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_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_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_hscrollbar_draw(
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); 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); 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);
/** /**
* *
* rct2: 0x006EB2A8 * rct2: 0x006EB2A8
*/ */
void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) 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_EMPTY:
case WWT_FRAME: break;
widget_frame_draw(dpi, w, widgetIndex); case WWT_FRAME:
break; widget_frame_draw(dpi, w, widgetIndex);
case WWT_RESIZE: break;
widget_resize_draw(dpi, w, widgetIndex); case WWT_RESIZE:
break; widget_resize_draw(dpi, w, widgetIndex);
case WWT_IMGBTN: break;
widget_button_draw(dpi, w, widgetIndex); case WWT_IMGBTN:
break; widget_button_draw(dpi, w, widgetIndex);
case WWT_COLOURBTN: break;
case WWT_TRNBTN: case WWT_COLOURBTN:
case WWT_TAB: case WWT_TRNBTN:
widget_tab_draw(dpi, w, widgetIndex); case WWT_TAB:
break; widget_tab_draw(dpi, w, widgetIndex);
case WWT_FLATBTN: break;
widget_flat_button_draw(dpi, w, widgetIndex); case WWT_FLATBTN:
break; widget_flat_button_draw(dpi, w, widgetIndex);
case WWT_BUTTON: break;
case WWT_TABLE_HEADER: case WWT_BUTTON:
widget_text_button(dpi, w, widgetIndex); case WWT_TABLE_HEADER:
break; widget_text_button(dpi, w, widgetIndex);
case WWT_LABEL_CENTRED: break;
widget_text_centred(dpi, w, widgetIndex); case WWT_LABEL_CENTRED:
break; widget_text_centred(dpi, w, widgetIndex);
case WWT_LABEL: break;
widget_text(dpi, w, widgetIndex); case WWT_LABEL:
break; widget_text(dpi, w, widgetIndex);
case WWT_SPINNER: break;
case WWT_DROPDOWN: case WWT_SPINNER:
case WWT_VIEWPORT: case WWT_DROPDOWN:
widget_text_inset(dpi, w, widgetIndex); case WWT_VIEWPORT:
break; widget_text_inset(dpi, w, widgetIndex);
case WWT_GROUPBOX: break;
widget_groupbox_draw(dpi, w, widgetIndex); case WWT_GROUPBOX:
break; widget_groupbox_draw(dpi, w, widgetIndex);
case WWT_CAPTION: break;
widget_caption_draw(dpi, w, widgetIndex); case WWT_CAPTION:
break; widget_caption_draw(dpi, w, widgetIndex);
case WWT_CLOSEBOX: break;
widget_closebox_draw(dpi, w, widgetIndex); case WWT_CLOSEBOX:
break; widget_closebox_draw(dpi, w, widgetIndex);
case WWT_SCROLL: break;
widget_scroll_draw(dpi, w, widgetIndex); case WWT_SCROLL:
break; widget_scroll_draw(dpi, w, widgetIndex);
case WWT_CHECKBOX: break;
widget_checkbox_draw(dpi, w, widgetIndex); case WWT_CHECKBOX:
break; widget_checkbox_draw(dpi, w, widgetIndex);
case WWT_PLACEHOLDER: break;
break; case WWT_PLACEHOLDER:
case WWT_TEXT_BOX: break;
widget_text_box_draw(dpi, w, widgetIndex); case WWT_TEXT_BOX:
break; widget_text_box_draw(dpi, w, widgetIndex);
break;
} }
} }
@@ -105,10 +110,10 @@ void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIn
* *
* rct2: 0x006EB6CE * rct2: 0x006EB6CE
*/ */
static void widget_frame_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_frame_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -141,10 +146,10 @@ static void widget_frame_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
* *
* rct2: 0x006EB765 * rct2: 0x006EB765
*/ */
static void widget_resize_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_resize_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -174,10 +179,10 @@ static void widget_resize_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
* *
* rct2: 0x006EB8E5 * rct2: 0x006EB8E5
*/ */
static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -186,12 +191,14 @@ static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
int32_t b = w->y + widget->bottom; int32_t b = w->y + widget->bottom;
// Check if the button is pressed down // 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 // Get the colour
uint8_t colour = w->colours[widget->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 // Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE); gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE);
return; return;
@@ -207,16 +214,17 @@ static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
* *
* rct2: 0x006EB806 * rct2: 0x006EB806
*/ */
static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_tab_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
if ((int32_t)widget->image == -1) if ((int32_t)widget->image == -1)
return; return;
// Draw widgets that aren't explicitly disabled. // 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); widget_draw_image(dpi, w, widgetIndex);
return; 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)) if (widget->type == WWT_TAB && widget->image != (IMAGE_TYPE_REMAP | SPR_G2_TAB_DISABLED))
return; return;
if (widget->type != WWT_TRNBTN) { if (widget->type != WWT_TRNBTN)
{
widget_draw_image(dpi, w, widgetIndex); widget_draw_image(dpi, w, widgetIndex);
return; return;
} }
@@ -246,15 +255,16 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
* *
* rct2: 0x006EB861 * rct2: 0x006EB861
*/ */
static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) 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); widget_button_draw(dpi, w, widgetIndex);
return; return;
} }
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -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]; uint8_t colour = w->colours[widget->colour];
// Check if the button is pressed down // Check if the button is pressed down
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) { if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
if ((int32_t)widget->image == -2) { {
if ((int32_t)widget->image == -2)
{
// Draw border with no fill // 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); gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE);
return; return;
@@ -285,10 +297,10 @@ static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_w
* *
* rct2: 0x006EBBEB * rct2: 0x006EBBEB
*/ */
static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_text_button(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -300,7 +312,8 @@ static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
uint8_t colour = w->colours[widget->colour]; uint8_t colour = w->colours[widget->colour];
// Border // 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); gfx_fill_rect_inset(dpi, l, t, r, b, colour, press);
// Button caption // Button caption
@@ -318,10 +331,10 @@ static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
* *
* rct2: 0x006EBC41 * rct2: 0x006EBC41
*/ */
static void widget_text_centred(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_text_centred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
if (widget->text == STR_NONE) if (widget->text == STR_NONE)
return; return;
@@ -349,24 +362,17 @@ static void widget_text_centred(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
t = w->y + widget->top; t = w->y + widget->top;
gfx_draw_string_centred_clipped( gfx_draw_string_centred_clipped(
dpi, dpi, widget->text, gCommonFormatArgs, colour, (l + r + 1) / 2 - 1, t, widget->right - widget->left - 2);
widget->text,
gCommonFormatArgs,
colour,
(l + r + 1) / 2 - 1,
t,
widget->right - widget->left - 2
);
} }
/** /**
* *
* rct2: 0x006EBD52 * rct2: 0x006EBD52
*/ */
static void widget_text(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_text(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
if (widget->text == STR_NONE || widget->text == STR_VIEWPORT) if (widget->text == STR_NONE || widget->text == STR_VIEWPORT)
return; return;
@@ -399,10 +405,10 @@ static void widget_text(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex w
* *
* rct2: 0x006EBD1F * rct2: 0x006EBD1F
*/ */
static void widget_text_inset(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_text_inset(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -421,10 +427,10 @@ static void widget_text_inset(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
* *
* rct2: 0x006EB535 * rct2: 0x006EB535
*/ */
static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_groupbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left + 5; int32_t l = w->x + widget->left + 5;
@@ -434,7 +440,8 @@ static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
int32_t textRight = l; int32_t textRight = l;
// Text // Text
if (widget->text != STR_NONE) { if (widget->text != STR_NONE)
{
uint8_t colour = w->colours[widget->colour] & 0x7F; uint8_t colour = w->colours[widget->colour] & 0x7F;
if (widget_is_disabled(w, widgetIndex)) if (widget_is_disabled(w, widgetIndex))
colour |= COLOUR_FLAG_INSET; colour |= COLOUR_FLAG_INSET;
@@ -482,10 +489,10 @@ static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
* *
* rct2: 0x006EB2F9 * rct2: 0x006EB2F9
*/ */
static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_caption_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -515,7 +522,8 @@ static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
l = widget->left + w->x + 2; l = widget->left + w->x + 2;
t = widget->top + w->y + 1; t = widget->top + w->y + 1;
int32_t width = widget->right - widget->left - 4; int32_t width = widget->right - widget->left - 4;
if ((widget + 1)->type == WWT_CLOSEBOX) { if ((widget + 1)->type == WWT_CLOSEBOX)
{
width -= 10; width -= 10;
if ((widget + 2)->type == WWT_CLOSEBOX) if ((widget + 2)->type == WWT_CLOSEBOX)
width -= 10; width -= 10;
@@ -528,10 +536,10 @@ static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
* *
* rct2: 0x006EBB85 * rct2: 0x006EBB85
*/ */
static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_closebox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -566,12 +574,12 @@ static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
/** /**
* *
* rct2: 0x006EBAD9 * rct2: 0x006EBAD9
*/ */
static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltb // Resolve the absolute ltb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -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); gfx_fill_rect_inset(dpi, l, yMid - 5, l + 9, yMid + 4, colour, INSET_RECT_F_60);
// fill it when checkbox is pressed // fill it when checkbox is pressed
if (widget_is_pressed(w, widgetIndex)) { if (widget_is_pressed(w, widgetIndex))
{
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, NOT_TRANSLUCENT(colour), l, yMid - 5); 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) if (widget->text == STR_NONE)
return; return;
if (widget_is_disabled(w, widgetIndex)) { if (widget_is_disabled(w, widgetIndex))
{
colour |= COLOUR_FLAG_INSET; colour |= COLOUR_FLAG_INSET;
} }
@@ -606,11 +616,11 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
* *
* rct2: 0x006EBD96 * rct2: 0x006EBD96
*/ */
static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_scroll_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
int32_t scrollIndex = window_get_scroll_data_index(w, widgetIndex); int32_t scrollIndex = window_get_scroll_data_index(w, widgetIndex);
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
rct_scroll* scroll = &w->scrolls[scrollIndex]; rct_scroll* scroll = &w->scrolls[scrollIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
@@ -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); 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; colour &= 0x7F;
// Trough // 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); gfx_fill_rect(dpi, l + 10, t + 8, r - 10, t + 8, ColourMapA[colour].lighter);
// Left button // 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); gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t);
// Thumb // Thumb
gfx_fill_rect_inset(dpi, gfx_fill_rect_inset(
std::max(l + 10, l + scroll->h_thumb_left - 1), t, dpi,
std::min(r - 10, l + scroll->h_thumb_right - 1), b, std::max(l + 10, l + scroll->h_thumb_left - 1),
colour, ((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); 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 // 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); 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; colour &= 0x7F;
// Trough // 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); gfx_fill_rect(dpi, l + 8, t + 10, l + 8, b - 10, ColourMapA[colour].lighter);
// Up button // 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); gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1);
// Thumb // Thumb
gfx_fill_rect_inset(dpi, gfx_fill_rect_inset(
l, std::max(t + 10, t + scroll->v_thumb_top - 1), dpi,
r, std::min(b - 10, t + scroll->v_thumb_bottom - 1), l,
colour, ((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); 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 // 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); gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9);
} }
@@ -729,10 +753,10 @@ static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
* *
* rct2: 0x006EB951 * rct2: 0x006EB951
*/ */
static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_draw_image(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Get the image // Get the image
int32_t image = widget->image; int32_t image = widget->image;
@@ -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)) if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
image++; image++;
if (widget_is_disabled(w, widgetIndex)) { if (widget_is_disabled(w, widgetIndex))
{
// Draw greyed out (light border bottom right shadow) // Draw greyed out (light border bottom right shadow)
colour = w->colours[widget->colour]; colour = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].lighter; 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 = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].mid_light; colour = ColourMapA[NOT_TRANSLUCENT(colour)].mid_light;
gfx_draw_sprite_solid(dpi, image, l, t, colour); 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)
{
// ? // ?
} }
@@ -774,40 +802,49 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
} }
} }
bool widget_is_enabled(rct_window *w, rct_widgetindex widgetIndex) bool widget_is_enabled(rct_window* w, rct_widgetindex widgetIndex)
{ {
return (w->enabled_widgets & (1LL << widgetIndex)) != 0; return (w->enabled_widgets & (1LL << widgetIndex)) != 0;
} }
bool widget_is_disabled(rct_window *w, rct_widgetindex widgetIndex) bool widget_is_disabled(rct_window* w, rct_widgetindex widgetIndex)
{ {
return (w->disabled_widgets & (1LL << widgetIndex)) != 0; return (w->disabled_widgets & (1LL << widgetIndex)) != 0;
} }
bool widget_is_pressed(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; return true;
} }
if (input_get_state() == INPUT_STATE_WIDGET_PRESSED || input_get_state() == INPUT_STATE_DROPDOWN_ACTIVE) { 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 (!(input_test_flag(INPUT_FLAG_WIDGET_PRESSED)))
if (gPressedWidget.window_number != w->number) return false; return false;
if (gPressedWidget.widget_index != widgetIndex) 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 true;
} }
return false; return false;
} }
bool widget_is_highlighted(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_classification != w->classification)
if (gHoverWidget.window_number != w->number) return false; return false;
if (gHoverWidget.widget_index != widgetIndex) return false; if (gHoverWidget.window_number != w->number)
return false;
if (gHoverWidget.widget_index != widgetIndex)
return false;
return true; return true;
} }
bool widget_is_active_tool(rct_window *w, rct_widgetindex widgetIndex) bool widget_is_active_tool(rct_window* w, rct_widgetindex widgetIndex)
{ {
if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE)))
return false; return false;
@@ -831,7 +868,15 @@ bool widget_is_active_tool(rct_window *w, rct_widgetindex widgetIndex)
* esi: w * esi: w
* edi: widget * 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; rct_widget* iterator = w->widgets;
*scroll_id = 0; *scroll_id = 0;
@@ -871,7 +916,7 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_
{ {
*output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT_TROUGH; *output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT_TROUGH;
} }
else if (x >(widget->left + w->x + w->scrolls[*scroll_id].h_thumb_right)) else if (x > (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_right))
{ {
*output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH; *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH;
} }
@@ -907,7 +952,7 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_
{ {
*output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP_TROUGH; *output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP_TROUGH;
} }
else if (y >(widget->top + w->y + w->scrolls[*scroll_id].v_thumb_bottom)) else if (y > (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_bottom))
{ {
*output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH; *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH;
} }
@@ -918,7 +963,7 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_
} }
else else
{ {
//view // view
*output_scroll_area = SCROLL_PART_VIEW; *output_scroll_area = SCROLL_PART_VIEW;
*output_x = x - widget->left; *output_x = x - widget->left;
*output_y = y - widget->top; *output_y = y - widget->top;
@@ -936,19 +981,21 @@ 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) void widget_set_enabled(rct_window* w, rct_widgetindex widgetIndex, bool enabled)
{ {
if (enabled) { if (enabled)
{
w->enabled_widgets |= (1ULL << widgetIndex); w->enabled_widgets |= (1ULL << widgetIndex);
w->disabled_widgets &= ~(1ULL << widgetIndex); w->disabled_widgets &= ~(1ULL << widgetIndex);
} }
else { else
{
w->enabled_widgets &= ~(1ULL << widgetIndex); w->enabled_widgets &= ~(1ULL << widgetIndex);
w->disabled_widgets |= (1ULL << widgetIndex); w->disabled_widgets |= (1ULL << widgetIndex);
} }
} }
void widget_set_checkbox_value(rct_window *w, rct_widgetindex widgetIndex, int32_t value) void widget_set_checkbox_value(rct_window* w, rct_widgetindex widgetIndex, int32_t value)
{ {
if (value) if (value)
w->pressed_widgets |= (1ULL << widgetIndex); w->pressed_widgets |= (1ULL << widgetIndex);
@@ -956,14 +1003,14 @@ void widget_set_checkbox_value(rct_window *w, rct_widgetindex widgetIndex, int32
w->pressed_widgets &= ~(1ULL << widgetIndex); w->pressed_widgets &= ~(1ULL << widgetIndex);
} }
static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex) static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{ {
int32_t no_lines = 0; int32_t no_lines = 0;
int32_t font_height = 0; int32_t font_height = 0;
char wrapped_string[TEXT_INPUT_SIZE]; char wrapped_string[TEXT_INPUT_SIZE];
// Get the widget // Get the widget
rct_widget *widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb // Resolve the absolute ltrb
int32_t l = w->x + widget->left; int32_t l = w->x + widget->left;
@@ -974,19 +1021,19 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
// Get the colour // Get the colour
uint8_t colour = w->colours[widget->colour]; uint8_t colour = w->colours[widget->colour];
bool active = w->classification == gCurrentTextBox.window.classification && bool active = w->classification == gCurrentTextBox.window.classification && w->number == gCurrentTextBox.window.number
w->number == gCurrentTextBox.window.number && && widgetIndex == gCurrentTextBox.widget_index;
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, 0x20 | (!active ? 0x40 : 0x00));
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_F_60); gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_F_60);
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gCurrentFontFlags = 0; gCurrentFontFlags = 0;
if (!active || gTextInput == nullptr) { if (!active || gTextInput == nullptr)
{
if (w->widgets[widgetIndex].text != 0) { if (w->widgets[widgetIndex].text != 0)
{
safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512); safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512);
gfx_wrap_string(wrapped_string, r - l - 5, &no_lines, &font_height); gfx_wrap_string(wrapped_string, r - l - 5, &no_lines, &font_height);
gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t); 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; return;
} }
safe_strcpy(wrapped_string, gTextBoxInput, TEXT_INPUT_SIZE); safe_strcpy(wrapped_string, gTextBoxInput, TEXT_INPUT_SIZE);
// String length needs to add 12 either side of box // String length needs to add 12 either side of box
// +13 for cursor when max length. // +13 for cursor when max length.
gfx_wrap_string(wrapped_string, r - l - 5 - 6, &no_lines, &font_height); 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); gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
size_t string_length = get_string_size(wrapped_string) - 1; size_t string_length = get_string_size(wrapped_string) - 1;
// Make a copy of the string for measuring the width. // 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 cur_x = l + gfx_get_string_width(temp_string) + 3;
int32_t width = 6; 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 // Make a new 1 character wide string for measuring the width
// of the character that the cursor is under. // of the character that the cursor is under.
temp_string[1] = '\0'; 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); width = std::max(gfx_get_string_width(temp_string) - 2, 4);
} }
if (gTextBoxFrameNo <= 15){ if (gTextBoxFrameNo <= 15)
{
colour = ColourMapA[w->colours[1]].mid_light; colour = ColourMapA[w->colours[1]].mid_light;
gfx_fill_rect(dpi, cur_x, t + 9, cur_x + width, t + 9, colour + 5); 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. * 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/audio/audio.h>
#include <openrct2/config/Config.h> #include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h> #include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h>
#include <openrct2/interface/Widget.h> #include <openrct2/interface/Widget.h>
#include <openrct2/localisation/StringIds.h> #include <openrct2/localisation/StringIds.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/sprites.h> #include <openrct2/sprites.h>
#include <openrct2/world/Sprite.h>
#include <openrct2/ui/UiContext.h> #include <openrct2/ui/UiContext.h>
#include "Theme.h" #include <openrct2/world/Sprite.h>
#include "Window.h"
using namespace OpenRCT2; 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) if (w->flags & WF_STICK_TO_BACK)
continue; continue;
if (x + width <= w->x) continue; if (x + width <= w->x)
if (x >= w->x + w->width) continue; continue;
if (y + height <= w->y) continue; if (x >= w->x + w->width)
if (y >= w->y + w->height) continue; continue;
if (y + height <= w->y)
continue;
if (y >= w->y + w->height)
continue;
return false; 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) static bool window_fits_within_space(int32_t x, int32_t y, int32_t width, int32_t height)
{ {
if (x < 0) return false; if (x < 0)
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false; return false;
if (x + width > context_get_width()) return false; if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
if (y + height > context_get_height()) return false; 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); 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; int32_t unk;
unk = -(width / 4); unk = -(width / 4);
if (x < unk) return false; if (x < unk)
return false;
unk = screenWidth + (unk * 2); unk = screenWidth + (unk * 2);
if (x > unk) return false; if (x > unk)
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) return false; return false;
if (y <= TOP_TOOLBAR_HEIGHT && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
return false;
unk = screenHeight - (height / 4); unk = screenHeight - (height / 4);
if (y > unk) return false; if (y > unk)
return false;
return window_fits_between_others(x, y, width, height); 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 // 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. // 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; w->flags = flags;
// Play sounds and flash the window // 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; w->flags |= WF_WHITE_BORDER_MASK;
audio_play_sound(SOUND_WINDOW_OPEN, 0, x + (width / 2)); 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; 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 uiContext = GetContext()->GetUiContext();
auto screenWidth = uiContext->GetWidth(); 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 // Place window in an empty corner of the screen
int32_t x = 0; int32_t x = 0;
int32_t y = 30; 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; x = screenWidth - width;
y = 30; 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; x = 0;
y = screenHeight - 34 - height; 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; x = screenWidth - width;
y = screenHeight - 34 - height; 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 // Place window next to another
for (auto& w : g_window_list) 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; x = w->x + w->width + 2;
y = w->y; 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; x = w->x - w->width - 2;
y = w->y; 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; x = w->x;
y = w->y + w->height + 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; x = w->x;
y = w->y - w->height - 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; x = w->x + w->width + 2;
y = w->y - w->height - 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; x = w->x - w->width - 2;
y = w->y - w->height - 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; x = w->x + w->width + 2;
y = w->y + w->height + 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; x = w->x - w->width - 2;
y = w->y + w->height + 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 // 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; x = w->x + w->width + 2;
y = w->y; 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; x = w->x - w->width - 2;
y = w->y; 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; x = w->x;
y = w->y + w->height + 2; 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; x = w->x;
y = w->y - w->height - 2; 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 // Cascade
@@ -282,7 +321,8 @@ foundSpace:
return window_create(x, y, width, height, event_handlers, cls, flags); 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 uiContext = GetContext()->GetUiContext();
auto screenWidth = uiContext->GetWidth(); auto screenWidth = uiContext->GetWidth();
@@ -293,23 +333,24 @@ rct_window * window_create_centred(int32_t width, int32_t height, rct_window_eve
return window_create(x, y, width, height, event_handlers, cls, flags); return window_create(x, y, width, height, event_handlers, cls, flags);
} }
static int32_t window_get_widget_index(rct_window *w, rct_widget *widget) static int32_t window_get_widget_index(rct_window* w, rct_widget* widget)
{ {
int32_t i = 0; int32_t i = 0;
for (rct_widget *widget2 = w->widgets; widget2->type != WWT_LAST; widget2++, i++) for (rct_widget* widget2 = w->widgets; widget2->type != WWT_LAST; widget2++, i++)
if (widget == widget2) if (widget == widget2)
return i; return i;
return -1; return -1;
} }
static int32_t window_get_scroll_index(rct_window *w, int32_t targetWidgetIndex) static int32_t window_get_scroll_index(rct_window* w, int32_t targetWidgetIndex)
{ {
if (w->widgets[targetWidgetIndex].type != WWT_SCROLL) if (w->widgets[targetWidgetIndex].type != WWT_SCROLL)
return -1; return -1;
int32_t scrollIndex = 0; int32_t scrollIndex = 0;
rct_widgetindex widgetIndex = 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) if (widgetIndex == targetWidgetIndex)
break; break;
if (widget->type == WWT_SCROLL) if (widget->type == WWT_SCROLL)
@@ -319,9 +360,10 @@ static int32_t window_get_scroll_index(rct_window *w, int32_t targetWidgetIndex)
return scrollIndex; return scrollIndex;
} }
static rct_widget *window_get_scroll_widget(rct_window *w, int32_t scrollIndex) 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) if (widget->type != WWT_SCROLL)
continue; continue;
@@ -337,19 +379,22 @@ static rct_widget *window_get_scroll_widget(rct_window *w, int32_t scrollIndex)
* *
* rct2: 0x006E78E3 * rct2: 0x006E78E3
*/ */
static void window_scroll_wheel_input(rct_window *w, int32_t scrollIndex, int32_t wheel) static void window_scroll_wheel_input(rct_window* w, int32_t scrollIndex, int32_t wheel)
{ {
rct_scroll *scroll = &w->scrolls[scrollIndex]; rct_scroll* scroll = &w->scrolls[scrollIndex];
rct_widget *widget = window_get_scroll_widget(w, scrollIndex); rct_widget* widget = window_get_scroll_widget(w, scrollIndex);
rct_widgetindex widgetIndex = window_get_widget_index(w, widget); 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; int32_t size = widget->bottom - widget->top - 1;
if (scroll->flags & HSCROLLBAR_VISIBLE) if (scroll->flags & HSCROLLBAR_VISIBLE)
size -= 11; size -= 11;
size = std::max(0, scroll->v_bottom - size); size = std::max(0, scroll->v_bottom - size);
scroll->v_top = std::min(std::max(0, scroll->v_top + wheel), size); scroll->v_top = std::min(std::max(0, scroll->v_top + wheel), size);
} else { }
else
{
int32_t size = widget->right - widget->left - 1; int32_t size = widget->right - widget->left - 1;
if (scroll->flags & VSCROLLBAR_VISIBLE) if (scroll->flags & VSCROLLBAR_VISIBLE)
size -= 11; size -= 11;
@@ -365,16 +410,18 @@ static void window_scroll_wheel_input(rct_window *w, int32_t scrollIndex, int32_
* *
* rct2: 0x006E793B * rct2: 0x006E793B
*/ */
static int32_t window_wheel_input(rct_window *w, int32_t wheel) static int32_t window_wheel_input(rct_window* w, int32_t wheel)
{ {
int32_t i = 0; 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) if (widget->type != WWT_SCROLL)
continue; continue;
// Originally always checked first scroll view, bug maybe? // Originally always checked first scroll view, bug maybe?
rct_scroll *scroll = &w->scrolls[i]; 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); window_scroll_wheel_input(w, i, wheel);
return 1; return 1;
} }
@@ -388,7 +435,7 @@ static int32_t window_wheel_input(rct_window *w, int32_t wheel)
* *
* rct2: 0x006E79FB * rct2: 0x006E79FB
*/ */
static void window_viewport_wheel_input(rct_window *w, int32_t wheel) static void window_viewport_wheel_input(rct_window* w, int32_t wheel)
{ {
if (gScreenFlags & (SCREEN_FLAGS_TRACK_MANAGER | SCREEN_FLAGS_TITLE_DEMO)) if (gScreenFlags & (SCREEN_FLAGS_TRACK_MANAGER | SCREEN_FLAGS_TITLE_DEMO))
return; return;
@@ -460,7 +507,8 @@ static bool window_other_wheel_input(rct_window* w, rct_widgetindex widgetIndex,
expectedContent[0] = STR_NUMERIC_UP; expectedContent[0] = STR_NUMERIC_UP;
expectedContent[1] = STR_NUMERIC_DOWN; expectedContent[1] = STR_NUMERIC_DOWN;
break; break;
default: return false; default:
return false;
} }
if (widget_is_disabled(w, buttonWidgetIndex)) if (widget_is_disabled(w, buttonWidgetIndex))
@@ -489,7 +537,7 @@ static bool window_other_wheel_input(rct_window* w, rct_widgetindex widgetIndex,
void window_all_wheel_input() void window_all_wheel_input()
{ {
// Get wheel value // Get wheel value
CursorState * cursorState = (CursorState *)context_get_cursor_state(); CursorState* cursorState = (CursorState*)context_get_cursor_state();
int32_t absolute_wheel = cursorState->wheel; int32_t absolute_wheel = cursorState->wheel;
int32_t relative_wheel = absolute_wheel - _previousAbsoluteWheel; int32_t relative_wheel = absolute_wheel - _previousAbsoluteWheel;
int32_t pixel_scroll = relative_wheel * WINDOW_SCROLL_PIXELS; int32_t pixel_scroll = relative_wheel * WINDOW_SCROLL_PIXELS;
@@ -499,28 +547,37 @@ void window_all_wheel_input()
return; return;
// Check window cursor is over // 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) { rct_window* w = window_find_from_point(cursorState->x, cursorState->y);
if (w != nullptr)
{
// Check if main window // 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); window_viewport_wheel_input(w, relative_wheel);
return; return;
} }
// Check scroll view, cursor is over // Check scroll view, cursor is over
rct_widgetindex widgetIndex = window_find_widget_from_point(w, cursorState->x, cursorState->y); 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) { rct_widget* widget = &w->widgets[widgetIndex];
if (widget->type == WWT_SCROLL)
{
int32_t scrollIndex = window_get_scroll_index(w, widgetIndex); int32_t scrollIndex = window_get_scroll_index(w, widgetIndex);
rct_scroll *scroll = &w->scrolls[scrollIndex]; 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); window_scroll_wheel_input(w, window_get_scroll_index(w, widgetIndex), pixel_scroll);
return; return;
} }
} else { }
if (window_other_wheel_input(w, widgetIndex, pixel_scroll)) { else
{
if (window_other_wheel_input(w, widgetIndex, pixel_scroll))
{
return; return;
} }
} }
@@ -537,7 +594,7 @@ void window_all_wheel_input()
* Initialises scroll widgets to their virtual size. * Initialises scroll widgets to their virtual size.
* rct2: 0x006EAEB8 * rct2: 0x006EAEB8
*/ */
void window_init_scroll_widgets(rct_window *w) void window_init_scroll_widgets(rct_window* w)
{ {
rct_widget* widget; rct_widget* widget;
rct_scroll* scroll; rct_scroll* scroll;
@@ -546,8 +603,10 @@ void window_init_scroll_widgets(rct_window *w)
widget_index = 0; widget_index = 0;
scroll_index = 0; scroll_index = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) { for (widget = w->widgets; widget->type != WWT_LAST; widget++)
if (widget->type != WWT_SCROLL) { {
if (widget->type != WWT_SCROLL)
{
widget_index++; widget_index++;
continue; continue;
} }
@@ -578,18 +637,19 @@ void window_init_scroll_widgets(rct_window *w)
* *
* rct2: 0x006EB15C * rct2: 0x006EB15C
*/ */
void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi) void window_draw_widgets(rct_window* w, rct_drawpixelinfo* dpi)
{ {
rct_widget *widget; rct_widget* widget;
rct_widgetindex widgetIndex; rct_widgetindex widgetIndex;
if ((w->flags & WF_TRANSPARENT) && !(w->flags & WF_NO_BACKGROUND)) if ((w->flags & WF_TRANSPARENT) && !(w->flags & WF_NO_BACKGROUND))
gfx_filter_rect(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, PALETTE_51); gfx_filter_rect(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, PALETTE_51);
//todo: some code missing here? Between 006EB18C and 006EB260 // todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0; 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 // 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->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) if (w->y + widget->top < dpi->y + dpi->height && w->y + widget->bottom >= dpi->y)
@@ -598,10 +658,12 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
widgetIndex++; widgetIndex++;
} }
//todo: something missing here too? Between 006EC32B and 006EC369 // todo: something missing here too? Between 006EC32B and 006EC369
if (w->flags & WF_WHITE_BORDER_MASK) { 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); {
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);
} }
} }
@@ -609,13 +671,14 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
* *
* rct2: 0x006EA776 * rct2: 0x006EA776
*/ */
static void window_invalidate_pressed_image_buttons(rct_window *w) static void window_invalidate_pressed_image_buttons(rct_window* w)
{ {
rct_widgetindex widgetIndex; rct_widgetindex widgetIndex;
rct_widget *widget; rct_widget* widget;
widgetIndex = 0; 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) if (widget->type != WWT_IMGBTN)
continue; continue;