cppgfx  0.1.0
C++17 educational graphics library
cppgfx::App Class Referenceabstract

The main application class. More...

#include <cppgfx.hpp>

Public Member Functions

virtual void setup ()=0
 This function is called once at the beginning of the program. More...
 
virtual void update ()=0
 This function is called repeatedly until the program is terminated. More...
 
virtual void cleanup ()
 This function is called once at the end of the program. More...
 
virtual bool onWindowClose ()
 This function can be used to intercept the window close event. More...
 
virtual void onTextInput (const sf::Event::TextEvent &event)
 This function is called when keys on the keyboard are pressed. To be used for text input. More...
 
virtual void onKeyPressed (const sf::Event::KeyEvent &event)
 This function is called when keys on the keyboard are pressed. To be used for key bindings, not text. More...
 
virtual void onKeyReleased (const sf::Event::KeyEvent &event)
 This function is called when keys on the keyboard are released. More...
 
virtual void onMousePressed (const sf::Event::MouseButtonEvent &event)
 This function is called when a mouse button is pressed. More...
 
virtual void onMouseReleased (const sf::Event::MouseButtonEvent &event)
 This function is called when a mouse button is released. More...
 
virtual void onMouseMoved (const sf::Event::MouseMoveEvent &event)
 This function is called when the mouse is moved. More...
 
virtual void onMouseWheel (const sf::Event::MouseWheelScrollEvent &event)
 This function is called when the mouse wheel is scrolled. More...
 
virtual void onMouseEnter ()
 This function is called when the mouse enters the window. More...
 
virtual void onMouseLeave ()
 This function is called when the mouse leaves the window. More...
 
virtual void onWindowResize ()
 This function is called when the window is resized. More...
 
virtual void onWindowFocus ()
 This function is called when the window is focused. More...
 
virtual void onWindowUnfocus ()
 This function is called when the window loses focus. More...
 
void background (const sf::Color &color)
 Set the background color of the window for the current frame. More...
 
void background (uint8_t shade)
 Set the background color of the window for the current frame. More...
 
void background (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the background color of the window. More...
 
void fill (const sf::Color &color)
 Set the infill color for primitives. More...
 
void fill (uint8_t shade)
 Set the infill color for primitives. More...
 
void fill (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the infill color for primitives. More...
 
void noFill ()
 Disable the infill color for primitives.
 
void stroke (const sf::Color &color)
 Set the outline color for primitives.
 
void stroke (uint8_t shade)
 Set the outline color for primitives. More...
 
void stroke (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the outline color for primitives. More...
 
void noStroke ()
 Disable the outline color for primitives.
 
void strokeWeight (float weight)
 Set the thickness of the outline for primitives. More...
 
void push ()
 Push the current draw style onto the stack. More...
 
void pop ()
 Pop the current draw style from the stack. More...
 
void line (float x1, float y1, float x2, float y2)
 Draw a line from (x1, y1) to (x2, y2) More...
 
void lineCap (LineCap cap)
 Set the line cap style. More...
 
void rect (float x, float y, float w, float h)
 Draw a rectangle at (x, y) with the given width and height. More...
 
void rectMode (RectMode mode)
 Where the origin of the rectangle is. More...
 
void circle (float x, float y, float radius)
 Draw a circle at (x, y) with the given radius. More...
 
void ellipse (float x, float y, float w, float h)
 Draw an ellipse at (x, y) with the given width and height. More...
 
void triangle (float x1, float y1, float x2, float y2, float x3, float y3)
 Draw a triangle with the given points. More...
 
void vector (float vectorX, float vectorY, float originX, float originY)
 Draw a vector arrow from the origin to origin + vector. More...
 
void textFont (const sf::Font &font)
 Set the current font to be used for rendering from now on. More...
 
sf::Font loadFont (const std::string &filename)
 Load a font from a file with a specific size. More...
 
void textAlign (TextAlign alignment)
 Set the current alignment for drawing text. More...
 
float textWidth (const std::string &text)
 Calculate the width of a text string in pixels. More...
 
void textSize (uint32_t size)
 Set the font size of the currently active font. More...
 
void text (const std::string &text, float x, float y)
 Draw text at (x, y) More...
 
void size (int w, int h)
 Set the size of the window. More...
 
void setTitle (const std::string &text)
 Set the title of the window. More...
 
void setFrameRate (float framerate)
 Set the maximum framerate limit in frames per second. More...
 
void fullscreen ()
 Switch to fullscreen mode. More...
 
void exitFullscreen ()
 Exit fullscreen mode. More...
 
void close ()
 Stop the application. More...
 
void focus ()
 Request the window to be focused. More...
 
template<typename... Args>
void print (Args &&... args)
 Print a formatted string without newline to the console (FMT/Python formatting supported) More...
 
template<typename... Args>
void println (Args &&... args)
 Print a formatted string with newline to the console (FMT/Python formatting supported) More...
 
std::string encodeBase64 (const std::vector< uint8_t > &input)
 Encode an arbitrary resource in base-64 encoding. More...
 
std::vector< uint8_t > decodeBase64 (const std::string &input)
 Decode a base-64 encoded string into its original form. More...
 
float dist (float x1, float y1, float x2, float y2)
 Get the distance between two points. More...
 
float radians (float degrees)
 Convert degrees to radians. More...
 
float degrees (float radians)
 Convert radians to degrees. More...
 
template<typename T >
max (T a, T b)
 Get the greater of two values. More...
 
template<typename T >
min (T a, T b)
 Get the lesser of two values. More...
 
template<typename T >
clamp (T value, T min, T max)
 Clamp the value between the given min and max. More...
 
void randomSeed (uint32_t seed)
 Set the seed for the random number generator. More...
 
int randomInt (int min, int max)
 Generate a random integer value between min and max. More...
 
int randomInt (int max)
 Generate a random integer value between 0 and the maximum. More...
 
float random (float min, float max)
 Generate a random floating point value between min and max. More...
 
float random (float max)
 Generate a random floating point value between 0 and the maximum. More...
 
uint64_t micros ()
 Get the number of microseconds since the program started. More...
 
uint64_t millis ()
 Get the number of milliseconds since the program started. More...
 
int second ()
 Get the current second from the system clock [0-59]. More...
 
int minute ()
 Get the current minute from the system clock [0-59]. More...
 
int hour ()
 Get the current hour from the system clock [0-23]. More...
 
int day ()
 Get the current day of the month [1-31]. More...
 
int month ()
 Get the current month of the year [1-12]. More...
 
int year ()
 Get the current year. More...
 
void run ()
 Run the application. More...
 

Static Public Member Functions

static AppGet ()
 

Public Attributes

sf::RenderWindow window
 The main window of your application. More...
 
bool darkTitleBar = true
 If the dark title bar should be used. More...
 
uint32_t width = 800
 The current width of the window [read only]. More...
 
uint32_t height = 600
 The current height of the window [read only]. More...
 
uint32_t displayWidth = 0
 The pixel width of the primary monitor [read only]. More...
 
uint32_t displayHeight = 0
 The pixel height of the primary monitor [read only]. More...
 
std::string title = "My cppgfx application"
 The current title of the window [read only]. More...
 
bool focused = true
 If the window is currently focused or not [read only]. More...
 
uint64_t frameCount = 0
 The frame count since the program started [read only]. More...
 
float frameTime = 0
 The elapsed time since the last frame in seconds [read only]. More...
 
float frameRate = 0
 The current frameRate [read only]. More...
 
int mouseX = 0
 The current mouse position X [read only]. More...
 
int mouseY = 0
 The current mouse position Y [read only]. More...
 
int pmouseX = 0
 The previous mouse position X [read only]. More...
 
int pmouseY = 0
 The previous mouse position Y [read only]. More...
 
int dmouseX = 0
 Delta X: The difference between the current and previous mouse position X [read only]. More...
 
int dmouseY = 0
 Delta Y: The difference between the current and previous mouse position Y [read only]. More...
 
bool mousePressed = false
 If any mouse button is currently pressed [read only]. More...
 

Static Public Attributes

constexpr static float PI = 3.14159265358979323846f
 The mathematical constant PI.
 

Detailed Description

The main application class.

This class is supposed to be inherited by the user.

Member Function Documentation

◆ clamp()

template<typename T >
T cppgfx::App::clamp ( value,
min,
max 
)
inline

Clamp the value between the given min and max.

Parameters
valueThe value to clamp
minThe minimum value
maxThe maximum value
Returns
The clamped value

◆ decodeBase64()

std::vector<uint8_t> cppgfx::App::decodeBase64 ( const std::string &  input)
inline

Decode a base-64 encoded string into its original form.

Parameters
inputThe base-64 encoded string to decode. The result can be a string, or any arbitrary byte sequence.
Returns
The decoded byte sequence or string

◆ degrees()

float cppgfx::App::degrees ( float  radians)

Convert radians to degrees.

Parameters
radiansThe angle in radians
Returns
The angle in degrees

◆ dist()

float cppgfx::App::dist ( float  x1,
float  y1,
float  x2,
float  y2 
)

Get the distance between two points.

Parameters
x1The x coordinate of the first point
y1The y coordinate of the first point
x2The x coordinate of the second point
y2The y coordinate of the second point
Returns
The distance between the two points

◆ encodeBase64()

std::string cppgfx::App::encodeBase64 ( const std::vector< uint8_t > &  input)
inline

Encode an arbitrary resource in base-64 encoding.

Parameters
inputThe byte sequence to encode. This can be a string, or any arbitrary byte sequence.
Returns
The base-64 encoded string

◆ max()

template<typename T >
T cppgfx::App::max ( a,
b 
)
inline

Get the greater of two values.

Parameters
aThe first value
bThe second value
Returns
The greater of the two

◆ min()

template<typename T >
T cppgfx::App::min ( a,
b 
)
inline

Get the lesser of two values.

Parameters
aThe first value
bThe second value
Returns
The lesser of the two values

◆ radians()

float cppgfx::App::radians ( float  degrees)

Convert degrees to radians.

Parameters
degreesThe angle in degrees
Returns
The angle in radians

◆ random() [1/2]

float cppgfx::App::random ( float  max)

Generate a random floating point value between 0 and the maximum.

Parameters
maxThe maximum value
Returns
The random value

◆ random() [2/2]

float cppgfx::App::random ( float  min,
float  max 
)

Generate a random floating point value between min and max.

Parameters
minThe minimum value
maxThe maximum value
Returns
The random value

◆ randomInt() [1/2]

int cppgfx::App::randomInt ( int  max)

Generate a random integer value between 0 and the maximum.

Parameters
maxThe maximum value
Returns
The random value

◆ randomInt() [2/2]

int cppgfx::App::randomInt ( int  min,
int  max 
)

Generate a random integer value between min and max.

Parameters
minThe minimum value
maxThe maximum value
Returns
The random value

◆ randomSeed()

void cppgfx::App::randomSeed ( uint32_t  seed)

Set the seed for the random number generator.

Parameters
seedThe seed

◆ run()

void cppgfx::App::run ( )

Run the application.

Warning
Do not call this function if you don't know what you are doing. It should only be called once in the main function, where it should already be in the template.

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