|
TinyGPU
|
Framebuffer with sprite placement and background restoration support. More...
#include <FrameBuffer.h>


Classes | |
| struct | Rect |
| struct | SpriteInfo |
Public Member Functions | |
| FrameBuffer ()=default | |
| Creates an empty framebuffer. | |
| FrameBuffer (size_t width, size_t height, IFont< RGB_T > &font) | |
| Creates a framebuffer with the specified size and font. | |
| bool | begin () override |
| Initializes the framebuffer surface. | |
| void | end () override |
| Closes the framebuffer and releases resources. | |
| SpriteInfo & | addSprite (size_t x, size_t y, const ISurface< RGB_T > &sprite, RGB_T invisibleColor=RGB_T(0)) |
| Adds a sprite to the framebuffer and draws it at the given position. | |
| SpriteInfo & | addSprite (size_t x, size_t y, size_t maxX, size_t maxY, const ISurface< RGB_T > &sprite, RGB_T invisibleColor=RGB_T(0)) |
| Adds a sprite with a preallocated max buffer size for transformations. | |
| void | removeSprite (SpriteInfo &spriteInfo) |
| Removes a sprite and restores the pixels behind it. | |
| void | moveSprite (SpriteInfo &spriteInfo, size_t newX, size_t newY) |
| Moves a sprite to a new position and redraws it. | |
| void | scaleSprite (SpriteInfo &spriteInfo, float scale) |
| Scales a sprite image and redraws it at its current position. | |
| void | rotateSprite (SpriteInfo &spriteInfo, float angleDegrees) |
| Rotates a sprite image and redraws it at its current position. | |
| void | setPixel (size_t x, size_t y, RGB_T color) override |
| ISurface<RGB_T> interface delegation. | |
| RGB_T | getPixel (size_t x, size_t y) const override |
| Returns the pixel at the given position. | |
| bool | resize (size_t w, size_t h) override |
| Resizes the framebuffer surface. | |
| size_t | width () const override |
| Returns the framebuffer width in pixels. | |
| size_t | height () const override |
| Returns the framebuffer height in pixels. | |
| void | setFont (IFont< RGB_T > &font) |
| Sets the font for text rendering. | |
| IFont< RGB_T > & | font () |
| Returns the currently set font for text rendering. | |
| void | clear (RGB_T color=RGB_T()) |
| Clears the framebuffer with a single color. | |
| void | scroll (int dx, int dy) override |
| Scrolls the framebuffer content by the specified offsets. | |
| void | drawLine (size_t x0, size_t y0, size_t x1, size_t y1, RGB_T color) |
| Draws a line between two points. | |
| void | drawRect (size_t x, size_t y, size_t w, size_t h, RGB_T color) |
| Draws a rectangle outline. | |
| void | fillRect (size_t x, size_t y, size_t w, size_t h, RGB_T color) |
| Fills a rectangle. | |
| void | drawCircle (size_t x, size_t y, size_t r, RGB_T color) |
| Draws a circle outline. | |
| void | fillCircle (size_t x, size_t y, size_t r, RGB_T color) |
| Fills a circle. | |
| void | drawSprite (size_t x, size_t y, const ISurface< RGB_T > &sprite, RGB_T invisibleColor=RGB_T()) |
| Draws a sprite. | |
| void | clearSprite (size_t x, size_t y, ISurface< RGB_T > &sprite, RGB_T clearColor=RGB_T()) |
| Clears a sprite. | |
| void | copySprite (size_t x, size_t y, const ISurface< RGB_T > &sprite) |
| Copies a sprite. | |
| void | drawText (int16_t x, int16_t y, const char *text, RGB_T foreground, RGB_T background=RGB_T(), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1) |
| Draws UTF-8 text. | |
| LinePrinter< RGB_T > & | linePrinter () |
| Returns the line printer for text rendering. | |
| bool | isInBounds (size_t x, size_t y) const |
| Checks if the given coordinates are within the surface bounds. | |
| void | setPixelClipped (size_t x, size_t y, RGB_T color) |
| Sets a pixel with clipping. | |
| void | drawHorizontalLineClipped (int x0, int x1, int y, RGB_T color) |
| Draws a horizontal line with clipping. | |
| const uint8_t * | data () const override |
| Returns the raw pixel buffer as bytes. | |
| size_t | size () const override |
| Returns the size of the buffer in bytes. | |
| bool | setData (uint8_t *data, size_t dataSize) |
| Sets the framebuffer pixel data directly, replacing the current content. | |
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 Member Functions | |
| IFont< RGB_T > & | activeFont () |
| Returns the currently active font used by the framebuffer. | |
| void | applyTransformedSprite (SpriteInfo &spriteInfo, Surface< RGB_T > &&transformedSprite) |
| void | restoreExposedPixels (const SpriteInfo &spriteInfo, const Rect &oldBounds, const Rect &overlap) |
| Surface< RGB_T > | captureUpdatedBackground (const SpriteInfo &spriteInfo, const Rect &oldBounds, const Rect &newBounds, const Rect &overlap) |
| Captures the updated background pixels after a sprite move/transform. | |
| void | drawSpriteRegion (const ISurface< RGB_T > &source, size_t sourceX, size_t sourceY, size_t destX, size_t destY, size_t width, size_t height) |
| Draws a rectangular region from a source surface onto the framebuffer. | |
| void | captureFramebufferRegion (Surface< RGB_T > &destination, size_t destX, size_t destY, size_t sourceX, size_t sourceY, size_t width, size_t height) |
| void | restoreOriginalPixels (const SpriteInfo &spriteInfo) |
| Restores the original background pixels behind a sprite. | |
| auto | findSprite (SpriteInfo &spriteInfo) |
| Finds the iterator to a sprite in the internal sprite list. | |
Static Protected Member Functions | |
| static Rect | intersect (const Rect &first, const Rect &second) |
| Returns the intersection rectangle of two rectangles. | |
| static bool | isEmpty (const Rect &rect) |
| Returns true if the rectangle is empty (zero width or height). | |
| static size_t | centeredCoordinate (size_t oldPosition, size_t oldSize, size_t newSize) |
| Calculates the coordinate to center a new size over an old position/size. | |
| static void | copySpriteRegion (const ISurface< RGB_T > &source, size_t sourceX, size_t sourceY, Surface< RGB_T > &destination, size_t destX, size_t destY, size_t width, size_t height) |
| static Surface< RGB_T > | scaleSpriteImage (const ISurface< RGB_T > &source, float scale, IFont< RGB_T > &font) |
| Returns a scaled copy of a sprite image. | |
| static Surface< RGB_T > | rotateSpriteImage (const ISurface< RGB_T > &source, float angleDegrees, RGB_T fillColor, IFont< RGB_T > &font) |
Protected Attributes | |
| SurfaceT | surface_ |
| Vector< std::unique_ptr< SpriteInfo > > | sprites_ |
Framebuffer with sprite placement and background restoration support.
The class extends TinyGPU with sprite bookkeeping so sprites can be added, moved, scaled, and removed while preserving the pixels behind them.
|
default |
Creates an empty framebuffer.
|
inline |
Creates a framebuffer with the specified size and font.
|
inlineprotected |
Returns the currently active font used by the framebuffer.
|
inline |
Adds a sprite to the framebuffer and draws it at the given position.
|
inline |
Adds a sprite with a preallocated max buffer size for transformations.
|
inlineprotected |
Applies a transformed sprite image to the framebuffer and updates bookkeeping.
|
inlineoverridevirtual |
Initializes the framebuffer surface.
Implements ISurface< RGB_T >.
|
inlineprotected |
Captures a rectangular region from the framebuffer into a destination surface.
|
inlineprotected |
Captures the updated background pixels after a sprite move/transform.
|
inlinestaticprotected |
Calculates the coordinate to center a new size over an old position/size.
|
inlinevirtual |
Clears the framebuffer with a single color.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Clears a sprite.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Copies a sprite.
Implements ISurface< RGB_T >.
|
inlinestaticprotected |
Copies a rectangular region from a source surface to a destination surface.
|
inlineoverridevirtual |
Returns the raw pixel buffer as bytes.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Draws a circle outline.
Implements ISurface< RGB_T >.
|
inline |
Draws a horizontal line with clipping.
|
inlinevirtual |
Draws a line between two points.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Draws a rectangle outline.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Draws a sprite.
Implements ISurface< RGB_T >.
|
inlineprotected |
Draws a rectangular region from a source surface onto the framebuffer.
|
inlinevirtual |
Draws UTF-8 text.
Implements ISurface< RGB_T >.
|
inlineoverridevirtual |
Closes the framebuffer and releases resources.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Fills a circle.
Implements ISurface< RGB_T >.
|
inlinevirtual |
Fills a rectangle.
Implements ISurface< RGB_T >.
|
inlineprotected |
Finds the iterator to a sprite in the internal sprite list.
|
inlinevirtual |
Returns the currently set font for text rendering.
Implements ISurface< RGB_T >.
|
inlineoverridevirtual |
Returns the pixel at the given position.
Implements ISurface< RGB_T >.
|
inlineoverridevirtual |
Returns the framebuffer height in pixels.
Implements ISurface< RGB_T >.
Returns the intersection rectangle of two rectangles.
|
inlinestaticprotected |
Returns true if the rectangle is empty (zero width or height).
|
inline |
Checks if the given coordinates are within the surface bounds.
|
inline |
Returns the line printer for text rendering.
|
inline |
Moves a sprite to a new position and redraws it.
|
inline |
Removes a sprite and restores the pixels behind it.
|
inlineoverridevirtual |
Resizes the framebuffer surface.
Implements ISurface< RGB_T >.
|
inlineprotected |
Restores only the pixels exposed by moving a sprite, using the overlap region.
|
inlineprotected |
Restores the original background pixels behind a sprite.
|
inline |
Rotates a sprite image and redraws it at its current position.
|
inlinestaticprotected |
Returns a rotated copy of a sprite image, filling empty space with fillColor.
|
inline |
Scales a sprite image and redraws it at its current position.
|
inlinestaticprotected |
Returns a scaled copy of a sprite image.
|
inlineoverridevirtual |
Scrolls the framebuffer content by the specified offsets.
Implements ISurface< RGB_T >.
|
inline |
Sets the framebuffer pixel data directly, replacing the current content.
|
inline |
Sets the font for text rendering.
|
inlineoverridevirtual |
ISurface<RGB_T> interface delegation.
Implements ISurface< RGB_T >.
|
inline |
Sets a pixel with clipping.
|
inlineoverridevirtual |
Returns the size of the buffer in bytes.
Implements ISurface< RGB_T >.
|
inlineoverridevirtual |
Returns the framebuffer width in pixels.
Implements ISurface< RGB_T >.
|
protected |
|
protected |