Initial commit for segments

This commit is contained in:
Adam Honse
2022-02-21 21:02:42 -06:00
parent e1e9af2f5d
commit 32121b45d0
6 changed files with 155 additions and 7 deletions

View File

@@ -135,6 +135,17 @@ typedef struct
unsigned int * map;
} matrix_map_type;
/*------------------------------------------------------------------*\
| Segment Struct |
\*------------------------------------------------------------------*/
typedef struct
{
std::string name; /* Segment name */
zone_type type; /* Segment type */
unsigned int start_idx; /* Start index within zone */
unsigned int leds_count; /* Number of LEDs in segment*/
} segment;
/*------------------------------------------------------------------*\
| Zone Struct |
\*------------------------------------------------------------------*/
@@ -149,6 +160,7 @@ typedef struct
unsigned int leds_min; /* Minimum number of LEDs */
unsigned int leds_max; /* Maximum number of LEDs */
matrix_map_type * matrix_map; /* Matrix map pointer */
std::vector<segment> segments; /* Segments in zone */
} zone;
/*------------------------------------------------------------------*\

View File

@@ -20,6 +20,7 @@
#define PAD_LED 0.1
#define PAD_TEXT 0.1
#define PAD_ZONE 1.0
#define PAD_SEGMENT 0.9
#define SIZE_TEXT 0.5
DeviceView::DeviceView(QWidget *parent) :
@@ -184,6 +185,7 @@ void DeviceView::setController(RGBController * controller_ptr)
| Process position and size for zones |
\*-----------------------------------------------------*/
unsigned int maxWidth = 0;
unsigned int segment_count = 0;
float totalHeight = 0;
/*-----------------------------------------------------*\
@@ -203,6 +205,17 @@ void DeviceView::setController(RGBController * controller_ptr)
| For all other zones, compute the height including |
| wrap-around |
\*-----------------------------------------------------*/
else if(controller->zones[zone_idx].segments.size() > 0)
{
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
{
unsigned int count = controller->zones[zone_idx].segments[segment_idx].leds_count;
zone_pos[zone_idx].matrix_w = std::min(count, (unsigned int)MAX_COLS);
totalHeight += (count / MAX_COLS) + ((count % MAX_COLS) > 0);
segment_count++;
}
}
else
{
unsigned int count = controller->zones[zone_idx].leds_count;
@@ -219,13 +232,17 @@ void DeviceView::setController(RGBController * controller_ptr)
}
}
segment_pos.resize(segment_count);
/*-----------------------------------------------------*\
| Add some space for zone names and padding |
\*-----------------------------------------------------*/
totalHeight += controller->zones.size() * PAD_ZONE;
totalHeight += segment_count * PAD_SEGMENT;
float current_y = 0; // We will be descending, placing each zone one unit below the previous one
matrix_h = totalHeight;
segment_count = 0;
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
{
@@ -324,6 +341,43 @@ void DeviceView::setController(RGBController * controller_ptr)
current_y += map->height;
}
else if(controller->zones[zone_idx].segments.size() > 0)
{
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
{
/*-----------------------------------------------------*\
| Calculate segment label position and size |
\*-----------------------------------------------------*/
segment_pos[segment_count].matrix_x = (maxWidth - zone_pos[zone_idx].matrix_w) / 2.0;
segment_pos[segment_count].matrix_y = current_y + SIZE_TEXT;
segment_pos[segment_count].matrix_w = zone_pos[zone_idx].matrix_w;
segment_pos[segment_count].matrix_h = SIZE_TEXT - PAD_TEXT;
current_y += PAD_SEGMENT;
segment_count++;
/*-----------------------------------------------------*\
| Calculate LED box positions for segmented zones |
\*-----------------------------------------------------*/
unsigned int leds_count = controller->zones[zone_idx].segments[segment_idx].leds_count;
for(unsigned int led_idx = 0; led_idx < leds_count; led_idx++)
{
unsigned int led_pos_idx = controller->zones[zone_idx].start_idx + controller->zones[zone_idx].segments[segment_idx].start_idx + led_idx;
led_pos[led_pos_idx].matrix_x = zone_pos[zone_idx].matrix_x + ((led_idx % MAX_COLS) + PAD_LED);
led_pos[led_pos_idx].matrix_y = current_y + ((led_idx / MAX_COLS) + PAD_LED);
/*-----------------------------------------------------*\
| LED is a 1x1 square, minus padding on all sides |
\*-----------------------------------------------------*/
led_pos[led_pos_idx].matrix_w = (1 - (2 * PAD_LED));
led_pos[led_pos_idx].matrix_h = (1 - (2 * PAD_LED));
}
current_y += (leds_count / MAX_COLS) + ((leds_count % MAX_COLS) > 0);
}
}
else
{
/*-----------------------------------------------------*\
@@ -367,7 +421,7 @@ void DeviceView::setController(RGBController * controller_ptr)
}
/*-----------------------------------------------------*\
| Scale the zones and LEDs |
| Scale the zones, segments, and LEDs |
| |
| Atom is the width of a single square; if the whole |
| thing becomes too tall, we ignore it and let the view |
@@ -383,6 +437,14 @@ void DeviceView::setController(RGBController * controller_ptr)
zone_pos[zone_idx].matrix_h *= atom;
}
for(std::size_t segment_idx = 0; segment_idx < segment_pos.size(); segment_idx++)
{
segment_pos[segment_idx].matrix_x *= atom;
segment_pos[segment_idx].matrix_y *= atom;
segment_pos[segment_idx].matrix_w *= atom;
segment_pos[segment_idx].matrix_h *= atom;
}
for(std::size_t led_idx = 0; led_idx < led_pos.size(); led_idx++)
{
led_pos[led_idx].matrix_x *= atom;
@@ -505,7 +567,7 @@ void DeviceView::mouseReleaseEvent(QMouseEvent* event)
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
{
int posx = zone_pos[zone_idx].matrix_x * size + offset_x;
int posx = zone_pos[zone_idx].matrix_x * size + offset_x + 12;
int posy = zone_pos[zone_idx].matrix_y * size;
int posw = zone_pos[zone_idx].matrix_w * size;
int posh = zone_pos[zone_idx].matrix_h * size;
@@ -614,8 +676,10 @@ void DeviceView::paintEvent(QPaintEvent* /* event */)
painter.setFont(font);
/*-----------------------------------------------------*\
| Zone names |
| Zone and Segment names |
\*-----------------------------------------------------*/
unsigned int segment_count = 0;
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
{
int posx = zone_pos[zone_idx].matrix_x * size + offset_x;
@@ -634,6 +698,28 @@ void DeviceView::paintEvent(QPaintEvent* /* event */)
painter.setPen(palette().windowText().color());
}
painter.drawText(posx, posy + posh, QString(controller->zones[zone_idx].name.c_str()));
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
{
posx = segment_pos[segment_count].matrix_x * size + offset_x;
posy = segment_pos[segment_count].matrix_y * size;
posw = segment_pos[segment_count].matrix_w * size;
posh = segment_pos[segment_count].matrix_h * size;
segment_count++;
rect = {posx, posy, posw, posh};
if(rect.contains(lastMousePos) && (!mouseDown || !mouseMoved))
{
painter.setPen(palette().highlight().color());
}
else
{
painter.setPen(palette().windowText().color());
}
painter.drawText(posx, posy + posh, QString(controller->zones[zone_idx].segments[segment_idx].name.c_str()));
}
}
/*-----------------------------------------------------*\

View File

@@ -48,6 +48,7 @@ private:
bool per_led;
std::vector<matrix_pos_size_type> zone_pos;
std::vector<matrix_pos_size_type> segment_pos;
std::vector<matrix_pos_size_type> led_pos;
std::vector<QString> led_labels;

View File

@@ -1083,6 +1083,19 @@ void Ui::OpenRGBDevicePage::on_ResizeButton_clicked()
{
device->ResizeZone(selected_zone, new_size);
segment new_segment;
new_segment.name = "Segment 1";
new_segment.start_idx = 0;
new_segment.leds_count = 5;
device->zones[selected_zone].segments.push_back(new_segment);
new_segment.name = "Segment 2";
new_segment.start_idx = 5;
new_segment.leds_count = device->zones[selected_zone].leds_count - 5;
device->zones[selected_zone].segments.push_back(new_segment);
/*-----------------------------------------------------*\
| Update LED box |
\*-----------------------------------------------------*/

View File

@@ -226,7 +226,7 @@
<item row="1" column="4">
<widget class="QPushButton" name="ResizeButton">
<property name="text">
<string>Resize</string>
<string>Edit</string>
</property>
</widget>
</item>

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>180</height>
<height>293</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,7 +17,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>140</y>
<y>260</y>
<width>341</width>
<height>32</height>
</rect>
@@ -46,12 +46,48 @@
<property name="geometry">
<rect>
<x>260</x>
<y>80</y>
<y>50</y>
<width>121</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QTreeView" name="treeView">
<property name="geometry">
<rect>
<x>20</x>
<y>90</y>
<width>361</width>
<height>101</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>60</x>
<y>210</y>
<width>131</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Add Segment</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>206</x>
<y>210</y>
<width>131</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Remove Segment</string>
</property>
</widget>
</widget>
<resources/>
<connections>