TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
SurfaceMonochrome Class Reference

In-memory 1-bit (monochrome) bitmap surface with 2D drawing and text rendering. More...

#include <SurfaceMonochrome.h>

Inheritance diagram for SurfaceMonochrome:
Inheritance graph
[legend]
Collaboration diagram for SurfaceMonochrome:
Collaboration graph
[legend]

Public Member Functions

 SurfaceMonochrome ()=default
 Default constructor. Creates an empty monochrome surface.
 
 SurfaceMonochrome (size_t w, size_t h, IFont< bool > &font)
 Constructs a monochrome surface with the given width, height, and font.
 
void setPixel (size_t x, size_t y, bool color) override
 Sets the pixel at (x, y) to the specified color (on/off).
 
bool getPixel (size_t x, size_t y) const override
 Gets the value of the pixel at (x, y).
 
bool resizeBuffer (size_t w, size_t h) override
 Resizes the internal bit-packed buffer to the specified width and height.
 
const uint8_t * data () const override
 Returns a pointer to the raw bit-packed data as bytes.
 
size_t size () const override
 Returns the size of the buffer in bytes.
 
- Public Member Functions inherited from SurfaceBase< bool >
 SurfaceBase ()=default
 Default constructor.
 
 SurfaceBase (size_t width, size_t height, IFont< bool > &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, bool color) override=0
 Abstract method: set a pixel at (x, y) to the specified color.
 
bool getPixel (size_t x, size_t y) const override=0
 Abstract method: get the pixel color at (x, y).
 
void setFont (IFont< bool > &font)
 Set the font for text rendering.
 
IFont< bool > & font () override
 Get the current font (mutable).
 
const IFont< bool > & 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 (bool color=bool()) 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, bool 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, bool 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, bool 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, bool 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, bool color) override
 Fill a circle centered at (x, y) with radius r and color.
 
void drawSprite (size_t x, size_t y, const ISurface< bool > &sprite, bool invisibleColor=bool()) override
 Draw a sprite at (x, y), skipping pixels matching invisibleColor.
 
void clearSprite (size_t x, size_t y, ISurface< bool > &sprite, bool clearColor=bool()) override
 Clear the region covered by a sprite at (x, y) to clearColor.
 
void copySprite (size_t x, size_t y, const ISurface< bool > &sprite) override
 Copy the framebuffer region at (x, y) into the sprite.
 
void drawText (int16_t x, int16_t y, const char *text, bool foreground, bool background=bool(), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1) override
 
LinePrinter< bool > & 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, bool color)
 Set a pixel only if (x, y) is in bounds.
 
void drawHorizontalLineClipped (int x0, int x1, int y, bool color)
 Draw a horizontal line from x0 to x1 at y, clipped to bounds.
 
- Public Member Functions inherited from ISurface< RGB_T >
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, RGB_T color)=0
 Sets a pixel at the given position.
 
virtual RGB_T 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 (RGB_T color=RGB_T(0))=0
 Clears the framebuffer with a single color.
 
virtual void drawLine (size_t x0, size_t y0, size_t x1, size_t y1, RGB_T color)=0
 Draws a line between two points.
 
virtual void drawRect (size_t x, size_t y, size_t w, size_t h, RGB_T color)=0
 Draws a rectangle outline.
 
virtual void fillRect (size_t x, size_t y, size_t w, size_t h, RGB_T color)=0
 Fills a rectangle.
 
virtual void drawCircle (size_t x, size_t y, size_t r, RGB_T color)=0
 Draws a circle outline.
 
virtual void fillCircle (size_t x, size_t y, size_t r, RGB_T color)=0
 Fills a circle.
 
virtual void drawSprite (size_t x, size_t y, const ISurface< RGB_T > &sprite, RGB_T invisibleColor=RGB_T(0))=0
 Draws a sprite using an optional transparent color.
 
virtual void clearSprite (size_t x, size_t y, ISurface< RGB_T > &sprite, RGB_T clearColor=RGB_T(0))=0
 Clears the area covered by a sprite.
 
virtual void copySprite (size_t x, size_t y, const ISurface< RGB_T > &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, RGB_T foreground, RGB_T background=RGB_T(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< RGB_T > & 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< uint8_t > buffer
 
- Protected Attributes inherited from SurfaceBase< bool >
size_t width_
 
size_t height_
 
IFont< bool > * font_
 
LinePrinter< bool > linePrinter_
 

Detailed Description

In-memory 1-bit (monochrome) bitmap surface with 2D drawing and text rendering.

SurfaceMonochrome stores pixels in a bit-packed buffer for efficient memory usage. It provides the same drawing and text API as color surfaces, but only supports two pixel values (on/off).

This class is ideal for displays or images where only black/white (or on/off) is needed.

Constructor & Destructor Documentation

◆ SurfaceMonochrome() [1/2]

SurfaceMonochrome ( )
default

Default constructor. Creates an empty monochrome surface.

◆ SurfaceMonochrome() [2/2]

SurfaceMonochrome ( size_t  w,
size_t  h,
IFont< bool > &  font 
)
inline

Constructs a monochrome 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 bit-packed data as bytes.

Returns
Pointer to the buffer as uint8_t

Implements ISurface< RGB_T >.

◆ getPixel()

bool getPixel ( size_t  x,
size_t  y 
) const
inlineoverridevirtual

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

Parameters
xX coordinate
yY coordinate
Returns
Pixel value (true=on, false=off)

Implements SurfaceBase< bool >.

◆ resizeBuffer()

bool resizeBuffer ( size_t  w,
size_t  h 
)
inlineoverridevirtual

Resizes the internal bit-packed buffer to the specified width and height.

Parameters
wNew width
hNew height

Implements SurfaceBase< bool >.

◆ setPixel()

void setPixel ( size_t  x,
size_t  y,
bool  color 
)
inlineoverridevirtual

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

Parameters
xX coordinate
yY coordinate
colorPixel value (true=on, false=off)

Implements SurfaceBase< bool >.

◆ size()

size_t size ( ) const
inlineoverridevirtual

Returns the size of the buffer in bytes.

Returns
Buffer size in bytes

Implements ISurface< RGB_T >.

Member Data Documentation

◆ buffer

Vector<uint8_t> buffer
protected

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