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
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
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
92 struct MenuBorder {
93 uint8_t top:2;
94 uint8_t left:2;
95 uint8_t bottom:2;
96 uint8_t right:2;
97
98 MenuBorder() = default;
99
100 explicit MenuBorder(uint8_t equalSides) {
101 top = left = bottom = right = equalSides;
102 }
103
105 top = top_;
106 right = right_;
107 left = left_;
108 bottom = bottom_;
109 }
110
111 bool areAllBordersEqual() const {
112 return (top == left) && (left == right) && (right == bottom);
113 }
114
115 bool isBorderOff() const {
116 return areAllBordersEqual() && top == 0;
117 }
118 };
119
120#ifndef TC_COORD_DEFINED
121#define TC_COORD_DEFINED
123 struct Coord {
126 x = y = 0;
127 }
128
134 Coord(int x, int y) {
135 this->x = x;
136 this->y = y;
137 }
138
139 Coord(const Coord &other) = default;
140 Coord& operator = (const Coord& other) = default;
141
142 int16_t x;
143 int16_t y;
144 };
145
146#endif // TC_COORD_DEFINED
147
153 public:
176 private:
177 uint16_t menuId;
178 Coord dimensions;
179 IconType iconType;
180 MemoryLocation location;
181 const uint8_t *normalIcon;
182 const uint8_t *selectedIcon;
183 const color_t* palette;
184 public:
188 DrawableIcon() : menuId(0), dimensions(0, 0), iconType(ICON_XBITMAP), location(STORED_IN_ROM),
189 normalIcon(nullptr), selectedIcon(nullptr), palette(nullptr) {}
190
194 DrawableIcon(const DrawableIcon &other) = default;
195 DrawableIcon& operator=(const DrawableIcon& other) = default;
196
206 const uint8_t *selected = nullptr)
207 : menuId(id), dimensions(size), iconType(ty), location(STORED_IN_ROM), normalIcon(normal),
208 selectedIcon(selected), palette(nullptr) {}
219 const uint8_t *selected = nullptr)
220 : menuId(id), dimensions(size), iconType(ty), location(STORED_IN_ROM), normalIcon(normal),
221 selectedIcon(selected), palette(paletteEntries) {}
222
228 const uint8_t *getIcon(bool selected) const {
229 return (selected && selectedIcon != nullptr) ? selectedIcon : normalIcon;
230 }
231
236 const color_t* getPalette() const {
237 return palette;
238 }
239
244 return dimensions;
245 };
246
251 return iconType;
252 }
253
254 uint16_t getKey() const {
255 return menuId;
256 }
257
258 void setFromValues(const Coord &size, IconType ty, const uint8_t *normal, const uint8_t *selected = nullptr) {
259 this->dimensions = size;
260 this->iconType = ty;
261 this->normalIcon = normal;
262 this->selectedIcon = selected;
263 }
264 };
265
266} // namespace tcgfx
267
268#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
Definition DrawingPrimitives.h:152
const color_t * getPalette() const
Definition DrawingPrimitives.h:236
DrawableIcon(uint16_t id, const Coord &size, IconType ty, const uint8_t *normal, const uint8_t *selected=nullptr)
Definition DrawingPrimitives.h:205
MemoryLocation
Definition DrawingPrimitives.h:168
@ STORED_IN_RAM
Definition DrawingPrimitives.h:172
@ STORED_IN_ROM
Definition DrawingPrimitives.h:170
@ LOAD_FROM_STORAGE
Definition DrawingPrimitives.h:174
Coord getDimensions() const
Definition DrawingPrimitives.h:243
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:218
const uint8_t * getIcon(bool selected) const
Definition DrawingPrimitives.h:228
DrawableIcon()
Definition DrawingPrimitives.h:188
IconType getIconType() const
Definition DrawingPrimitives.h:250
IconType
Definition DrawingPrimitives.h:154
@ ICON_NATIVE
Definition DrawingPrimitives.h:166
@ ICON_XBITMAP
Definition DrawingPrimitives.h:156
@ ICON_MONO
Definition DrawingPrimitives.h:158
@ ICON_PALLETE_2BPP
Definition DrawingPrimitives.h:161
@ ICON_PALLETE_4BPP
Definition DrawingPrimitives.h:164
Definition GfxMenuConfig.h:32
Definition DrawingPrimitives.h:123
Coord()
Definition DrawingPrimitives.h:125
Coord(int x, int y)
Definition DrawingPrimitives.h:134
Definition DrawingPrimitives.h:92
Definition DrawingPrimitives.h:45
Definition DrawingPrimitives.h:56