tcMenu
Public Member Functions | List of all members
tcgfx::DeviceDrawableHelper Class Reference

#include <DeviceDrawableHelper.h>

Public Member Functions

 DeviceDrawableHelper (DeviceDrawable *root, color_t *palette, uint8_t paletteSize, const Coord &startPosition, const Coord &size)
 
 DeviceDrawableHelper (DeviceDrawable *root)
 
void reConfigure (color_t *palette, uint8_t paletteSize, const Coord &startPosition, const Coord &size)
 
DeviceDrawablegetDrawable ()
 
Coord offsetLocation (const Coord &source) const
 
Coord offsetLocation (const Coord &source, int xOffs, int yOffs) const
 
void endDraw ()
 
void setFont (const DeviceFontDrawingMode &font)
 
void drawText (const Coord &where, color_t color, const char *text)
 
Coord textExtents (const char *text, int *bl)
 
void setFontFromParameters (const void *font, uint8_t mag)
 

Detailed Description

Wraps a drawable regardless of if we are on a sub device or root device, this class handles all the differences between the two with helper functions for dealing with palette colors and offset differences. It also has helpers that work out if TcUnicode(Adafruit or Unicode)/Native fonts are being used and calls the right drawing functions

Constructor & Destructor Documentation

◆ DeviceDrawableHelper() [1/2]

DeviceDrawableHelper::DeviceDrawableHelper ( DeviceDrawable root,
color_t palette,
uint8_t  paletteSize,
const Coord startPosition,
const Coord size 
)

Create a drawable helper given the drawable, palette, position and size, if it is possible, it will create a subdevice for drawing. When you call drawing functions that take a where coordinate, use the offsetLocation function that corrects for the sub drawable for you automatically.

Parameters
rootthe root device drawable
palettethe palette of colors for the sub drawable
paletteSizethe size of the palette
startPositionthe starting position on the screen to draw at
sizehow large the area is

◆ DeviceDrawableHelper() [2/2]

DeviceDrawableHelper::DeviceDrawableHelper ( DeviceDrawable root)
explicit

For global constructions, we can also initially construct as root, and it will reconfigure later.

Parameters
rootthe drawable that will act as root

Member Function Documentation

◆ getDrawable()

DeviceDrawable* tcgfx::DeviceDrawableHelper::getDrawable ( )
inline

Get the drawable, not that this could be either the root device or a sub-device, always use offset location to ensure your where parameters are correctly positioned

Returns
the drawable

◆ offsetLocation() [1/2]

Coord tcgfx::DeviceDrawableHelper::offsetLocation ( const Coord source) const
inline

If on a sub-device, this call will correct the coordinate to match the area of the screen that the sub-device is drawing to.

Parameters
sourcethe source in screen coordinates
Returns
the coordinates correct for the current drawable

◆ offsetLocation() [2/2]

Coord DeviceDrawableHelper::offsetLocation ( const Coord source,
int  xOffs,
int  yOffs 
) const

If on a sub-device, this call will correct the coordinate to match the area of the screen that the sub-device is drawing to.

Parameters
sourcethe source in screen coordinates
xOffsan additional x offset to apply
yOffsan additional y offset to apply
Returns
the coordinates correct for the current drawable

◆ endDraw()

void tcgfx::DeviceDrawableHelper::endDraw ( )
inline

You must call this once drawing is concluded to ensure that the results are drawn, in the case of a sub-device this is critical.

◆ setFont()

void tcgfx::DeviceDrawableHelper::setFont ( const DeviceFontDrawingMode font)
inline

Set the font drawing mode for the subsequent text operations

Parameters
fontthe font drawing mode

◆ drawText()

void DeviceDrawableHelper::drawText ( const Coord where,
color_t  color,
const char *  text 
)

Draw text in the current font onto the display using the current drawable. Ensure you've called setFont before this with a suitable font.

Parameters
wherewhere to draw (will automatically apply offsetLocation)
colorthe color to draw in (not the index)
textthe text to be presented

◆ textExtents()

Coord DeviceDrawableHelper::textExtents ( const char *  text,
int *  bl 
)

Gets the size of the text for the current font as set by setFont. It's coordinates are returned, and the baseline is copied into the baseline parameter

Parameters
textthe text to measure
blthe baseline pointer to fill in - int pointer
Returns
the size of the text.

◆ setFontFromParameters()

void DeviceDrawableHelper::setFontFromParameters ( const void *  font,
uint8_t  mag 
)

Set the font from the theme font pointer and magnification values, by determining if tcUnicode is enabled and then choosing either native or TcUnicode based operation.


The documentation for this class was generated from the following files: