libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::OneBitGraphicsDisplayImpl< ChildType > Class Template Reference

Detailed Description

template<class ChildType>
class daisy::OneBitGraphicsDisplayImpl< ChildType >

This class is intended as a intermediary class for your actual implementation of the OneBitGraphicsDisplay interface. It uses the CRTP design pattern where the template argument is the child class. It provides implementations for most of the functions, except DrawPixel(), Update() and Fill(), which you'll have to provide in your child class. The main goal of this class is to provide common drawing functions without relying on massive amounts of virtual function calls that would result in a performance loss. To achieve this, any drawing function that is implemented here and internally calls other drawing functions (e.g. DrawRect() which internally calls DrawPixel() and DrawLine()) makes these calls via the qualified name of these functions to explicitly suppress the virtual dispatch mechanism like this:

ChildType::DrawPixel(...); // no virtual function call; direct call into the child class function

To create a custom OneBitGraphicsDisplay implementation, you can A) inherit from OneBitGraphicsDisplay directly and provide all the drawing functions yourself B) Inherit from OneBitGraphicsDisplayImpl and only provide DrawPixel(), Fill() and Update() like this:

class MyDisplayClass : public OneBitGraphicsDisplayImpl<MyDisplayClass> { public: void Fill() override { ... }; void DrawPixel(uint_fast8_t x, uint_fast8_t y, bool on) override { ... }; void Update() override { ... } };

#include <display.h>

Inheritance diagram for daisy::OneBitGraphicsDisplayImpl< ChildType >:
daisy::OneBitGraphicsDisplay daisy::OledDisplay< daisy::SSD130xDriver >

Public Member Functions

 OneBitGraphicsDisplayImpl ()
 
virtual ~OneBitGraphicsDisplayImpl ()
 
void DrawLine (uint_fast8_t x1, uint_fast8_t y1, uint_fast8_t x2, uint_fast8_t y2, bool on) override
 
void DrawRect (uint_fast8_t x1, uint_fast8_t y1, uint_fast8_t x2, uint_fast8_t y2, bool on, bool fill=false) override
 
void DrawArc (uint_fast8_t x, uint_fast8_t y, uint_fast8_t radius, int_fast16_t start_angle, int_fast16_t sweep, bool on) override
 
char WriteChar (char ch, FontDef font, bool on) override
 
char WriteString (const char *str, FontDef font, bool on) override
 
Rectangle WriteStringAligned (const char *str, const FontDef &font, Rectangle boundingBox, Alignment alignment, bool on) override
 
- Public Member Functions inherited from daisy::OneBitGraphicsDisplay
 OneBitGraphicsDisplay ()
 
virtual ~OneBitGraphicsDisplay ()
 
virtual uint16_t Height () const =0
 
virtual uint16_t Width () const =0
 
Rectangle GetBounds () const
 
size_t CurrentX ()
 
size_t CurrentY ()
 
virtual void Fill (bool on)=0
 
virtual void DrawPixel (uint_fast8_t x, uint_fast8_t y, bool on)=0
 
void DrawRect (const Rectangle &rect, bool on, bool fill=false)
 
void DrawCircle (uint_fast8_t x, uint_fast8_t y, uint_fast8_t radius, bool on)
 
void SetCursor (uint16_t x, uint16_t y)
 
virtual void Update ()=0
 

Additional Inherited Members

- Protected Attributes inherited from daisy::OneBitGraphicsDisplay
uint16_t currentX_
 
uint16_t currentY_
 

Constructor & Destructor Documentation

◆ OneBitGraphicsDisplayImpl()

template<class ChildType >
daisy::OneBitGraphicsDisplayImpl< ChildType >::OneBitGraphicsDisplayImpl ( )
inline

◆ ~OneBitGraphicsDisplayImpl()

Member Function Documentation

◆ DrawArc()

template<class ChildType >
void daisy::OneBitGraphicsDisplayImpl< ChildType >::DrawArc ( uint_fast8_t  x,
uint_fast8_t  y,
uint_fast8_t  radius,
int_fast16_t  start_angle,
int_fast16_t  sweep,
bool  on 
)
inlineoverridevirtual

Draws an arc around the specified coordinate

Parameters
xx Coordinate of the center of the arc
yy Coordinate of the center of the arc
radiusradius of the arc
start_angleangle where to start the arc
sweeptotal angle of the arc
onon or off

Implements daisy::OneBitGraphicsDisplay.

◆ DrawLine()

template<class ChildType >
void daisy::OneBitGraphicsDisplayImpl< ChildType >::DrawLine ( uint_fast8_t  x1,
uint_fast8_t  y1,
uint_fast8_t  x2,
uint_fast8_t  y2,
bool  on 
)
inlineoverridevirtual

Draws a line from (x1, y1) to (y1, y2)

Parameters
x1x Coordinate of the starting point
y1y Coordinate of the starting point
x2x Coordinate of the ending point
y2y Coordinate of the ending point
onon or off

Implements daisy::OneBitGraphicsDisplay.

◆ DrawRect()

template<class ChildType >
void daisy::OneBitGraphicsDisplayImpl< ChildType >::DrawRect ( uint_fast8_t  x1,
uint_fast8_t  y1,
uint_fast8_t  x2,
uint_fast8_t  y2,
bool  on,
bool  fill = false 
)
inlineoverridevirtual

Draws a rectangle based on two coordinates.

Parameters
x1x Coordinate of the first point
y1y Coordinate of the first point
x2x Coordinate of the second point
y2y Coordinate of the second point
onon or off
fillfill the rectangle or draw only the outline

Implements daisy::OneBitGraphicsDisplay.

◆ WriteChar()

template<class ChildType >
char daisy::OneBitGraphicsDisplayImpl< ChildType >::WriteChar ( char  ch,
FontDef  font,
bool  on 
)
inlineoverridevirtual

Writes the character with the specific FontDef to the display buffer at the current Cursor position.

Parameters
chcharacter to be written
fontfont to be written in
onon or off
Returns
&

Implements daisy::OneBitGraphicsDisplay.

◆ WriteString()

template<class ChildType >
char daisy::OneBitGraphicsDisplayImpl< ChildType >::WriteString ( const char str,
FontDef  font,
bool  on 
)
inlineoverridevirtual

Similar to WriteChar, except it will handle an entire String. Wrapping does not happen automatically, so the width of the string must be kept within the dimensions of the screen.

Parameters
strstring to be written
fontfont to use
onon or off
Returns
&

Implements daisy::OneBitGraphicsDisplay.

◆ WriteStringAligned()

template<class ChildType >
Rectangle daisy::OneBitGraphicsDisplayImpl< ChildType >::WriteStringAligned ( const char str,
const FontDef font,
Rectangle  boundingBox,
Alignment  alignment,
bool  on 
)
inlineoverridevirtual

Similar to WriteString but justified within a bounding box.

Parameters
strstring to be written
fontfont to use
boundingBoxthe bounding box to draw the text in
alignmentthe alignment to use
onon or off
Returns
The rectangle that was drawn to

Implements daisy::OneBitGraphicsDisplay.


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