forked from DustinWatts/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFTButton.h
101 lines (93 loc) · 3.05 KB
/
FTButton.h
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
#pragma once
#include "globals.hpp"
#include "FTAction.h"
#include "UserConfig.h"
#include "ImageWrapper.h"
#include "ActionsSequence.h"
namespace FreeTouchDeck
{
enum class ButtonTypes
{
NONE,
STANDARD,
MENU,
LATCH,
ENDLIST
};
const char *enum_to_string(ButtonTypes type);
class FTButton
{
protected:
bool Latched = false;
bool NeedsDraw = true;
bool NeedsDrawImage = true;
bool IsPressed = false;
private:
uint16_t CenterX = 0;
uint16_t CenterY = 0;
uint16_t X = 0;
uint16_t Y = 0;
uint16_t ButtonWidth = 0;
bool IsLabel = false;
uint8_t Spacing = 0;
uint16_t ButtonHeight = 0;
uint16_t AdjustedWidth;
uint16_t AdjustedHeight;
uint16_t TextAdjustedWidth;
std::string _jsonLogo;
std::string _jsonLatchedLogo;
void ExecuteActions();
public:
static FTButton EmptyButton;
bool contains(uint16_t x, uint16_t y);
ButtonTypes ButtonType;
uint32_t BackgroundColor = 0;
uint32_t MenuBackgroundColor = 0;
uint32_t Outline = 0;
uint8_t TextSize = 0;
uint32_t TextColor = 0;
std::string Label;
static void InitConstants();
static const char *JsonLabelLogo;
static const char *JsonLabelLatchedLogo;
static const char *JsonLabelType;
static const char *JsonLabelLabel;
static const char *JsonLabelActions;
static const char *JsonLabelOutline;
static const char *JsonLabelBackground;
static const char *JsonLabelTextColor;
static const char *JsonLabelTextSize;
static const char *backButtonTemplate;
static const char *homeButtonTemplate;
bool IsShared = false;
bool IsMenu();
std::vector<ActionsSequences> Sequences;
FTButton(cJSON *button);
FTButton();
FTButton(cJSON *button, uint32_t BackgroundColor, uint32_t Outline, uint32_t TextColor);
FTButton(ButtonTypes buttonType, const char *label, const char *logo, const char *latchedLogo, uint32_t outline, uint8_t textSize, uint32_t textColor);
void Init(cJSON *button);
FTButton(const char *tmpl, bool isShared = false);
static FTButton *BackButton;
static FTButton *HomeButton;
void SetCoordinates(uint16_t width, uint16_t height, uint16_t row, uint16_t col, uint8_t spacing);
~FTButton();
bool Latch(FTAction *action);
ImageWrapper *LatchedLogo();
ImageWrapper *GetActiveImage();
ImageWrapper *Logo();
bool HasKeyboardActions();
uint16_t Width();
uint16_t Height();
void DrawShape(bool force);
void DrawImage(bool force);
void Draw(bool force);
void Invalidate();
void Press();
void UnPress();
void Release();
cJSON *ToJSON();
};
static ButtonTypes &operator++(ButtonTypes &state, int);
ButtonTypes parse_button_types(const char *buttonType);
}