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

An ISurface that reports a full width x height extent but physically redirects every pixel write into a much smaller backing surface, offset by (offsetX, offsetY), dropping anything that then falls outside backing's own bounds. More...

#include <WindowedSurface.h>

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

Public Member Functions

 WindowedSurface (ISurface< RGB_T > &backing, int32_t offsetX, int32_t offsetY, size_t fullWidth, size_t fullHeight, IFont< RGB_T > &font)
 
size_t width () const override
 
size_t height () const override
 Get the height of the surface.
 
void setPixel (size_t x, size_t y, RGB_T color) override
 
RGB_T getPixel (size_t x, size_t y) const override
 Abstract method: get the pixel color at (x, y).
 
bool resizeBuffer (size_t, size_t) override
 
const uint8_t * data () const override
 
size_t size () const override
 Provides the total data size in bytes.
 
bool contains (size_t x, size_t y) override
 
- 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
 
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)
 
void drawHorizontalLineClipped (int x0, int x1, int y, PixelT color)
 
bool contains (size_t x, size_t y) override
 Checks if the given coordinates are within the surface bounds.
 
void pushClipRect (size_t x, size_t y, size_t w, size_t h) override
 
void popClipRect () override
 See ISurface::popClipRect().
 
bool isClipVisible (size_t x, size_t y) const override
 See ISurface::isClipVisible().
 
- 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 drawRoundRect (size_t x, size_t y, size_t w, size_t h, size_t radius, PixelT color)
 
virtual void fillRoundRect (size_t x, size_t y, size_t w, size_t h, size_t radius, PixelT color)
 
virtual void drawArc (size_t cx, size_t cy, size_t r, float startDeg, float endDeg, PixelT color, uint8_t thickness=1)
 
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.
 
virtual bool contains (size_t x, size_t y)=0
 Checks if the given coordinates are within the surface bounds.
 
virtual void pushClipRect (size_t x, size_t y, size_t w, size_t h)
 
virtual void popClipRect ()
 
virtual bool isClipVisible (size_t x, size_t y) const
 

Additional Inherited Members

- 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::WindowedSurface< RGB_T >

An ISurface that reports a full width x height extent but physically redirects every pixel write into a much smaller backing surface, offset by (offsetX, offsetY), dropping anything that then falls outside backing's own bounds.

Exists so a widget (or a handful of them) can be rendered into one small reused buffer instead of a full-screen framebuffer - see tinymd::Screen::drawDirect(), which uses this two ways:

Either way, every higher-level drawing call a widget's draw() makes (fillRect, drawLine, drawCircle, drawText, drawSprite, fillRoundRect, a modal's full-width/height scrim fill, ...) is inherited unchanged from SurfaceBase, which implements all of them purely in terms of setPixel()/getPixel() - the only two primitives overridden here - so nothing being drawn needs to know the difference from a real surface.

A widget always draws using absolute screen coordinates (its own this->bounds.x/y, not 0), so - critically - the width_/height_ SurfaceBase itself uses internally to clip fillRect()/drawSprite()/etc. (inherited, not reimplemented here) must be set to where backing's far edge actually falls in that same absolute space - offsetX + backing.width(), not just backing.width() - or every one of those clips silently rejects nearly everything for any widget not sitting at (0, 0). What width()/height() report to callers (a modal's scrim math, chiefly) is a separate, independently overridden pair of accessors below, exactly because the two needs (correct internal clipping vs. "how big does the caller think the canvas is") are different numbers whenever offsetX/offsetY aren't both 0.

One instance is (cheaply) constructed per widget/strip; it owns no pixel storage of its own.

Constructor & Destructor Documentation

◆ WindowedSurface()

WindowedSurface ( ISurface< RGB_T > &  backing,
int32_t  offsetX,
int32_t  offsetY,
size_t  fullWidth,
size_t  fullHeight,
IFont< RGB_T > &  font 
)
inline

backing must outlive this object. fullWidth/fullHeight are what width()/height() report (see the class comment for the two ways callers pick these); offsetX/offsetY is where backing's own (0, 0) sits within that full logical space.

Member Function Documentation

◆ contains()

bool contains ( size_t  x,
size_t  y 
)
inlineoverridevirtual

Absolute-coordinate bounds check, consistent with setPixel()/ getPixel() above (and so with SurfaceBase's inherited fillRect() etc., which clip against the same underlying width_/height_) - deliberately not fullWidth_/fullHeight_, which is what a caller (Dialog's/Drawer's own drawArc()-free code never calls contains() directly, but this keeps the two consistent regardless).

Reimplemented from SurfaceBase< PixelT >.

◆ data()

const uint8_t * data ( ) const
inlineoverridevirtual

Not backed by one contiguous buffer, so there's no single pointer/ size to hand back - nothing in the normal widget draw() path calls these (pixels go through setPixel()/getPixel() instead), so these are stubs rather than real implementations.

Implements ISurface< PixelT >.

◆ getPixel()

RGB_T getPixel ( size_t  x,
size_t  y 
) const
inlineoverridevirtual

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

Implements SurfaceBase< PixelT >.

◆ height()

size_t height ( ) const
inlineoverridevirtual

Get the height of the surface.

Reimplemented from SurfaceBase< PixelT >.

◆ resizeBuffer()

bool resizeBuffer ( size_t  ,
size_t   
)
inlineoverridevirtual

No storage of its own to (re)allocate - the internal clip bound is fixed at construction (see above). Only exists to satisfy SurfaceBase's pure-virtual resizeBuffer(); never meaningfully called.

Implements SurfaceBase< PixelT >.

◆ setPixel()

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

◆ size()

size_t size ( ) const
inlineoverridevirtual

Provides the total data size in bytes.

Implements ISurface< PixelT >.

◆ width()

size_t width ( ) const
inlineoverridevirtual

Reports the logical size (see class comment) - not the same as the internal clip bound SurfaceBase's inherited fillRect() etc. use, when offsetX/offsetY aren't both 0.

Reimplemented from SurfaceBase< PixelT >.


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