cppgfx  0.1.0
C++17 educational graphics library
Graphics

Drawing primitives and styles. More...

Functions

void cppgfx::App::background (const sf::Color &color)
 Set the background color of the window for the current frame. More...
 
void cppgfx::App::background (uint8_t shade)
 Set the background color of the window for the current frame. More...
 
void cppgfx::App::background (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the background color of the window. More...
 
void cppgfx::App::fill (const sf::Color &color)
 Set the infill color for primitives. More...
 
void cppgfx::App::fill (uint8_t shade)
 Set the infill color for primitives. More...
 
void cppgfx::App::fill (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the infill color for primitives. More...
 
void cppgfx::App::noFill ()
 Disable the infill color for primitives.
 
void cppgfx::App::stroke (const sf::Color &color)
 Set the outline color for primitives.
 
void cppgfx::App::stroke (uint8_t shade)
 Set the outline color for primitives. More...
 
void cppgfx::App::stroke (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Set the outline color for primitives. More...
 
void cppgfx::App::noStroke ()
 Disable the outline color for primitives.
 
void cppgfx::App::strokeWeight (float weight)
 Set the thickness of the outline for primitives. More...
 
void cppgfx::App::push ()
 Push the current draw style onto the stack. More...
 
void cppgfx::App::pop ()
 Pop the current draw style from the stack. More...
 
void cppgfx::App::line (float x1, float y1, float x2, float y2)
 Draw a line from (x1, y1) to (x2, y2) More...
 
void cppgfx::App::lineCap (LineCap cap)
 Set the line cap style. More...
 
void cppgfx::App::rect (float x, float y, float w, float h)
 Draw a rectangle at (x, y) with the given width and height. More...
 
void cppgfx::App::rectMode (RectMode mode)
 Where the origin of the rectangle is. More...
 
void cppgfx::App::circle (float x, float y, float radius)
 Draw a circle at (x, y) with the given radius. More...
 
void cppgfx::App::ellipse (float x, float y, float w, float h)
 Draw an ellipse at (x, y) with the given width and height. More...
 
void cppgfx::App::triangle (float x1, float y1, float x2, float y2, float x3, float y3)
 Draw a triangle with the given points. More...
 
void cppgfx::App::vector (float vectorX, float vectorY, float originX, float originY)
 Draw a vector arrow from the origin to origin + vector. More...
 
void cppgfx::App::textFont (const sf::Font &font)
 Set the current font to be used for rendering from now on. More...
 
sf::Font cppgfx::App::loadFont (const std::string &filename)
 Load a font from a file with a specific size. More...
 
void cppgfx::App::textAlign (TextAlign alignment)
 Set the current alignment for drawing text. More...
 
float cppgfx::App::textWidth (const std::string &text)
 Calculate the width of a text string in pixels. More...
 
void cppgfx::App::textSize (uint32_t size)
 Set the font size of the currently active font. More...
 
void cppgfx::App::text (const std::string &text, float x, float y)
 Draw text at (x, y) More...
 

Detailed Description

Drawing primitives and styles.

Function Documentation

◆ background() [1/3]

void cppgfx::App::background ( const sf::Color &  color)

Set the background color of the window for the current frame.

Parameters
colorThe background color

◆ background() [2/3]

void cppgfx::App::background ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)

Set the background color of the window.

Parameters
rThe red component of the background color [0-255]
gThe green component of the background color [0-255]
bThe blue component of the background color [0-255]
aThe alpha component of the background color [0-255] (optional)

◆ background() [3/3]

void cppgfx::App::background ( uint8_t  shade)

Set the background color of the window for the current frame.

Parameters
shadeThe background color for r, g and b [0-255]

◆ circle()

void cppgfx::App::circle ( float  x,
float  y,
float  radius 
)

Draw a circle at (x, y) with the given radius.

Parameters
xThe x coordinate of the center of the circle in pixels, relative to the top left corner of the window
yThe y coordinate of the center of the circle in pixels, relative to the top left corner of the window
radiusThe radius of the circle in pixels

◆ ellipse()

void cppgfx::App::ellipse ( float  x,
float  y,
float  w,
float  h 
)

Draw an ellipse at (x, y) with the given width and height.

Parameters
xThe x coordinate of the center of the ellipse in pixels, relative to the top left corner of the window
yThe y coordinate of the center of the ellipse in pixels, relative to the top left corner of the window
wThe width of the ellipse in pixels
hThe height of the ellipse in pixels

◆ fill() [1/3]

void cppgfx::App::fill ( const sf::Color &  color)

Set the infill color for primitives.

Parameters
colorThe infill color

◆ fill() [2/3]

void cppgfx::App::fill ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)

Set the infill color for primitives.

Parameters
rThe red component of the infill color [0-255]
gThe green component of the infill color [0-255]
bThe blue component of the infill color [0-255]
aThe alpha component of the infill color [0-255] (optional)

◆ fill() [3/3]

void cppgfx::App::fill ( uint8_t  shade)

Set the infill color for primitives.

Parameters
shadeThe infill color for r, g and b [0-255]

◆ line()

void cppgfx::App::line ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a line from (x1, y1) to (x2, y2)

Parameters
x1The x coordinate of the first point in pixels, relative to the top left corner of the window
y1The y coordinate of the first point in pixels, relative to the top left corner of the window
x2The x coordinate of the second point in pixels, relative to the top left corner of the window
y2The y coordinate of the second point in pixels, relative to the top left corner of the window

◆ lineCap()

void cppgfx::App::lineCap ( LineCap  cap)

Set the line cap style.

Parameters
capThe line cap style

◆ loadFont()

sf::Font cppgfx::App::loadFont ( const std::string &  filename)

Load a font from a file with a specific size.

Parameters
filenameThe filename of the font to load
Returns
The loaded font

◆ pop()

void cppgfx::App::pop ( )

Pop the current draw style from the stack.

This function will pop the current draw style from the stack, so that it can be restored later. This mechanism is very useful when you want to temporarily change the draw style, and later change it back to what it was.

◆ push()

void cppgfx::App::push ( )

Push the current draw style onto the stack.

This function will push the current draw style onto the stack, so that it can be restored later. This mechanism is very useful when you want to temporarily change the draw style, and later change it back to what it was.

◆ rect()

void cppgfx::App::rect ( float  x,
float  y,
float  w,
float  h 
)

Draw a rectangle at (x, y) with the given width and height.

What the x, y, w and h parameters mean depends on the current rectMode.

Parameters
xThe first x coordinate in pixels, relative to the top left corner of the window
yThe first y coordinate in pixels, relative to the top left corner of the window
wThe second x coordinate in pixels, relative to the top left corner of the window
hThe second y coordinate in pixels, relative to the top left corner of the window

◆ rectMode()

void cppgfx::App::rectMode ( RectMode  mode)

Where the origin of the rectangle is.

This function will change the meaning of the x, y, w and h parameters of the rect() function. The default is RectMode::Corner. RectMode::Corner means that x and y are the top left corner of the rectangle and w and h are the width and height of the rectangle. RectMode::Center means that x and y are the center of the rectangle and w and h are the width and height of the rectangle. RectMode::Corners means that x and y are the top left corner of the rectangle and w and h are the bottom right corner of the rectangle.

Parameters
modeThe rectMode

◆ stroke() [1/2]

void cppgfx::App::stroke ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)

Set the outline color for primitives.

Parameters
rThe red component of the outline color [0-255]
gThe green component of the outline color [0-255]
bThe blue component of the outline color [0-255]
aThe alpha component of the outline color [0-255] (optional)

◆ stroke() [2/2]

void cppgfx::App::stroke ( uint8_t  shade)

Set the outline color for primitives.

Parameters
shadeThe outline color for r, g and b [0-255]

◆ strokeWeight()

void cppgfx::App::strokeWeight ( float  weight)

Set the thickness of the outline for primitives.

Parameters
weightThe thickness of the outline in pixels

◆ text()

void cppgfx::App::text ( const std::string &  text,
float  x,
float  y 
)

Draw text at (x, y)

Parameters
textThe text to draw
xThe x coordinate of the text in pixels, relative to the top left corner of the window
yThe y coordinate of the text in pixels, relative to the top left corner of the window

◆ textAlign()

void cppgfx::App::textAlign ( TextAlign  alignment)

Set the current alignment for drawing text.

Parameters
alignmentThe alignment

◆ textFont()

void cppgfx::App::textFont ( const sf::Font &  font)

Set the current font to be used for rendering from now on.

Parameters
fontThe SFML font to use

◆ textSize()

void cppgfx::App::textSize ( uint32_t  size)

Set the font size of the currently active font.

Parameters
sizeThe font size in pixels

◆ textWidth()

float cppgfx::App::textWidth ( const std::string &  text)

Calculate the width of a text string in pixels.

Parameters
textThe text to measure
Returns
The width of the text in pixels

◆ triangle()

void cppgfx::App::triangle ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3 
)

Draw a triangle with the given points.

Parameters
x1The x coordinate of the first point in pixels, relative to the top left corner of the window
y1The y coordinate of the first point in pixels, relative to the top left corner of the window
x2The x coordinate of the second point in pixels, relative to the top left corner of the window
y2The y coordinate of the second point in pixels, relative to the top left corner of the window
x3The x coordinate of the third point in pixels, relative to the top left corner of the window
y3The y coordinate of the third point in pixels, relative to the top left corner of the window

◆ vector()

void cppgfx::App::vector ( float  vectorX,
float  vectorY,
float  originX,
float  originY 
)

Draw a vector arrow from the origin to origin + vector.

This function will draw a vector arrow from the origin to origin + vector. It is meant to be used for scientific visualization purposes.

Parameters
vectorXThe x component of the vector
vectorYThe y component of the vector
originXThe x coordinate of the origin of the vector in pixels, relative to the top left corner of the window
originYThe y coordinate of the origin of the vector in pixels, relative to the top left corner of the window