TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Surface< RGB_T > Class Template Reference

In-memory bitmap surface with basic 2D drawing and text rendering. More...

#include <Surface.h>

Inheritance diagram for Surface< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for Surface< RGB_T >:
Collaboration graph
[legend]

Public Member Functions

 Surface ()=default
 Default constructor. Creates an empty surface.
 
 Surface (size_t w, size_t h, IFont< RGB_T > &font)
 Constructs a surface with the given width, height, and font.
 
void setPixel (size_t x, size_t y, RGB_T color) override
 Sets the pixel at (x, y) to the specified color.
 
RGB_T getPixel (size_t x, size_t y) const override
 Gets the color of the pixel at (x, y).
 
bool resizeBuffer (size_t w, size_t h) override
 Resizes the internal pixel buffer to the specified width and height.
 
const uint8_t * data () const override
 Returns a pointer to the raw data as bytes.
 
size_t size () const override
 Returns the size of the buffer in bytes.
 
- Public Member Functions inherited from SurfaceBase< PixelT >
 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

Vector< RGB_T > buffer
 
- Protected Attributes inherited from SurfaceBase< PixelT >
size_t width_ = 0
 
size_t height_ = 0
 
IFont< PixelT > * font_ = nullptr
 
LinePrinter< PixelT > linePrinter_
 

Detailed Description

template<typename RGB_T = RGB565>
class tinygpu::Surface< RGB_T >

In-memory bitmap surface with basic 2D drawing and text rendering.

Template Parameters
RGB_TThe pixel color type. Can be RGB565, RGB666, RGB888, etc.

The class stores pixel data in a contiguous buffer and provides helpers for drawing lines, rectangles, circles, sprites, and UTF-8 text.

Example usage: Surface<RGB565> surf565(240, 320); Surface<RGB666> surf666(240, 320); Surface<RGB888> surf888(240, 320);

Constructor & Destructor Documentation

◆ Surface() [1/2]

Surface ( )
default

Default constructor. Creates an empty surface.

◆ Surface() [2/2]

Surface ( size_t  w,
size_t  h,
IFont< RGB_T > &  font 
)
inline

Constructs a surface with the given width, height, and font.

Parameters
wSurface width in pixels
hSurface height in pixels
fontReference to the font used for text rendering

Member Function Documentation

◆ data()

const uint8_t * data ( ) const
inlineoverridevirtual

Returns a pointer to the raw data as bytes.

Returns
Pointer to the buffer as uint8_t

Implements ISurface< PixelT >.

◆ getPixel()

RGB_T getPixel ( size_t  x,
size_t  y 
) const
inlineoverridevirtual

Gets the color of the pixel at (x, y).

Parameters
xX coordinate
yY coordinate
Returns
Pixel color value

Implements SurfaceBase< PixelT >.

◆ resizeBuffer()

bool resizeBuffer ( size_t  w,
size_t  h 
)
inlineoverridevirtual

Resizes the internal pixel buffer to the specified width and height.

Parameters
wNew width
hNew height

Implements SurfaceBase< PixelT >.

◆ setPixel()

void setPixel ( size_t  x,
size_t  y,
RGB_T  color 
)
inlineoverride

Sets the pixel at (x, y) to the specified color.

Parameters
xX coordinate
yY coordinate
colorPixel color value

◆ size()

size_t size ( ) const
inlineoverridevirtual

Returns the size of the buffer in bytes.

Returns
Buffer size in bytes

Implements ISurface< PixelT >.

Member Data Documentation

◆ buffer

Vector<RGB_T> buffer
protected

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