-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPaletteFrame.h
More file actions
54 lines (47 loc) · 1.84 KB
/
Copy pathColorPaletteFrame.h
File metadata and controls
54 lines (47 loc) · 1.84 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
#pragma once
#include "fabgl.h"
#include "fabui.h"
#include "AppData.h"
#define NUM_COLORS 8
#define BUTTONS_PER_ROW 4
struct ColorPaletteFrame : public uiFrame
{
AppData *appData;
uint16_t paletteButtonSizeX, paletteButtonSizeY;
uiButton *paletteButtons[NUM_COLORS / BUTTONS_PER_ROW][BUTTONS_PER_ROW];
ColorPaletteFrame(uiFrame * parent, AppData *appData)
: uiFrame(parent, "", Point(480, 0), Size(160, 160), true)
{
frameStyle().backgroundColor = RGB888(255, 0, 0);
windowStyle().borderSize = 0;
frameProps().resizeable = false;
this->appData = appData;
paletteButtonSizeX = 160 / BUTTONS_PER_ROW;
paletteButtonSizeY = 160 / (NUM_COLORS / BUTTONS_PER_ROW);
int colorNum;
for (int i = 0; i < NUM_COLORS / BUTTONS_PER_ROW; i++) {
for (int j = 0; j < BUTTONS_PER_ROW; j++) {
paletteButtons[i][j] = new uiButton(
this,
"",
Point(j*paletteButtonSizeX, i*paletteButtonSizeY),
Size(paletteButtonSizeX, paletteButtonSizeY)
);
colorNum = i*BUTTONS_PER_ROW + j; // pick colors from enum class
if (i != 0 || j != 0)
colorNum = colorNum + 8; // choose "Bright..." colors except for black which isn't supported
paletteButtons[i][j]->buttonStyle().backgroundColor = (Color)colorNum;
paletteButtons[i][j]->buttonStyle().downBackgroundColor = Color::BrightWhite;
paletteButtons[i][j]->buttonStyle().mouseDownBackgroundColor = Color::BrightWhite;
paletteButtons[i][j]->buttonStyle().mouseOverBackgroundColor = (Color)colorNum;
paletteButtons[i][j]->onClick = [&]() { onPaletteButtonClick(); };
}
}
}
void onPaletteButtonClick() {
MouseStatus mouseStatus = app()->mouse()->status();
int j = (mouseStatus.X - 480) / paletteButtonSizeX; // substract sprite grid size
int i = mouseStatus.Y / paletteButtonSizeY;
appData->activeCol = paletteButtons[i][j]->buttonStyle().backgroundColor;
}
};