TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
SurfaceBase< PixelT > Class Template Referenceabstract

Base class for 2D surfaces with drawing and text rendering support. More...

#include <SurfaceBase.h>

Inheritance diagram for SurfaceBase< PixelT >:
Inheritance graph
[legend]
Collaboration diagram for SurfaceBase< PixelT >:
Collaboration graph
[legend]

Public Member Functions

 SurfaceBase ()=default
 Default constructor.
 
 SurfaceBase (size_t width, size_t height, IFont< PixelT > &font)
 Construct with width, height, and font.
 
bool begin ()
 Initializes the surface by resizing it to the current dimensions.
 
void end ()
 Clears the surface and releases any allocated resources.
 
 ~SurfaceBase () override=default
 Virtual destructor.
 
void setPixel (size_t x, size_t y, PixelT color) override=0
 Abstract method: set a pixel at (x, y) to the specified color.
 
PixelT getPixel (size_t x, size_t y) const override=0
 Abstract method: get the pixel color at (x, y).
 
void setFont (IFont< PixelT > &font)
 Set the font for text rendering.
 
IFont< PixelT > & font () override
 Get the current font (mutable).
 
const IFont< PixelT > & font () const
 Get the current font (const).
 
bool resize (size_t newWidth, size_t newHeight) override
 Resize the surface to new dimensions.
 
size_t width () const override
 Get the width of the surface.
 
size_t height () const override
 Get the height of the surface.
 
virtual bool resizeBuffer (size_t, size_t)=0
 
void clear (PixelT color=PixelT()) override
 Clears the framebuffer with a single color.
 
void scroll (int dx, int dy)
 Scroll the surface content by (dx, dy) pixels.
 
void drawLine (size_t x0, size_t y0, size_t x1, size_t y1, PixelT color) override
 Draw a line from (x0, y0) to (x1, y1) with the given color.
 
void drawRect (size_t x, size_t y, size_t w, size_t h, PixelT color) override
 Draw a rectangle outline at (x, y) with width w, height h, and color.
 
void fillRect (size_t x, size_t y, size_t w, size_t h, PixelT color) override
 Fill a rectangle at (x, y) with width w, height h, and color.
 
void drawCircle (size_t x, size_t y, size_t r, PixelT color) override
 Draw a circle outline centered at (x, y) with radius r and color.
 
void fillCircle (size_t x, size_t y, size_t r, PixelT color) override
 Fill a circle centered at (x, y) with radius r and color.
 
void drawSprite (size_t x, size_t y, const ISurface< PixelT > &sprite, PixelT invisibleColor=PixelT()) override
 Draw a sprite at (x, y), skipping pixels matching invisibleColor.
 
void clearSprite (size_t x, size_t y, ISurface< PixelT > &sprite, PixelT clearColor=PixelT()) override
 Clear the region covered by a sprite at (x, y) to clearColor.
 
void copySprite (size_t x, size_t y, const ISurface< PixelT > &sprite) override
 Copy the framebuffer region at (x, y) into the sprite.
 
void drawText (int16_t x, int16_t y, const char *text, PixelT foreground, PixelT background=PixelT(), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1) override
 
LinePrinter< PixelT > & linePrinter ()
 Get the line printer for this surface.
 
bool isInBounds (size_t x, size_t y) const
 Returns true if (x, y) is within the surface bounds.
 
void setPixelClipped (size_t x, size_t y, PixelT color)
 Set a pixel only if (x, y) is in bounds.
 
void drawHorizontalLineClipped (int x0, int x1, int y, PixelT color)
 Draw a horizontal line from x0 to x1 at y, clipped to bounds.
 
- Public Member Functions inherited from ISurface< PixelT >
virtual ~ISurface ()=default
 Destroys the framebuffer interface.
 
virtual bool begin ()=0
 Initializes the framebuffer surface.
 
virtual void end ()=0
 Closes the framebuffer and releases resources.
 
virtual bool resize (size_t newWidth, size_t newHeight)=0
 Resizes the framebuffer surface.
 
virtual void setPixel (size_t x, size_t y, PixelT color)=0
 Sets a pixel at the given position.
 
virtual PixelT getPixel (size_t x, size_t y) const=0
 Returns the pixel at the given position.
 
virtual void scroll (int dx, int dy)=0
 Scrolls the framebuffer content by the specified offsets.
 
virtual void clear (PixelT color=PixelT(0))=0
 Clears the framebuffer with a single color.
 
virtual void drawLine (size_t x0, size_t y0, size_t x1, size_t y1, PixelT color)=0
 Draws a line between two points.
 
virtual void drawRect (size_t x, size_t y, size_t w, size_t h, PixelT color)=0
 Draws a rectangle outline.
 
virtual void fillRect (size_t x, size_t y, size_t w, size_t h, PixelT color)=0
 Fills a rectangle.
 
virtual void drawCircle (size_t x, size_t y, size_t r, PixelT color)=0
 Draws a circle outline.
 
virtual void fillCircle (size_t x, size_t y, size_t r, PixelT color)=0
 Fills a circle.
 
virtual void drawSprite (size_t x, size_t y, const ISurface< PixelT > &sprite, PixelT invisibleColor=PixelT(0))=0
 Draws a sprite using an optional transparent color.
 
virtual void clearSprite (size_t x, size_t y, ISurface< PixelT > &sprite, PixelT clearColor=PixelT(0))=0
 Clears the area covered by a sprite.
 
virtual void copySprite (size_t x, size_t y, const ISurface< PixelT > &sprite)=0
 Copies pixels from the framebuffer into a sprite.
 
virtual size_t width () const=0
 Returns the framebuffer width in pixels.
 
virtual size_t height () const=0
 Returns the framebuffer height in pixels.
 
virtual void drawText (int16_t x, int16_t y, const char *text, PixelT foreground, PixelT background=PixelT(0), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1)=0
 Draws UTF-8 text using the configured font.
 
virtual IFont< PixelT > & font ()=0
 Returns the currently set font for text rendering.
 
virtual const uint8_t * data () const=0
 Provides access to the framebuffer as a byte buffer.
 
virtual size_t size () const=0
 Provides the total data size in bytes.
 

Protected Attributes

size_t width_ = 0
 
size_t height_ = 0
 
IFont< PixelT > * font_ = nullptr
 
LinePrinter< PixelT > linePrinter_
 

Detailed Description

template<typename PixelT>
class tinygpu::SurfaceBase< PixelT >

Base class for 2D surfaces with drawing and text rendering support.

SurfaceBase provides common logic for managing surface dimensions, font handling, and basic geometry operations. It is intended to be subclassed by concrete surface implementations that provide pixel storage and access (e.g., Surface, SurfaceMonochrome).

Template Parameters
PixelTThe pixel color type (e.g., RGB565, bool, etc.)

Constructor & Destructor Documentation

◆ SurfaceBase() [1/2]

SurfaceBase ( )
default

Default constructor.

◆ SurfaceBase() [2/2]

SurfaceBase ( size_t  width,
size_t  height,
IFont< PixelT > &  font 
)
inline

Construct with width, height, and font.

◆ ~SurfaceBase()

~SurfaceBase ( )
overridedefault

Virtual destructor.

Member Function Documentation

◆ begin()

bool begin ( )
inlinevirtual

Initializes the surface by resizing it to the current dimensions.

Implements ISurface< PixelT >.

◆ clear()

void clear ( PixelT  color = PixelT())
inlineoverridevirtual

Clears the framebuffer with a single color.

Implements ISurface< PixelT >.

◆ clearSprite()

void clearSprite ( size_t  x,
size_t  y,
ISurface< PixelT > &  sprite,
PixelT  clearColor = PixelT() 
)
inlineoverridevirtual

Clear the region covered by a sprite at (x, y) to clearColor.

Implements ISurface< PixelT >.

◆ copySprite()

void copySprite ( size_t  x,
size_t  y,
const ISurface< PixelT > &  sprite 
)
inlineoverridevirtual

Copy the framebuffer region at (x, y) into the sprite.

Implements ISurface< PixelT >.

◆ drawCircle()

void drawCircle ( size_t  x,
size_t  y,
size_t  r,
PixelT  color 
)
inlineoverridevirtual

Draw a circle outline centered at (x, y) with radius r and color.

Implements ISurface< PixelT >.

◆ drawHorizontalLineClipped()

void drawHorizontalLineClipped ( int  x0,
int  x1,
int  y,
PixelT  color 
)
inline

Draw a horizontal line from x0 to x1 at y, clipped to bounds.

◆ drawLine()

void drawLine ( size_t  x0,
size_t  y0,
size_t  x1,
size_t  y1,
PixelT  color 
)
inlineoverridevirtual

Draw a line from (x0, y0) to (x1, y1) with the given color.

Implements ISurface< PixelT >.

◆ drawRect()

void drawRect ( size_t  x,
size_t  y,
size_t  w,
size_t  h,
PixelT  color 
)
inlineoverridevirtual

Draw a rectangle outline at (x, y) with width w, height h, and color.

Implements ISurface< PixelT >.

◆ drawSprite()

void drawSprite ( size_t  x,
size_t  y,
const ISurface< PixelT > &  sprite,
PixelT  invisibleColor = PixelT() 
)
inlineoverridevirtual

Draw a sprite at (x, y), skipping pixels matching invisibleColor.

Implements ISurface< PixelT >.

◆ drawText()

void drawText ( int16_t  x,
int16_t  y,
const char *  text,
PixelT  foreground,
PixelT  background = PixelT(),
bool  opaque = false,
uint8_t  scale = 1,
uint8_t  spacing = 1,
uint8_t  lineSpacing = 1 
)
inlineoverridevirtual

Draw text at (x, y) with foreground/background color and formatting options.

Implements ISurface< PixelT >.

◆ end()

void end ( )
inlinevirtual

Clears the surface and releases any allocated resources.

Implements ISurface< PixelT >.

◆ fillCircle()

void fillCircle ( size_t  x,
size_t  y,
size_t  r,
PixelT  color 
)
inlineoverridevirtual

Fill a circle centered at (x, y) with radius r and color.

Implements ISurface< PixelT >.

◆ fillRect()

void fillRect ( size_t  x,
size_t  y,
size_t  w,
size_t  h,
PixelT  color 
)
inlineoverridevirtual

Fill a rectangle at (x, y) with width w, height h, and color.

Implements ISurface< PixelT >.

◆ font() [1/2]

const IFont< PixelT > & font ( ) const
inline

Get the current font (const).

◆ font() [2/2]

IFont< PixelT > & font ( )
inlineoverridevirtual

Get the current font (mutable).

Implements ISurface< PixelT >.

◆ getPixel()

PixelT getPixel ( size_t  x,
size_t  y 
) const
overridepure virtual

Abstract method: get the pixel color at (x, y).

Implements ISurface< PixelT >.

Implemented in Surface< RGB_T >, Surface< RGB565 >, and SurfaceMonochrome.

◆ height()

size_t height ( ) const
inlineoverridevirtual

Get the height of the surface.

Implements ISurface< PixelT >.

◆ isInBounds()

bool isInBounds ( size_t  x,
size_t  y 
) const
inline

Returns true if (x, y) is within the surface bounds.

◆ linePrinter()

LinePrinter< PixelT > & linePrinter ( )
inline

Get the line printer for this surface.

◆ resize()

bool resize ( size_t  newWidth,
size_t  newHeight 
)
inlineoverridevirtual

Resize the surface to new dimensions.

Implements ISurface< PixelT >.

◆ resizeBuffer()

virtual bool resizeBuffer ( size_t  ,
size_t   
)
pure virtual

◆ scroll()

void scroll ( int  dx,
int  dy 
)
inlinevirtual

Scroll the surface content by (dx, dy) pixels.

Implements ISurface< PixelT >.

◆ setFont()

void setFont ( IFont< PixelT > &  font)
inline

Set the font for text rendering.

◆ setPixel()

void setPixel ( size_t  x,
size_t  y,
PixelT  color 
)
overridepure virtual

Abstract method: set a pixel at (x, y) to the specified color.

Implements ISurface< PixelT >.

Implemented in SurfaceMonochrome.

◆ setPixelClipped()

void setPixelClipped ( size_t  x,
size_t  y,
PixelT  color 
)
inline

Set a pixel only if (x, y) is in bounds.

◆ width()

size_t width ( ) const
inlineoverridevirtual

Get the width of the surface.

Implements ISurface< PixelT >.

Member Data Documentation

◆ font_

IFont<PixelT>* font_ = nullptr
protected

◆ height_

size_t height_ = 0
protected

◆ linePrinter_

LinePrinter<PixelT> linePrinter_
protected

◆ width_

size_t width_ = 0
protected

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