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
144 void reConfigure(color_t *palette, uint8_t paletteSize, const Coord &startPosition, const Coord &size);
145
151 DeviceDrawable *getDrawable() { return drawable; }
152
160 return isSubDevice ? Coord(source.x - startPos.x, source.y - startPos.y) : source;
161 }
162
171 Coord offsetLocation(const Coord &source, int xOffs, int yOffs) const;
172
177 void endDraw() {
178 if (isSubDevice) {
179 drawable->endDraw(true);
180 drawable = rootDrawable;
181 }
182 }
183
189 fontMode = font;
190 }
191
199 void drawText(const Coord& where, color_t color, const char* text);
207 Coord textExtents(const char* text, int* bl);
208
213 void setFontFromParameters(const void* font, uint8_t mag);
214 };
215
216}
217
218#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:151
void endDraw()
Definition DeviceDrawableHelper.h:177
Coord offsetLocation(const Coord &source) const
Definition DeviceDrawableHelper.h:159
Coord textExtents(const char *text, int *bl)
Definition DeviceDrawableHelper.cpp:37
void setFont(const DeviceFontDrawingMode &font)
Definition DeviceDrawableHelper.h:188
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