Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Public Member Functions | Static Public Member Functions | List of all members
gf::Grid Class Reference

A grid of cells. More...

#include <gf/Grid.h>

Inheritance diagram for gf::Grid:
Inheritance graph
[legend]

Public Member Functions

 Grid ()
 Constructor. More...
 
void setGridSize (Vector2i gridSize)
 Set the grid size. More...
 
Vector2i getGridSize () const noexcept
 Get the grid size. More...
 
void setColor (const Color4f &color)
 Set the color of the grid frame. More...
 
const Color4fgetColor () const noexcept
 Get the color of the grid frame. More...
 
void setSelectedColor (const Color4f &color)
 Set the color of the selected cell. More...
 
const Color4fgetSelectedColor () const noexcept
 Get the color of the selected cell. More...
 
void setLineWidth (float lineWidth) noexcept
 Set the width of the grid frame. More...
 
float getLineWidth () const noexcept
 Get the width of the grid frame. More...
 
void hover (Vector2f pointer)
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
void setAnchor (Anchor anchor)
 Set the anchor origin of the entity. More...
 
VertexBuffer commitGeometry () const
 Create a buffer with the current geometry. More...
 
void draw (RenderTarget &target, const RenderStates &states) override
 Draw the object to a render target. More...
 
- Public Member Functions inherited from gf::Transformable
 Transformable ()
 Default constructor. More...
 
void setOrigin (Vector2f origin)
 Set the local origin of the object. More...
 
Vector2f getOrigin () const
 Get the local origin of the object. More...
 
void setPosition (Vector2f position)
 Set the position of the object. More...
 
Vector2f getPosition () const
 Get the position of the object. More...
 
void move (Vector2f offset)
 Move the object by a given offset. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void setScale (Vector2f factors)
 Set the scale factors of the object. More...
 
void setScale (float factor)
 Set the scale factor of the object. More...
 
Vector2f getScale () const
 Get the current scale of the object. More...
 
void scale (Vector2f factors)
 Scale the object. More...
 
void scale (float factor)
 Scale the object. More...
 
Matrix3f getTransform () const
 Get the combined transform of the object. More...
 
Matrix3f getInverseTransform () const
 Get the inverse of the combined transform of the object. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 
virtual void draw (RenderTarget &target, const RenderStates &states)=0
 Draw the object to a render target. More...
 

Static Public Member Functions

static Grid createOrthogonal (Vector2i gridSize, Vector2f cellSize)
 Create an orthogonal grid. More...
 
static Grid createStaggered (Vector2i gridSize, Vector2f cellSize, CellAxis axis, CellIndex index)
 Create a staggered grid. More...
 
static Grid createHexagonal (Vector2i gridSize, Vector2f cellSize, float sideLength, CellAxis axis, CellIndex index)
 Create a hexagonal grid. More...
 
static Grid createHexagonal (Vector2i gridSize, float radius, CellAxis axis, CellIndex index)
 Create a regular hexagonal grid. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

A grid of cells.

A grid is a set of regular cells. The cells can be orthogonal, staggered or hexagonal.

The grid shows the limits of the cells and, optionnaly, the selected cell. It can be used for debugging purpose.

See also
gf::Cells

Constructor & Destructor Documentation

◆ Grid()

gf::Grid::Grid ( )

Constructor.

Member Function Documentation

◆ commitGeometry()

VertexBuffer gf::Grid::commitGeometry ( ) const

Create a buffer with the current geometry.

The geometry is uploaded in the graphics memory so that it's faster to draw.

Returns
A buffer with the current geometry

◆ createHexagonal() [1/2]

static Grid gf::Grid::createHexagonal ( Vector2i  gridSize,
float  radius,
CellAxis  axis,
CellIndex  index 
)
static

Create a regular hexagonal grid.

Parameters
gridSizeThe size of the grid
radiusThe radius of the regular hexagon
axisThe cells axis
indexThe cells index

◆ createHexagonal() [2/2]

static Grid gf::Grid::createHexagonal ( Vector2i  gridSize,
Vector2f  cellSize,
float  sideLength,
CellAxis  axis,
CellIndex  index 
)
static

Create a hexagonal grid.

Parameters
gridSizeThe size of the grid
cellSizeThe size of a cell
sideLengthThe side length
axisThe cells axis
indexThe cells index

◆ createOrthogonal()

static Grid gf::Grid::createOrthogonal ( Vector2i  gridSize,
Vector2f  cellSize 
)
static

Create an orthogonal grid.

Parameters
gridSizeThe size of the grid
cellSizeThe size of a cell

◆ createStaggered()

static Grid gf::Grid::createStaggered ( Vector2i  gridSize,
Vector2f  cellSize,
CellAxis  axis,
CellIndex  index 
)
static

Create a staggered grid.

Parameters
gridSizeThe size of the grid
cellSizeThe size of a cell
axisThe cells axis
indexThe cells index

◆ draw()

void gf::Grid::draw ( RenderTarget target,
const RenderStates states 
)
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

◆ getColor()

const Color4f & gf::Grid::getColor ( ) const
inlinenoexcept

Get the color of the grid frame.

Returns
The current color of the grid frame

◆ getGridSize()

Vector2i gf::Grid::getGridSize ( ) const
inlinenoexcept

Get the grid size.

Returns
The current grid size

◆ getLineWidth()

float gf::Grid::getLineWidth ( ) const
inlinenoexcept

Get the width of the grid frame.

Returns
The current width of the grid frame

◆ getLocalBounds()

RectF gf::Grid::getLocalBounds ( ) const

Get the local bounding rectangle of the entity.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Returns
Local bounding rectangle of the entity

◆ getSelectedColor()

const Color4f & gf::Grid::getSelectedColor ( ) const
inlinenoexcept

Get the color of the selected cell.

Returns
The current color of the selected cell

◆ hover()

void gf::Grid::hover ( Vector2f  pointer)

◆ setAnchor()

void gf::Grid::setAnchor ( Anchor  anchor)

Set the anchor origin of the entity.

Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin().

Parameters
anchorThe anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()

◆ setColor()

void gf::Grid::setColor ( const Color4f color)

Set the color of the grid frame.

Parameters
colorThe new color of the grid frame

◆ setGridSize()

void gf::Grid::setGridSize ( Vector2i  gridSize)

Set the grid size.

Parameters
gridSizeThe new grid size

◆ setLineWidth()

void gf::Grid::setLineWidth ( float  lineWidth)
inlinenoexcept

Set the width of the grid frame.

Parameters
lineWidthThe new width of the grid frame

◆ setSelectedColor()

void gf::Grid::setSelectedColor ( const Color4f color)

Set the color of the selected cell.

Parameters
colorThe new color of the selected cell