TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
SpriteInfo< RGB_T, SurfaceT > Struct Template Reference

#include <SpriteInfo.h>

Inheritance diagram for SpriteInfo< RGB_T, SurfaceT >:
Inheritance graph
[legend]
Collaboration diagram for SpriteInfo< RGB_T, SurfaceT >:
Collaboration graph
[legend]

Public Member Functions

 SpriteInfo (size_t startX, size_t startY, const ISurface< RGB_T > &sourceSprite, RGB_T transparentColor, IFont< RGB_T > &font)
 
virtual ~SpriteInfo ()
 
Rect getRect () const
 
Rect clampedSize (size_t rawWidth, size_t rawHeight) const
 
const ISurface< RGB_T > & currentSprite () const
 Returns the sprite image currently used for drawing.
 
virtual void saveOriginalPixels (ISurface< RGB_T > &framebuffer)
 Saves the background pixels currently covered by the sprite.
 
void onTouch (Point point)
 
void setMaxSize (size_t maxX, size_t maxY)
 Set the maximum buffer size for transformedSprite and allocate buffer.
 
void setTransformedSprite (SurfaceT &&newSprite)
 

Public Attributes

size_t x = 0
 
size_t y = 0
 
size_t maxWidth = 0
 
size_t maxHeight = 0
 
RGB_T invisibleColor = RGB_T(0)
 
const ISurface< RGB_T > * sprite = nullptr
 
bool isSurfaceAutoDelete = false
 
std::unique_ptr< SurfaceT > transformedSprite
 
bool hasTransformedContent = false
 
float currentScale = 1.0f
 
float currentAngleDegrees = 0.0f
 
SurfaceT originalPixels
 
IFont< RGB_T > & fontRef
 
void(* onTouchCallback )(SpriteInfo &, Point) = nullptr
 

Detailed Description

template<typename RGB_T = RGB565, typename SurfaceT = Surface<RGB_T>>
struct tinygpu::SpriteInfo< RGB_T, SurfaceT >

Tracks a sprite instance together with its saved background pixels.

Each SpriteInfo stores the sprite position, transparent color, current sprite image, and a snapshot of the framebuffer region covered by it.

Constructor & Destructor Documentation

◆ SpriteInfo()

SpriteInfo ( size_t  startX,
size_t  startY,
const ISurface< RGB_T > &  sourceSprite,
RGB_T  transparentColor,
IFont< RGB_T > &  font 
)
inline

◆ ~SpriteInfo()

virtual ~SpriteInfo ( )
inlinevirtual

Member Function Documentation

◆ clampedSize()

Rect clampedSize ( size_t  rawWidth,
size_t  rawHeight 
) const
inline

Returns the size a transformed image of (rawWidth, rawHeight) will actually end up stored/drawn at by setTransformedSprite() below. Once a fixed buffer exists (from setMaxSize() or an earlier setTransformedSprite() call), the drawn size is ALWAYS exactly maxWidth x maxHeight - never the raw image's own size - because setTransformedSprite() pads a smaller image with invisibleColor rather than shrinking the buffer to fit it (e.g. scaling down) and crops a larger one down to the buffer (e.g. rotating a square grows its bounding box). Only when no fixed buffer exists yet does the drawn size match the raw image exactly (setTransformedSprite() allocates the very first buffer to fit it precisely).

Callers computing where to anchor/redraw a transformed sprite (see FrameBuffer::applyTransformedSprite(), SpriteDisplay:: applyTransformedSprite()) must use this size, not the raw transformed image's own size, or their background restore/capture bounds won't match the region setTransformedSprite() + drawSprite() actually touch - leaving stale, un-restored pixels on screen (visible as a second, "ghost" copy of the sprite trailing the real one).

◆ currentSprite()

const ISurface< RGB_T > & currentSprite ( ) const
inline

Returns the sprite image currently used for drawing.

◆ getRect()

Rect getRect ( ) const
inline

◆ onTouch()

void onTouch ( Point  point)
inline

◆ saveOriginalPixels()

virtual void saveOriginalPixels ( ISurface< RGB_T > &  framebuffer)
inlinevirtual

Saves the background pixels currently covered by the sprite.

Reimplemented in SpriteInfoWithoutBackground< RGB_T, SurfaceT >.

◆ setMaxSize()

void setMaxSize ( size_t  maxX,
size_t  maxY 
)
inline

Set the maximum buffer size for transformedSprite and allocate buffer.

◆ setTransformedSprite()

void setTransformedSprite ( SurfaceT &&  newSprite)
inline

Replaces the current transformed sprite image, using only the allocated buffer.

Member Data Documentation

◆ currentAngleDegrees

float currentAngleDegrees = 0.0f

◆ currentScale

float currentScale = 1.0f

◆ fontRef

IFont<RGB_T>& fontRef

◆ hasTransformedContent

bool hasTransformedContent = false

◆ invisibleColor

RGB_T invisibleColor = RGB_T(0)

◆ isSurfaceAutoDelete

bool isSurfaceAutoDelete = false

◆ maxHeight

size_t maxHeight = 0

◆ maxWidth

size_t maxWidth = 0

◆ onTouchCallback

void(* onTouchCallback) (SpriteInfo &, Point) = nullptr

◆ originalPixels

SurfaceT originalPixels

◆ sprite

const ISurface<RGB_T>* sprite = nullptr

◆ transformedSprite

std::unique_ptr<SurfaceT> transformedSprite

◆ x

size_t x = 0

◆ y

size_t y = 0

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