Initial implementation of zone flags field in RGBController, new flag to mark resizable zone as effects-only

This commit is contained in:
Adam Honse
2023-12-26 18:56:55 -06:00
parent 16938483a1
commit 77319af172
4 changed files with 78 additions and 18 deletions

View File

@@ -25,6 +25,25 @@ mode::~mode()
colors.clear();
}
zone::zone()
{
name = "";
type = 0;
leds = NULL;
colors = NULL;
start_idx = 0;
leds_count = 0;
leds_min = 0;
leds_max = 0;
matrix_map = NULL;
flags = 0;
}
zone::~zone()
{
}
RGBController::RGBController()
{
DeviceThreadRunning = true;
@@ -1503,6 +1522,7 @@ void RGBController::SetSingleLEDColorDescription(unsigned char* data_buf)
void RGBController::SetupColors()
{
unsigned int total_led_count;
unsigned int zone_led_count;
/*---------------------------------------------------------*\
| Determine total number of LEDs on the device |
@@ -1511,7 +1531,7 @@ void RGBController::SetupColors()
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
total_led_count += zones[zone_idx].leds_count;
total_led_count += GetLEDsInZone(zone_idx);
}
/*---------------------------------------------------------*\
@@ -1526,9 +1546,10 @@ void RGBController::SetupColors()
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
zones[zone_idx].start_idx=total_led_count;
zones[zone_idx].start_idx = total_led_count;
zone_led_count = GetLEDsInZone(zone_idx);
if((colors.size() > 0) && (zones[zone_idx].leds_count > 0))
if((colors.size() > 0) && (zone_led_count > 0))
{
zones[zone_idx].colors = &colors[total_led_count];
}
@@ -1537,7 +1558,7 @@ void RGBController::SetupColors()
zones[zone_idx].colors = NULL;
}
if((leds.size() > 0) && (zones[zone_idx].leds_count > 0))
if((leds.size() > 0) && (zone_led_count > 0))
{
zones[zone_idx].leds = &leds[total_led_count];
}
@@ -1547,10 +1568,25 @@ void RGBController::SetupColors()
}
total_led_count += zones[zone_idx].leds_count;
total_led_count += zone_led_count;
}
}
unsigned int RGBController::GetLEDsInZone(unsigned int zone)
{
unsigned int leds_count = zones[zone].leds_count;
if(zones[zone].flags & ZONE_FLAG_RESIZE_EFFECTS_ONLY)
{
if(leds_count > 1)
{
leds_count = 1;
}
}
return(leds_count);
}
RGBColor RGBController::GetLED(unsigned int led)
{
if(led < colors.size())
@@ -1581,7 +1617,7 @@ void RGBController::SetAllLEDs(RGBColor color)
void RGBController::SetAllZoneLEDs(int zone, RGBColor color)
{
for (std::size_t color_idx = 0; color_idx < zones[zone].leds_count; color_idx++)
for (std::size_t color_idx = 0; color_idx < GetLEDsInZone(zone); color_idx++)
{
zones[zone].colors[color_idx] = color;
}

View File

@@ -113,6 +113,15 @@ typedef struct
unsigned int value; /* Device-specific LED value */
} led;
/*------------------------------------------------------------------*\
| Zone Flags |
\*------------------------------------------------------------------*/
enum
{
ZONE_FLAG_RESIZE_EFFECTS_ONLY = (1 << 0), /* Zone is resizable, but only for */
/* effects - treat as single LED */
};
/*------------------------------------------------------------------*\
| Zone Types |
\*------------------------------------------------------------------*/
@@ -147,10 +156,11 @@ typedef struct
} segment;
/*------------------------------------------------------------------*\
| Zone Struct |
| Zone Class |
\*------------------------------------------------------------------*/
typedef struct
class zone
{
public:
std::string name; /* Zone name */
zone_type type; /* Zone type */
led * leds; /* List of LEDs in zone */
@@ -161,7 +171,14 @@ typedef struct
unsigned int leds_max; /* Maximum number of LEDs */
matrix_map_type * matrix_map; /* Matrix map pointer */
std::vector<segment> segments; /* Segments in zone */
} zone;
unsigned int flags; /* Zone flags bitfield */
/*--------------------------------------------------------------*\
| Zone Constructor / Destructor |
\*--------------------------------------------------------------*/
zone();
~zone();
};
/*------------------------------------------------------------------*\
| Device Types |
@@ -207,6 +224,8 @@ class RGBControllerInterface
public:
virtual void SetupColors() = 0;
virtual unsigned int GetLEDsInZone(unsigned int zone) = 0;
virtual RGBColor GetLED(unsigned int led) = 0;
virtual void SetLED(unsigned int led, RGBColor color) = 0;
virtual void SetAllLEDs(RGBColor color) = 0;
@@ -288,6 +307,8 @@ public:
\*---------------------------------------------------------*/
void SetupColors();
unsigned int GetLEDsInZone(unsigned int zone);
RGBColor GetLED(unsigned int led);
void SetLED(unsigned int led, RGBColor color);
void SetAllLEDs(RGBColor color);

View File

@@ -299,7 +299,7 @@ void DeviceView::InitDeviceView()
}
else
{
unsigned int count = controller->zones[zone_idx].leds_count;
unsigned int count = controller->GetLEDsInZone(zone_idx);
zone_pos[zone_idx].matrix_w = std::min(count, (unsigned int)MAX_COLS);
totalHeight += (count / MAX_COLS) + ((count % MAX_COLS) > 0);
}
@@ -467,7 +467,7 @@ void DeviceView::InitDeviceView()
/*-----------------------------------------------------*\
| Calculate LED box positions for single/linear zones |
\*-----------------------------------------------------*/
unsigned int leds_count = controller->zones[zone_idx].leds_count;
unsigned int leds_count = controller->GetLEDsInZone(zone_idx);
for(unsigned int led_idx = 0; led_idx < leds_count; led_idx++)
{
@@ -1009,7 +1009,7 @@ bool DeviceView::selectZone(int zone, bool add)
int zoneStart = controller->zones[zone].start_idx;
for(std::size_t led_idx = 0; led_idx < controller->zones[zone].leds_count; ++led_idx)
for(std::size_t led_idx = 0; led_idx < controller->GetLEDsInZone(zone); ++led_idx)
{
if(!selectionFlags[zoneStart + led_idx])
{

View File

@@ -283,13 +283,15 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int index)
\*-----------------------------------------*/
else if(selected_zone != -1 && selected_segment == -1)
{
unsigned int leds_in_zone = device->GetLEDsInZone(selected_zone);
/*-------------------------------------*\
| If there are multiple LEDs, add the |
| "Entire Zone" option to the LED box |
| and enable it, otherwise there is |
| only one LED so disable it |
\*-------------------------------------*/
if(device->zones[selected_zone].leds_count > 1)
if(leds_in_zone > 1)
{
ui->LEDBox->addItem(tr("Entire Zone"));
ui->LEDBox->setEnabled(1);
@@ -303,7 +305,7 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int index)
| Fill in the LED list with all LEDs in |
| the zone |
\*-------------------------------------*/
for(std::size_t led_idx = 0; led_idx < device->zones[selected_zone].leds_count; led_idx++)
for(std::size_t led_idx = 0; led_idx < leds_in_zone; led_idx++)
{
ui->LEDBox->addItem(device->zones[selected_zone].leds[led_idx].name.c_str());
}
@@ -567,9 +569,9 @@ void Ui::OpenRGBDevicePage::on_LEDBox_currentIndexChanged(int index)
/*-------------------------------------*\
| Handle single selected LED |
\*-------------------------------------*/
if(device->zones[selected_zone].leds_count == 1 || selected_led != -1)
if(device->GetLEDsInZone(selected_zone) == 1 || selected_led != -1)
{
if((unsigned int)selected_led < device->zones[selected_zone].leds_count)
if((unsigned int)selected_led < device->GetLEDsInZone(selected_zone))
{
/*-----------------------------*\
| Get selected LED's current |
@@ -1487,9 +1489,10 @@ void Ui::OpenRGBDevicePage::on_EditZoneButton_clicked()
}
/*-----------------------------------------*\
| Only allow resizing linear zones |
| Only allow resizing linear zones or |
| effects-only resizable zones |
\*-----------------------------------------*/
if(device->zones[selected_zone].type == ZONE_TYPE_LINEAR)
if((device->zones[selected_zone].type == ZONE_TYPE_LINEAR) || (device->zones[selected_zone].flags & ZONE_FLAG_RESIZE_EFFECTS_ONLY))
{
OpenRGBZoneResizeDialog dlg(device, selected_zone);