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

#include <graphics.hpp>

Inheritance diagram for fcn::Graphics:
fcn::opengl::Graphics fcn::sdl2::Graphics

Public Types

enum class  Alignment : uint8_t { Left = 0 , Center , Right }

Public Member Functions

virtual void _beginDraw ()
virtual void _endDraw ()
virtual std::shared_ptr< FontcreateFont (std::string const &filename, int size)
virtual void drawBezier (PointVector const &points, int steps, unsigned int width)=0
virtual void drawCircle (Point const &p, unsigned int radius)=0
virtual void drawCircleSegment (Point const &p, unsigned int radius, int sangle, int eangle)=0
virtual void drawFillCircle (Point const &p, unsigned int radius)=0
virtual void drawFillCircleSegment (Point const &p, unsigned int radius, int sangle, int eangle)=0
virtual void drawImage (Image const *image, int dstX, int dstY)
virtual void drawImage (Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
virtual void drawLine (int x1, int y1, int x2, int y2)=0
virtual void drawLine (int x1, int y1, int x2, int y2, unsigned int width)=0
virtual void drawPoint (int x, int y)=0
virtual void drawPolyLine (PointVector const &points, unsigned int width)=0
void drawRectangle (int x, int y, int width, int height)
virtual void drawRectangle (Rectangle const &rectangle)=0
virtual void drawRoundStroke (int x1, int y1, int x2, int y2, unsigned int width)
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 void fillRectangle (Rectangle const &rectangle)=0
virtual Color const & getColor () const =0
virtual ClipRectangle const & getCurrentClipArea ()
 Graphics (Graphics &&)=delete
 Graphics (Graphics const &)=delete
Graphics & operator= (Graphics &&)=delete
Graphics & operator= (Graphics const &)=delete
virtual void popClipArea ()
virtual bool pushClipArea (Rectangle area)
virtual void setColor (Color const &color)=0
virtual void setFont (Font *font)

Protected Attributes

std::stack< ClipRectanglemClipStack
FontmFont {nullptr}

Detailed Description

Abstract interface providing primitive drawing functions (lines, rectangles, etc.).

It contains all vital functions for drawing.

FifeGUI contains implementations of Graphics for common libraries like the OpenGL library and the SDL library. If you want to use FifeGUI with another library you will have to implement a Graphics class for that library.

In Graphics you can set clip areas to limit drawing to certain areas of the screen. Clip areas are put on a stack, which means that you can push smaller and smaller clip areas onto the stack. All coordinates will be relative to the top most clip area. In most cases you won't have to worry about the clip areas, unless you want to implement some really complex widget. Pushing and poping of clip areas are handled automatically by container widgets when their child widgets are drawn.

IMPORTANT: Remember to pop each clip area that you pushed on the stack after you are done with it.

If you feel that Graphics is to restrictive for your needs, there is no one stopping you from using your own code for drawing in widgets. You could for instance use pure SDL in the drawing of widgets bypassing Graphics. This might however hurt portability of your application.

See also
OpenGLGraphics, SDLGraphics, Image

Definition at line 56 of file graphics.hpp.

Member Enumeration Documentation

◆ Alignment

enum class fcn::Graphics::Alignment : uint8_t
strong

Alignments for text drawing.

Definition at line 62 of file graphics.hpp.

Member Function Documentation

◆ _beginDraw()

virtual void fcn::Graphics::_beginDraw ( )
inlinevirtual

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 in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Definition at line 89 of file graphics.hpp.

◆ _endDraw()

virtual void fcn::Graphics::_endDraw ( )
inlinevirtual

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 in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Definition at line 101 of file graphics.hpp.

◆ createFont()

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

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 in fcn::sdl2::Graphics.

Definition at line 84 of file graphics.cpp.

Referenced by getColor().

◆ drawBezier()

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

Draws a bezier curve.

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

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

◆ drawCircle()

virtual void fcn::Graphics::drawCircle ( Point const & p,
unsigned int radius )
pure virtual

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

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

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

◆ drawCircleSegment()

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

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.

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

◆ drawFillCircle()

virtual void fcn::Graphics::drawFillCircle ( Point const & p,
unsigned int radius )
pure virtual

Draws a filled circle.

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

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Referenced by fcn::PointGraph::draw(), and fcn::CheckBox::drawDot().

◆ drawFillCircleSegment()

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

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.

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Referenced by fcn::PieGraph::draw().

◆ drawImage() [1/2]

void fcn::Graphics::drawImage ( Image const * image,
int dstX,
int dstY )
virtual

Draws an image.

A simplified version of the other drawImage. It will draw a whole image at the coordinate you specify. It is equivalent to calling:

drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), \
image->getHeight());
virtual void drawImage(Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
Draws a part of an image.

Reimplemented in fcn::opengl::Graphics.

Definition at line 74 of file graphics.cpp.

References drawImage(), fcn::Image::getHeight(), and fcn::Image::getWidth().

◆ drawImage() [2/2]

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

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);

Will draw a rectangular piece of myImage starting at coordinate (10, 10) in myImage, with width and height 40. The piece will be drawn with it's top left corner at coordinate (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.

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

References drawImage().

Referenced by fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::CheckBox::drawBox(), fcn::ImageFont::drawGlyph(), drawImage(), drawImage(), and fcn::CheckBox::drawMarkerImage().

◆ drawLine() [1/2]

◆ drawLine() [2/2]

virtual void fcn::Graphics::drawLine ( int x1,
int y1,
int x2,
int y2,
unsigned int width )
pure virtual

Draws a thick line.

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

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

◆ drawPoint()

virtual void fcn::Graphics::drawPoint ( int x,
int y )
pure virtual

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

◆ drawPolyLine()

virtual void fcn::Graphics::drawPolyLine ( PointVector const & points,
unsigned int width )
pure virtual

Draws lines between points with given width.

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

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Referenced by fcn::CurveGraph::draw().

◆ drawRectangle() [1/2]

void fcn::Graphics::drawRectangle ( int x,
int y,
int width,
int height )
inline

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

This is an overload provided for convenience.

Parameters
xThe x coordinate of the rectangle
yThe y coordinate of the rectangle
widthThe width of the rectangle
heightThe height of the rectangle

Definition at line 249 of file graphics.hpp.

References drawRectangle().

◆ drawRectangle() [2/2]

virtual void fcn::Graphics::drawRectangle ( Rectangle const & rectangle)
pure virtual

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

Parameters
rectangleThe rectangle to draw.

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Referenced by fcn::DropDown::draw(), fcn::Tab::draw(), fcn::TextField::draw(), fcn::DefaultFont::drawGlyph(), fcn::ImageFont::drawGlyph(), fcn::Slider::drawMarker(), and drawRectangle().

◆ drawRoundStroke()

virtual void fcn::Graphics::drawRoundStroke ( int x1,
int y1,
int x2,
int y2,
unsigned int width )
inlinevirtual

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 in fcn::sdl2::Graphics.

Definition at line 209 of file graphics.hpp.

References drawLine().

Referenced by fcn::CurveGraph::draw(), fcn::LineGraph::draw(), and fcn::PointGraph::draw().

◆ drawText() [1/2]

void fcn::Graphics::drawText ( std::string const & text,
int x,
int y )
inline

Draws text with a default left alignment.

This overload forwards to the alignment-aware overload using Alignment::Left.

Parameters
textThe text to draw.
xThe x coordinate where to draw the text.
yThe y coordinate where to draw the text.
Exceptions
Exceptionwhen no font has been set.

Definition at line 362 of file graphics.hpp.

References drawText().

Referenced by fcn::Button::draw(), fcn::CheckBox::draw(), fcn::DropDown::draw(), fcn::ImageButton::draw(), fcn::Label::draw(), fcn::ListBox::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Window::draw(), and drawText().

◆ drawText() [2/2]

void fcn::Graphics::drawText ( std::string const & text,
int x,
int y,
Alignment alignment )
virtual

Draws text with the requested alignment.

Parameters
textThe text to draw.
xThe x coordinate where to draw the text.
yThe y coordinate where to draw the text.
alignmentThe alignment to use when drawing (Left/Center/Right).
Exceptions
Exceptionwhen no font has been set.

Definition at line 91 of file graphics.cpp.

References mFont.

◆ fillRectangle() [1/2]

void fcn::Graphics::fillRectangle ( int x,
int y,
int width,
int height )
inline

Draws a filled rectangle.

This is an overload provided for convenience.

Parameters
xThe x coordinate of the rectangle
yThe y coordinate of the rectangle
widthThe width of the rectangle
heightThe height of the rectangle

Definition at line 272 of file graphics.hpp.

References fillRectangle().

◆ fillRectangle() [2/2]

◆ getColor()

virtual Color const & fcn::Graphics::getColor ( ) const
pure virtual

Gets the color to use when drawing.

Returns
The color used when drawing.
See also
setColor

Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

References createFont(), and setFont().

Referenced by fcn::sdl2::TrueTypeFont::drawString().

◆ getCurrentClipArea()

ClipRectangle const & fcn::Graphics::getCurrentClipArea ( )
virtual

Gets the current clip area.

Useful if you want to do drawing bypassing Graphics.

Returns
The current clip area.

Definition at line 65 of file graphics.cpp.

References mClipStack.

Referenced by fcn::DropDown::draw(), fcn::ListBox::draw(), fcn::Tab::draw(), fcn::DropDown::drawButton(), and fcn::TextField::drawCaret().

◆ popClipArea()

◆ pushClipArea()

bool fcn::Graphics::pushClipArea ( Rectangle area)
virtual

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 in fcn::opengl::Graphics, and fcn::sdl2::Graphics.

Definition at line 18 of file graphics.cpp.

References fcn::Rectangle::height, fcn::Rectangle::intersection(), fcn::Rectangle::isEmpty(), mClipStack, fcn::Rectangle::width, fcn::Rectangle::x, fcn::ClipRectangle::xOffset, fcn::Rectangle::y, and fcn::ClipRectangle::yOffset.

Referenced by fcn::Widget::_draw(), fcn::DropDown::draw(), fcn::ImageProgressBar::draw(), fcn::Tab::draw(), fcn::TextField::draw(), fcn::Window::draw(), fcn::ScrollArea::drawDownButton(), fcn::ScrollArea::drawHBar(), fcn::ScrollArea::drawHMarker(), fcn::ScrollArea::drawLeftButton(), fcn::CheckBox::drawRhombus(), fcn::ScrollArea::drawRightButton(), fcn::ScrollArea::drawUpButton(), fcn::ScrollArea::drawVBar(), fcn::ScrollArea::drawVMarker(), fcn::opengl::Graphics::pushClipArea(), and fcn::sdl2::Graphics::pushClipArea().

◆ setColor()

◆ setFont()

void fcn::Graphics::setFont ( Font * font)
virtual

Sets the font to use when drawing text.

Parameters
fontThe font to use when drawing.

Definition at line 79 of file graphics.cpp.

References mFont.

Referenced by fcn::Button::draw(), fcn::CheckBox::draw(), fcn::DropDown::draw(), fcn::ImageButton::draw(), fcn::Label::draw(), fcn::ListBox::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Window::draw(), and getColor().

Member Data Documentation

◆ mClipStack

◆ mFont

Font* fcn::Graphics::mFont {nullptr}
protected

Holds the current font.

Definition at line 387 of file graphics.hpp.

Referenced by drawText(), and setFont().


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