-
Notifications
You must be signed in to change notification settings - Fork 1
/
palette.cpp
38 lines (30 loc) · 860 Bytes
/
palette.cpp
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
#include "palette.h"
#include "sprite.h"
Palette::Palette(QWidget *parent) : QLabel(parent)
{
}
void Palette::showPalette(options *opt)
{
this->opt = opt;
QImage img(this->width,this->height,QImage::Format_RGB32);
QPainter painter;
painter.begin(&img);
for (int i = 0; i < 8; i++)
{
painter.fillRect(44*i,0,44,28, opt->col_list.at(i));
painter.fillRect(44*i,28,44,28, opt->col_list.at(8+i));
}
painter.end();
this->setPixmap(QPixmap::fromImage(img));
}
void Palette::mousePressEvent(QMouseEvent *ev)
{
if (ev->pos().x() < 0 || ev->pos().x() > this->width)
return;
if (ev->pos().y() < 0 || ev->pos().y() > this->height)
return;
int color_pos = 0;
color_pos += ev->pos().x()/44;
color_pos += 8*(ev->pos().y()/28);
emit palette_clicked(ev->button(),color_pos);
}