From 2090de91c16196163f5c871bc5a75fd44550496a Mon Sep 17 00:00:00 2001 From: Pedro de Medeiros Date: Thu, 8 Jun 2023 00:31:33 -0300 Subject: [PATCH 1/2] PaletteDialog: replace apply with restore defaults --- src/BitMapViewer.cpp | 23 ++--------------------- src/PaletteDialog.cpp | 15 +++++++++++++-- src/PaletteDialog.h | 1 + src/PaletteDialog.ui | 4 ++-- src/TileViewer.cpp | 24 ++---------------------- src/VDPDataStore.cpp | 25 +++++++++++++++++++++++++ src/VDPDataStore.h | 1 + 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/BitMapViewer.cpp b/src/BitMapViewer.cpp index 0e627dff..b62851dc 100644 --- a/src/BitMapViewer.cpp +++ b/src/BitMapViewer.cpp @@ -6,26 +6,7 @@ #include -// static to feed to PaletteDialog and be used when VDP colors aren't selected -static uint8_t currentPalette[32] = { -// RB G - 0x00, 0, - 0x00, 0, - 0x11, 6, - 0x33, 7, - 0x17, 1, - 0x27, 3, - 0x51, 1, - 0x27, 6, - 0x71, 1, - 0x73, 3, - 0x61, 6, - 0x64, 6, - 0x11, 4, - 0x65, 2, - 0x55, 5, - 0x77, 7, -}; +static uint8_t currentPalette[32] = { 0 }; BitMapViewer::BitMapViewer(QWidget* parent) : QDialog(parent) @@ -69,7 +50,7 @@ BitMapViewer::BitMapViewer(QWidget* parent) imageWidget->setVramAddress(0); // Palette data not received from VDPDataStore yet causing black image, so // we start by using fixed palette until VDPDataStoreDataRefreshed kicks in. - imageWidget->setPaletteSource(currentPalette); + imageWidget->setPaletteSource(VDPDataStore::instance().getDefaultPalettePointer()); // now hook up some signals and slots connect(&VDPDataStore::instance(), &VDPDataStore::dataRefreshed, diff --git a/src/PaletteDialog.cpp b/src/PaletteDialog.cpp index 3dcecb5d..fc22548d 100644 --- a/src/PaletteDialog.cpp +++ b/src/PaletteDialog.cpp @@ -4,6 +4,7 @@ #include #include "PaletteDialog.h" #include "Convert.h" +#include "VDPDataStore.h" #include "ranges.h" @@ -172,6 +173,15 @@ void PaletteDialog::syncToSource() emit paletteSynced(); } +void PaletteDialog::restoreDefaultPalette() +{ + memcpy(myPal, VDPDataStore::instance().getDefaultPalettePointer(), 32); + emit paletteChanged(myPal); + if (autoSync) { + syncToSource(); + } +} + void PaletteDialog::setAutoSync(bool value) { if (autoSync == value) return; @@ -199,8 +209,9 @@ void PaletteDialog::on_horizontalSlider_B_valueChanged(int value) void PaletteDialog::on_buttonBox_clicked(QAbstractButton* button) { - if (button== ui->buttonBox->button(QDialogButtonBox::Apply) || - button== ui->buttonBox->button(QDialogButtonBox::Ok)) { + if (button== ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)) { + restoreDefaultPalette(); + } else if (button== ui->buttonBox->button(QDialogButtonBox::Ok)) { syncToSource(); } else if (button== ui->buttonBox->button(QDialogButtonBox::Reset) || button== ui->buttonBox->button(QDialogButtonBox::Cancel)) { diff --git a/src/PaletteDialog.h b/src/PaletteDialog.h index 89536aaa..faf36300 100644 --- a/src/PaletteDialog.h +++ b/src/PaletteDialog.h @@ -41,6 +41,7 @@ class PaletteDialog : public QDialog void setPalette(uint8_t* pal); uint8_t* getPalette(); void syncToSource(); + void restoreDefaultPalette(); void setAutoSync(bool value); signals: diff --git a/src/PaletteDialog.ui b/src/PaletteDialog.ui index 538acd53..c5b4a9bf 100644 --- a/src/PaletteDialog.ui +++ b/src/PaletteDialog.ui @@ -7,7 +7,7 @@ 0 0 513 - 271 + 278 @@ -139,7 +139,7 @@ Qt::Horizontal - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults diff --git a/src/TileViewer.cpp b/src/TileViewer.cpp index 803308be..4440a025 100644 --- a/src/TileViewer.cpp +++ b/src/TileViewer.cpp @@ -7,27 +7,7 @@ #include -// static to feed to PaletteDialog and be used when VDP colors aren't selected -static uint8_t currentPalette[32] = { -// RB G - 0x00, 0, - 0x00, 0, - 0x11, 6, - 0x33, 7, - 0x17, 1, - 0x27, 3, - 0x51, 1, - 0x27, 6, - 0x71, 1, - 0x73, 3, - 0x61, 6, - 0x64, 6, - 0x11, 4, - 0x65, 2, - 0x55, 5, - 0x77, 7, -}; - +static uint8_t currentPalette[32] = { 0 }; TileViewer::TileViewer(QWidget* parent) : QDialog(parent), image4label(32, 32, QImage::Format_RGB32) @@ -82,7 +62,7 @@ TileViewer::TileViewer(QWidget* parent) scrollArea->setWidget(imageWidget); - imageWidget->setPaletteSource(currentPalette); + imageWidget->setPaletteSource(VDPDataStore::instance().getDefaultPalettePointer()); imageWidget->setUseBlink(cb_blinkcolors->isChecked()); imageWidget->setDrawGrid(cb_drawgrid->isChecked()); diff --git a/src/VDPDataStore.cpp b/src/VDPDataStore.cpp index abe070a4..026a4e73 100644 --- a/src/VDPDataStore.cpp +++ b/src/VDPDataStore.cpp @@ -1,6 +1,27 @@ #include "VDPDataStore.h" #include "CommClient.h" +// static vector to feed PaletteDialog and be used when VDP colors aren't selected +static const uint8_t defaultPalette[32] = { +// RB G + 0x00, 0, + 0x00, 0, + 0x11, 6, + 0x33, 7, + 0x17, 1, + 0x27, 3, + 0x51, 1, + 0x27, 6, + 0x71, 1, + 0x73, 3, + 0x61, 6, + 0x64, 6, + 0x11, 4, + 0x65, 2, + 0x55, 5, + 0x77, 7, +}; + class VDPDataStoreVersionCheck : public SimpleCommand { public: @@ -149,6 +170,10 @@ const uint8_t* VDPDataStore::getVramPointer() const { return &vram[0]; } +const uint8_t* VDPDataStore::getDefaultPalettePointer() const +{ + return defaultPalette; +} const uint8_t* VDPDataStore::getPalettePointer() const { return &vram[vramSize]; diff --git a/src/VDPDataStore.h b/src/VDPDataStore.h index d70e2693..d04c85d9 100644 --- a/src/VDPDataStore.h +++ b/src/VDPDataStore.h @@ -15,6 +15,7 @@ class VDPDataStore : public QObject, public SimpleHexRequestUser static VDPDataStore& instance(); const uint8_t* getVramPointer() const; + const uint8_t* getDefaultPalettePointer() const; const uint8_t* getPalettePointer() const; const uint8_t* getRegsPointer() const; const uint8_t* getStatusRegsPointer() const; From bfa7c58f53ce2180be9390c7d0d20343a4cebf08 Mon Sep 17 00:00:00 2001 From: Pedro de Medeiros Date: Thu, 8 Jun 2023 01:19:46 -0300 Subject: [PATCH 2/2] formatting --- src/PaletteDialog.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/PaletteDialog.cpp b/src/PaletteDialog.cpp index fc22548d..06c8bcd5 100644 --- a/src/PaletteDialog.cpp +++ b/src/PaletteDialog.cpp @@ -41,14 +41,12 @@ void PalettePatch::setHighlightTest(int colorNr) void PalettePatch::paintEvent(QPaintEvent* /*event*/) { - QPainter painter(this); - painter.setPen(isSelected ? Qt::white : QColor(myColor)); - painter.setBrush(QBrush(myColor)); - painter.drawRect(0, 0, this->width() - 1, this->height() - 1); + QPainter painter(this); + painter.setPen(isSelected ? Qt::white : QColor(myColor)); + painter.setBrush(QBrush(myColor)); + painter.drawRect(0, 0, this->width() - 1, this->height() - 1); } - - PaletteDialog::PaletteDialog(QWidget* parent) : QDialog(parent), ui(std::make_unique()) {