-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaletteedit.cpp
More file actions
152 lines (137 loc) · 5.55 KB
/
paletteedit.cpp
File metadata and controls
152 lines (137 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "paletteedit.h"
#include "ui_paletteedit.h"
#include "tile.h"
#include "project.h"
#include "mainwindow.h"
extern Project project;
PaletteEdit::PaletteEdit(QWidget *parent, MainWindow* main_window)
: QDockWidget(parent)
, ui(new Ui::PaletteEdit)
{
ui->setupUi(this);
this->main_window= main_window;
ui->tblPalette->setCurrentCell(0,0);
connect(ui->sliRedChannel, &QSlider::valueChanged, main_window, &MainWindow::on_colorChanged);
connect(ui->sliBlueChannel, &QSlider::valueChanged, main_window, &MainWindow::on_colorChanged);
connect(ui->sliGreenChannel, &QSlider::valueChanged, main_window, &MainWindow::on_colorChanged);
connect(ui->spbRedChannel, QOverload<int>::of(&QSpinBox::valueChanged), main_window, &MainWindow::on_colorChanged);
connect(ui->spbBlueChannel, QOverload<int>::of(&QSpinBox::valueChanged), main_window, &MainWindow::on_colorChanged);
connect(ui->spbGreenChannel, QOverload<int>::of(&QSpinBox::valueChanged), main_window, &MainWindow::on_colorChanged);
}
PaletteEdit::~PaletteEdit()
{
delete ui;
}
void PaletteEdit::Update()
{
ui->tblPalette->clear();
for (int iy=0; iy<PALETTE_H; iy++)
{
for (int ix=0; ix<PALETTE_W; ix++)
{
QTableWidgetItem* item= new QTableWidgetItem();
QBrush bru_bg;
if (ix+iy*PALETTE_W < project.tileset.palette.count())
bru_bg.setColor(project.tileset.palette[ix+iy*PALETTE_W]);
else
{
int lumarand= rand()%32;
bru_bg.setColor(QColor::fromRgb(lumarand*8, lumarand*8, lumarand*8));
}
if (project.tileset.isSubPalettedFormat())
{
if (project.paltable_current_row == iy && project.paltable_current_column == ix)
bru_bg.setStyle(Qt::Dense3Pattern);
else if (project.paltable_current_row == iy)
bru_bg.setStyle(Qt::Dense1Pattern);
else
bru_bg.setStyle(Qt::SolidPattern);
}
else
{
if (project.paltable_current_row == iy && project.paltable_current_column == ix)
bru_bg.setStyle(Qt::Dense3Pattern);
else
bru_bg.setStyle(Qt::SolidPattern);
}
item->setBackground(bru_bg);
if (project.tileset.isSubPalettedFormat())
item->setToolTip("Pal #"+QString::number(iy)+": "+QString::number(ix));
else
item->setToolTip("Index: "+QString::number(ix+iy*PALETTE_W));
ui->tblPalette->setItem(iy, ix, item);
}
}
switch (project.tileset.format)
{
case Tileset::GBA_4bpp:
setWindowTitle("Palettes (4bpp)");
break;
case Tileset::GBA_8bpp:
setWindowTitle("Palette (8bpp)");
break;
default:
setWindowTitle("Palette (invalid tile format!)");
break;
}
}
void PaletteEdit::on_tblPalette_cellClicked(int row, int column)
{
project.paltable_current_column= column;
project.paltable_current_row= row;
Update();
int palind= column+row*PALETTE_W;
if (palind >= project.tileset.palette.count())
return;
block_pal_updates= true;
ui->sliRedChannel->setValue(qRed(project.tileset.palette[palind])/8);
ui->sliGreenChannel->setValue(qGreen(project.tileset.palette[palind])/8);
ui->sliBlueChannel->setValue(qBlue(project.tileset.palette[palind])/8);
UpdateColorStatus(true);
block_pal_updates= false;
main_window->on_actionTilePicker_selected_pal_triggered();
}
void PaletteEdit::UpdateColorStatus(bool force)
{
if (ui->sliRedChannel->hasFocus() || force)
ui->spbRedChannel->setValue(ui->sliRedChannel->value());
if (ui->sliGreenChannel->hasFocus() || force)
ui->spbGreenChannel->setValue(ui->sliGreenChannel->value());
if (ui->sliBlueChannel->hasFocus() || force)
ui->spbBlueChannel->setValue(ui->sliBlueChannel->value());
if (ui->spbRedChannel->hasFocus() && !force)
ui->sliRedChannel->setValue(ui->spbRedChannel->value());
if (ui->spbGreenChannel->hasFocus() && !force)
ui->sliGreenChannel->setValue(ui->spbGreenChannel->value());
if (ui->spbBlueChannel->hasFocus() && !force)
ui->sliBlueChannel->setValue(ui->spbBlueChannel->value());
ui->widPrimaryColor->setStyleSheet("border: 1px solid black; background-color: rgb("
+ QString::number(ui->spbRedChannel->value()*8) + ","
+ QString::number(ui->spbGreenChannel->value()*8) + ","
+ QString::number(ui->spbBlueChannel->value()*8) + ");");
int paltable_index= project.paltable_current_column+project.paltable_current_row*PALETTE_W;
QRgb new_col= QColor(ui->spbRedChannel->value()*8,
ui->spbGreenChannel->value()*8, ui->spbBlueChannel->value()*8).rgb();
if (paltable_index < project.tileset.palette.count() && !force)
{
project.tileset.palette[paltable_index]= new_col;
if (block_pal_updates) return;
Update();
}
}
#if QT_VERSION_MAJOR > 5
void PaletteEdit::enterEvent(QEnterEvent* event)
#else
void PaletteEdit::enterEvent(QEvent* event)
#endif
{
if (!project.statusbar)
return;
project.statusbar->showMessage("Click a color cell in the table to select it. In 4bpp tile mode, the current row will be used as the draw palette");
}
void PaletteEdit::leaveEvent(QEvent* event)
{
if (!project.statusbar)
return;
project.statusbar->clearMessage();
}