diff --git a/forms/colorpicker.ui b/forms/colorpicker.ui new file mode 100644 index 00000000..213116ee --- /dev/null +++ b/forms/colorpicker.ui @@ -0,0 +1,192 @@ + + + ColorPicker + + + + 0 + 0 + 357 + 186 + + + + Color Picker + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + + 120 + 120 + + + + + 120 + 120 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 50 + 50 + + + + + 50 + 50 + + + + + 50 + 50 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Courier + + + + RGB (000, 000, 000) + + + + + + + + Courier + + + + #FFFFFF + + + + + + + + + + + diff --git a/forms/paletteeditor.ui b/forms/paletteeditor.ui index b87b4398..cfc529fd 100644 --- a/forms/paletteeditor.ui +++ b/forms/paletteeditor.ui @@ -7,7 +7,7 @@ 0 0 817 - 739 + 879 @@ -65,14 +65,14 @@ QFrame::Raised - - + + - Color 4 + Color 2 - + - + 32 @@ -94,14 +94,14 @@ - + Red - + 31 @@ -120,21 +120,21 @@ - + Green - + Blue - + 31 @@ -144,7 +144,7 @@ - + 31 @@ -154,990 +154,45 @@ - - - - - - - - - - - - - Color 5 - - - - - - - 32 - 32 - - - - - 32 - 32 - - + - QFrame::StyledPanel + QFrame::NoFrame QFrame::Raised - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 7 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 6 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 10 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 8 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 9 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 11 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 12 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 14 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - - - - - - - - - - Color 13 - - - - - - - 32 - 32 - - - - - 32 - 32 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + @@ -1232,83 +287,58 @@ - - - + + + QFrame::NoFrame + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + - - + + - Color 0 + Color 14 - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - 31 - - - Qt::Horizontal - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - + - + 32 @@ -1329,13 +359,1438 @@ - - + + - + Red + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 9 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 8 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 7 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 10 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 6 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 11 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 13 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 12 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 4 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 5 + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + @@ -1428,108 +1883,45 @@ - - - - - - - - - - - - - Color 2 - - - - - - - 32 - 32 - - - - - 32 - 32 - - + - QFrame::StyledPanel + QFrame::NoFrame QFrame::Raised - - - - - - Red - - - - - - - 31 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - Green - - - - - - - Blue - - - - - - - 31 - - - Qt::Horizontal - - - - - - - 31 - - - Qt::Horizontal - - - - - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + @@ -1624,9 +2016,177 @@ - + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + + + Color 0 + + + + - + Red + + + + + + + 31 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + Green + + + + + + + 31 + + + Qt::Horizontal + + + + + + + Blue + + + + + + + 31 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + QFrame::StyledPanel + + + QFrame::Raised @@ -1644,7 +2204,7 @@ 0 0 817 - 21 + 22 @@ -1692,6 +2252,8 @@ - + + + diff --git a/include/ui/colorpicker.h b/include/ui/colorpicker.h new file mode 100644 index 00000000..fa431341 --- /dev/null +++ b/include/ui/colorpicker.h @@ -0,0 +1,33 @@ +#ifndef COLORPICKER_H +#define COLORPICKER_H + +#include +#include + +namespace Ui { +class ColorPicker; +} + +class ColorPicker : public QDialog +{ + Q_OBJECT + +public: + explicit ColorPicker(QWidget *parent = nullptr); + ~ColorPicker(); + + QColor getColor() { return this->color; } + +private: + Ui::ColorPicker *ui; + QGraphicsScene *scene = nullptr; + QTimer *timer = nullptr; + + QPoint lastCursorPos = QPoint(0, 0); + + QColor color = Qt::white; + + void hover(int mouseX, int mouseY); +}; + +#endif // COLORPICKER_H diff --git a/include/ui/paletteeditor.h b/include/ui/paletteeditor.h index 2dbd6d29..cc662aa0 100644 --- a/include/ui/paletteeditor.h +++ b/include/ui/paletteeditor.h @@ -34,6 +34,7 @@ private: QList> sliders; QList frames; QList rgbLabels; + QList pickButtons; Tileset *primaryTileset; Tileset *secondaryTileset; QList> palettesHistory; @@ -48,6 +49,7 @@ private: void restoreWindowState(); void setColorsFromHistory(PaletteHistoryItem*, int); void closeEvent(QCloseEvent*); + void pickColor(int i); signals: void closed(); diff --git a/porymap.pro b/porymap.pro index 1b78ebcc..ce74c50c 100644 --- a/porymap.pro +++ b/porymap.pro @@ -82,6 +82,7 @@ SOURCES += src/core/block.cpp \ src/ui/multikeyedit.cpp \ src/ui/preferenceeditor.cpp \ src/ui/regionmappropertiesdialog.cpp \ + src/ui/colorpicker.cpp \ src/config.cpp \ src/editor.cpp \ src/main.cpp \ @@ -164,6 +165,7 @@ HEADERS += include/core/block.h \ include/ui/multikeyedit.h \ include/ui/preferenceeditor.h \ include/ui/regionmappropertiesdialog.h \ + include/ui/colorpicker.h \ include/config.h \ include/editor.h \ include/mainwindow.h \ @@ -184,6 +186,7 @@ FORMS += forms/mainwindow.ui \ forms/shortcutseditor.ui \ forms/preferenceeditor.ui \ forms/regionmappropertiesdialog.ui + forms/colorpicker.ui RESOURCES += \ resources/images.qrc \ diff --git a/src/ui/colorpicker.cpp b/src/ui/colorpicker.cpp new file mode 100644 index 00000000..aa5853d8 --- /dev/null +++ b/src/ui/colorpicker.cpp @@ -0,0 +1,81 @@ +#include "colorpicker.h" +#include "ui_colorpicker.h" + +#include + +const int zoom_box_dimensions = 7; + +ColorPicker::ColorPicker(QWidget *parent) : + QDialog(parent), + ui(new Ui::ColorPicker) +{ + ui->setupUi(this); + + this->scene = new QGraphicsScene; + + // listen for spacebar press to take color + QShortcut *takeColor = new QShortcut(Qt::Key_Space, this); + QObject::connect(takeColor, &QShortcut::activated, [this](){ + timer->stop(); + this->accept(); + }); + + // need to set up a timer because there is no good way to get global mouse movement + // outside of the application in a cross-platform way + timer = new QTimer(this); + connect(timer, &QTimer::timeout, [this]() { + QPoint cursorPos = QCursor::pos(); + if (lastCursorPos != cursorPos) { + lastCursorPos = cursorPos; + this->hover(cursorPos.x(), cursorPos.y()); + } + }); + timer->start(10); +} + +ColorPicker::~ColorPicker() +{ + delete scene; + delete timer; + delete ui; +} + +void ColorPicker::hover(int mouseX, int mouseY) { + QScreen *screen = QGuiApplication::primaryScreen(); + if (const QWindow *window = windowHandle()) + screen = window->screen(); + if (!screen) + return; + + // 15 X 15 box with 8x magnification = 120px square) + QRect zoomRect(mouseX - 7, mouseY - 7, 15, 15); + QPixmap grab = screen->grabWindow(0, mouseX - 7, mouseY - 7, 15, 15); + int pixelRatio = grab.devicePixelRatio(); + + // TODO: investigate for high dpi displays why text is too high res + grab.setDevicePixelRatio(1); + QPixmap magnified = grab.scaled(120, 120, Qt::KeepAspectRatio); + + QPainter painter(&magnified); + painter.setRenderHint(QPainter::Antialiasing, false); + QRectF rect(55, 55, 9, 9); + painter.drawRect(rect); + painter.end(); + + // TODO: bounds checking? + + this->color = grab.toImage().pixelColor(7 * pixelRatio, 7 * pixelRatio); + int r = this->color.red(); + int g = this->color.green(); + int b = this->color.blue(); + + // update the displayed color value + QString rgb = QString("rgb(%1, %2, %3)").arg(r).arg(g).arg(b); + QString stylesheet = QString("background-color: %1;").arg(rgb); + this->ui->frame_centralColor->setStyleSheet(stylesheet); + + this->ui->label_RGB->setText(rgb); + this->ui->label_HEX->setText(color.name()); + + this->ui->viewport->setPixmap(magnified); +} diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index d03615fa..3aa205eb 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -1,8 +1,10 @@ #include "paletteeditor.h" #include "ui_paletteeditor.h" +#include "colorpicker.h" #include "paletteutil.h" #include "config.h" #include "log.h" + #include #include @@ -105,11 +107,40 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset this->rgbLabels.append(this->ui->label_rgb14); this->rgbLabels.append(this->ui->label_rgb15); + this->pickButtons.clear(); + this->pickButtons.append(this->ui->toolButton_0); + this->pickButtons.append(this->ui->toolButton_1); + this->pickButtons.append(this->ui->toolButton_2); + this->pickButtons.append(this->ui->toolButton_3); + this->pickButtons.append(this->ui->toolButton_4); + this->pickButtons.append(this->ui->toolButton_5); + this->pickButtons.append(this->ui->toolButton_6); + this->pickButtons.append(this->ui->toolButton_7); + this->pickButtons.append(this->ui->toolButton_8); + this->pickButtons.append(this->ui->toolButton_9); + this->pickButtons.append(this->ui->toolButton_10); + this->pickButtons.append(this->ui->toolButton_11); + this->pickButtons.append(this->ui->toolButton_12); + this->pickButtons.append(this->ui->toolButton_13); + this->pickButtons.append(this->ui->toolButton_14); + this->pickButtons.append(this->ui->toolButton_15); + // Setup edit-undo history for each of the palettes. for (int i = 0; i < Project::getNumPalettesTotal(); i++) { this->palettesHistory.append(History()); } + // Connect the color picker's selection to the correct color index + for (int i = 0; i < 16; i++) { + connect(this->pickButtons[i], &QToolButton::clicked, [this, i](){ + disableSliderSignals(); + this->pickColor(i); + this->setColor(i); + enableSliderSignals(); + }); + this->pickButtons[i]->setEnabled(i < (Project::getNumPalettesTotal() - 1)); + } + this->initColorSliders(); this->setPaletteId(paletteId); this->commitEditHistory(this->ui->spinBox_PaletteId->value()); @@ -211,6 +242,18 @@ void PaletteEditor::setColor(int colorIndex) { emit this->changedPaletteColor(); } +void PaletteEditor::pickColor(int i) { + ColorPicker picker(this); + if (picker.exec() == QDialog::Accepted) { + QColor c = picker.getColor(); + // TODO: round? or keep floor? + this->sliders[i][0]->setValue(c.red() / 8); + this->sliders[i][1]->setValue(c.green() / 8); + this->sliders[i][2]->setValue(c.blue() / 8); + } + return; +} + void PaletteEditor::on_spinBox_PaletteId_valueChanged(int paletteId) { this->refreshColorSliders(); this->refreshColors();