Loading...
Searching...
No Matches
ml::ImageRects Class Reference

A grid-indexed collection of sf::IntRect regions. More...

#include <Malena/Utilities/ImageRects.h>

Public Member Functions

 ImageRects (int cols)
 Construct an empty ImageRects with a known column count.
const sf::IntRectgetIntRect (int row, int col) const
 Return the rect for a given row and column.
RowProxy operator[] (int row) const
 Row-indexed access — returns a proxy for column subscript.
void push (const sf::IntRect &int_rect)
 Append a rect to the collection.

Detailed Description

A grid-indexed collection of sf::IntRect regions.

ImageRects stores the sub-rectangle regions produced by TextureSlicer::getImageRects when a texture is divided into a uniform grid of rows and columns. Each rect describes the pixel bounds of one cell within the source texture, ready to be passed to sf::Sprite::setTextureRect for sprite-sheet animation or tile-based rendering.

Rects are stored in row-major order and accessed by (row, col) index.

Usage

// Access frame (row 1, col 3)
sprite.setTextureRect(rects.getIntRect(1, 3));
A grid-indexed collection of sf::IntRect regions.
Definition ImageRects.h:41
const sf::IntRect & getIntRect(int row, int col) const
Return the rect for a given row and column.
static ml::ImageRects getImageRects(const sf::Texture &texture, int rows, int cols)
Slice a texture into a rows × cols grid of equal rectangles.
See also
TextureSlicer

Definition at line 40 of file ImageRects.h.

Constructor & Destructor Documentation

◆ ImageRects()

ml::ImageRects::ImageRects ( int cols)

Construct an empty ImageRects with a known column count.

Parameters
colsNumber of columns in the source grid. Used to convert (row, col) indices to a flat vector position.

Member Function Documentation

◆ getIntRect()

const sf::IntRect & ml::ImageRects::getIntRect ( int row,
int col ) const

Return the rect for a given row and column.

Parameters
rowZero-based row index.
colZero-based column index.
Returns
Const reference to the sf::IntRect for that cell.

◆ operator[]()

RowProxy ml::ImageRects::operator[] ( int row) const
inline

Row-indexed access — returns a proxy for column subscript.

Enables two-dimensional subscript syntax:

sprite.setTextureRect(rects[1][3]);

Definition at line 80 of file ImageRects.h.

◆ push()

void ml::ImageRects::push ( const sf::IntRect & int_rect)

Append a rect to the collection.

Called by TextureSlicer to populate the collection in row-major order. Direct use is uncommon outside of framework internals.

Parameters
int_rectThe rect to append.

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