-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteGridFrame.h
More file actions
57 lines (50 loc) · 1.64 KB
/
Copy pathSpriteGridFrame.h
File metadata and controls
57 lines (50 loc) · 1.64 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
#pragma once
#include "fabgl.h"
#include "fabui.h"
#include "AppData.h"
#define GRID_SIZE 16 // FIXME taille plus grande crash (probleme de memoire)
struct SpriteGridFrame : public uiFrame
{
AppData *appData;
RGB888 activeCol;
uint16_t gridButtonSize;
uiButton *gridButtons[GRID_SIZE][GRID_SIZE];
SpriteGridFrame(uiFrame * parent, AppData *appData)
: uiFrame(parent, "", Point(0, 0), Size(480, 480), true)
{
frameStyle().backgroundColor = RGB888(255, 255, 255);
windowStyle().borderSize = 0;
frameProps().resizeable = false;
this->appData = appData;
gridButtonSize = 480 / GRID_SIZE;
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
gridButtons[i][j] = new uiButton(
this,
"",
Point(i*gridButtonSize, j*gridButtonSize),
Size(gridButtonSize, gridButtonSize)
);
gridButtons[i][j]->buttonStyle().backgroundColor = Color::BrightWhite;
gridButtons[i][j]->buttonStyle().downBackgroundColor = Color::BrightWhite;
gridButtons[i][j]->buttonStyle().mouseDownBackgroundColor = Color::BrightWhite;
gridButtons[i][j]->buttonStyle().mouseOverBackgroundColor = Color::BrightWhite;
gridButtons[i][j]->onClick = [&]() { onGridButtonClick(); };
}
}
}
void onGridButtonClick() {
MouseStatus mouseStatus = app()->mouse()->status();
int i = mouseStatus.X / gridButtonSize;
int j = mouseStatus.Y / gridButtonSize;
gridButtons[i][j]->buttonStyle().backgroundColor = appData->activeCol;
}
void clear()
{
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
gridButtons[i][j]->buttonStyle().backgroundColor = Color::BrightWhite;
}
}
}
};