tcMenu
Loading...
Searching...
No Matches
DrawingPrimitives.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3 * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4 */
5
10
11#ifndef TCMENU_DRAWING_PRIMITIVES_H
12#define TCMENU_DRAWING_PRIMITIVES_H
13
14#include <PlatformDetermination.h>
15
16namespace tcgfx {
17
21#define DRAW_NO_MASK 0xff
22
23
24#ifdef NEED_32BIT_COLOR_T_ALPHA
29 typedef uint32_t color_t;
31#define RGB(r, g, b) (uint32_t)( 0xff000000UL | ((r)<<16UL) | ((g)<<8UL) | (b) )
32#else
37 typedef uint16_t color_t;
39#define RGB(r, g, b) (uint16_t)( (((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3) )
40#endif
41
45 struct MenuFontDef {
46 const void* fontData;
47 const uint8_t fontMag;
48
49 MenuFontDef(const void* data, uint8_t mag) : fontData(data), fontMag(mag) { }
50 };
51
56 struct MenuPadding {
57 uint16_t top: 4;
58 uint16_t right: 4;
59 uint16_t bottom: 4;
60 uint16_t left: 4;
61
62 MenuPadding(int top_, int right_, int bottom_, int left_) {
63 top = top_;
64 bottom = bottom_;
65 right = right_;
66 left = left_;
67 }
68
69 explicit MenuPadding(int equalAll = 0) {
70 top = bottom = right = left = equalAll;
71 }
72 };
73
82 inline void makePadding(MenuPadding& padding, int top, int right, int bottom, int left) {
83 padding.top = top;
84 padding.right = right;
85 padding.bottom = bottom;
86 padding.left = left;
87 }
88
102
107 struct MenuBorder {
108 uint16_t top:3;
109 uint16_t left:3;
110 uint16_t bottom:3;
111 uint16_t right:3;
112 uint16_t borderType:3;
113
114 MenuBorder() = default;
115
116 explicit MenuBorder(uint8_t equalSides, BorderType type = BORD_OUTLINE_SQUARE) {
117 top = left = bottom = right = equalSides;
118 borderType = type;
119 }
120
121 MenuBorder(uint8_t top_, uint8_t right_, uint8_t bottom_, uint8_t left_, BorderType type = BORD_OUTLINE_SQUARE) {
122 top = top_;
123 right = right_;
124 left = left_;
125 bottom = bottom_;
126 borderType = type;
127 }
128
129 [[nodiscard]] BorderType getBorderType() const {
130 return static_cast<BorderType>(borderType);
131 }
132
133 [[nodiscard]] bool areAllBordersEqual() const {
134 return (top == left) && (left == right) && (right == bottom);
135 }
136
137 [[nodiscard]] bool isBorderOff() const {
138 return areAllBordersEqual() && top == 0;
139 }
140
141 [[nodiscard]] uint16_t getBoxDim(uint16_t size) const {
142 return borderType == BORD_FILL_ROUNDED ? size /2 : size;
143 }
144 };
145
146#ifndef TC_COORD_DEFINED
147#define TC_COORD_DEFINED
149 struct Coord {
152 x = y = 0;
153 }
154
160 Coord(int x, int y) {
161 this->x = x;
162 this->y = y;
163 }
164
165 Coord(const Coord &other) = default;
166 Coord& operator = (const Coord& other) = default;
167
168 int16_t x;
169 int16_t y;
170 };
171
172#endif // TC_COORD_DEFINED
173
179 public:
202 private:
203 uint16_t menuId;
204 Coord dimensions;
205 IconType iconType;
206 MemoryLocation location;
207 const uint8_t *normalIcon;
208 const uint8_t *selectedIcon;
209 const color_t* palette;
210 public:
214 DrawableIcon() : menuId(0), dimensions(0, 0), iconType(ICON_XBITMAP), location(STORED_IN_ROM),
215 normalIcon(nullptr), selectedIcon(nullptr), palette(nullptr) {}
216
220 DrawableIcon(const DrawableIcon &other) = default;
221 DrawableIcon& operator=(const DrawableIcon& other) = default;
222
231 DrawableIcon(uint16_t id, const Coord &size, IconType ty, const uint8_t *normal,
232 const uint8_t *selected = nullptr)
233 : menuId(id), dimensions(size), iconType(ty), location(STORED_IN_ROM), normalIcon(normal),
234 selectedIcon(selected), palette(nullptr) {}
235
244 DrawableIcon(uint16_t id, const Coord &size, IconType ty, const color_t* paletteEntries, const uint8_t *normal,
245 const uint8_t *selected = nullptr)
246 : menuId(id), dimensions(size), iconType(ty), location(STORED_IN_ROM), normalIcon(normal),
247 selectedIcon(selected), palette(paletteEntries) {}
248
254 const uint8_t *getIcon(bool selected) const {
255 return (selected && selectedIcon != nullptr) ? selectedIcon : normalIcon;
256 }
257
262 const color_t* getPalette() const {
263 return palette;
264 }
265
270 return dimensions;
271 };
272
277 return iconType;
278 }
279
280 uint16_t getKey() const {
281 return menuId;
282 }
283
284 void setFromValues(const Coord &size, IconType ty, const uint8_t *normal, const uint8_t *selected = nullptr) {
285 this->dimensions = size;
286 this->iconType = ty;
287 this->normalIcon = normal;
288 this->selectedIcon = selected;
289 }
290 };
291
292} // namespace tcgfx
293
294#define RGB_COL_BLACK RGB(0, 0, 0)
295#define RGB_COL_WHITE RGB(255, 255, 255)
296#define RGB_COL_RED RGB(255, 0, 0)
297#define RGB_COL_GREEN RGB(0, 255, 0)
298#define RGB_COL_BLUE RGB(0, 0, 255)
299#define RGB_COL_YELLOW RGB(255, 255, 0)
300#define RGB_COL_MAGENTA RGB(255, 0, 255)
301#define RGB_COL_CYAN RGB(0, 255, 255)
302#define RGB_COL_ORANGE RGB(255, 128, 0)
303#define RGB_COL_PURPLE RGB(128, 0, 128)
304#define RGB_COL_BROWN RGB(128, 64, 0)
305#define RGB_COL_LIGHT_GRAY RGB(192, 192, 192)
306#define RGB_COL_DARK_GRAY RGB(64, 64, 64)
307#define RGB_COL_LIGHT_RED RGB(255, 128, 128)
308#define RGB_COL_LIGHT_GREEN RGB(128, 255, 128)
309#define RGB_COL_LIGHT_BLUE RGB(128, 128, 255)
310#define RGB_COL_SEL_BLUE RGB(123, 196, 206)
311#define RGB_COL_LIGHT_YELLOW RGB(255, 255, 128)
312
313#endif //TCMENU_DRAWING_PRIMITIVES_H
uint32_t color_t
Definition DrawingPrimitives.h:29
void makePadding(MenuPadding &padding, int top, int right, int bottom, int left)
Definition DrawingPrimitives.h:82
BorderType
Definition DrawingPrimitives.h:93
@ BORD_OUTLINE_SQUARE
Definition DrawingPrimitives.h:95
@ BORD_FILL_ROUNDED
Definition DrawingPrimitives.h:97
@ BORD_OUTLINE_ROUNDED
Definition DrawingPrimitives.h:100
const color_t * getPalette() const
Definition DrawingPrimitives.h:262
DrawableIcon(uint16_t id, const Coord &size, IconType ty, const uint8_t *normal, const uint8_t *selected=nullptr)
Definition DrawingPrimitives.h:231
MemoryLocation
Definition DrawingPrimitives.h:194
@ STORED_IN_RAM
Definition DrawingPrimitives.h:198
@ STORED_IN_ROM
Definition DrawingPrimitives.h:196
@ LOAD_FROM_STORAGE
Definition DrawingPrimitives.h:200
Coord getDimensions() const
Definition DrawingPrimitives.h:269
DrawableIcon(const DrawableIcon &other)=default
DrawableIcon(uint16_t id, const Coord &size, IconType ty, const color_t *paletteEntries, const uint8_t *normal, const uint8_t *selected=nullptr)
Definition DrawingPrimitives.h:244
const uint8_t * getIcon(bool selected) const
Definition DrawingPrimitives.h:254
DrawableIcon()
Definition DrawingPrimitives.h:214
IconType getIconType() const
Definition DrawingPrimitives.h:276
IconType
Definition DrawingPrimitives.h:180
@ ICON_NATIVE
Definition DrawingPrimitives.h:192
@ ICON_XBITMAP
Definition DrawingPrimitives.h:182
@ ICON_MONO
Definition DrawingPrimitives.h:184
@ ICON_PALLETE_2BPP
Definition DrawingPrimitives.h:187
@ ICON_PALLETE_4BPP
Definition DrawingPrimitives.h:190
Definition DrawingPrimitives.h:149
Coord()
Definition DrawingPrimitives.h:151
Coord(int x, int y)
Definition DrawingPrimitives.h:160
Definition DrawingPrimitives.h:56