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

#include <SpriteDisplay.h>

Collaboration diagram for SpriteDisplay< RGB_T >:
Collaboration graph
[legend]

Public Member Functions

 SpriteDisplay (size_t width, size_t height, DisplayDriver< RGB_T > &driver, RGB_T backgroundColor=RGB_T(0))
 
 SpriteDisplay (LCDBoard &board, RGB_T backgroundColor=RGB_T(0))
 
SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite (size_t x, size_t y, const ISurface< RGB_T > &sprite)
 Adds a sprite to the framebuffer and draws it at the given position.
 
bool begin ()
 
void end ()
 Ends the processing.
 
SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite (size_t x, size_t y, size_t maxX, size_t maxY, RGB_T backgroundColor)
 Adds a sprite with a preallocated max buffer size for transformations.
 
SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite (size_t x, size_t y, size_t maxX, size_t maxY, const ISurface< RGB_T > &sprite)
 Adds a sprite with a preallocated max buffer size for transformations.
 
void removeSprite (SpriteInfo< RGB_T, Surface< RGB_T > > &sprite)
 Removes a sprite and restores the pixels behind it.
 
SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite (size_t x, size_t y)
 Returns a reference to the sprite at the given position, if any.
 
size_t getSpriteCount () const
 Returns the number of sprites currently managed by the framebuffer.
 
SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite (int idx)
 Returns a reference to the sprite at the given index, if valid.
 
SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite (const ISurface< RGB_T > &sprite)
 
void moveSprite (SpriteInfo< RGB_T, Surface< RGB_T > > &sprite, size_t newX, size_t newY)
 Moves a sprite to a new position and redraws it.
 
void scaleSprite (SpriteInfo< RGB_T, Surface< RGB_T > > &sprite, float scale)
 
void rotateSprite (SpriteInfo< RGB_T, Surface< RGB_T > > &sprite, float angleDegrees)
 
void clear ()
 Clears the display and resets the background color.
 
void refresh ()
 
void setTouchDriver (TouchDriver &touch)
 Defines the touch driver.
 
void processTouch ()
 Processes touch input and dispatches events to sprites if touched.
 
void fillScreen (RGB_T color)
 Fills/clears the entire display with the specified color.
 
void setClearOnSpriteMove (bool clear)
 Activates/deactivates the automatic clearing when we move a sprite.
 
bool isClearOnSpriteMove () const
 Returns whether the automatic clearing is active when we move a sprite.
 

Protected Member Functions

void applyTransformedSprite (SpriteInfo< RGB_T, Surface< RGB_T > > &spriteInfo, Surface< RGB_T > &&transformedSprite)
 Applies a transformed sprite image to the display and updates bookkeeping.
 
void clearSprite (size_t x, size_t y, const ISurface< RGB_T > &sprite)
 
void clearSprite (Rect rect)
 
void clearSprite (size_t x, size_t y, size_t width, size_t height)
 
void displaySprite (size_t x, size_t y, const ISurface< RGB_T > &sprite)
 Draws a sprite at (x, y)
 

Static Protected Member Functions

static size_t centeredCoordinate (size_t pos, size_t oldDim, size_t newDim)
 Helper to calculate centered coordinate when scaling/rotating.
 

Protected Attributes

DisplayDriver< RGB_T > & driver_
 
TouchDriver * p_touchDriver = nullptr
 
LCDBoard * p_board_ = nullptr
 
Sprite< RGB_T > actual_sprite_background_
 
size_t width_
 
size_t height_
 
RGB_T backgroundColor_
 
Vector< std::unique_ptr< SpriteInfo< RGB_T, Surface< RGB_T > > > > sprites_
 
Font5x7< RGB_T > defaultFont_
 
bool is_clear_on_sprite_move = true
 

Constructor & Destructor Documentation

◆ SpriteDisplay() [1/2]

SpriteDisplay ( size_t  width,
size_t  height,
DisplayDriver< RGB_T > &  driver,
RGB_T  backgroundColor = RGB_T(0) 
)
inline

◆ SpriteDisplay() [2/2]

SpriteDisplay ( LCDBoard &  board,
RGB_T  backgroundColor = RGB_T(0) 
)
inlineexplicit

Constructs from an LCDBoard (see LCDBoards.h): takes its display driver and dimensions, and auto-attaches its touch controller if one is present. Only valid for RGB_T = RGB565, since every LCDBoard's display() is RGB565.

begin() on the resulting SpriteDisplay calls LCDBoard::begin() (backlight + SPI/QSPI bus + display controller + touch controller) instead of just the display driver's begin() - do not also call board.begin() yourself, or the display controller's init sequence (and, on boards that need it, the display-inversion fix) runs twice.

Member Function Documentation

◆ addSprite() [1/3]

SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite ( size_t  x,
size_t  y,
const ISurface< RGB_T > &  sprite 
)
inline

Adds a sprite to the framebuffer and draws it at the given position.

◆ addSprite() [2/3]

SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite ( size_t  x,
size_t  y,
size_t  maxX,
size_t  maxY,
const ISurface< RGB_T > &  sprite 
)
inline

Adds a sprite with a preallocated max buffer size for transformations.

◆ addSprite() [3/3]

SpriteInfo< RGB_T, Surface< RGB_T > > & addSprite ( size_t  x,
size_t  y,
size_t  maxX,
size_t  maxY,
RGB_T  backgroundColor 
)
inline

Adds a sprite with a preallocated max buffer size for transformations.

◆ applyTransformedSprite()

void applyTransformedSprite ( SpriteInfo< RGB_T, Surface< RGB_T > > &  spriteInfo,
Surface< RGB_T > &&  transformedSprite 
)
inlineprotected

Applies a transformed sprite image to the display and updates bookkeeping.

◆ begin()

bool begin ( )
inline

Starts the processing. If constructed from an LCDBoard, this brings up the whole board (LCDBoard::begin()); otherwise just the display driver (driver_.begin()).

◆ centeredCoordinate()

static size_t centeredCoordinate ( size_t  pos,
size_t  oldDim,
size_t  newDim 
)
inlinestaticprotected

Helper to calculate centered coordinate when scaling/rotating.

◆ clear()

void clear ( )
inline

Clears the display and resets the background color.

◆ clearSprite() [1/3]

void clearSprite ( Rect  rect)
inlineprotected

◆ clearSprite() [2/3]

void clearSprite ( size_t  x,
size_t  y,
const ISurface< RGB_T > &  sprite 
)
inlineprotected

Clears the background of the indicated sprite at (x, y) with the background color.

◆ clearSprite() [3/3]

void clearSprite ( size_t  x,
size_t  y,
size_t  width,
size_t  height 
)
inlineprotected

◆ displaySprite()

void displaySprite ( size_t  x,
size_t  y,
const ISurface< RGB_T > &  sprite 
)
inlineprotected

Draws a sprite at (x, y)

◆ end()

void end ( )
inline

Ends the processing.

◆ fillScreen()

void fillScreen ( RGB_T  color)
inline

Fills/clears the entire display with the specified color.

◆ getSprite() [1/3]

SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite ( const ISurface< RGB_T > &  sprite)
inline

Returns a reference to the SpriteInfo for the indicated surface, if it exists.

◆ getSprite() [2/3]

SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite ( int  idx)
inline

Returns a reference to the sprite at the given index, if valid.

◆ getSprite() [3/3]

SpriteInfo< RGB_T, Surface< RGB_T > > * getSprite ( size_t  x,
size_t  y 
)
inline

Returns a reference to the sprite at the given position, if any.

◆ getSpriteCount()

size_t getSpriteCount ( ) const
inline

Returns the number of sprites currently managed by the framebuffer.

◆ isClearOnSpriteMove()

bool isClearOnSpriteMove ( ) const
inline

Returns whether the automatic clearing is active when we move a sprite.

◆ moveSprite()

void moveSprite ( SpriteInfo< RGB_T, Surface< RGB_T > > &  sprite,
size_t  newX,
size_t  newY 
)
inline

Moves a sprite to a new position and redraws it.

◆ processTouch()

void processTouch ( )
inline

Processes touch input and dispatches events to sprites if touched.

◆ refresh()

void refresh ( )
inline

Refreshes the display and redraws all sprites in their current positions and states.

◆ removeSprite()

void removeSprite ( SpriteInfo< RGB_T, Surface< RGB_T > > &  sprite)
inline

Removes a sprite and restores the pixels behind it.

◆ rotateSprite()

void rotateSprite ( SpriteInfo< RGB_T, Surface< RGB_T > > &  sprite,
float  angleDegrees 
)
inline

Rotates a sprite image and redraws it at its current position. Always re-renders from the pristine original at (currentScale, angleDegrees)

◆ scaleSprite()

void scaleSprite ( SpriteInfo< RGB_T, Surface< RGB_T > > &  sprite,
float  scale 
)
inline

Scales a sprite image and redraws it at its current position. Always re-renders from the pristine original at (scale, currentAngleDegrees)

◆ setClearOnSpriteMove()

void setClearOnSpriteMove ( bool  clear)
inline

Activates/deactivates the automatic clearing when we move a sprite.

◆ setTouchDriver()

void setTouchDriver ( TouchDriver &  touch)
inline

Defines the touch driver.

Member Data Documentation

◆ actual_sprite_background_

Sprite<RGB_T> actual_sprite_background_
protected

◆ backgroundColor_

RGB_T backgroundColor_
protected

◆ defaultFont_

Font5x7<RGB_T> defaultFont_
protected

◆ driver_

DisplayDriver<RGB_T>& driver_
protected

◆ height_

size_t height_
protected

◆ is_clear_on_sprite_move

bool is_clear_on_sprite_move = true
protected

◆ p_board_

LCDBoard* p_board_ = nullptr
protected

◆ p_touchDriver

TouchDriver* p_touchDriver = nullptr
protected

◆ sprites_

Vector<std::unique_ptr<SpriteInfo<RGB_T, Surface<RGB_T> > > > sprites_
protected

◆ width_

size_t width_
protected

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