Gamedev Framework (gf)  0.2.0
A C++11 framework for 2D games
Public Member Functions | List of all members
gf::WindowGeometryTracker Class Reference

A window geometry tracker. More...

#include <gf/WindowGeometryTracker.h>

Public Member Functions

 WindowGeometryTracker ()
 Default constructor. More...
 
float getXCentered (float width) const
 Compute x for a centered element. More...
 
float getXFromRight (float width) const
 Compute x for a right aligned element. More...
 
float getXRatio (float ratio, float width) const
 Compute x for an element at some percent from the left. More...
 
float getYCentered (float height) const
 Compute y for a centered element. More...
 
float getYFromBottom (float height) const
 Compute y for a bottom aligned element. More...
 
float getYRatio (float ratio, float height) const
 Compute y for an element at some percent from the top. More...
 
Vector2f getCornerPosition (const Vector2f &pos) const
 Get a position relative to a corner. More...
 
void update (const Event &event)
 Update the geometry thanks to the event. More...
 
void onScreenResize (Vector2u screenSize)
 Update the geometry with the new screen size. More...
 

Detailed Description

A window geometry tracker.

The window geometry tracker computes position relative to the borders of the screen. It tracks the changes of the window geometry (especially the size of the window).

This class is very useful for computing HUD elements' position.

Constructor & Destructor Documentation

gf::WindowGeometryTracker::WindowGeometryTracker ( )

Default constructor.

Member Function Documentation

Vector2f gf::WindowGeometryTracker::getCornerPosition ( const Vector2f pos) const

Get a position relative to a corner.

If the position has a negative coordinate, it is considered on the other side than a positive coordinate.

pos.x pos.y Final position
\( > 0 \) \( > 0 \) top-left corner
\( < 0 \) \( > 0 \) top-right corner
\( > 0 \) \( < 0 \) bottom-left corner
\( < 0 \) \( < 0 \) bottom-right corner
Parameters
posThe position
Returns
The computed position
float gf::WindowGeometryTracker::getXCentered ( float  width) const

Compute x for a centered element.

Compute the x coordinate of an element of size width that must be centered on the window.

Parameters
widthThe width of the element
Returns
The computed x coordinate
See also
getXRatio()
float gf::WindowGeometryTracker::getXFromRight ( float  width) const

Compute x for a right aligned element.

Compute the x coordinate of an element of size width that must be right aligned on the window.

Parameters
widthThe width of the element
Returns
The computed x coordinate
float gf::WindowGeometryTracker::getXRatio ( float  ratio,
float  width 
) const

Compute x for an element at some percent from the left.

Compute the x coordinate of an element of size width that must be at a given percentage from the left. \( 0 \) puts the element on the left, \( 0.5 \) puts the element in the center (see getXCentered()), \( 1 \) puts the element on the right (see getXFromRight()).

Parameters
ratioThe percentage, in the interval \( [0,1] \)
widthThe width of the element
Returns
The computed x coordinate
float gf::WindowGeometryTracker::getYCentered ( float  height) const

Compute y for a centered element.

Compute the y coordinate of an element of size height that must be centered on the window.

Parameters
heightThe height of the element
See also
getYRatio()
Returns
The computed y coordinate
float gf::WindowGeometryTracker::getYFromBottom ( float  height) const

Compute y for a bottom aligned element.

Compute the x coordinate of an element of size height that must be bottom aligned on the window.

Parameters
heightThe height of the element
Returns
The computed y coordinate
float gf::WindowGeometryTracker::getYRatio ( float  ratio,
float  height 
) const

Compute y for an element at some percent from the top.

Compute the y coordinate of an element of size height that must be at a given percentage from the top. \( 0 \) puts the element on the top, \( 0.5 \) puts the element in the center (see getYCentered()), \( 1 \) puts the element on the bottom (see getYFromBottom()).

Parameters
ratioThe percentage, in the interval \( [0,1] \)
heightThe height of the element
Returns
The computed y coordinate
void gf::WindowGeometryTracker::onScreenResize ( Vector2u  screenSize)

Update the geometry with the new screen size.

Parameters
screenSizeThe new size of the screen
void gf::WindowGeometryTracker::update ( const Event event)

Update the geometry thanks to the event.

Internally it calls onScreenResize() if a resize event occurs.

Parameters
eventAn event