FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::sdl3::Graphics Class Reference

#include <graphics.hpp>

Inheritance diagram for fcn::sdl3::Graphics:
fcn::Graphics

Public Member Functions

void _beginDraw () override
void _endDraw () override
std::shared_ptr< FontcreateFont (std::string const &filename, int size) override
void drawBezier (PointVector const &points, int segments, unsigned int width) override
void drawCircle (Point const &center, unsigned int radius) override
void drawCircleSegment (Point const &center, unsigned int radius, int startAngle, int endAngle) override
void drawFillCircle (Point const &center, unsigned int radius) override
void drawFillCircleSegment (Point const &center, unsigned int radius, int startAngle, int endAngle) override
void drawImage (fcn::Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height) override
void drawLine (int x1, int y1, int x2, int y2) override
void drawLine (int x1, int y1, int x2, int y2, unsigned int width) override
void drawPoint (int x, int y) override
void drawPolyLine (PointVector const &points, unsigned int width) override
void drawRectangle (Rectangle const &rectangle) override
void drawRoundStroke (int x1, int y1, int x2, int y2, unsigned int width) override
virtual void drawSDLTexture (SDL_Texture *texture, SDL_FRect source, SDL_FRect destination)
void fillRectangle (Rectangle const &rectangle) override
Color const & getColor () const override
virtual SDL_Renderer * getRenderTarget () const
void popClipArea () override
bool pushClipArea (fcn::Rectangle area) override
void setColor (Color const &color) override
virtual void setTarget (SDL_Renderer *renderer, int width, int height)
Public Member Functions inherited from fcn::Graphics
virtual void drawImage (Image const *image, int dstX, int dstY)
void drawRectangle (int x, int y, int width, int height)
void drawText (std::string const &text, int x, int y)
virtual void drawText (std::string const &text, int x, int y, Alignment alignment)
void fillRectangle (int x, int y, int width, int height)
virtual ClipRectangle const & getCurrentClipArea ()
 Graphics (Graphics &&)=delete
 Graphics (Graphics const &)=delete
Graphics & operator= (Graphics &&)=delete
Graphics & operator= (Graphics const &)=delete
virtual void setFont (Font *font)

Protected Member Functions

void drawHorizontalLine (int x1, int y, int x2)
void drawVerticalLine (int x, int y1, int y2)
void restoreRenderColor ()
void saveRenderColor ()

Protected Attributes

Uint8 a {}
Uint8 b {}
Uint8 g {}
bool mAlpha
Color mColor
int mHeight = 0
SDL_Renderer * mRenderTarget {}
int mWidth = 0
Uint8 r {}
Protected Attributes inherited from fcn::Graphics
std::stack< ClipRectanglemClipStack
FontmFont {nullptr}

Additional Inherited Members

Public Types inherited from fcn::Graphics
enum class  Alignment : uint8_t { Left = 0 , Center , Right }
enum class  VerticalAlignment : uint8_t { Top = 0 , Center , Bottom }

Detailed Description

SDL3 renderer-specific implementation of the Graphics interface.

This is the primary graphics backend - it uses SDL_Renderer for all drawing operations.

Definition at line 38 of file backends/sdl3/graphics.hpp.

Constructor & Destructor Documentation

◆ Graphics()

fcn::sdl3::Graphics::Graphics ( )

Definition at line 62 of file backends/sdl3/graphics.cpp.

◆ ~Graphics()

fcn::sdl3::Graphics::~Graphics ( )
overridevirtualdefault

Reimplemented from fcn::Graphics.

Member Function Documentation

◆ _beginDraw()

void fcn::sdl3::Graphics::_beginDraw ( )
overridevirtual

Initializes drawing.

Called by the GUI when Gui::draw() is called. It is needed by some implementations of Graphics to perform preparations before drawing. An example of such an implementation is the OpenGLGraphics.

Note
You will never need to call this function yourself, unless you use a Graphics object outside the library.
See also
_endDraw, Gui::draw

Reimplemented from fcn::Graphics.

Definition at line 68 of file backends/sdl3/graphics.cpp.

References _beginDraw(), fcn::Rectangle::height, mHeight, mWidth, pushClipArea(), fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

Referenced by _beginDraw().

◆ _endDraw()

void fcn::sdl3::Graphics::_endDraw ( )
overridevirtual

Deinitializes the drawing process.

Called by the GUI when Gui::draw() is complete. It should reset any state changes made by _beginDraw().

Note
You generally won't need to call this function yourself unless you are using a Graphics object outside of the library.
See also
_beginDraw, Gui::draw

Reimplemented from fcn::Graphics.

Definition at line 78 of file backends/sdl3/graphics.cpp.

References _endDraw(), and popClipArea().

Referenced by _endDraw().

◆ createFont()

std::shared_ptr< Font > fcn::sdl3::Graphics::createFont ( std::string const & filename,
int size )
overridevirtual

Creates a font for this graphics backend.

Backends that do not provide runtime font loading may return nullptr.

Parameters
filenamePath to the font file.
sizeRequested point size.
Returns
Shared pointer to a created font, or nullptr.

Reimplemented from fcn::Graphics.

Definition at line 982 of file backends/sdl3/graphics.cpp.

References createFont().

Referenced by createFont().

◆ drawBezier()

void fcn::sdl3::Graphics::drawBezier ( PointVector const & points,
int steps,
unsigned int width )
overridevirtual

Draws a bezier curve.

Parameters
pointsThe coordinates as points in a vector.
stepsThe steps for each line between two points.
widthThe line width.

Implements fcn::Graphics.

Definition at line 773 of file backends/sdl3/graphics.cpp.

References drawBezier(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawBezier().

◆ drawCircle()

void fcn::sdl3::Graphics::drawCircle ( Point const & p,
unsigned int radius )
overridevirtual

Draws a simple, non-filled circle with a one pixel width.

Parameters
pThe circle center coordinate as point.
radiusThe circle radius.

Implements fcn::Graphics.

Definition at line 668 of file backends/sdl3/graphics.cpp.

References drawCircle(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawCircle().

◆ drawCircleSegment()

void fcn::sdl3::Graphics::drawCircleSegment ( Point const & p,
unsigned int radius,
int sangle,
int eangle )
overridevirtual

Draws a simple, non-filled circle segment with a one pixel width.

Note
The start angle must be less than the end angle. 0 angle is right side.
Parameters
pThe circle center coordinate as point.
radiusThe circle radius.
sangleThe start angle of the segment.
eangleThe end angle of the segment.

Implements fcn::Graphics.

Definition at line 715 of file backends/sdl3/graphics.cpp.

References drawCircleSegment(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawCircleSegment().

◆ drawFillCircle()

void fcn::sdl3::Graphics::drawFillCircle ( Point const & p,
unsigned int radius )
overridevirtual

Draws a filled circle.

Parameters
pThe circle center coordinate as point.
radiusThe circle radius.

Implements fcn::Graphics.

Definition at line 519 of file backends/sdl3/graphics.cpp.

References drawFillCircle(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawFillCircle(), drawLine(), and drawRoundStroke().

◆ drawFillCircleSegment()

void fcn::sdl3::Graphics::drawFillCircleSegment ( Point const & p,
unsigned int radius,
int sangle,
int eangle )
overridevirtual

Draws a filled circle segment.

Note
The start angle must be less than the end angle. 0 angle is right side.
Parameters
pThe circle center coordinate as point.
radiusThe circle radius.
sangleThe start angle of the segment.
eangleThe end angle of the segment.

Implements fcn::Graphics.

Definition at line 594 of file backends/sdl3/graphics.cpp.

References drawFillCircleSegment(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawFillCircleSegment().

◆ drawHorizontalLine()

void fcn::sdl3::Graphics::drawHorizontalLine ( int x1,
int y,
int x2 )
protected

Draws a horizontal line.

Parameters
x1the start coordinate of the line.
ythe y coordinate of the line.
x2the end coordinate of the line.

Definition at line 217 of file backends/sdl3/graphics.cpp.

References drawHorizontalLine(), fcn::Rectangle::height, fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::Rectangle::width, fcn::Rectangle::x, fcn::ClipRectangle::xOffset, fcn::Rectangle::y, and fcn::ClipRectangle::yOffset.

Referenced by drawHorizontalLine(), and drawRectangle().

◆ drawImage()

void fcn::sdl3::Graphics::drawImage ( fcn::Image const * image,
int srcX,
int srcY,
int dstX,
int dstY,
int width,
int height )
overridevirtual

Draws a part of an image.

Note
Width and height arguments will not scale the image but specifies the size of the part to be drawn. If you want to draw the whole image there is a simplified version of this function.
Example
drawImage(myImage, 10, 10, 20, 20, 40, 40);
void drawImage(fcn::Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height) override
Draws a part of an image.
This draws a rectangular region of myImage starting at (10, 10) with width and height 40. The extracted region is placed with its top-left corner at (20, 20).
Parameters
imageThe image to draw.
srcXThe source image x coordinate.
srcYThe source image y coordinate.
dstXThe destination x coordinate.
dstYThe destination y coordinate.
widthThe width of the piece.
heightThe height of the piece.
See also
drawImage(const Image& image, int dstX, int dstY)

Implements fcn::Graphics.

Definition at line 132 of file backends/sdl3/graphics.cpp.

References drawImage(), fcn::sdl3::Image::getTexture(), fcn::Graphics::mClipStack, mRenderTarget, fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawImage().

◆ drawLine() [1/2]

void fcn::sdl3::Graphics::drawLine ( int x1,
int y1,
int x2,
int y2 )
overridevirtual

Draws a line.

Parameters
x1The first x coordinate.
y1The first y coordinate.
x2The second x coordinate.
y2The second y coordinate.

Implements fcn::Graphics.

Definition at line 317 of file backends/sdl3/graphics.cpp.

References drawLine(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawLine(), drawLine(), and drawRoundStroke().

◆ drawLine() [2/2]

void fcn::sdl3::Graphics::drawLine ( int x1,
int y1,
int x2,
int y2,
unsigned int width )
overridevirtual

Draws a thick line.

Parameters
x1The first x coordinate.
y1The first y coordinate.
x2The second x coordinate.
y2The second y coordinate.
widthThe line width.

Implements fcn::Graphics.

Definition at line 338 of file backends/sdl3/graphics.cpp.

References drawFillCircle(), drawLine(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

◆ drawPoint()

void fcn::sdl3::Graphics::drawPoint ( int x,
int y )
overridevirtual

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements fcn::Graphics.

Definition at line 194 of file backends/sdl3/graphics.cpp.

References drawPoint(), fcn::Rectangle::isContaining(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawPoint().

◆ drawPolyLine()

void fcn::sdl3::Graphics::drawPolyLine ( PointVector const & points,
unsigned int width )
overridevirtual

Draws lines between points with given width.

Parameters
pointsContains the points that are used for drawing.
widthThe line width.

Implements fcn::Graphics.

Definition at line 873 of file backends/sdl3/graphics.cpp.

References drawPolyLine(), and fcn::Graphics::mClipStack.

Referenced by drawPolyLine().

◆ drawRectangle()

void fcn::sdl3::Graphics::drawRectangle ( Rectangle const & rectangle)
overridevirtual

Draws a simple, non-filled rectangle with a one pixel width.

Parameters
rectangleThe rectangle to draw.

Implements fcn::Graphics.

Definition at line 303 of file backends/sdl3/graphics.cpp.

References drawHorizontalLine(), drawRectangle(), drawVerticalLine(), fcn::Rectangle::height, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

Referenced by drawRectangle().

◆ drawRoundStroke()

void fcn::sdl3::Graphics::drawRoundStroke ( int x1,
int y1,
int x2,
int y2,
unsigned int width )
overridevirtual

Draws a round brush stroke along the line segment.

Unlike drawLine(..., width), this uses a round brush footprint and therefore produces round caps and a softer joint shape.

Backends that do not provide a dedicated implementation fall back to drawLine(..., width).

Parameters
x1The first x coordinate.
y1The first y coordinate.
x2The second x coordinate.
y2The second y coordinate.
widthThe brush width.

Reimplemented from fcn::Graphics.

Definition at line 425 of file backends/sdl3/graphics.cpp.

References drawFillCircle(), drawLine(), drawRoundStroke(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawRoundStroke().

◆ drawSDLTexture()

void fcn::sdl3::Graphics::drawSDLTexture ( SDL_Texture * texture,
SDL_FRect source,
SDL_FRect destination )
virtual

Draws an SDL_Texture on the target surface.

Note
The clip areas will be taken into account.

Definition at line 987 of file backends/sdl3/graphics.cpp.

References drawSDLTexture(), fcn::Graphics::mClipStack, mRenderTarget, fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.

Referenced by drawSDLTexture().

◆ drawVerticalLine()

void fcn::sdl3::Graphics::drawVerticalLine ( int x,
int y1,
int y2 )
protected

Draws a vertical line.

Parameters
xthe x coordinate of the line.
y1the start coordinate of the line.
y2the end coordinate of the line.

Definition at line 260 of file backends/sdl3/graphics.cpp.

References drawVerticalLine(), fcn::Rectangle::height, fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::Rectangle::width, fcn::Rectangle::x, fcn::ClipRectangle::xOffset, fcn::Rectangle::y, and fcn::ClipRectangle::yOffset.

Referenced by drawRectangle(), and drawVerticalLine().

◆ fillRectangle()

void fcn::sdl3::Graphics::fillRectangle ( Rectangle const & rectangle)
overridevirtual

◆ getColor()

Color const & fcn::sdl3::Graphics::getColor ( ) const
overridevirtual

Gets the color to use when drawing.

Returns
The color used when drawing.
See also
setColor

Implements fcn::Graphics.

Definition at line 977 of file backends/sdl3/graphics.cpp.

References getColor(), and mColor.

Referenced by getColor().

◆ getRenderTarget()

SDL_Renderer * fcn::sdl3::Graphics::getRenderTarget ( ) const
virtual

Gets the target SDL_Renderer.

Returns
the target SDL_Renderer.

Definition at line 127 of file backends/sdl3/graphics.cpp.

References getRenderTarget(), and mRenderTarget.

Referenced by getRenderTarget().

◆ popClipArea()

void fcn::sdl3::Graphics::popClipArea ( )
overridevirtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from fcn::Graphics.

Definition at line 108 of file backends/sdl3/graphics.cpp.

References fcn::Rectangle::height, fcn::Graphics::mClipStack, mRenderTarget, fcn::Graphics::popClipArea(), popClipArea(), fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

Referenced by _endDraw(), and popClipArea().

◆ pushClipArea()

bool fcn::sdl3::Graphics::pushClipArea ( fcn::Rectangle area)
overridevirtual

Pushes a clip area onto the stack.

The x and y coordinates in the rectangle is relative to the last pushed clip area. If the new area falls outside the current clip area, it will be clipped as necessary.

If a clip area is outside of the top clip area a clip area with zero width and height will be pushed.

Parameters
areaThe clip area to be pushed onto the stack.
Returns
False if the the new area lays outside the current clip area.

Reimplemented from fcn::Graphics.

Definition at line 90 of file backends/sdl3/graphics.cpp.

References fcn::Rectangle::height, fcn::Graphics::mClipStack, mRenderTarget, fcn::Graphics::pushClipArea(), pushClipArea(), fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

Referenced by _beginDraw(), and pushClipArea().

◆ restoreRenderColor()

void fcn::sdl3::Graphics::restoreRenderColor ( )
protected

◆ saveRenderColor()

void fcn::sdl3::Graphics::saveRenderColor ( )
protected

Save the current rendering color before drawing.

Does not affect the mColor attribute.

Definition at line 1005 of file backends/sdl3/graphics.cpp.

References a, b, g, mRenderTarget, r, and saveRenderColor().

Referenced by drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawHorizontalLine(), drawLine(), drawLine(), drawPoint(), drawRoundStroke(), drawVerticalLine(), fillRectangle(), and saveRenderColor().

◆ setColor()

void fcn::sdl3::Graphics::setColor ( Color const & color)
overridevirtual

Sets the color to use when drawing.

Parameters
colorA color.
See also
getColor

Implements fcn::Graphics.

Definition at line 970 of file backends/sdl3/graphics.cpp.

References fcn::Color::a, mAlpha, mColor, and setColor().

Referenced by setColor().

◆ setTarget()

void fcn::sdl3::Graphics::setTarget ( SDL_Renderer * renderer,
int width,
int height )
virtual

Sets the target SDL_Renderer to use for drawing.

Preferably done only once.

Parameters
rendererthe SDL_Renderer to use for drawing.
widthscreen width
heightscreen height

Definition at line 83 of file backends/sdl3/graphics.cpp.

References mHeight, mRenderTarget, mWidth, and setTarget().

Referenced by setTarget().

Member Data Documentation

◆ a

Uint8 fcn::sdl3::Graphics::a {}
protected

Previous alpha component from renderer.

Definition at line 147 of file backends/sdl3/graphics.hpp.

Referenced by restoreRenderColor(), and saveRenderColor().

◆ b

Uint8 fcn::sdl3::Graphics::b {}
protected

Previous blue component from renderer.

Definition at line 145 of file backends/sdl3/graphics.hpp.

Referenced by restoreRenderColor(), and saveRenderColor().

◆ g

Uint8 fcn::sdl3::Graphics::g {}
protected

Previous green component from renderer.

Definition at line 143 of file backends/sdl3/graphics.hpp.

Referenced by restoreRenderColor(), and saveRenderColor().

◆ mAlpha

bool fcn::sdl3::Graphics::mAlpha
protected

Whether alpha blending is enabled.

Definition at line 150 of file backends/sdl3/graphics.hpp.

Referenced by setColor().

◆ mColor

◆ mHeight

int fcn::sdl3::Graphics::mHeight = 0
protected

Screen height.

Definition at line 134 of file backends/sdl3/graphics.hpp.

Referenced by _beginDraw(), and setTarget().

◆ mRenderTarget

◆ mWidth

int fcn::sdl3::Graphics::mWidth = 0
protected

Screen width.

Definition at line 131 of file backends/sdl3/graphics.hpp.

Referenced by _beginDraw(), and setTarget().

◆ r

Uint8 fcn::sdl3::Graphics::r {}
protected

Cached renderer color components (previous renderer color).

Previous red component from renderer.

Definition at line 141 of file backends/sdl3/graphics.hpp.

Referenced by restoreRenderColor(), and saveRenderColor().


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