1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +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
#include <openrct2/common.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_LAND_PICKER 0xFFFF
#define DROPDOWN_ITEMS_MAX_SIZE 128
#define DROPDOWN_FORMAT_LAND_PICKER 0xFFFF
#define DROPDOWN_ITEMS_MAX_SIZE 128
enum
{
@@ -39,9 +39,27 @@ void dropdown_set_checked(int32_t index, bool value);
void dropdown_set_disabled(int32_t index, bool value);
void window_dropdown_show_text(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t flags, size_t num_items);
void window_dropdown_show_text_custom_width(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t custom_height, uint8_t flags, size_t num_items, int32_t width);
void window_dropdown_show_image(int32_t x, int32_t y, int32_t extray, uint8_t colour, uint8_t flags, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns);
void window_dropdown_show_text_custom_width(
int32_t x,
int32_t y,
int32_t extray,
uint8_t colour,
uint8_t custom_height,
uint8_t flags,
size_t num_items,
int32_t width);
void window_dropdown_show_image(
int32_t x,
int32_t y,
int32_t extray,
uint8_t colour,
uint8_t flags,
int32_t numItems,
int32_t itemWidth,
int32_t itemHeight,
int32_t numColumns);
void window_dropdown_close();
int32_t dropdown_index_from_point(int32_t x, int32_t y, rct_window* w);
void window_dropdown_show_colour(rct_window *w, rct_widget *widget, uint8_t dropdownColour, uint8_t selectedColour);
void window_dropdown_show_colour_available(rct_window *w, rct_widget *widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours);
void window_dropdown_show_colour(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);

View File

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

View File

@@ -13,7 +13,8 @@
#include <openrct2/common.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_money32(rct_drawpixelinfo *dpi, money32 *history, int32_t count, int32_t baseX, int32_t baseY, int32_t modifier, int32_t offset);
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);
#endif

View File

@@ -7,19 +7,21 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "InGameConsole.h"
#include "Theme.h"
#include <algorithm>
#include <cstring>
#include <openrct2/config/Config.h>
#include <openrct2/Context.h>
#include <openrct2/Version.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/interface/Window.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/localisation/LocalisationService.h>
#include <openrct2/Version.h>
#include "InGameConsole.h"
#include "Theme.h"
using namespace OpenRCT2::Ui;
@@ -40,74 +42,82 @@ void InGameConsole::WritePrompt()
void InGameConsole::Input(CONSOLE_INPUT input)
{
switch (input) {
case CONSOLE_INPUT_LINE_CLEAR:
ClearInput();
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();
switch (input)
{
case CONSOLE_INPUT_LINE_CLEAR:
ClearInput();
RefreshCaret();
}
ScrollToEnd();
break;
case CONSOLE_INPUT_HISTORY_PREVIOUS:
if (_consoleHistoryIndex > 0) {
_consoleHistoryIndex--;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE);
}
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer);
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
break;
case CONSOLE_INPUT_HISTORY_NEXT:
if (_consoleHistoryIndex < _consoleHistoryCount - 1) {
_consoleHistoryIndex++;
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], CONSOLE_INPUT_SIZE);
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();
RefreshCaret();
}
ScrollToEnd();
break;
case CONSOLE_INPUT_HISTORY_PREVIOUS:
if (_consoleHistoryIndex > 0)
{
_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_HISTORY_NEXT:
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_PREVIOUS:
{
int32_t scrollAmt = GetNumVisibleLines() - 1;
Scroll(scrollAmt);
break;
}
case CONSOLE_INPUT_SCROLL_NEXT:
{
int32_t scrollAmt = GetNumVisibleLines() - 1;
Scroll(-scrollAmt);
break;
}
default:
break;
case CONSOLE_INPUT_SCROLL_NEXT:
{
int32_t scrollAmt = GetNumVisibleLines() - 1;
Scroll(-scrollAmt);
break;
}
default:
break;
}
}
void InGameConsole::ClearInput()
{
_consoleCurrentLine[0] = 0;
if (_isOpen) {
if (_isOpen)
{
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++)
memcpy(_consoleHistory[i], _consoleHistory[i + 1], CONSOLE_INPUT_SIZE);
_consoleHistoryCount--;
@@ -133,7 +143,7 @@ void InGameConsole::Scroll(int32_t linesToScroll)
if (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
// 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);
std::string line;
std::size_t splitPos = 0;
std::size_t splitPos = 0;
std::size_t stringOffset = 0;
while (splitPos != std::string::npos)
{
splitPos = input.find('\n', stringOffset);
line = input.substr(stringOffset, splitPos - stringOffset);
line = input.substr(stringOffset, splitPos - stringOffset);
_consoleLines.push_back(colourCodepoint + line);
stringOffset = splitPos + 1;
}
@@ -220,13 +230,17 @@ void InGameConsole::Update()
_consoleRight = context_get_width();
_consoleBottom = 322;
if (_isOpen) {
if (_isOpen)
{
// When scrolling the map, the console pixels get copied... therefore invalidate the screen
rct_window *mainWindow = window_get_main();
if (mainWindow != nullptr) {
rct_viewport *mainViewport = window_get_viewport(mainWindow);
if (mainViewport != nullptr) {
if (_lastMainViewportX != mainViewport->view_x || _lastMainViewportY != mainViewport->view_y) {
rct_window* mainWindow = window_get_main();
if (mainWindow != nullptr)
{
rct_viewport* mainViewport = window_get_viewport(mainWindow);
if (mainViewport != nullptr)
{
if (_lastMainViewportX != mainViewport->view_x || _lastMainViewportY != mainViewport->view_y)
{
_lastMainViewportX = mainViewport->view_x;
_lastMainViewportY = mainViewport->view_y;
@@ -243,17 +257,17 @@ void InGameConsole::Update()
_consoleCaretTicks = (_consoleCaretTicks + 1) % 30;
}
void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
void InGameConsole::Draw(rct_drawpixelinfo* dpi) const
{
if (!_isOpen)
return;
// Set font
gCurrentFontSpriteBase = (gConfigInterface.console_small_font ? FONT_SPRITE_BASE_SMALL : FONT_SPRITE_BASE_MEDIUM);
gCurrentFontFlags = 0;
uint8_t textColour = NOT_TRANSLUCENT(theme_get_colour(WC_CONSOLE, 1));
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t maxLines = GetNumVisibleLines();
gCurrentFontSpriteBase = (gConfigInterface.console_small_font ? FONT_SPRITE_BASE_SMALL : FONT_SPRITE_BASE_MEDIUM);
gCurrentFontFlags = 0;
uint8_t textColour = NOT_TRANSLUCENT(theme_get_colour(WC_CONSOLE, 1));
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t maxLines = GetNumVisibleLines();
// This is something of a hack to ensure the text is actually black
// as opposed to a desaturated grey
@@ -281,17 +295,26 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
// Paint background colour.
uint8_t backgroundColour = theme_get_colour(WC_CONSOLE, 0);
gfx_fill_rect_inset(dpi, _consoleLeft, _consoleTop, _consoleRight, _consoleBottom, backgroundColour, INSET_RECT_FLAG_FILL_NONE);
gfx_fill_rect_inset(dpi, _consoleLeft + 1, _consoleTop + 1, _consoleRight - 1, _consoleBottom - 1, backgroundColour, INSET_RECT_FLAG_BORDER_INSET);
gfx_fill_rect_inset(
dpi, _consoleLeft, _consoleTop, _consoleRight, _consoleBottom, backgroundColour, INSET_RECT_FLAG_FILL_NONE);
gfx_fill_rect_inset(
dpi,
_consoleLeft + 1,
_consoleTop + 1,
_consoleRight - 1,
_consoleBottom - 1,
backgroundColour,
INSET_RECT_FLAG_BORDER_INSET);
std::string lineBuffer;
int32_t x = _consoleLeft + CONSOLE_EDGE_PADDING;
int32_t y = _consoleTop + CONSOLE_EDGE_PADDING;
int32_t x = _consoleLeft + CONSOLE_EDGE_PADDING;
int32_t y = _consoleTop + CONSOLE_EDGE_PADDING;
// Draw text inside console
for (std::size_t i = 0; i < _consoleLines.size() && i < (size_t)maxLines; i++) {
for (std::size_t i = 0; i < _consoleLines.size() && i < (size_t)maxLines; i++)
{
const size_t index = i + _consoleScrollPos;
lineBuffer = colourFormatStr + _consoleLines[index];
lineBuffer = colourFormatStr + _consoleLines[index];
gfx_draw_string(dpi, lineBuffer.c_str(), textColour, x, y);
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);
// Draw caret
if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD) {
if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD)
{
int32_t caretX = x + gfx_get_string_width(_consoleCurrentLine);
int32_t caretY = y + lineHeight;
@@ -316,8 +340,10 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
uint8_t borderColour2 = ColourMapA[BASE_COLOUR(backgroundColour)].mid_dark;
// Input area top border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 11, _consoleRight, _consoleBottom - lineHeight - 11, borderColour1);
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - lineHeight - 10, _consoleRight, _consoleBottom - lineHeight - 10, borderColour2);
gfx_fill_rect(
dpi, _consoleLeft, _consoleBottom - lineHeight - 11, _consoleRight, _consoleBottom - lineHeight - 11, borderColour1);
gfx_fill_rect(
dpi, _consoleLeft, _consoleBottom - lineHeight - 10, _consoleRight, _consoleBottom - lineHeight - 10, borderColour2);
// Input area bottom border
gfx_fill_rect(dpi, _consoleLeft, _consoleBottom - 1, _consoleRight, _consoleBottom - 1, borderColour1);
@@ -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.
int32_t InGameConsole::GetNumVisibleLines() const
{
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t consoleHeight = _consoleBottom - _consoleTop;
const int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase);
const int32_t consoleHeight = _consoleBottom - _consoleTop;
const int32_t drawableHeight = consoleHeight - 2 * lineHeight - 4; // input line, separator - padding
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_CARET_WIDTH = 6;
bool _isOpen = false;
int32_t _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
int32_t _lastMainViewportX, _lastMainViewportY;
bool _isOpen = false;
int32_t _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
int32_t _lastMainViewportX, _lastMainViewportY;
std::deque<std::string> _consoleLines;
utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE] = {};
int32_t _consoleCaretTicks;
int32_t _consoleScrollPos = 0;
TextInputSession * _consoleTextInputSession;
utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
int32_t _consoleHistoryIndex = 0;
int32_t _consoleHistoryCount = 0;
utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE] = {};
int32_t _consoleCaretTicks;
int32_t _consoleScrollPos = 0;
TextInputSession* _consoleTextInputSession;
utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
int32_t _consoleHistoryIndex = 0;
int32_t _consoleHistoryCount = 0;
public:
InGameConsole();
InGameConsole(const InGameConsole& src) = delete;
bool IsOpen() const { return _isOpen; }
bool IsOpen() const
{
return _isOpen;
}
void Clear() override;
void Open();
void Close() override;
void Hide() override;
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 RefreshCaret();
void Scroll(int32_t linesToScroll);
void Update();
void Draw(rct_drawpixelinfo * dpi) const;
void Draw(rct_drawpixelinfo* dpi) const;
private:
void ClearInput();
void ClearLine();
void HistoryAdd(const utf8 * src);
void HistoryAdd(const utf8* src);
void WritePrompt();
void ScrollToEnd();
void Invalidate() const;

View File

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

View File

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

View File

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

View File

@@ -12,36 +12,37 @@
#include <openrct2/common.h>
#include <openrct2/interface/Window.h>
enum {
UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,
UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT = 1 << 3,
UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR = 1 << 4,
enum
{
UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,
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_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_load_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_config_name(size_t index);
const utf8 * theme_manager_get_available_theme_name(size_t index);
size_t theme_manager_get_active_available_theme_index();
void theme_manager_set_active_available_theme(size_t index);
size_t theme_get_index_for_name(const utf8 * name);
void theme_manager_initialise();
void theme_manager_load_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_config_name(size_t index);
const utf8* theme_manager_get_available_theme_name(size_t index);
size_t theme_manager_get_active_available_theme_index();
void theme_manager_set_active_available_theme(size_t index);
size_t theme_get_index_for_name(const utf8* name);
colour_t theme_get_colour(rct_windowclass wc, uint8_t index);
void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour);
uint8_t theme_get_flags();
void theme_set_flags(uint8_t flags);
void theme_save();
void theme_rename(const utf8 * name);
void theme_duplicate(const utf8 * name);
void theme_delete();
void theme_set_colour(rct_windowclass wc, uint8_t index, colour_t colour);
uint8_t theme_get_flags();
void theme_set_flags(uint8_t flags);
void theme_save();
void theme_rename(const utf8* name);
void theme_duplicate(const utf8* name);
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);

View File

@@ -7,12 +7,17 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <openrct2/core/Math.hpp>
#include "Viewport.h"
#include "Window.h"
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/WallRemoveAction.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
@@ -20,35 +25,31 @@
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Banner.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/LargeScenery.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Scenery.h>
#include <openrct2/world/Sprite.h>
#include <openrct2/world/Surface.h>
#include <openrct2/world/Wall.h>
#include <openrct2/Context.h>
#include <openrct2/actions/WallRemoveAction.hpp>
#include "Viewport.h"
#include "Window.h"
static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, int32_t x, int32_t y);
static void viewport_interaction_remove_footpath(rct_tile_element *tileElement, int32_t x, int32_t y);
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_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 rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance);
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_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_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 rct_peep* viewport_interaction_get_closest_peep(int32_t x, int32_t y, int32_t maxDistance);
/**
*
* 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_sprite *sprite;
rct_vehicle *vehicle;
rct_tile_element* tileElement;
rct_sprite* sprite;
rct_vehicle* vehicle;
// 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))
@@ -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;
LocationXY16 mapCoord = {};
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK, &mapCoord.x, &mapCoord.y, &info->type, &info->tileElement, nullptr);
get_map_coordinates_from_pos(
x,
y,
VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK,
&mapCoord.x,
&mapCoord.y,
&info->type,
&info->tileElement,
nullptr);
info->x = mapCoord.x;
info->y = mapCoord.y;
tileElement = info->tileElement;
sprite = (rct_sprite*)tileElement;
switch (info->type) {
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (sprite->unknown.sprite_identifier) {
case SPRITE_IDENTIFIER_VEHICLE:
vehicle = &(sprite->vehicle);
if (vehicle->ride_subtype != 255)
vehicle_set_map_toolbar(vehicle);
else
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (sprite->unknown.sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
vehicle = &(sprite->vehicle);
if (vehicle->ride_subtype != 255)
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;
case SPRITE_IDENTIFIER_PEEP:
peep_set_map_tooltip(&sprite->peep);
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;
}
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 (info->type == VIEWPORT_INTERACTION_ITEM_NONE) {
if (info->type == VIEWPORT_INTERACTION_ITEM_NONE)
{
info->peep = viewport_interaction_get_closest_peep(x, y, 32);
if (info->peep == nullptr)
return VIEWPORT_INTERACTION_ITEM_NONE;
@@ -111,13 +123,14 @@ int32_t viewport_interaction_left_over(int32_t x, int32_t y)
{
viewport_interaction_info info;
switch (viewport_interaction_get_item_left(x, y, &info)) {
case VIEWPORT_INTERACTION_ITEM_SPRITE:
case VIEWPORT_INTERACTION_ITEM_RIDE:
case VIEWPORT_INTERACTION_ITEM_PARK:
return 1;
default:
return 0;
switch (viewport_interaction_get_item_left(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
case VIEWPORT_INTERACTION_ITEM_RIDE:
case VIEWPORT_INTERACTION_ITEM_PARK:
return 1;
default:
return 0;
}
}
@@ -125,49 +138,60 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y)
{
viewport_interaction_info info;
switch (viewport_interaction_get_item_left(x, y, &info)) {
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (info.sprite->unknown.sprite_identifier) {
case SPRITE_IDENTIFIER_VEHICLE:
{
auto intent = Intent(WD_VEHICLE);
intent.putExtra(INTENT_EXTRA_VEHICLE, info.vehicle);
context_open_intent(&intent);
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);
switch (viewport_interaction_get_item_left(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (info.sprite->unknown.sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
{
auto intent = Intent(WD_VEHICLE);
intent.putExtra(INTENT_EXTRA_VEHICLE, info.vehicle);
context_open_intent(&intent);
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_RIDE:
{
auto intent = Intent(WD_TRACK);
intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.tileElement);
context_open_intent(&intent);
return true;
}
case VIEWPORT_INTERACTION_ITEM_PARK:
context_open_window(WC_PARK_INFORMATION);
return 1;
default:
return 0;
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
*/
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_scenery_entry *sceneryEntry;
rct_banner *banner;
Ride *ride;
rct_tile_element* tileElement;
rct_scenery_entry* sceneryEntry;
rct_banner* banner;
Ride* ride;
int32_t i, stationIndex;
// 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;
LocationXY16 mapCoord = {};
get_map_coordinates_from_pos(x, y, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), &mapCoord.x, &mapCoord.y, &info->type, &info->tileElement, nullptr);
get_map_coordinates_from_pos(
x,
y,
~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER),
&mapCoord.x,
&mapCoord.y,
&info->type,
&info->tileElement,
nullptr);
info->x = mapCoord.x;
info->y = mapCoord.y;
tileElement = info->tileElement;
switch (info->type) {
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
tileElement += 6;
ride = get_ride(tileElement->type);
if (ride->status == RIDE_STATUS_CLOSED) {
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)) {
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
tileElement += 6;
ride = get_ride(tileElement->type);
if (ride->status == RIDE_STATUS_CLOSED)
{
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, uint32_t, ride->name_arguments);
set_map_tooltip_format_arg(4, rct_string_id, ride->name);
set_map_tooltip_format_arg(6, uint32_t, ride->name_arguments);
set_map_tooltip_format_arg(
10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);
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;
}
set_map_tooltip_format_arg(4, rct_string_id, ride->name);
set_map_tooltip_format_arg(6, uint32_t, ride->name_arguments);
set_map_tooltip_format_arg(10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);
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(2, rct_string_id, sceneryEntry->name);
return info->type;
}
break;
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;
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);
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(2, rct_string_id, sceneryEntry->name);
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 (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr) {
if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE)))
{
if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr)
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
}
switch (info->type) {
case VIEWPORT_INTERACTION_ITEM_SCENERY:
sceneryEntry = get_small_scenery_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
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 {
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SCENERY:
sceneryEntry = get_small_scenery_entry(tileElement->properties.scenery.type);
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
}
return info->type;
return info->type;
case VIEWPORT_INTERACTION_ITEM_PARK:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
break;
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;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
break;
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);
}
return info->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, STR_OBJECT_SELECTION_PARK_ENTRANCE);
return info->type;
case VIEWPORT_INTERACTION_ITEM_PARK:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
break;
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;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
break;
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;
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_OBJECT_SELECTION_PARK_ENTRANCE);
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;
@@ -370,41 +431,42 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
CoordsXYE tileElement;
viewport_interaction_info info;
switch (viewport_interaction_get_item_right(x, y, &info)) {
case VIEWPORT_INTERACTION_ITEM_NONE:
return 0;
switch (viewport_interaction_get_item_right(x, y, &info))
{
case VIEWPORT_INTERACTION_ITEM_NONE:
return 0;
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if (info.sprite->unknown.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE)
ride_construct(info.sprite->vehicle.ride);
break;
case VIEWPORT_INTERACTION_ITEM_RIDE:
tileElement.x = info.x;
tileElement.y = info.y;
tileElement.element = info.tileElement;
ride_modify(&tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_SCENERY:
viewport_interaction_remove_scenery(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
viewport_interaction_remove_footpath(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
viewport_interaction_remove_footpath_item(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
viewport_interaction_remove_park_entrance(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_WALL:
viewport_interaction_remove_park_wall(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
viewport_interaction_remove_large_scenery(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
context_open_detail_window(WD_BANNER, info.tileElement->properties.banner.index);
break;
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if (info.sprite->unknown.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE)
ride_construct(info.sprite->vehicle.ride);
break;
case VIEWPORT_INTERACTION_ITEM_RIDE:
tileElement.x = info.x;
tileElement.y = info.y;
tileElement.element = info.tileElement;
ride_modify(&tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_SCENERY:
viewport_interaction_remove_scenery(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
viewport_interaction_remove_footpath(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
viewport_interaction_remove_footpath_item(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
viewport_interaction_remove_park_entrance(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_WALL:
viewport_interaction_remove_park_wall(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
viewport_interaction_remove_large_scenery(info.tileElement, info.x, info.y);
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
context_open_detail_window(WD_BANNER, info.tileElement->properties.banner.index);
break;
}
return 1;
@@ -414,7 +476,7 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
*
* 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;
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,
GAME_COMMAND_REMOVE_SCENERY,
0,
0
);
0);
}
/**
*
* 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;
rct_window *w;
rct_tile_element *tileElement2;
rct_window* w;
rct_tile_element* tileElement2;
z = tileElement->base_height;
@@ -445,8 +506,10 @@ static void viewport_interaction_remove_footpath(rct_tile_element *tileElement,
footpath_provisional_update();
tileElement2 = map_get_first_element_at(x / 32, y / 32);
do {
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z) {
do
{
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z)
{
gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE;
footpath_remove(x, y, z, GAME_COMMAND_FLAG_APPLY);
break;
@@ -458,7 +521,7 @@ static void viewport_interaction_remove_footpath(rct_tile_element *tileElement,
*
* 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;
@@ -474,26 +537,26 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElem
(type << 8) | tileElement->base_height,
GAME_COMMAND_PLACE_PATH,
0,
0
);
0);
}
/**
*
* 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);
switch (tileElement->properties.entrance.index & 0x0F) {
case 1:
x += CoordsDirectionDelta[rotation].x;
y += CoordsDirectionDelta[rotation].y;
break;
case 2:
x -= CoordsDirectionDelta[rotation].x;
y -= CoordsDirectionDelta[rotation].y;
break;
switch (tileElement->properties.entrance.index & 0x0F)
{
case 1:
x += CoordsDirectionDelta[rotation].x;
y += CoordsDirectionDelta[rotation].y;
break;
case 2:
x -= CoordsDirectionDelta[rotation].x;
y -= CoordsDirectionDelta[rotation].y;
break;
}
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);
@@ -503,9 +566,9 @@ void viewport_interaction_remove_park_entrance(rct_tile_element *tileElement, in
*
* 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)
{
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
*/
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)
{
BannerIndex bannerIndex = scenery_large_get_banner_id(tileElement);
context_open_detail_window(WD_SIGN, bannerIndex);
} else {
}
else
{
gGameCommandErrorTitle = STR_CANT_REMOVE_THIS;
game_do_command(
x,
@@ -539,17 +604,16 @@ static void viewport_interaction_remove_large_scenery(rct_tile_element *tileElem
tileElement->base_height | (scenery_large_get_sequence(tileElement) << 8),
GAME_COMMAND_REMOVE_LARGE_SCENERY,
0,
0
);
0);
}
}
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;
uint16_t spriteIndex;
rct_window *w;
rct_viewport *viewport;
rct_window* w;
rct_viewport* viewport;
rct_peep *peep, *closestPeep;
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;
closestDistance = 0xFFFF;
FOR_ALL_PEEPS(spriteIndex, peep) {
FOR_ALL_PEEPS (spriteIndex, peep)
{
if (peep->sprite_left == LOCATION_NULL)
continue;
distance =
abs(((peep->sprite_left + peep->sprite_right) / 2) - x) +
abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
distance
= abs(((peep->sprite_left + peep->sprite_right) / 2) - x) + abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y);
if (distance > maxDistance)
continue;
if (distance < closestDistance) {
if (distance < closestDistance)
{
closestPeep = peep;
closestDistance = distance;
}
@@ -588,30 +653,42 @@ static rct_peep *viewport_interaction_get_closest_peep(int32_t x, int32_t y, int
*
* 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;
int32_t interactionType;
rct_tile_element *myTileElement;
rct_viewport *viewport;
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, &my_x, &my_y, &interactionType, &myTileElement, &viewport);
rct_tile_element* myTileElement;
rct_viewport* viewport;
get_map_coordinates_from_pos(
screenX,
screenY,
VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER,
&my_x,
&my_y,
&interactionType,
&myTileElement,
&viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{
*x = LOCATION_NULL;
return;
}
int16_t originalZ = 0;
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER)
{
originalZ = surface_get_water_height(myTileElement) << 4;
}
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(viewport, screenX, screenY);
LocationXY16 map_pos = { (int16_t)(my_x + 16), (int16_t)(my_y + 16) };
for (int32_t i = 0; i < 5; i++) {
for (int32_t i = 0; i < 5; i++)
{
int16_t z = originalZ;
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER) {
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER)
{
z = tile_element_height(map_pos.x, map_pos.y);
}
map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
@@ -623,22 +700,33 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t *x, int16_t *y, int32_
int32_t myDirection;
int32_t mod_x = map_pos.x & 0x1F;
int32_t mod_y = map_pos.y & 0x1F;
if (mod_x < mod_y) {
if (mod_x + mod_y < 32) {
if (mod_x < mod_y)
{
if (mod_x + mod_y < 32)
{
myDirection = 0;
} else {
}
else
{
myDirection = 1;
}
} else {
if (mod_x + mod_y < 32) {
}
else
{
if (mod_x + mod_y < 32)
{
myDirection = 3;
} else {
}
else
{
myDirection = 2;
}
}
*x = map_pos.x & ~0x1F;
*y = map_pos.y & ~0x1F;
if (direction != nullptr) *direction = myDirection;
if (tileElement != nullptr) *tileElement = myTileElement;
if (direction != nullptr)
*direction = myDirection;
if (tileElement != nullptr)
*tileElement = myTileElement;
}

View File

@@ -7,97 +7,102 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "Widget.h"
#include "Window.h"
#include <algorithm>
#include <cmath>
#include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include "Widget.h"
#include "Window.h"
static void widget_frame_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
static void widget_resize_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
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_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_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_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_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_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_draw_image(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_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_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_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_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_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_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_closebox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_scroll_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
static void widget_hscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_vscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour);
static void widget_draw_image(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex);
/**
*
* 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) {
case WWT_EMPTY:
break;
case WWT_FRAME:
widget_frame_draw(dpi, w, widgetIndex);
break;
case WWT_RESIZE:
widget_resize_draw(dpi, w, widgetIndex);
break;
case WWT_IMGBTN:
widget_button_draw(dpi, w, widgetIndex);
break;
case WWT_COLOURBTN:
case WWT_TRNBTN:
case WWT_TAB:
widget_tab_draw(dpi, w, widgetIndex);
break;
case WWT_FLATBTN:
widget_flat_button_draw(dpi, w, widgetIndex);
break;
case WWT_BUTTON:
case WWT_TABLE_HEADER:
widget_text_button(dpi, w, widgetIndex);
break;
case WWT_LABEL_CENTRED:
widget_text_centred(dpi, w, widgetIndex);
break;
case WWT_LABEL:
widget_text(dpi, w, widgetIndex);
break;
case WWT_SPINNER:
case WWT_DROPDOWN:
case WWT_VIEWPORT:
widget_text_inset(dpi, w, widgetIndex);
break;
case WWT_GROUPBOX:
widget_groupbox_draw(dpi, w, widgetIndex);
break;
case WWT_CAPTION:
widget_caption_draw(dpi, w, widgetIndex);
break;
case WWT_CLOSEBOX:
widget_closebox_draw(dpi, w, widgetIndex);
break;
case WWT_SCROLL:
widget_scroll_draw(dpi, w, widgetIndex);
break;
case WWT_CHECKBOX:
widget_checkbox_draw(dpi, w, widgetIndex);
break;
case WWT_PLACEHOLDER:
break;
case WWT_TEXT_BOX:
widget_text_box_draw(dpi, w, widgetIndex);
break;
switch (w->widgets[widgetIndex].type)
{
case WWT_EMPTY:
break;
case WWT_FRAME:
widget_frame_draw(dpi, w, widgetIndex);
break;
case WWT_RESIZE:
widget_resize_draw(dpi, w, widgetIndex);
break;
case WWT_IMGBTN:
widget_button_draw(dpi, w, widgetIndex);
break;
case WWT_COLOURBTN:
case WWT_TRNBTN:
case WWT_TAB:
widget_tab_draw(dpi, w, widgetIndex);
break;
case WWT_FLATBTN:
widget_flat_button_draw(dpi, w, widgetIndex);
break;
case WWT_BUTTON:
case WWT_TABLE_HEADER:
widget_text_button(dpi, w, widgetIndex);
break;
case WWT_LABEL_CENTRED:
widget_text_centred(dpi, w, widgetIndex);
break;
case WWT_LABEL:
widget_text(dpi, w, widgetIndex);
break;
case WWT_SPINNER:
case WWT_DROPDOWN:
case WWT_VIEWPORT:
widget_text_inset(dpi, w, widgetIndex);
break;
case WWT_GROUPBOX:
widget_groupbox_draw(dpi, w, widgetIndex);
break;
case WWT_CAPTION:
widget_caption_draw(dpi, w, widgetIndex);
break;
case WWT_CLOSEBOX:
widget_closebox_draw(dpi, w, widgetIndex);
break;
case WWT_SCROLL:
widget_scroll_draw(dpi, w, widgetIndex);
break;
case WWT_CHECKBOX:
widget_checkbox_draw(dpi, w, widgetIndex);
break;
case WWT_PLACEHOLDER:
break;
case WWT_TEXT_BOX:
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
*/
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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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
*/
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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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
*/
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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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;
// Check if the button is pressed down
uint8_t press = widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press
= widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
// Get the colour
uint8_t colour = w->colours[widget->colour];
if ((int32_t)widget->image == -2) {
if ((int32_t)widget->image == -2)
{
// Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE);
return;
@@ -207,16 +214,17 @@ static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
if ((int32_t)widget->image == -1)
return;
// Draw widgets that aren't explicitly disabled.
if (!widget_is_disabled(w, widgetIndex)) {
if (!widget_is_disabled(w, widgetIndex))
{
widget_draw_image(dpi, w, widgetIndex);
return;
}
@@ -225,7 +233,8 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
if (widget->type == WWT_TAB && widget->image != (IMAGE_TYPE_REMAP | SPR_G2_TAB_DISABLED))
return;
if (widget->type != WWT_TRNBTN) {
if (widget->type != WWT_TRNBTN)
{
widget_draw_image(dpi, w, widgetIndex);
return;
}
@@ -246,15 +255,16 @@ static void widget_tab_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetind
*
* 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);
return;
}
// Get the widget
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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];
// Check if the button is pressed down
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) {
if ((int32_t)widget->image == -2) {
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
{
if ((int32_t)widget->image == -2)
{
// Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE);
return;
@@ -285,10 +297,10 @@ static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_w
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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];
// Border
uint8_t press = widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press
= widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press);
// Button caption
@@ -318,10 +331,10 @@ static void widget_text_button(rct_drawpixelinfo *dpi, rct_window *w, rct_widget
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
if (widget->text == STR_NONE)
return;
@@ -349,24 +362,17 @@ static void widget_text_centred(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
t = w->y + widget->top;
gfx_draw_string_centred_clipped(
dpi,
widget->text,
gCommonFormatArgs,
colour,
(l + r + 1) / 2 - 1,
t,
widget->right - widget->left - 2
);
dpi, widget->text, gCommonFormatArgs, colour, (l + r + 1) / 2 - 1, t, widget->right - widget->left - 2);
}
/**
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
if (widget->text == STR_NONE || widget->text == STR_VIEWPORT)
return;
@@ -399,10 +405,10 @@ static void widget_text(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex w
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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
*/
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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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;
// Text
if (widget->text != STR_NONE) {
if (widget->text != STR_NONE)
{
uint8_t colour = w->colours[widget->colour] & 0x7F;
if (widget_is_disabled(w, widgetIndex))
colour |= COLOUR_FLAG_INSET;
@@ -482,10 +489,10 @@ static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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;
t = widget->top + w->y + 1;
int32_t width = widget->right - widget->left - 4;
if ((widget + 1)->type == WWT_CLOSEBOX) {
if ((widget + 1)->type == WWT_CLOSEBOX)
{
width -= 10;
if ((widget + 2)->type == WWT_CLOSEBOX)
width -= 10;
@@ -528,10 +536,10 @@ static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widge
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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
*/
static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex)
* rct2: 0x006EBAD9
*/
static void widget_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex)
{
// Get the widget
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltb
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);
// fill it when checkbox is pressed
if (widget_is_pressed(w, widgetIndex)) {
if (widget_is_pressed(w, widgetIndex))
{
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, NOT_TRANSLUCENT(colour), l, yMid - 5);
}
@@ -595,7 +604,8 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
if (widget->text == STR_NONE)
return;
if (widget_is_disabled(w, widgetIndex)) {
if (widget_is_disabled(w, widgetIndex))
{
colour |= COLOUR_FLAG_INSET;
}
@@ -606,11 +616,11 @@ static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
*
* 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
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];
// 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);
}
static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
static void widget_hscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
{
colour &= 0x7F;
// Trough
@@ -685,21 +696,28 @@ static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
gfx_fill_rect(dpi, l + 10, t + 8, r - 10, t + 8, ColourMapA[colour].lighter);
// Left button
gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, ((scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, t, l + 9, b, colour, ((scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t);
// Thumb
gfx_fill_rect_inset(dpi,
std::max(l + 10, l + scroll->h_thumb_left - 1), t,
std::min(r - 10, l + scroll->h_thumb_right - 1), b,
colour, ((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi,
std::max(l + 10, l + scroll->h_thumb_left - 1),
t,
std::min(r - 10, l + scroll->h_thumb_right - 1),
b,
colour,
((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
// Right button
gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, ((scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, r - 9, t, r, b, colour, ((scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackRightArrowString, COLOUR_BLACK, r - 6, t);
}
static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
static void widget_vscrollbar_draw(
rct_drawpixelinfo* dpi, rct_scroll* scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour)
{
colour &= 0x7F;
// Trough
@@ -711,17 +729,23 @@ static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
gfx_fill_rect(dpi, l + 8, t + 10, l + 8, b - 10, ColourMapA[colour].lighter);
// Up button
gfx_fill_rect_inset(dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1);
// Thumb
gfx_fill_rect_inset(dpi,
l, std::max(t + 10, t + scroll->v_thumb_top - 1),
r, std::min(b - 10, t + scroll->v_thumb_bottom - 1),
colour, ((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi,
l,
std::max(t + 10, t + scroll->v_thumb_top - 1),
r,
std::min(b - 10, t + scroll->v_thumb_bottom - 1),
colour,
((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
// Down button
gfx_fill_rect_inset(dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_fill_rect_inset(
dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9);
}
@@ -729,10 +753,10 @@ static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
*
* 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
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Get the 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))
image++;
if (widget_is_disabled(w, widgetIndex)) {
if (widget_is_disabled(w, widgetIndex))
{
// Draw greyed out (light border bottom right shadow)
colour = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].lighter;
@@ -760,8 +785,11 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgeti
colour = w->colours[widget->colour];
colour = ColourMapA[NOT_TRANSLUCENT(colour)].mid_light;
gfx_draw_sprite_solid(dpi, image, l, t, colour);
} else {
if (image & IMAGE_TYPE_REMAP_2_PLUS) {
}
else
{
if (image & IMAGE_TYPE_REMAP_2_PLUS)
{
// ?
}
@@ -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;
}
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;
}
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;
}
if (input_get_state() == INPUT_STATE_WIDGET_PRESSED || input_get_state() == INPUT_STATE_DROPDOWN_ACTIVE) {
if (!(input_test_flag(INPUT_FLAG_WIDGET_PRESSED))) return false;
if (gPressedWidget.window_classification != w->classification) return false;
if (gPressedWidget.window_number != w->number) return false;
if (gPressedWidget.widget_index != widgetIndex) return false;
if (input_get_state() == INPUT_STATE_WIDGET_PRESSED || input_get_state() == INPUT_STATE_DROPDOWN_ACTIVE)
{
if (!(input_test_flag(INPUT_FLAG_WIDGET_PRESSED)))
return false;
if (gPressedWidget.window_classification != w->classification)
return false;
if (gPressedWidget.window_number != w->number)
return false;
if (gPressedWidget.widget_index != widgetIndex)
return false;
return true;
}
return false;
}
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_number != w->number) return false;
if (gHoverWidget.widget_index != widgetIndex) return false;
if (gHoverWidget.window_classification != w->classification)
return false;
if (gHoverWidget.window_number != w->number)
return false;
if (gHoverWidget.widget_index != widgetIndex)
return false;
return true;
}
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)))
return false;
@@ -831,7 +868,15 @@ bool widget_is_active_tool(rct_window *w, rct_widgetindex widgetIndex)
* esi: w
* edi: widget
*/
void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_t y, int32_t *output_x, int32_t *output_y, int32_t *output_scroll_area, int32_t *scroll_id)
void widget_scroll_get_part(
rct_window* w,
rct_widget* widget,
int32_t x,
int32_t y,
int32_t* output_x,
int32_t* output_y,
int32_t* output_scroll_area,
int32_t* scroll_id)
{
rct_widget* iterator = w->widgets;
*scroll_id = 0;
@@ -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;
}
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;
}
@@ -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;
}
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;
}
@@ -918,7 +963,7 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int32_t x, int32_
}
else
{
//view
// view
*output_scroll_area = SCROLL_PART_VIEW;
*output_x = x - widget->left;
*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->disabled_widgets &= ~(1ULL << widgetIndex);
}
else {
else
{
w->enabled_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)
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);
}
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 font_height = 0;
char wrapped_string[TEXT_INPUT_SIZE];
// Get the widget
rct_widget *widget = &w->widgets[widgetIndex];
rct_widget* widget = &w->widgets[widgetIndex];
// Resolve the absolute ltrb
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
uint8_t colour = w->colours[widget->colour];
bool active = w->classification == gCurrentTextBox.window.classification &&
w->number == gCurrentTextBox.window.number &&
widgetIndex == gCurrentTextBox.widget_index;
bool active = w->classification == gCurrentTextBox.window.classification && w->number == gCurrentTextBox.window.number
&& widgetIndex == gCurrentTextBox.widget_index;
//gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00));
// gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00));
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_F_60);
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gCurrentFontFlags = 0;
if (!active || gTextInput == nullptr) {
if (w->widgets[widgetIndex].text != 0) {
if (!active || gTextInput == nullptr)
{
if (w->widgets[widgetIndex].text != 0)
{
safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512);
gfx_wrap_string(wrapped_string, r - l - 5, &no_lines, &font_height);
gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
@@ -994,17 +1041,14 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
return;
}
safe_strcpy(wrapped_string, gTextBoxInput, TEXT_INPUT_SIZE);
// String length needs to add 12 either side of box
// +13 for cursor when max length.
gfx_wrap_string(wrapped_string, r - l - 5 - 6, &no_lines, &font_height);
gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
size_t string_length = get_string_size(wrapped_string) - 1;
// Make a copy of the string for measuring the width.
@@ -1013,7 +1057,8 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
int32_t cur_x = l + gfx_get_string_width(temp_string) + 3;
int32_t width = 6;
if ((uint32_t)gTextInput->SelectionStart < strlen(gTextBoxInput)){
if ((uint32_t)gTextInput->SelectionStart < strlen(gTextBoxInput))
{
// Make a new 1 character wide string for measuring the width
// of the character that the cursor is under.
temp_string[1] = '\0';
@@ -1021,7 +1066,8 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
width = std::max(gfx_get_string_width(temp_string) - 2, 4);
}
if (gTextBoxFrameNo <= 15){
if (gTextBoxFrameNo <= 15)
{
colour = ColourMapA[w->colours[1]].mid_light;
gfx_fill_rect(dpi, cur_x, t + 9, cur_x + width, t + 9, colour + 5);
}

View File

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