Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Olympe::GridSnapping Class Reference

Singleton grid-snapping helper. More...

#include <GridSnapping.h>

Public Member Functions

bool IsEnabled () const
 
void SetEnabled (bool enabled)
 
void Toggle ()
 Toggles snapping on/off.
 
int GetGridSize () const
 Returns the current grid cell size in pixels (default: 16).
 
void SetGridSize (int size)
 Sets the grid cell size.
 
float SnapX (float x) const
 Snaps a single x coordinate to the nearest grid line.
 
float SnapY (float y) const
 Snaps a single y coordinate to the nearest grid line.
 
void Snap (float &x, float &y) const
 Snaps both x and y coordinates in place.
 

Static Public Member Functions

static GridSnappingGet ()
 Returns the single shared instance.
 

Private Member Functions

 GridSnapping ()
 

Private Attributes

bool m_Enabled
 
int m_GridSize
 

Detailed Description

Singleton grid-snapping helper.

Typical usage:

gs.SetEnabled(true);
gs.SetGridSize(16);
float x = 123.7f, y = 88.2f;
gs.Snap(x, y); // x == 128.0f, y == 80.0f
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static GridSnapping & Get()
Returns the single shared instance.

Definition at line 36 of file GridSnapping.h.

Constructor & Destructor Documentation

◆ GridSnapping()

Olympe::GridSnapping::GridSnapping ( )
private

Definition at line 28 of file GridSnapping.cpp.

Member Function Documentation

◆ Get()

GridSnapping & Olympe::GridSnapping::Get ( )
static

Returns the single shared instance.

Definition at line 18 of file GridSnapping.cpp.

◆ GetGridSize()

int Olympe::GridSnapping::GetGridSize ( ) const

Returns the current grid cell size in pixels (default: 16).

Definition at line 57 of file GridSnapping.cpp.

References m_GridSize.

◆ IsEnabled()

bool Olympe::GridSnapping::IsEnabled ( ) const

Definition at line 38 of file GridSnapping.cpp.

References m_Enabled.

◆ SetEnabled()

void Olympe::GridSnapping::SetEnabled ( bool  enabled)

Definition at line 43 of file GridSnapping.cpp.

References m_Enabled.

◆ SetGridSize()

void Olympe::GridSnapping::SetGridSize ( int  size)

Sets the grid cell size.

Values <= 0 are ignored.

Definition at line 62 of file GridSnapping.cpp.

References m_GridSize.

◆ Snap()

void Olympe::GridSnapping::Snap ( float x,
float y 
) const

Snaps both x and y coordinates in place.

Definition at line 90 of file GridSnapping.cpp.

References SnapX(), and SnapY().

+ Here is the call graph for this function:

◆ SnapX()

float Olympe::GridSnapping::SnapX ( float  x) const

Snaps a single x coordinate to the nearest grid line.

Definition at line 72 of file GridSnapping.cpp.

References GetComponentTypeID_Static(), m_Enabled, and m_GridSize.

Referenced by Snap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SnapY()

float Olympe::GridSnapping::SnapY ( float  y) const

Snaps a single y coordinate to the nearest grid line.

Definition at line 81 of file GridSnapping.cpp.

References GetComponentTypeID_Static(), m_Enabled, and m_GridSize.

Referenced by Snap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Toggle()

void Olympe::GridSnapping::Toggle ( )

Toggles snapping on/off.

Definition at line 48 of file GridSnapping.cpp.

References m_Enabled.

Member Data Documentation

◆ m_Enabled

bool Olympe::GridSnapping::m_Enabled
private

Definition at line 97 of file GridSnapping.h.

Referenced by IsEnabled(), SetEnabled(), SnapX(), SnapY(), and Toggle().

◆ m_GridSize

int Olympe::GridSnapping::m_GridSize
private

Definition at line 98 of file GridSnapping.h.

Referenced by GetGridSize(), SetGridSize(), SnapX(), and SnapY().


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