Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
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 | processEvent (const Event &event) |
Update the geometry thanks to the event. More... | |
void | onScreenResize (Vector2u screenSize) |
Update the geometry with the new screen size. More... | |
void | setInitialScreenSize (Vector2u screenSize) |
Set the initial screen size. More... | |
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.
gf::WindowGeometryTracker::WindowGeometryTracker | ( | ) |
Default constructor.
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 |
pos | The 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.
width | The width of the element |
x
coordinate 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.
width | The width of the element |
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()).
ratio | The percentage, in the interval \( [0,1] \) |
width | The width of the element |
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.
height | The height of the element |
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.
height | The height of the element |
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()).
ratio | The percentage, in the interval \( [0,1] \) |
height | The height of the element |
y
coordinate void gf::WindowGeometryTracker::onScreenResize | ( | Vector2u | screenSize | ) |
Update the geometry with the new screen size.
screenSize | The new size of the screen |
void gf::WindowGeometryTracker::processEvent | ( | const Event & | event | ) |
Update the geometry thanks to the event.
Internally it calls onScreenResize() if a resize event occurs.
event | An event |
void gf::WindowGeometryTracker::setInitialScreenSize | ( | Vector2u | screenSize | ) |
Set the initial screen size.
screenSize | The initial size of the screen |