tcMenu
Loading...
Searching...
No Matches
DeviceDrawable.h
1
2#ifndef TCLIBRARYDEV_DEVICEDRAWABLE_H
3#define TCLIBRARYDEV_DEVICEDRAWABLE_H
4
5#include <PlatformDetermination.h>
6#include "GfxMenuConfig.h"
7#include "DrawingPrimitives.h"
8
9class UnicodeFontHandler;
10
11namespace tcgfx {
35 public:
36 enum SubDeviceType {
37 NO_SUB_DEVICE, SUB_DEVICE_4BPP, SUB_DEVICE_2BPP
38 };
39 protected:
40 UnicodeFontHandler *fontHandler = nullptr;
41 color_t backgroundColor = 0, drawColor = 0;
42 SubDeviceType subDeviceType = NO_SUB_DEVICE;
43 public:
44 virtual ~DeviceDrawable() = default;
49
60 virtual DeviceDrawable *
61 getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize) = 0;
62
69 virtual void setPaletteEntry(size_t index, color_t col) {
70 }
71
72
82 void drawText(const Coord &where, const void *font, int mag, const char *text);
83
84 virtual void internalDrawText(const Coord &where, const void *font, int mag, const char *text) = 0;
85
94 virtual void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) = 0;
95
104 virtual void drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) = 0;
105
113 virtual void drawBox(const Coord &where, const Coord &size, bool filled) = 0;
114
121 virtual void drawCircle(const Coord &where, int radius, bool filled) = 0;
122
132 virtual void drawPolygon(const Coord points[], int numPoints, bool filled) = 0;
133
140 virtual color_t getUnderlyingColor(color_t col) { return col; }
141
150 virtual void drawRoundRect(const Coord& where, const Coord& size, int radius, bool filled) {}
151
152
159 virtual void transaction(bool isStarting, bool redrawNeeded) = 0;
160
170 virtual Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline) = 0;
171
181 Coord textExtents(const void *font, int mag, const char *text, int *baseline);
182
189 virtual void drawPixel(uint16_t x, uint16_t y) = 0;
190
198 Coord textExtents(const void *font, int mag, const char *text) {
199 return textExtents(font, mag, text, nullptr);
200 }
201
206 void startDraw() {
207 transaction(true, false);
208 }
209
215 void endDraw(bool needsDrawing = true) {
216 transaction(false, needsDrawing);
217 }
218
224 void setColors(color_t fg, color_t bg) {
225 backgroundColor = getUnderlyingColor(bg);
226 drawColor = getUnderlyingColor(fg);
227 }
228
233 void setDrawColor(color_t fg) { drawColor = getUnderlyingColor(fg); }
234
240 void enableTcUnicode() { if (fontHandler == nullptr) fontHandler = createFontHandler(); }
241
246 bool isTcUnicodeEnabled() { return fontHandler != nullptr; }
247
254 UnicodeFontHandler *getUnicodeHandler(bool enableIfNeeded = true);
255
261 void setFontHandler(UnicodeFontHandler* handler) {fontHandler = handler;}
262
266 SubDeviceType getSubDeviceType() { return subDeviceType; }
267
268 protected:
274 virtual UnicodeFontHandler *createFontHandler();
275
281 void setSubDeviceType(SubDeviceType s) { subDeviceType = s; }
282 };
283
284 void setTcFontAccordingToMag(UnicodeFontHandler* handler, const void* font, int mag);
285}
286
287#endif //TCLIBRARYDEV_DEVICEDRAWABLE_H
contains a series of core components needed by all graphical renderers
uint32_t color_t
Definition DrawingPrimitives.h:29
Definition DeviceDrawable.h:34
Coord textExtents(const void *font, int mag, const char *text, int *baseline)
Definition DeviceDrawable.cpp:31
virtual void drawPixel(uint16_t x, uint16_t y)=0
virtual void transaction(bool isStarting, bool redrawNeeded)=0
virtual Coord getDisplayDimensions()=0
bool isTcUnicodeEnabled()
Definition DeviceDrawable.h:246
virtual DeviceDrawable * getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize)=0
void endDraw(bool needsDrawing=true)
Definition DeviceDrawable.h:215
virtual Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline)=0
Coord textExtents(const void *font, int mag, const char *text)
Definition DeviceDrawable.h:198
virtual void drawBox(const Coord &where, const Coord &size, bool filled)=0
void setSubDeviceType(SubDeviceType s)
Definition DeviceDrawable.h:281
UnicodeFontHandler * getUnicodeHandler(bool enableIfNeeded=true)
Definition DeviceDrawable.cpp:20
virtual void drawRoundRect(const Coord &where, const Coord &size, int radius, bool filled)
Definition DeviceDrawable.h:150
virtual UnicodeFontHandler * createFontHandler()
Definition DeviceDrawable.cpp:27
virtual void drawCircle(const Coord &where, int radius, bool filled)=0
virtual void setPaletteEntry(size_t index, color_t col)
Definition DeviceDrawable.h:69
void setDrawColor(color_t fg)
Definition DeviceDrawable.h:233
void drawText(const Coord &where, const void *font, int mag, const char *text)
Definition DeviceDrawable.cpp:8
virtual color_t getUnderlyingColor(color_t col)
Definition DeviceDrawable.h:140
virtual void drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data)=0
virtual void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected)=0
void setColors(color_t fg, color_t bg)
Definition DeviceDrawable.h:224
void startDraw()
Definition DeviceDrawable.h:206
void setFontHandler(UnicodeFontHandler *handler)
Definition DeviceDrawable.h:261
virtual void drawPolygon(const Coord points[], int numPoints, bool filled)=0
void enableTcUnicode()
Definition DeviceDrawable.h:240
SubDeviceType getSubDeviceType()
Definition DeviceDrawable.h:266
Definition DrawingPrimitives.h:178
This file contains the base drawing structures and helper methods for drawing onto graphical screens,...
Definition DrawingPrimitives.h:149