Merge pull request #11123 from tupaschoal/reduce-c-casts-2

Reduce c-style cast on openrct2-ui/(input/interface/title)
This commit is contained in:
Michael Steenbeek 2020-03-28 22:40:33 +01:00 committed by GitHub
commit 09cd6a82ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 30 deletions

View file

@ -110,7 +110,7 @@ static void game_handle_key_scroll()
static int32_t input_scancode_to_rct_keycode(int32_t sdl_key)
{
char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key);
char keycode = static_cast<char>(SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(sdl_key)));
// Until we reshuffle the text files to use the new positions
// this will suffice to move the majority to the correct positions.

View file

@ -230,14 +230,14 @@ ScreenCoordsXY KeyboardShortcuts::GetKeyboardMapScroll(const uint8_t* keysState)
// Check if SHIFT is either set in the shortcut key and currently pressed,
// or not set in the shortcut key and not currently pressed (in other words: check if they match).
if ((bool)(shortcutKey & SHIFT) != (keysState[SDL_SCANCODE_LSHIFT] || keysState[SDL_SCANCODE_RSHIFT]))
if (static_cast<bool>(shortcutKey & SHIFT) != (keysState[SDL_SCANCODE_LSHIFT] || keysState[SDL_SCANCODE_RSHIFT]))
continue;
if ((bool)(shortcutKey & CTRL) != (keysState[SDL_SCANCODE_LCTRL] || keysState[SDL_SCANCODE_RCTRL]))
if (static_cast<bool>(shortcutKey & CTRL) != (keysState[SDL_SCANCODE_LCTRL] || keysState[SDL_SCANCODE_RCTRL]))
continue;
if ((bool)(shortcutKey & ALT) != (keysState[SDL_SCANCODE_LALT] || keysState[SDL_SCANCODE_RALT]))
if (static_cast<bool>(shortcutKey & ALT) != (keysState[SDL_SCANCODE_LALT] || keysState[SDL_SCANCODE_RALT]))
continue;
#ifdef __MACOSX__
if ((bool)(shortcutKey & CMD) != (keysState[SDL_SCANCODE_LGUI] || keysState[SDL_SCANCODE_RGUI]))
if (static_cast<bool>(shortcutKey & CMD) != (keysState[SDL_SCANCODE_LGUI] || keysState[SDL_SCANCODE_RGUI]))
continue;
#endif
switch (shortcutId)

View file

@ -483,7 +483,7 @@ static void input_window_resize_begin(rct_window* w, rct_widgetindex widgetIndex
static void input_window_resize_continue(rct_window* w, const ScreenCoordsXY& screenCoords)
{
if (screenCoords.y < (int32_t)context_get_height() - 2)
if (screenCoords.y < static_cast<int32_t>(context_get_height()) - 2)
{
auto differentialCoords = screenCoords - gInputDragLast;
int32_t targetWidth = _originalWindowWidth + differentialCoords.x - w->width;
@ -1482,7 +1482,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, con
*/
int32_t get_next_key()
{
uint8_t* keysPressed = (uint8_t*)context_get_keys_pressed();
uint8_t* keysPressed = const_cast<uint8_t*>(context_get_keys_pressed());
for (int32_t i = 0; i < 221; i++)
{
if (keysPressed[i])

View file

@ -131,7 +131,7 @@ void InGameConsole::ScrollToEnd()
if (maxLines == 0)
_consoleScrollPos = 0;
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()
@ -142,7 +142,7 @@ void InGameConsole::RefreshCaret()
void InGameConsole::Scroll(int32_t linesToScroll)
{
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)
{
int32_t maxScrollValue = numLines - maxVisibleLines;
@ -308,7 +308,7 @@ void InGameConsole::Draw(rct_drawpixelinfo* dpi) const
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 < static_cast<size_t>(maxLines); i++)
{
const size_t index = i + _consoleScrollPos;
lineBuffer = colourFormatStr + _consoleLines[index];

View file

@ -295,7 +295,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc* wtDesc, c
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);
UIThemeWindowEntry result{};
@ -304,7 +304,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc* wtDesc, c
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;
@ -571,7 +571,7 @@ namespace ThemeManager
if (theme == nullptr)
{
// Fall-back to default
theme = (UITheme*)&PredefinedThemeRCT2;
theme = const_cast<UITheme*>(&PredefinedThemeRCT2);
LoadTheme(theme);
}
else
@ -590,7 +590,7 @@ namespace ThemeManager
{
if (theme.Path.empty())
{
LoadTheme((UITheme*)PredefinedThemes[i].Theme);
LoadTheme(const_cast<UITheme*>(PredefinedThemes[i].Theme));
}
else
{
@ -606,7 +606,7 @@ namespace ThemeManager
static void Initialise()
{
ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes);
LoadTheme((UITheme*)&PredefinedThemeRCT2);
LoadTheme(const_cast<UITheme*>(&PredefinedThemeRCT2));
ActiveAvailableThemeIndex = 1;
bool configValid = false;
@ -688,7 +688,7 @@ void theme_manager_set_active_available_theme(size_t index)
{
if (index < ThemeManager::NumPredefinedThemes)
{
ThemeManager::LoadTheme((UITheme*)PredefinedThemes[index].Theme);
ThemeManager::LoadTheme(const_cast<UITheme*>(PredefinedThemes[index].Theme));
}
else
{
@ -835,7 +835,7 @@ void theme_duplicate(const utf8* name)
void theme_delete()
{
File::Delete(ThemeManager::CurrentThemePath);
ThemeManager::LoadTheme((UITheme*)&PredefinedThemeRCT2);
ThemeManager::LoadTheme(const_cast<UITheme*>(&PredefinedThemeRCT2));
ThemeManager::ActiveAvailableThemeIndex = 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
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
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
rct_widget* widget = &w->widgets[widgetIndex];
if ((int32_t)widget->image == -1)
if (static_cast<int32_t>(widget->image) == -1)
return;
// 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
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
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))
{
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
@ -701,7 +701,7 @@ static void widget_hscrollbar_draw(
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_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
@ -718,7 +718,7 @@ static void widget_hscrollbar_draw(
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_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
gfx_fill_rect_inset(
dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1);
gfx_draw_string(dpi, static_cast<const char*>(BlackUpArrowString), COLOUR_BLACK, l + 1, t - 1);
// Thumb
gfx_fill_rect_inset(
@ -747,7 +747,7 @@ static void widget_vscrollbar_draw(
// 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_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 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
// 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
// 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
for (auto& w : g_window_list)

View file

@ -222,7 +222,7 @@ private:
void IncrementPosition()
{
_position++;
if (_position >= (int32_t)_sequence->NumCommands)
if (_position >= static_cast<int32_t>(_sequence->NumCommands))
{
_position = 0;
}
@ -250,7 +250,7 @@ private:
case TITLE_SCRIPT_WAIT:
// The waitCounter is measured in 25-ms game ticks. Previously it was seconds * 40 ticks/second, now it is ms /
// 25 ms/tick
_waitCounter = std::max<int32_t>(1, command->Milliseconds / (uint32_t)GAME_UPDATE_TIME_MS);
_waitCounter = std::max<int32_t>(1, command->Milliseconds / static_cast<uint32_t>(GAME_UPDATE_TIME_MS));
break;
case TITLE_SCRIPT_LOCATION:
{
@ -280,7 +280,7 @@ private:
TitleSequenceParkHandle* parkHandle = TitleSequenceGetParkHandle(_sequence, saveIndex);
if (parkHandle != nullptr)
{
loadSuccess = LoadParkFromStream((IStream*)parkHandle->Stream, parkHandle->HintPath);
loadSuccess = LoadParkFromStream(static_cast<IStream*>(parkHandle->Stream), parkHandle->HintPath);
TitleSequenceCloseParkHandle(parkHandle);
}
if (!loadSuccess)