From 648c7fbc26c331504484a830d9416619f94a9fcd Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Wed, 5 Mar 2025 17:05:09 +0100 Subject: [PATCH] RMG-Input: use c++ style casts instead of c style casts --- Source/RMG-Input/UserInterface/MainDialog.cpp | 30 ++++++++--------- .../Widget/ControllerImageWidget.cpp | 10 +++--- .../Widget/ControllerImageWidget.hpp | 2 +- .../UserInterface/Widget/ControllerWidget.cpp | 32 +++++++++---------- .../UserInterface/Widget/HotkeyButton.cpp | 2 +- .../UserInterface/Widget/MappingButton.cpp | 2 +- Source/RMG-Input/VRU.cpp | 2 +- Source/RMG-Input/main.cpp | 18 +++++------ 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/Source/RMG-Input/UserInterface/MainDialog.cpp b/Source/RMG-Input/UserInterface/MainDialog.cpp index d7eb34a9..c8ec9456 100644 --- a/Source/RMG-Input/UserInterface/MainDialog.cpp +++ b/Source/RMG-Input/UserInterface/MainDialog.cpp @@ -69,12 +69,12 @@ MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread, bool romCo // so we only have to expose it there if (controllerWidget == this->controllerWidgets.last()) { - controllerWidget->AddInputDevice({"Voice Recognition Unit", "", "", (int)InputDeviceType::EmulateVRU}); + controllerWidget->AddInputDevice({"Voice Recognition Unit", "", "", static_cast(InputDeviceType::EmulateVRU)}); } #endif // VRU - controllerWidget->AddInputDevice({"None", "", "", (int)InputDeviceType::None}); - controllerWidget->AddInputDevice({"Automatic", "", "", (int)InputDeviceType::Automatic}); - controllerWidget->AddInputDevice({"Keyboard", "", "", (int)InputDeviceType::Keyboard}); + controllerWidget->AddInputDevice({"None", "", "", static_cast(InputDeviceType::None)}); + controllerWidget->AddInputDevice({"Automatic", "", "", static_cast(InputDeviceType::Automatic)}); + controllerWidget->AddInputDevice({"Keyboard", "", "", static_cast(InputDeviceType::Keyboard)}); controllerWidget->SetInitialized(true); } @@ -114,9 +114,9 @@ void MainDialog::openInputDevice(SDLDevice device) controllerWidget = this->controllerWidgets.at(this->tabWidget->currentIndex()); // we don't need to open a keyboard or VRU - if (device.number == (int)InputDeviceType::None || - device.number == (int)InputDeviceType::Keyboard || - device.number == (int)InputDeviceType::EmulateVRU) + if (device.number == static_cast(InputDeviceType::None) || + device.number == static_cast(InputDeviceType::Keyboard) || + device.number == static_cast(InputDeviceType::EmulateVRU)) { this->currentDevice = { "", "", "", device.number }; controllerWidget->SetCurrentJoystickID(this->currentDevice.number); @@ -125,7 +125,7 @@ void MainDialog::openInputDevice(SDLDevice device) } // handle automatic mode - if (device.number == (int)InputDeviceType::Automatic) + if (device.number == static_cast(InputDeviceType::Automatic)) { int currentIndex = this->tabWidget->currentIndex(); if (currentIndex < this->inputDeviceList.size()) @@ -134,7 +134,7 @@ void MainDialog::openInputDevice(SDLDevice device) } else { // no device found, fallback to keyboard - this->currentDevice = { "", "", "", (int)InputDeviceType::Keyboard }; + this->currentDevice = { "", "", "", static_cast(InputDeviceType::Keyboard) }; controllerWidget->SetCurrentJoystickID(this->currentDevice.number); controllerWidget->SetCurrentJoystick(nullptr, nullptr); return; @@ -238,9 +238,9 @@ void MainDialog::on_ControllerWidget_CurrentInputDeviceChanged(ControllerWidget* this->closeInputDevice(); // only open device when needed - if (device.number != (int)InputDeviceType::None && - device.number != (int)InputDeviceType::Keyboard && - device.number != (int)InputDeviceType::EmulateVRU) + if (device.number != static_cast(InputDeviceType::None) && + device.number != static_cast(InputDeviceType::Keyboard) && + device.number != static_cast(InputDeviceType::EmulateVRU)) { this->openInputDevice(device); } @@ -303,9 +303,9 @@ void MainDialog::on_tabWidget_currentChanged(int index) controllerWidget->GetCurrentInputDevice(device); // only open device when needed - if (device.number != (int)InputDeviceType::None && - device.number != (int)InputDeviceType::Keyboard && - device.number != (int)InputDeviceType::EmulateVRU) + if (device.number != static_cast(InputDeviceType::None) && + device.number != static_cast(InputDeviceType::Keyboard) && + device.number != static_cast(InputDeviceType::EmulateVRU)) { this->openInputDevice(device); } diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp index 63377be5..c92e5be4 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp @@ -28,9 +28,9 @@ ControllerImageWidget::~ControllerImageWidget() void ControllerImageWidget::SetButtonState(enum N64ControllerButton button, bool state) { - if (this->buttonState[(int)button] != state) + if (this->buttonState[static_cast(button)] != state) { - this->buttonState[(int)button] = state; + this->buttonState[static_cast(button)] = state; this->needImageUpdate = true; } } @@ -74,7 +74,7 @@ void ControllerImageWidget::SetSensitivity(int value) void ControllerImageWidget::ClearControllerState() { // reset button state - for (int i = 0; i < (int)N64ControllerButton::Invalid; i++) + for (int i = 0; i < static_cast(N64ControllerButton::Invalid); i++) { if (this->buttonState[i]) { @@ -149,7 +149,7 @@ void ControllerImageWidget::paintEvent(QPaintEvent *event) // when the button is pressed for (auto& button : buttons) { - if (this->buttonState[(int)button.button]) + if (this->buttonState[static_cast(button.button)]) { renderer.load(button.imageUri); renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatio); @@ -166,7 +166,7 @@ void ControllerImageWidget::paintEvent(QPaintEvent *event) const int height = rectF.height(); // we'll move the analog stick by a percentage // of the total width/height from the image - const double absoluteMaxOffset = ((double)(height * 0.12265f) / 2); + const double absoluteMaxOffset = (static_cast(height * 0.12265f) / 2); // slope as in line gradient const double offsetSlope = absoluteMaxOffset / 100; // take sensitivity into account diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.hpp index af4772e7..85997d73 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.hpp @@ -24,7 +24,7 @@ class ControllerImageWidget : public QWidget private: // button state - bool buttonState[(int)N64ControllerButton::Invalid] = {0}; + bool buttonState[static_cast(N64ControllerButton::Invalid)] = {0}; // x axis state, -100-100 int xAxisState = 0; // y axis state, -100-100 diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index c67e2144..be8287b0 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -247,8 +247,8 @@ bool ControllerWidget::isCurrentDeviceKeyboard() { SDLDevice device = this->inputDeviceComboBox->currentData().value(); - return device.number == (int)InputDeviceType::Automatic || - device.number == (int)InputDeviceType::Keyboard; + return device.number == static_cast(InputDeviceType::Automatic) || + device.number == static_cast(InputDeviceType::Keyboard); } bool ControllerWidget::isCurrentDeviceNotFound() @@ -283,7 +283,7 @@ void ControllerWidget::enableAllChildren() continue; } - QWidget* widget = (QWidget*)object; + QWidget* widget = static_cast(object); if (!widget->isEnabled()) { widget->setEnabled(true); @@ -314,9 +314,9 @@ void ControllerWidget::removeDuplicates(MappingButton* button) for (size_t i = 0; i < inputType.size(); i++) { - if (buttonWidget->HasInputData((InputType)inputType.at(i), inputData.at(i), extraInputData.at(i))) + if (buttonWidget->HasInputData(static_cast(inputType.at(i)), inputData.at(i), extraInputData.at(i))) { - buttonWidget->RemoveInputData((InputType)inputType.at(i), inputData.at(i), extraInputData.at(i)); + buttonWidget->RemoveInputData(static_cast(inputType.at(i)), inputData.at(i), extraInputData.at(i)); } } } @@ -506,7 +506,7 @@ void ControllerWidget::showErrorMessage(QString text, QString details) void ControllerWidget::AddInputDevice(SDLDevice device) { - QString deviceName = QString::fromStdString(device.name); + QString deviceName = QString::fromStdString(device.name); QString name = deviceName; if (device.number >= 0) @@ -572,9 +572,9 @@ void ControllerWidget::CheckInputDeviceSettings(QString sectionQString) } // account for old setting - if (!isPluggedIn && deviceNum != (int)InputDeviceType::None) + if (!isPluggedIn && deviceNum != static_cast(InputDeviceType::None)) { - device = { "None", "", "", (int)InputDeviceType::None }; + device = { "None", "", "", static_cast(InputDeviceType::None) }; } // clear (not found) devices first @@ -624,7 +624,7 @@ void ControllerWidget::CheckInputDeviceSettings(QString sectionQString) this->inputDeviceComboBox->setCurrentIndex(deviceIndex); // force-refresh automatic input device - if (deviceNum == (int)InputDeviceType::Automatic) + if (deviceNum == static_cast(InputDeviceType::Automatic)) { this->on_inputDeviceComboBox_currentIndexChanged(deviceIndex); } @@ -732,8 +732,8 @@ void ControllerWidget::on_inputDeviceComboBox_currentIndexChanged(int value) } // set plugged in state - this->setPluggedIn(device.number != (int)InputDeviceType::None && - device.number != (int)InputDeviceType::EmulateVRU); + this->setPluggedIn(device.number != static_cast(InputDeviceType::None) && + device.number != static_cast(InputDeviceType::EmulateVRU)); emit this->CurrentInputDeviceChanged(this, device); } @@ -883,7 +883,7 @@ void ControllerWidget::on_resetButton_clicked() void ControllerWidget::on_optionsButton_clicked() { SDLDevice device = this->inputDeviceComboBox->currentData().value(); - bool isKeyboard = device.number == (int)InputDeviceType::Keyboard; + bool isKeyboard = device.number == static_cast(InputDeviceType::Keyboard); OptionsDialog dialog(this, this->optionsDialogSettings, isKeyboard ? nullptr : this->currentJoystick, @@ -1329,7 +1329,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event) { if (joystick.buttonWidget->HasInputData(inputType, sdlAxis, sdlAxisDirection)) { - const int value = -(double)((double)sdlAxisValue / SDL_AXIS_PEAK * 100); + const int value = -(static_cast(sdlAxisValue) / SDL_AXIS_PEAK * 100); switch (joystick.direction) { @@ -1451,7 +1451,7 @@ void ControllerWidget::on_MainDialog_SdlEventPollFinished() bool ControllerWidget::IsPluggedIn() { - return this->inputDeviceComboBox->currentData().toInt() != (int)InputDeviceType::None; + return this->inputDeviceComboBox->currentData().toInt() != static_cast(InputDeviceType::None); } void ControllerWidget::SetOnlyLoadGameProfile(bool value, CoreRomHeader romHeader, CoreRomSettings romSettings) @@ -1712,7 +1712,7 @@ void ControllerWidget::SaveDefaultSettings() CoreSettingsSetValue(SettingsID::Input_PluggedIn, section, false); CoreSettingsSetValue(SettingsID::Input_DeviceName, section, std::string("None")); - CoreSettingsSetValue(SettingsID::Input_DeviceNum, section, (int)InputDeviceType::None); + CoreSettingsSetValue(SettingsID::Input_DeviceNum, section, static_cast(InputDeviceType::None)); CoreSettingsSetValue(SettingsID::Input_DevicePath, section, std::string("")); CoreSettingsSetValue(SettingsID::Input_DeviceSerial, section, std::string("")); CoreSettingsSetValue(SettingsID::Input_Deadzone, section, 9); @@ -1724,7 +1724,7 @@ void ControllerWidget::SaveDefaultSettings() for (auto& buttonSetting : this->buttonSettingMappings) { - CoreSettingsSetValue(buttonSetting.inputTypeSettingsId, section, std::vector({ (int)InputType::Invalid })); + CoreSettingsSetValue(buttonSetting.inputTypeSettingsId, section, std::vector({ static_cast(InputType::Invalid) })); CoreSettingsSetValue(buttonSetting.nameSettingsId, section, std::vector({ std::string() })); CoreSettingsSetValue(buttonSetting.dataSettingsId, section, std::vector({ 0 })); CoreSettingsSetValue(buttonSetting.extraDataSettingsId, section, std::vector({ 0 })); diff --git a/Source/RMG-Input/UserInterface/Widget/HotkeyButton.cpp b/Source/RMG-Input/UserInterface/Widget/HotkeyButton.cpp index c51ba90b..1956519e 100644 --- a/Source/RMG-Input/UserInterface/Widget/HotkeyButton.cpp +++ b/Source/RMG-Input/UserInterface/Widget/HotkeyButton.cpp @@ -93,7 +93,7 @@ std::vector HotkeyButton::GetInputType() for (const auto& data : this->inputData) { - inputTypeList.push_back((int)data.Type); + inputTypeList.push_back(static_cast(data.Type)); } return inputTypeList; diff --git a/Source/RMG-Input/UserInterface/Widget/MappingButton.cpp b/Source/RMG-Input/UserInterface/Widget/MappingButton.cpp index a1a506a1..1686b419 100644 --- a/Source/RMG-Input/UserInterface/Widget/MappingButton.cpp +++ b/Source/RMG-Input/UserInterface/Widget/MappingButton.cpp @@ -139,7 +139,7 @@ std::vector MappingButton::GetInputType() for (const auto& data : this->inputData) { - inputTypeList.push_back((int)data.Type); + inputTypeList.push_back(static_cast(data.Type)); } return inputTypeList; diff --git a/Source/RMG-Input/VRU.cpp b/Source/RMG-Input/VRU.cpp index cc50ef71..c7f521c2 100644 --- a/Source/RMG-Input/VRU.cpp +++ b/Source/RMG-Input/VRU.cpp @@ -442,7 +442,7 @@ EXPORT void CALL SendVRUWord(uint16_t length, uint16_t* word, uint8_t lang) } // try to create a new recognizer - l_VoskRecognizer = l_vosk_recognizer_new_grm(l_VoskModel, (float)l_AudioDeviceSpec.freq, json_document.toJson().constData()); + l_VoskRecognizer = l_vosk_recognizer_new_grm(l_VoskModel, static_cast(l_AudioDeviceSpec.freq), json_document.toJson().constData()); if (l_VoskRecognizer != nullptr) { l_vosk_recognizer_set_max_alternatives(l_VoskRecognizer, 3); diff --git a/Source/RMG-Input/main.cpp b/Source/RMG-Input/main.cpp index c734f4cb..1d6ea786 100644 --- a/Source/RMG-Input/main.cpp +++ b/Source/RMG-Input/main.cpp @@ -407,7 +407,7 @@ static void apply_controller_profiles(void) { InputProfile* profile = &l_InputProfiles[i]; int plugin = PLUGIN_NONE; - bool emulateVRU = (profile->DeviceNum == (int)InputDeviceType::EmulateVRU); + bool emulateVRU = (profile->DeviceNum == static_cast(InputDeviceType::EmulateVRU)); switch (profile->ControllerPak) { @@ -549,7 +549,7 @@ static void setup_device_automatic(int num, InputProfile* profile) { // fallback to keyboard if (num == 0) { - profile->DeviceNum = (int)InputDeviceType::Keyboard; + profile->DeviceNum = static_cast(InputDeviceType::Keyboard); } else { @@ -576,12 +576,12 @@ static void open_controllers(void) profile->InputDevice.CloseDevice(); - if (profile->DeviceNum == (int)InputDeviceType::Automatic) + if (profile->DeviceNum == static_cast(InputDeviceType::Automatic)) { setup_device_automatic(i, profile); } - if (profile->DeviceNum != (int)InputDeviceType::Keyboard) + if (profile->DeviceNum != static_cast(InputDeviceType::Keyboard)) { profile->InputDevice.OpenDevice(profile->DeviceName, profile->DevicePath, profile->DeviceSerial, profile->DeviceNum); } @@ -830,8 +830,8 @@ static void simulate_octagon(const double deadzone, const double inputX, const d if (std::abs(ax) > maxAxis) ax = std::copysign(maxAxis, ax); if (std::abs(ay) > maxAxis) ay = std::copysign(maxAxis, ay); - outputX = (int)ax; - outputY = (int)ay; + outputX = static_cast(ax); + outputY = static_cast(ay); } static unsigned char data_crc(unsigned char *data, int length) @@ -1100,7 +1100,7 @@ EXPORT m64p_error CALL PluginConfigWithRomConfig(void* parent, int romConfig, Co l_SDLThread->SetAction(SDLThreadAction::SDLPumpEvents); - UserInterface::MainDialog dialog((QWidget*)parent, l_SDLThread, romConfig, *romHeader, *romSettings); + UserInterface::MainDialog dialog(static_cast(parent), l_SDLThread, romConfig, *romHeader, *romSettings); dialog.exec(); // when PluginShutdown() is called during PluginConfig2(), @@ -1213,7 +1213,7 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys) #ifdef VRU // when we're emulating the VRU, // we need to check the mic state - if (profile->DeviceNum == (int)InputDeviceType::EmulateVRU) + if (profile->DeviceNum == static_cast(InputDeviceType::EmulateVRU)) { if (GetVRUMicState()) { @@ -1237,7 +1237,7 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys) { profile->LastDeviceCheckTime = currentTime; - if (profile->DeviceNum != (int)InputDeviceType::Keyboard) + if (profile->DeviceNum != static_cast(InputDeviceType::Keyboard)) { if (profile->InputDevice.IsOpeningDevice()) {