From db3351691a7df6e7e1d1f0cfbbfc0eb8b542fdf3 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Mon, 23 Feb 2026 22:44:29 -0600 Subject: [PATCH] Add matrix map automatic generation to matrix map editor --- .../OpenRGBMatrixMapEditorDialog.cpp | 189 ++++++++++++++++++ .../OpenRGBMatrixMapEditorDialog.h | 3 +- .../OpenRGBMatrixMapEditorDialog.ui | 35 +++- 3 files changed, 218 insertions(+), 9 deletions(-) diff --git a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.cpp b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.cpp index 2404caff2..0bb96706d 100644 --- a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.cpp +++ b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.cpp @@ -16,6 +16,26 @@ #include "OpenRGBMatrixMapEditorDialog.h" #include "ui_OpenRGBMatrixMapEditorDialog.h" +enum +{ + MATRIX_ORDER_HORIZONTAL_TOP_LEFT, + MATRIX_ORDER_HORIZONTAL_TOP_LEFT_ZIGZAG, + MATRIX_ORDER_HORIZONTAL_TOP_RIGHT, + MATRIX_ORDER_HORIZONTAL_TOP_RIGHT_ZIGZAG, + MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT, + MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT_ZIGZAG, + MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT, + MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT_ZIGZAG, + MATRIX_ORDER_VERTICAL_TOP_LEFT, + MATRIX_ORDER_VERTICAL_TOP_LEFT_ZIGZAG, + MATRIX_ORDER_VERTICAL_TOP_RIGHT, + MATRIX_ORDER_VERTICAL_TOP_RIGHT_ZIGZAG, + MATRIX_ORDER_VERTICAL_BOTTOM_LEFT, + MATRIX_ORDER_VERTICAL_BOTTOM_LEFT_ZIGZAG, + MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT, + MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT_ZIGZAG +}; + OpenRGBMatrixMapEditorDialog::OpenRGBMatrixMapEditorDialog(QString name, matrix_map_type* edit_map_ptr, unsigned int led_count, QWidget *parent) : QDialog(parent), ui(new Ui::OpenRGBMatrixMapEditorDialog) @@ -41,6 +61,26 @@ OpenRGBMatrixMapEditorDialog::OpenRGBMatrixMapEditorDialog(QString name, matrix_ setWindowTitle(newTitle); } + /*-----------------------------------------------------*\ + | Populate Auto-Generate Combo Box | + \*-----------------------------------------------------*/ + ui->ComboBoxAutoGenerate->addItem("Horizontal from Top Left"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Top Left Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Top Right"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Top Right Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Bottom Left"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Bottom Left Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Bottom Right"); + ui->ComboBoxAutoGenerate->addItem("Horizontal from Bottom Right Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Top Left"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Top Left Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Top Right"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Top Right Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Bottom Left"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Bottom Left Zigzag"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Bottom Right"); + ui->ComboBoxAutoGenerate->addItem("Vertical from Bottom Right Zigzag"); + /*-----------------------------------------------------*\ | Initialize matrix map table | \*-----------------------------------------------------*/ @@ -125,6 +165,155 @@ int OpenRGBMatrixMapEditorDialog::show() return(ret_val); } +void OpenRGBMatrixMapEditorDialog::on_ButtonAutoGenerate_clicked() +{ + /*-----------------------------------------------------*\ + | Loop control variables | + \*-----------------------------------------------------*/ + unsigned int led_idx = 0; + unsigned int height = ui->LineEditHeight->text().toInt(); + unsigned int width = ui->LineEditWidth->text().toInt(); + int matrix_order = ui->ComboBoxAutoGenerate->currentIndex(); + bool outer_loop_y = true; + bool outer_loop_inverted = false; + bool inner_loop_inverted = false; + bool zigzag = false; + + /*-----------------------------------------------------*\ + | Initialize loop control variables | + \*-----------------------------------------------------*/ + switch(matrix_order) + { + case MATRIX_ORDER_HORIZONTAL_TOP_LEFT: + case MATRIX_ORDER_HORIZONTAL_TOP_LEFT_ZIGZAG: + outer_loop_y = true; + outer_loop_inverted = false; + inner_loop_inverted = false; + break; + + case MATRIX_ORDER_HORIZONTAL_TOP_RIGHT: + case MATRIX_ORDER_HORIZONTAL_TOP_RIGHT_ZIGZAG: + outer_loop_y = true; + outer_loop_inverted = false; + inner_loop_inverted = true; + break; + + case MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT_ZIGZAG: + outer_loop_y = true; + outer_loop_inverted = true; + inner_loop_inverted = false; + break; + + case MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT_ZIGZAG: + outer_loop_y = true; + outer_loop_inverted = true; + inner_loop_inverted = true; + break; + + case MATRIX_ORDER_VERTICAL_TOP_LEFT: + case MATRIX_ORDER_VERTICAL_TOP_LEFT_ZIGZAG: + outer_loop_y = false; + outer_loop_inverted = false; + inner_loop_inverted = false; + break; + + case MATRIX_ORDER_VERTICAL_TOP_RIGHT: + case MATRIX_ORDER_VERTICAL_TOP_RIGHT_ZIGZAG: + outer_loop_y = false; + outer_loop_inverted = true; + inner_loop_inverted = false; + break; + + case MATRIX_ORDER_VERTICAL_BOTTOM_LEFT: + case MATRIX_ORDER_VERTICAL_BOTTOM_LEFT_ZIGZAG: + outer_loop_y = false; + outer_loop_inverted = false; + inner_loop_inverted = true; + break; + + case MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT: + case MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT_ZIGZAG: + outer_loop_y = false; + outer_loop_inverted = true; + inner_loop_inverted = true; + break; + } + + /*-----------------------------------------------------*\ + | Initialize zigzag flag | + \*-----------------------------------------------------*/ + switch(matrix_order) + { + case MATRIX_ORDER_HORIZONTAL_TOP_LEFT: + case MATRIX_ORDER_HORIZONTAL_TOP_RIGHT: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT: + case MATRIX_ORDER_VERTICAL_TOP_LEFT: + case MATRIX_ORDER_VERTICAL_TOP_RIGHT: + case MATRIX_ORDER_VERTICAL_BOTTOM_LEFT: + case MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT: + zigzag = false; + break; + + case MATRIX_ORDER_HORIZONTAL_TOP_LEFT_ZIGZAG: + case MATRIX_ORDER_HORIZONTAL_TOP_RIGHT_ZIGZAG: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_LEFT_ZIGZAG: + case MATRIX_ORDER_HORIZONTAL_BOTTOM_RIGHT_ZIGZAG: + case MATRIX_ORDER_VERTICAL_TOP_LEFT_ZIGZAG: + case MATRIX_ORDER_VERTICAL_TOP_RIGHT_ZIGZAG: + case MATRIX_ORDER_VERTICAL_BOTTOM_LEFT_ZIGZAG: + case MATRIX_ORDER_VERTICAL_BOTTOM_RIGHT_ZIGZAG: + zigzag = true; + break; + } + + /*-----------------------------------------------------*\ + | Initialize and clear table | + \*-----------------------------------------------------*/ + ui->TableWidgetMatrixMap->setRowCount(height); + ui->TableWidgetMatrixMap->setColumnCount(width); + + ui->TableWidgetMatrixMap->clearContents(); + + /*-----------------------------------------------------*\ + | Generate matrix map | + \*-----------------------------------------------------*/ + for(int outer = (outer_loop_inverted ? ((outer_loop_y ? height : width) - 1) : 0); + (outer_loop_inverted ? (outer >= 0) : (outer < (int)(outer_loop_y ? height : width))) ; + (outer_loop_inverted ? (outer--) : (outer++))) + { + for(int inner = (inner_loop_inverted ? ((outer_loop_y ? width : height) - 1) : 0); + (inner_loop_inverted ? (inner >= 0) : (inner < (int)(outer_loop_y ? width : height))) ; + (inner_loop_inverted ? (inner--) : (inner++))) + { + QTableWidgetItem* table_item = new QTableWidgetItem; + + if(led_idx < edit_led_count) + { + table_item->setText(QString::number(led_idx)); + } + + if(outer_loop_y) + { + ui->TableWidgetMatrixMap->setItem(outer, inner, table_item); + } + else + { + ui->TableWidgetMatrixMap->setItem(inner, outer, table_item); + } + + led_idx++; + } + + if(zigzag) + { + inner_loop_inverted = !inner_loop_inverted; + } + } +} + void OpenRGBMatrixMapEditorDialog::on_LineEditHeight_textChanged(const QString &arg1) { ui->TableWidgetMatrixMap->setRowCount(arg1.toInt()); diff --git a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.h b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.h index b09ff8cb2..96160dd65 100644 --- a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.h +++ b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.h @@ -31,9 +31,8 @@ public: private slots: void changeEvent(QEvent *event); - + void on_ButtonAutoGenerate_clicked(); void on_LineEditHeight_textChanged(const QString &arg1); - void on_LineEditWidth_textChanged(const QString &arg1); private: diff --git a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.ui b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.ui index bd4967a02..56a9ff8c5 100644 --- a/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.ui +++ b/qt/OpenRGBMatrixMapEditorDialog/OpenRGBMatrixMapEditorDialog.ui @@ -32,6 +32,12 @@ + + + + + + @@ -39,8 +45,26 @@ - - + + + + + + Auto-Generate Matrix + + + + + + + + 0 + 0 + + + + + @@ -49,11 +73,8 @@ - - - - - + +