Skip to content

Commit 543e1c9

Browse files
authored
Merge pull request #184 from pvmm/restore-palette
PaletteDialog: replace apply with restore defaults
2 parents 28cc598 + bfa7c58 commit 543e1c9

File tree

7 files changed

+50
-53
lines changed

7 files changed

+50
-53
lines changed

src/BitMapViewer.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@
66
#include <QMessageBox>
77

88

9-
// static to feed to PaletteDialog and be used when VDP colors aren't selected
10-
static uint8_t currentPalette[32] = {
11-
// RB G
12-
0x00, 0,
13-
0x00, 0,
14-
0x11, 6,
15-
0x33, 7,
16-
0x17, 1,
17-
0x27, 3,
18-
0x51, 1,
19-
0x27, 6,
20-
0x71, 1,
21-
0x73, 3,
22-
0x61, 6,
23-
0x64, 6,
24-
0x11, 4,
25-
0x65, 2,
26-
0x55, 5,
27-
0x77, 7,
28-
};
9+
static uint8_t currentPalette[32] = { 0 };
2910

3011
BitMapViewer::BitMapViewer(QWidget* parent)
3112
: QDialog(parent)
@@ -69,7 +50,7 @@ BitMapViewer::BitMapViewer(QWidget* parent)
6950
imageWidget->setVramAddress(0);
7051
// Palette data not received from VDPDataStore yet causing black image, so
7152
// we start by using fixed palette until VDPDataStoreDataRefreshed kicks in.
72-
imageWidget->setPaletteSource(currentPalette);
53+
imageWidget->setPaletteSource(VDPDataStore::instance().getDefaultPalettePointer());
7354

7455
// now hook up some signals and slots
7556
connect(&VDPDataStore::instance(), &VDPDataStore::dataRefreshed,

src/PaletteDialog.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QPainter>
55
#include "PaletteDialog.h"
66
#include "Convert.h"
7+
#include "VDPDataStore.h"
78
#include "ranges.h"
89

910

@@ -40,14 +41,12 @@ void PalettePatch::setHighlightTest(int colorNr)
4041

4142
void PalettePatch::paintEvent(QPaintEvent* /*event*/)
4243
{
43-
QPainter painter(this);
44-
painter.setPen(isSelected ? Qt::white : QColor(myColor));
45-
painter.setBrush(QBrush(myColor));
46-
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
44+
QPainter painter(this);
45+
painter.setPen(isSelected ? Qt::white : QColor(myColor));
46+
painter.setBrush(QBrush(myColor));
47+
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
4748
}
4849

49-
50-
5150
PaletteDialog::PaletteDialog(QWidget* parent)
5251
: QDialog(parent), ui(std::make_unique<Ui::PaletteDialog>())
5352
{
@@ -172,6 +171,15 @@ void PaletteDialog::syncToSource()
172171
emit paletteSynced();
173172
}
174173

174+
void PaletteDialog::restoreDefaultPalette()
175+
{
176+
memcpy(myPal, VDPDataStore::instance().getDefaultPalettePointer(), 32);
177+
emit paletteChanged(myPal);
178+
if (autoSync) {
179+
syncToSource();
180+
}
181+
}
182+
175183
void PaletteDialog::setAutoSync(bool value)
176184
{
177185
if (autoSync == value) return;
@@ -199,8 +207,9 @@ void PaletteDialog::on_horizontalSlider_B_valueChanged(int value)
199207

200208
void PaletteDialog::on_buttonBox_clicked(QAbstractButton* button)
201209
{
202-
if (button== ui->buttonBox->button(QDialogButtonBox::Apply) ||
203-
button== ui->buttonBox->button(QDialogButtonBox::Ok)) {
210+
if (button== ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)) {
211+
restoreDefaultPalette();
212+
} else if (button== ui->buttonBox->button(QDialogButtonBox::Ok)) {
204213
syncToSource();
205214
} else if (button== ui->buttonBox->button(QDialogButtonBox::Reset) ||
206215
button== ui->buttonBox->button(QDialogButtonBox::Cancel)) {

src/PaletteDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class PaletteDialog : public QDialog
4141
void setPalette(uint8_t* pal);
4242
uint8_t* getPalette();
4343
void syncToSource();
44+
void restoreDefaultPalette();
4445
void setAutoSync(bool value);
4546

4647
signals:

src/PaletteDialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>513</width>
10-
<height>271</height>
10+
<height>278</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -139,7 +139,7 @@
139139
<enum>Qt::Horizontal</enum>
140140
</property>
141141
<property name="standardButtons">
142-
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
142+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
143143
</property>
144144
</widget>
145145
</item>

src/TileViewer.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@
77
#include <QMessageBox>
88

99

10-
// static to feed to PaletteDialog and be used when VDP colors aren't selected
11-
static uint8_t currentPalette[32] = {
12-
// RB G
13-
0x00, 0,
14-
0x00, 0,
15-
0x11, 6,
16-
0x33, 7,
17-
0x17, 1,
18-
0x27, 3,
19-
0x51, 1,
20-
0x27, 6,
21-
0x71, 1,
22-
0x73, 3,
23-
0x61, 6,
24-
0x64, 6,
25-
0x11, 4,
26-
0x65, 2,
27-
0x55, 5,
28-
0x77, 7,
29-
};
30-
10+
static uint8_t currentPalette[32] = { 0 };
3111

3212
TileViewer::TileViewer(QWidget* parent)
3313
: QDialog(parent), image4label(32, 32, QImage::Format_RGB32)
@@ -82,7 +62,7 @@ TileViewer::TileViewer(QWidget* parent)
8262

8363
scrollArea->setWidget(imageWidget);
8464

85-
imageWidget->setPaletteSource(currentPalette);
65+
imageWidget->setPaletteSource(VDPDataStore::instance().getDefaultPalettePointer());
8666
imageWidget->setUseBlink(cb_blinkcolors->isChecked());
8767
imageWidget->setDrawGrid(cb_drawgrid->isChecked());
8868

src/VDPDataStore.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
#include "VDPDataStore.h"
22
#include "CommClient.h"
33

4+
// static vector to feed PaletteDialog and be used when VDP colors aren't selected
5+
static const uint8_t defaultPalette[32] = {
6+
// RB G
7+
0x00, 0,
8+
0x00, 0,
9+
0x11, 6,
10+
0x33, 7,
11+
0x17, 1,
12+
0x27, 3,
13+
0x51, 1,
14+
0x27, 6,
15+
0x71, 1,
16+
0x73, 3,
17+
0x61, 6,
18+
0x64, 6,
19+
0x11, 4,
20+
0x65, 2,
21+
0x55, 5,
22+
0x77, 7,
23+
};
24+
425
class VDPDataStoreVersionCheck : public SimpleCommand
526
{
627
public:
@@ -149,6 +170,10 @@ const uint8_t* VDPDataStore::getVramPointer() const
149170
{
150171
return &vram[0];
151172
}
173+
const uint8_t* VDPDataStore::getDefaultPalettePointer() const
174+
{
175+
return defaultPalette;
176+
}
152177
const uint8_t* VDPDataStore::getPalettePointer() const
153178
{
154179
return &vram[vramSize];

src/VDPDataStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class VDPDataStore : public QObject, public SimpleHexRequestUser
1515
static VDPDataStore& instance();
1616

1717
const uint8_t* getVramPointer() const;
18+
const uint8_t* getDefaultPalettePointer() const;
1819
const uint8_t* getPalettePointer() const;
1920
const uint8_t* getRegsPointer() const;
2021
const uint8_t* getStatusRegsPointer() const;

0 commit comments

Comments
 (0)