tcMenu
Loading...
Searching...
No Matches
DeviceDrawableHelper.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 TCLIBRARYDEV_DEVICEDRAWABLEHELPER_H
12#define TCLIBRARYDEV_DEVICEDRAWABLEHELPER_H
13
14#include <PlatformDetermination.h>
15#include <tcUnicodeHelper.h>
16#include "GfxMenuConfig.h"
17#include "DeviceDrawable.h"
18
19namespace tcgfx {
24 private:
25 const void* ptr;
26 uint8_t mag;
27
28 public:
29 NativeFontDesc(const void *ptr, uint8_t mag) : ptr(ptr), mag(mag) {}
30 NativeFontDesc(const NativeFontDesc& other) = default;
32
33 uint8_t getMag() const { return mag; }
34 const void* getPtr() const { return ptr; }
35 };
36
42 ADAFRUIT_FONT, TCUNICODE_FONT, NATIVE_FONT, NO_FONT_SEL
43 };
44
49 private:
50 union {
51 const GFXfont *adaFont;
52 const UnicodeFont *uniFont;
53 NativeFontDesc nativeFont;
54 };
55 DeviceFontMode mode;
56 public:
57
62 mode = NO_FONT_SEL;
63 adaFont = nullptr;
64 }
65
67 DeviceFontDrawingMode& operator=(const DeviceFontDrawingMode& other) = default;
68
74 mode = ADAFRUIT_FONT;
75 adaFont = adaTc;
76 }
77
83 mode = TCUNICODE_FONT;
84 uniFont = adaTc;
85 }
91 mode = NATIVE_FONT;
92 nativeFont = nativeFontDesc;
93 }
94
95 bool isTcUnicode() { return mode == TCUNICODE_FONT || mode == ADAFRUIT_FONT; }
96
97 void setFontTcUnicode(UnicodeFontHandler* handler) {
98 if(mode == ADAFRUIT_FONT) {
99 handler->setFont(adaFont);
100 } else if(mode == TCUNICODE_FONT){
101 handler->setFont(uniFont);
102 }
103 }
104
105 const NativeFontDesc& getNativeDesc() const {
106 return nativeFont;
107 }
108 };
109
110
117 private:
118 DeviceDrawable *rootDrawable = nullptr;
119 DeviceDrawable *drawable = nullptr;
120 Coord startPos = {};
121 DeviceFontDrawingMode fontMode;
122 bool isSubDevice = false;
123 public:
136
141 explicit DeviceDrawableHelper(DeviceDrawable* root);
142
143 void setDrawable(DeviceDrawable* dr) {
144 this-> drawable = dr;
145 this->rootDrawable = dr;
146 }
147
148
149 void reConfigure(color_t *palette, uint8_t paletteSize, const Coord &startPosition, const Coord &size);
150
156 DeviceDrawable *getDrawable() { return drawable; }
157
165 return isSubDevice ? Coord(source.x - startPos.x, source.y - startPos.y) : source;
166 }
167
176 Coord offsetLocation(const Coord &source, int xOffs, int yOffs) const;
177
182 void endDraw() {
183 if (isSubDevice) {
184 drawable->endDraw(true);
185 drawable = rootDrawable;
186 }
187 }
188
194 fontMode = font;
195 }
196
204 void drawText(const Coord& where, color_t color, const char* text);
212 Coord textExtents(const char* text, int* bl);
213
218 void setFontFromParameters(const void* font, uint8_t mag);
219 };
220
221}
222
223#endif //TCLIBRARYDEV_DEVICEDRAWABLEHELPER_H
DeviceFontMode
Definition DeviceDrawableHelper.h:41
uint32_t color_t
Definition DrawingPrimitives.h:29
Definition DeviceDrawableHelper.h:116
DeviceDrawable * getDrawable()
Definition DeviceDrawableHelper.h:156
void endDraw()
Definition DeviceDrawableHelper.h:182
Coord offsetLocation(const Coord &source) const
Definition DeviceDrawableHelper.h:164
Coord textExtents(const char *text, int *bl)
Definition DeviceDrawableHelper.cpp:37
void setFont(const DeviceFontDrawingMode &font)
Definition DeviceDrawableHelper.h:193
void setFontFromParameters(const void *font, uint8_t mag)
Definition DeviceDrawableHelper.cpp:78
void drawText(const Coord &where, color_t color, const char *text)
Definition DeviceDrawableHelper.cpp:52
Definition DeviceDrawable.h:34
void endDraw(bool needsDrawing=true)
Definition DeviceDrawable.h:194
Definition DeviceDrawableHelper.h:48
DeviceFontDrawingMode(const NativeFontDesc &nativeFontDesc)
Definition DeviceDrawableHelper.h:90
DeviceFontDrawingMode(const GFXfont *adaTc)
Definition DeviceDrawableHelper.h:73
DeviceFontDrawingMode(const UnicodeFont *adaTc)
Definition DeviceDrawableHelper.h:82
DeviceFontDrawingMode()
Definition DeviceDrawableHelper.h:61
Definition DeviceDrawableHelper.h:23
Definition GfxMenuConfig.h:32
Definition DrawingPrimitives.h:123