From 6fd2ea927684b6ab1afab5de6a8efe0d3f46b6d9 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 8 Feb 2021 14:53:48 +1100 Subject: [PATCH] Initial commit for Brightness in RGBController API * Added DeviceHasBrightness() = false; to RGBController as overridable * Added Brightness to Mode struct * Added BrightnessSlider to the OpenRGBDevicePage ui and the supporting code to pass to the RGBController Commit amended for code style and to split API changes and controller changes out by Adam Honse --- RGBController/RGBController.h | 3 + qt/OpenRGBDevicePage.cpp | 79 +++++++-- qt/OpenRGBDevicePage.h | 8 +- qt/OpenRGBDevicePage.ui | 296 ++++++++++++++++++---------------- qt/OpenRGBDialog2.cpp | 2 +- qt/OpenRGBDialog2.h | 1 + 6 files changed, 234 insertions(+), 155 deletions(-) diff --git a/RGBController/RGBController.h b/RGBController/RGBController.h index ef8de91c..58069186 100644 --- a/RGBController/RGBController.h +++ b/RGBController/RGBController.h @@ -74,6 +74,8 @@ public: unsigned int flags; /* Mode flags bitfield */ unsigned int speed_min; /* speed minimum value */ unsigned int speed_max; /* speed maximum value */ + unsigned int brightness_min; /*brightness min value */ + unsigned int brightness_max; /*brightness max value */ unsigned int colors_min; /* minimum number of mode colors*/ unsigned int colors_max; /* maximum numver of mode colors*/ @@ -81,6 +83,7 @@ public: | Mode Settings | \*--------------------------------------------------------------*/ unsigned int speed; /* Mode speed parameter value */ + unsigned int brightness; /* Mode brightness value */ unsigned int direction; /* Mode direction value */ unsigned int color_mode; /* Mode color selection */ std::vector diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index 664a4722..6dec979e 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -405,6 +405,14 @@ void Ui::OpenRGBDevicePage::on_RandomCheck_clicked() UpdateModeUi(); } +void Ui::OpenRGBDevicePage::on_BrightnessSlider_valueChanged(int /*value*/) +{ + /*-----------------------------------------------------*\ + | Change device mode | + \*-----------------------------------------------------*/ + UpdateMode(); +} + void Ui::OpenRGBDevicePage::on_SpeedSlider_valueChanged(int /*value*/) { /*-----------------------------------------------------*\ @@ -443,6 +451,7 @@ void Ui::OpenRGBDevicePage::UpdateModeUi() bool supports_mode_specific = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_MODE_SPECIFIC_COLOR ); bool supports_random = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_RANDOM_COLOR ); bool supports_speed = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_SPEED ); + bool supports_brightness = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_BRIGHTNESS); bool supports_dir_lr = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_DIRECTION_LR ); bool supports_dir_ud = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_DIRECTION_UD ); bool supports_dir_hv = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_DIRECTION_HV ); @@ -484,6 +493,36 @@ void Ui::OpenRGBDevicePage::UpdateModeUi() ui->SpeedSlider->blockSignals(false); } + if(supports_brightness) + { + ui->BrightnessSlider->blockSignals(true); + InvertedBrightness = device->modes[selected_mode].brightness_min > device->modes[selected_mode].brightness_max; + + if(InvertedBrightness) + { + /*-----------------------------------------------------*\ + | If Brightness Slider is inverted, invert value | + \*-----------------------------------------------------*/ + ui->BrightnessSlider->setMinimum(device->modes[selected_mode].brightness_max); + ui->BrightnessSlider->setMaximum(device->modes[selected_mode].brightness_min); + } + else + { + ui->BrightnessSlider->setMinimum(device->modes[selected_mode].brightness_min); + ui->BrightnessSlider->setMaximum(device->modes[selected_mode].brightness_max); + } + + ui->BrightnessSlider->setValue(device->modes[selected_mode].brightness); + ui->BrightnessSlider->setEnabled(true); + ui->BrightnessSlider->blockSignals(false); + } + else + { + ui->BrightnessSlider->blockSignals(true); + ui->BrightnessSlider->setEnabled(false); + ui->BrightnessSlider->blockSignals(false); + } + ui->DirectionBox->blockSignals(true); ui->DirectionBox->clear(); @@ -694,15 +733,16 @@ void Ui::OpenRGBDevicePage::UpdateMode() if(current_mode >= 0) { - int current_speed = 0; - bool current_per_led = ui->PerLEDCheck->isChecked(); - bool current_mode_specific = ui->ModeSpecificCheck->isChecked(); - bool current_random = ui->RandomCheck->isChecked(); - int current_dir_idx = ui->DirectionBox->currentIndex(); - int current_direction = 0; - bool supports_dir_lr = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_LR ); - bool supports_dir_ud = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_UD ); - bool supports_dir_hv = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_HV ); + int current_speed = 0; + int current_brightness = 0; + bool current_per_led = ui->PerLEDCheck->isChecked(); + bool current_mode_specific = ui->ModeSpecificCheck->isChecked(); + bool current_random = ui->RandomCheck->isChecked(); + int current_dir_idx = ui->DirectionBox->currentIndex(); + int current_direction = 0; + bool supports_dir_lr = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_LR ); + bool supports_dir_ud = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_UD ); + bool supports_dir_hv = ( device->modes[(unsigned int)current_mode].flags & MODE_FLAG_HAS_DIRECTION_HV ); /*-----------------------------------------------------*\ | Set the direction value | @@ -761,6 +801,24 @@ void Ui::OpenRGBDevicePage::UpdateMode() } } + /*-----------------------------------------------------*\ + | If Brightness Slider is enabled, read the value | + \*-----------------------------------------------------*/ + if(ui->BrightnessSlider->isEnabled()) + { + /*-----------------------------------------------------*\ + | If Brightness Slider is inverted, invert value | + \*-----------------------------------------------------*/ + if(InvertedBrightness) + { + current_brightness = device->modes[(unsigned int)current_mode].brightness_min - ui->BrightnessSlider->value() + device->modes[current_mode].brightness_max; + } + else + { + current_brightness = ui->BrightnessSlider->value(); + } + } + /*-----------------------------------------------------*\ | Don't set the mode if the current mode is invalid | \*-----------------------------------------------------*/ @@ -769,7 +827,8 @@ void Ui::OpenRGBDevicePage::UpdateMode() /*-----------------------------------------------------*\ | Update mode parameters | \*-----------------------------------------------------*/ - device->modes[(unsigned int)current_mode].speed = current_speed; + device->modes[(unsigned int)current_mode].speed = current_speed; + device->modes[(unsigned int)current_mode].brightness = current_brightness; if(current_per_led) { diff --git a/qt/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage.h index 194fb8e7..fe54b6d7 100644 --- a/qt/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage.h @@ -36,6 +36,7 @@ private slots: void on_DirectionBox_currentIndexChanged(int index); void on_ZoneBox_currentIndexChanged(int index); void on_LEDBox_currentIndexChanged(int index); + void on_BrightnessSlider_valueChanged(int value); void on_ModeBox_currentIndexChanged(int index); void on_SpeedSlider_valueChanged(int value); void on_RedSpinBox_valueChanged(int arg1); @@ -60,9 +61,10 @@ private: Ui::OpenRGBDevicePageUi *ui; RGBController *device; - bool UpdatingColor = false; - bool InvertedSpeed = false; - bool MultipleSelected = false; + bool UpdatingColor = false; + bool InvertedSpeed = false; + bool InvertedBrightness = false; + bool MultipleSelected = false; void updateRGB(); void updateHSV(); diff --git a/qt/OpenRGBDevicePage.ui b/qt/OpenRGBDevicePage.ui index 0cf1bc52..ac0e42d6 100644 --- a/qt/OpenRGBDevicePage.ui +++ b/qt/OpenRGBDevicePage.ui @@ -14,10 +14,59 @@ Frame - - + + - Per-LED + G: + + + + + + + H: + + + + + + + Speed: + + + + + + + Qt::Horizontal + + + + + + + 255 + + + + + + + Random + + + + + + + B: + + + + + + + LED: @@ -28,22 +77,36 @@ - - - - Zone: + + + + 255 - - + + - Apply Colors To Selection + R: - - + + + + + + + Dir: + + + + + + + 255 + + @@ -52,6 +115,40 @@ + + + + S: + + + + + + + 255 + + + + + + + + + + + + + Select All + + + + + + + Per-LED + + + @@ -59,16 +156,23 @@ - - + + + + Zone: + + - - - - - 0 - 0 - + + + + + + + <html><head/><body><p align="justify">Sets all devices to<br/><b>Static</b> mode and<br/>applies the selected color.</p></body></html> + + + Apply All Devices @@ -88,65 +192,6 @@ - - - - V: - - - - - - - Select All - - - - - - - G: - - - - - - - H: - - - - - - - 255 - - - - - - - - - - Speed: - - - - - - - B: - - - - - - - S: - - - @@ -154,50 +199,30 @@ - - + + - R: + V: - - - - Qt::Horizontal + + + + + 0 + 0 + - - + + - Random + Apply Colors To Selection - - - - 255 - - - - - - - <html><head/><body><p align="justify">Sets all devices to<br/><b>Static</b> mode and<br/>applies the selected color.</p></body></html> - - - Apply All Devices - - - - - - - - - @@ -205,34 +230,6 @@ - - - - Dir: - - - - - - - 255 - - - - - - - LED: - - - - - - - 255 - - - @@ -240,6 +237,23 @@ + + + + + + + Qt::Horizontal + + + + + + + Brightness: + + + diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index a7fd8c18..b2ece692 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -392,7 +392,7 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op AddSoftwareInfoPage(); /*-----------------------------------------------------*\ - | Add the supported Devices page | + | Add the Supported Devices page | \*-----------------------------------------------------*/ AddSupportedDevicesPage(); diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index f4416d98..f82f3649 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace Ui {