tcMenu
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 
9 class UnicodeFontHandler;
10 
11 namespace 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;
48  virtual Coord getDisplayDimensions() = 0;
49 
60  virtual DeviceDrawable *
61  getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize) = 0;
62 
72  void drawText(const Coord &where, const void *font, int mag, const char *text);
73 
74  virtual void internalDrawText(const Coord &where, const void *font, int mag, const char *text) = 0;
75 
84  virtual void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) = 0;
85 
94  virtual void drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) = 0;
95 
103  virtual void drawBox(const Coord &where, const Coord &size, bool filled) = 0;
104 
111  virtual void drawCircle(const Coord &where, int radius, bool filled) = 0;
112 
122  virtual void drawPolygon(const Coord points[], int numPoints, bool filled) = 0;
123 
130  virtual color_t getUnderlyingColor(color_t col) { return col; }
131 
138  virtual void transaction(bool isStarting, bool redrawNeeded) = 0;
139 
149  virtual Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline) = 0;
150 
160  Coord textExtents(const void *font, int mag, const char *text, int *baseline);
161 
168  virtual void drawPixel(uint16_t x, uint16_t y) = 0;
169 
177  Coord textExtents(const void *font, int mag, const char *text) {
178  return textExtents(font, mag, text, nullptr);
179  }
180 
185  void startDraw() {
186  transaction(true, false);
187  }
188 
194  void endDraw(bool needsDrawing = true) {
195  transaction(false, needsDrawing);
196  }
197 
203  void setColors(color_t fg, color_t bg) {
204  backgroundColor = getUnderlyingColor(bg);
205  drawColor = getUnderlyingColor(fg);
206  }
207 
212  void setDrawColor(color_t fg) { drawColor = getUnderlyingColor(fg); }
213 
219  void enableTcUnicode() { if (fontHandler == nullptr) fontHandler = createFontHandler(); }
220 
225  bool isTcUnicodeEnabled() { return fontHandler != nullptr; }
226 
233  UnicodeFontHandler *getUnicodeHandler(bool enableIfNeeded = true);
234 
240  void setFontHandler(UnicodeFontHandler* handler) {fontHandler = handler;}
241 
245  SubDeviceType getSubDeviceType() { return subDeviceType; }
246 
247  protected:
253  virtual UnicodeFontHandler *createFontHandler();
254 
260  void setSubDeviceType(SubDeviceType s) { subDeviceType = s; }
261  };
262 
263  void setTcFontAccordingToMag(UnicodeFontHandler* handler, const void* font, int mag);
264 }
265 
266 #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:225
void endDraw(bool needsDrawing=true)
Definition: DeviceDrawable.h:194
virtual Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline)=0
virtual DeviceDrawable * getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize)=0
Coord textExtents(const void *font, int mag, const char *text)
Definition: DeviceDrawable.h:177
virtual void drawBox(const Coord &where, const Coord &size, bool filled)=0
void setSubDeviceType(SubDeviceType s)
Definition: DeviceDrawable.h:260
UnicodeFontHandler * getUnicodeHandler(bool enableIfNeeded=true)
Definition: DeviceDrawable.cpp:20
virtual UnicodeFontHandler * createFontHandler()
Definition: DeviceDrawable.cpp:27
virtual void drawCircle(const Coord &where, int radius, bool filled)=0
void setDrawColor(color_t fg)
Definition: DeviceDrawable.h:212
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:130
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:203
void startDraw()
Definition: DeviceDrawable.h:185
void setFontHandler(UnicodeFontHandler *handler)
Definition: DeviceDrawable.h:240
virtual void drawPolygon(const Coord points[], int numPoints, bool filled)=0
void enableTcUnicode()
Definition: DeviceDrawable.h:219
SubDeviceType getSubDeviceType()
Definition: DeviceDrawable.h:245
Definition: DrawingPrimitives.h:152
Definition: DrawingPrimitives.h:123