Use named casts on openrct2-ui/interface

This commit is contained in:
Tulio Leao 2020-03-28 16:36:51 -03:00
parent 8823658972
commit b579771364
4 changed files with 20 additions and 20 deletions

View file

@ -131,7 +131,7 @@ void InGameConsole::ScrollToEnd()
if (maxLines == 0) if (maxLines == 0)
_consoleScrollPos = 0; _consoleScrollPos = 0;
else else
_consoleScrollPos = std::max<int32_t>(0, (int32_t)_consoleLines.size() - maxLines); _consoleScrollPos = std::max<int32_t>(0, static_cast<int32_t>(_consoleLines.size()) - maxLines);
} }
void InGameConsole::RefreshCaret() void InGameConsole::RefreshCaret()
@ -142,7 +142,7 @@ void InGameConsole::RefreshCaret()
void InGameConsole::Scroll(int32_t linesToScroll) void InGameConsole::Scroll(int32_t linesToScroll)
{ {
const int32_t maxVisibleLines = GetNumVisibleLines(); const int32_t maxVisibleLines = GetNumVisibleLines();
const int32_t numLines = (int32_t)_consoleLines.size(); const int32_t numLines = static_cast<int32_t>(_consoleLines.size());
if (numLines > maxVisibleLines) if (numLines > maxVisibleLines)
{ {
int32_t maxScrollValue = numLines - maxVisibleLines; int32_t maxScrollValue = numLines - maxVisibleLines;
@ -308,7 +308,7 @@ void InGameConsole::Draw(rct_drawpixelinfo* dpi) const
int32_t y = _consoleTop + CONSOLE_EDGE_PADDING; int32_t y = _consoleTop + CONSOLE_EDGE_PADDING;
// Draw text inside console // Draw text inside console
for (std::size_t i = 0; i < _consoleLines.size() && i < (size_t)maxLines; i++) for (std::size_t i = 0; i < _consoleLines.size() && i < static_cast<size_t>(maxLines); i++)
{ {
const size_t index = i + _consoleScrollPos; const size_t index = i + _consoleScrollPos;
lineBuffer = colourFormatStr + _consoleLines[index]; lineBuffer = colourFormatStr + _consoleLines[index];

View file

@ -295,7 +295,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc* wtDesc, c
ThrowThemeLoadException(); ThrowThemeLoadException();
} }
uint8_t numColours = (uint8_t)json_array_size(jsonColours); uint8_t numColours = static_cast<uint8_t>(json_array_size(jsonColours));
numColours = std::min(numColours, wtDesc->NumColours); numColours = std::min(numColours, wtDesc->NumColours);
UIThemeWindowEntry result{}; UIThemeWindowEntry result{};
@ -304,7 +304,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc* wtDesc, c
for (uint8_t i = 0; i < numColours; i++) for (uint8_t i = 0; i < numColours; i++)
{ {
result.Theme.Colours[i] = (colour_t)json_integer_value(json_array_get(jsonColours, i)); result.Theme.Colours[i] = static_cast<colour_t>(json_integer_value(json_array_get(jsonColours, i)));
} }
return result; return result;
@ -571,7 +571,7 @@ namespace ThemeManager
if (theme == nullptr) if (theme == nullptr)
{ {
// Fall-back to default // Fall-back to default
theme = (UITheme*)&PredefinedThemeRCT2; theme = const_cast<UITheme*>(&PredefinedThemeRCT2);
LoadTheme(theme); LoadTheme(theme);
} }
else else
@ -590,7 +590,7 @@ namespace ThemeManager
{ {
if (theme.Path.empty()) if (theme.Path.empty())
{ {
LoadTheme((UITheme*)PredefinedThemes[i].Theme); LoadTheme(const_cast<UITheme*>(PredefinedThemes[i].Theme));
} }
else else
{ {
@ -606,7 +606,7 @@ namespace ThemeManager
static void Initialise() static void Initialise()
{ {
ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes); ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes);
LoadTheme((UITheme*)&PredefinedThemeRCT2); LoadTheme(const_cast<UITheme*>(&PredefinedThemeRCT2));
ActiveAvailableThemeIndex = 1; ActiveAvailableThemeIndex = 1;
bool configValid = false; bool configValid = false;
@ -688,7 +688,7 @@ void theme_manager_set_active_available_theme(size_t index)
{ {
if (index < ThemeManager::NumPredefinedThemes) if (index < ThemeManager::NumPredefinedThemes)
{ {
ThemeManager::LoadTheme((UITheme*)PredefinedThemes[index].Theme); ThemeManager::LoadTheme(const_cast<UITheme*>(PredefinedThemes[index].Theme));
} }
else else
{ {
@ -835,7 +835,7 @@ void theme_duplicate(const utf8* name)
void theme_delete() void theme_delete()
{ {
File::Delete(ThemeManager::CurrentThemePath); File::Delete(ThemeManager::CurrentThemePath);
ThemeManager::LoadTheme((UITheme*)&PredefinedThemeRCT2); ThemeManager::LoadTheme(const_cast<UITheme*>(&PredefinedThemeRCT2));
ThemeManager::ActiveAvailableThemeIndex = 1; ThemeManager::ActiveAvailableThemeIndex = 1;
String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1));
} }

View file

@ -197,7 +197,7 @@ static void widget_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget
// Get the colour // Get the colour
uint8_t colour = w->colours[widget->colour]; uint8_t colour = w->colours[widget->colour];
if ((int32_t)widget->image == -2) if (static_cast<int32_t>(widget->image) == -2)
{ {
// Draw border with no fill // Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE); gfx_fill_rect_inset(dpi, l, t, r, b, colour, press | INSET_RECT_FLAG_FILL_NONE);
@ -219,7 +219,7 @@ static void widget_tab_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetind
// Get the widget // Get the widget
rct_widget* widget = &w->widgets[widgetIndex]; rct_widget* widget = &w->widgets[widgetIndex];
if ((int32_t)widget->image == -1) if (static_cast<int32_t>(widget->image) == -1)
return; return;
// Draw widgets that aren't explicitly disabled. // Draw widgets that aren't explicitly disabled.
@ -278,7 +278,7 @@ static void widget_flat_button_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_w
// Check if the button is pressed down // Check if the button is pressed down
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
{ {
if ((int32_t)widget->image == -2) if (static_cast<int32_t>(widget->image) == -2)
{ {
// Draw border with no fill // Draw border with no fill
gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE); gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE);
@ -603,7 +603,7 @@ static void widget_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg
if (widget_is_pressed(w, widgetIndex)) if (widget_is_pressed(w, widgetIndex))
{ {
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, NOT_TRANSLUCENT(colour), l, yMid - 5); gfx_draw_string(dpi, static_cast<const char*>(CheckBoxMarkString), NOT_TRANSLUCENT(colour), l, yMid - 5);
} }
// draw the text // draw the text
@ -701,7 +701,7 @@ static void widget_hscrollbar_draw(
uint8_t flags = (scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0; uint8_t flags = (scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0;
gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, flags); gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, flags);
gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t); gfx_draw_string(dpi, static_cast<const char*>(BlackLeftArrowString), COLOUR_BLACK, l + 1, t);
} }
// Thumb // Thumb
@ -718,7 +718,7 @@ static void widget_hscrollbar_draw(
uint8_t flags = (scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0; uint8_t flags = (scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0;
gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, flags); gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, flags);
gfx_draw_string(dpi, (char*)BlackRightArrowString, COLOUR_BLACK, r - 6, t); gfx_draw_string(dpi, static_cast<const char*>(BlackRightArrowString), COLOUR_BLACK, r - 6, t);
} }
} }
@ -737,7 +737,7 @@ static void widget_vscrollbar_draw(
// Up button // Up button
gfx_fill_rect_inset( gfx_fill_rect_inset(
dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1); gfx_draw_string(dpi, static_cast<const char*>(BlackUpArrowString), COLOUR_BLACK, l + 1, t - 1);
// Thumb // Thumb
gfx_fill_rect_inset( gfx_fill_rect_inset(
@ -747,7 +747,7 @@ static void widget_vscrollbar_draw(
// Down button // Down button
gfx_fill_rect_inset( gfx_fill_rect_inset(
dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9); gfx_draw_string(dpi, static_cast<const char*>(BlackDownArrowString), COLOUR_BLACK, l + 1, b - 9);
} }
/** /**
@ -1049,7 +1049,7 @@ static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg
int32_t cur_x = l + gfx_get_string_width(temp_string) + 3; int32_t cur_x = l + gfx_get_string_width(temp_string) + 3;
int32_t width = 6; int32_t width = 6;
if ((uint32_t)gTextInput->SelectionStart < strlen(gTextBoxInput)) if (static_cast<uint32_t>(gTextInput->SelectionStart) < strlen(gTextBoxInput))
{ {
// Make a new 1 character wide string for measuring the width // Make a new 1 character wide string for measuring the width
// of the character that the cursor is under. // of the character that the cursor is under.

View file

@ -91,7 +91,7 @@ rct_window* window_create(
{ {
// Check if there are any window slots left // Check if there are any window slots left
// include WINDOW_LIMIT_RESERVED for items such as the main viewport and toolbars to not appear to be counted. // include WINDOW_LIMIT_RESERVED for items such as the main viewport and toolbars to not appear to be counted.
if (g_window_list.size() >= (size_t)(gConfigGeneral.window_limit + WINDOW_LIMIT_RESERVED)) if (g_window_list.size() >= static_cast<size_t>(gConfigGeneral.window_limit + WINDOW_LIMIT_RESERVED))
{ {
// Close least recently used window // Close least recently used window
for (auto& w : g_window_list) for (auto& w : g_window_list)