|
FifeGUI 0.3.0
A C++ GUI library designed for games.
|
#include <graphics.hpp>
Public Types | |
| enum class | Alignment : uint8_t { Left = 0 , Center , Right } |
| enum class | VerticalAlignment : uint8_t { Top = 0 , Center , Bottom } |
Public Member Functions | |
| virtual void | _beginDraw () |
| virtual void | _endDraw () |
| virtual std::shared_ptr< Font > | createFont (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< ClipRectangle > | mClipStack |
| Font * | mFont {nullptr} |
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.
Definition at line 57 of file graphics.hpp.
|
strong |
Horizontal alignments for text drawing.
Definition at line 63 of file graphics.hpp.
|
strong |
Vertical alignments for text drawing.
Definition at line 73 of file graphics.hpp.
|
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.
Reimplemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Definition at line 103 of file graphics.hpp.
|
inlinevirtual |
Deinitializes the drawing process.
Called by the GUI when Gui::draw() is complete. It should reset any state changes made by _beginDraw().
Reimplemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Definition at line 118 of file graphics.hpp.
|
virtual |
Creates a font for this graphics backend.
Backends that do not provide runtime font loading may return nullptr.
| filename | Path to the font file. |
| size | Requested point size. |
Reimplemented in fcn::sdl3::Graphics.
Definition at line 96 of file graphics.cpp.
Referenced by getColor(), and fcn::font::FontLoader::loadFont().
|
pure virtual |
Draws a bezier curve.
| points | The coordinates as points in a vector. |
| steps | The steps for each line between two points. |
| width | The line width. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
|
pure virtual |
Draws a simple, non-filled circle with a one pixel width.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
|
pure virtual |
Draws a simple, non-filled circle segment with a one pixel width.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
| sangle | The start angle of the segment. |
| eangle | The end angle of the segment. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
|
pure virtual |
Draws a filled circle.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::PointGraph::draw(), and fcn::CheckBox::drawDot().
|
pure virtual |
Draws a filled circle segment.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
| sangle | The start angle of the segment. |
| eangle | The end angle of the segment. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::PieGraph::draw().
|
virtual |
Draws an image.
A simplified version of the other drawImage. It will draw a whole image at the coordinate you specify.
| image | The image to draw. |
| dstX | The destination x coordinate. |
| dstY | The destination y coordinate. |
Reimplemented in fcn::opengl::Graphics.
Definition at line 83 of file graphics.cpp.
References drawImage(), fcn::Image::getHeight(), fcn::Image::getWidth(), and fcn::throwException().
|
pure virtual |
Draws a part of an image.
| image | The image to draw. |
| srcX | The source image x coordinate. |
| srcY | The source image y coordinate. |
| dstX | The destination x coordinate. |
| dstY | The destination y coordinate. |
| width | The width of the piece. |
| height | The height of the piece. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
References drawImage().
Referenced by fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::MenuItem::draw(), fcn::CheckBox::drawBox(), fcn::ImageFont::drawGlyph(), drawImage(), drawImage(), and fcn::CheckBox::drawMarkerImage().
|
pure virtual |
Draws a line.
| x1 | The first x coordinate. |
| y1 | The first y coordinate. |
| x2 | The second x coordinate. |
| y2 | The second y coordinate. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::ActivityBar::draw(), fcn::DropDown::draw(), fcn::HorizontalBar::draw(), fcn::LineGraph::draw(), fcn::Panel::draw(), fcn::PointGraph::draw(), fcn::StatusBar::draw(), fcn::Tab::draw(), fcn::TabbedArea::draw(), fcn::TextField::draw(), fcn::Widget::drawBorder(), fcn::CheckBox::drawBox(), fcn::DropDown::drawButton(), fcn::TextBox::drawCaret(), fcn::TextField::drawCaret(), fcn::ScrollArea::drawDownButton(), fcn::ScrollArea::drawHBar(), fcn::ScrollArea::drawHMarker(), fcn::Window::drawInnerBorder(), fcn::ScrollArea::drawLeftButton(), fcn::Slider::drawMarker(), fcn::Widget::drawOutline(), fcn::CheckBox::drawRhombus(), fcn::ScrollArea::drawRightButton(), drawRoundStroke(), fcn::Widget::drawSelectionFrame(), fcn::ScrollArea::drawUpButton(), fcn::ScrollArea::drawVBar(), and fcn::ScrollArea::drawVMarker().
|
pure virtual |
Draws a thick line.
| x1 | The first x coordinate. |
| y1 | The first y coordinate. |
| x2 | The second x coordinate. |
| y2 | The second y coordinate. |
| width | The line width. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
|
pure virtual |
Draws a single point/pixel.
| x | The x coordinate. |
| y | The y coordinate. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
|
pure virtual |
Draws lines between points with given width.
| points | Contains the points that are used for drawing. |
| width | The line width. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::CurveGraph::draw().
|
inline |
Draws a simple, non-filled rectangle with a one pixel width.
This is an overload provided for convenience.
| x | The x coordinate of the rectangle |
| y | The y coordinate of the rectangle |
| width | The width of the rectangle |
| height | The height of the rectangle |
Definition at line 285 of file graphics.hpp.
References drawRectangle().
|
pure virtual |
Draws a simple, non-filled rectangle with a one pixel width.
| rectangle | The rectangle to draw. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::DropDown::draw(), fcn::Tab::draw(), fcn::TextField::draw(), fcn::Tooltip::draw(), fcn::DefaultFont::drawGlyph(), fcn::ImageFont::drawGlyph(), fcn::Slider::drawMarker(), and drawRectangle().
|
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).
| x1 | The first x coordinate. |
| y1 | The first y coordinate. |
| x2 | The second x coordinate. |
| y2 | The second y coordinate. |
| width | The brush width. |
Reimplemented in fcn::sdl3::Graphics.
Definition at line 246 of file graphics.hpp.
References drawLine().
Referenced by fcn::CurveGraph::draw(), fcn::LineGraph::draw(), and fcn::PointGraph::draw().
|
inline |
Draws text with a default left alignment.
This overload forwards to the alignment-aware overload using Alignment::Left.
| text | The text to draw. |
| x | The x coordinate where to draw the text. |
| y | The y coordinate where to draw the text. |
| Exception | when no font has been set. |
Definition at line 401 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::MenuItem::draw(), fcn::Panel::draw(), fcn::StatusBar::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Window::draw(), and drawText().
|
virtual |
Draws text with the requested alignment.
| text | The text to draw. |
| x | The x coordinate where to draw the text. |
| y | The y coordinate where to draw the text. |
| alignment | The alignment to use when drawing (Left/Center/Right). |
| Exception | when no font has been set. |
Definition at line 103 of file graphics.cpp.
References mFont, and fcn::throwException().
|
inline |
Draws a filled rectangle.
This is an overload provided for convenience.
| x | The x coordinate of the rectangle |
| y | The y coordinate of the rectangle |
| width | The width of the rectangle |
| height | The height of the rectangle |
Definition at line 307 of file graphics.hpp.
References fillRectangle().
|
pure virtual |
Draws a filled rectangle.
| rectangle | The filled rectangle to draw. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::ActivityBar::draw(), fcn::BarGraph::draw(), fcn::Button::draw(), fcn::Container::draw(), fcn::CurveGraph::draw(), fcn::DropDown::draw(), fcn::HorizontalBar::draw(), fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::LineGraph::draw(), fcn::ListBox::draw(), fcn::MenuBar::draw(), fcn::MenuItem::draw(), fcn::MenuPopup::draw(), fcn::Panel::draw(), fcn::PieGraph::draw(), fcn::PointGraph::draw(), fcn::ScrollArea::draw(), fcn::Slider::draw(), fcn::Tab::draw(), fcn::TabbedArea::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Tooltip::draw(), fcn::Window::draw(), fcn::ScrollArea::drawBackground(), fcn::CheckBox::drawBox(), fcn::DropDown::drawButton(), fcn::ScrollArea::drawDownButton(), fcn::ScrollArea::drawHBar(), fcn::ScrollArea::drawHMarker(), fcn::ScrollArea::drawLeftButton(), fcn::Slider::drawMarker(), fcn::ScrollArea::drawRightButton(), fcn::ScrollArea::drawUpButton(), fcn::ScrollArea::drawVBar(), fcn::ScrollArea::drawVMarker(), and fillRectangle().
|
pure virtual |
Gets the color to use when drawing.
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
References createFont(), and setFont().
Referenced by fcn::sdl3::TrueTypeFont::drawString().
|
virtual |
Gets the current clip area.
Useful if you want to do drawing bypassing Graphics.
Definition at line 74 of file graphics.cpp.
References mClipStack, and fcn::throwException().
Referenced by fcn::DropDown::draw(), fcn::ListBox::draw(), fcn::Tab::draw(), fcn::DropDown::drawButton(), and fcn::TextField::drawCaret().
|
virtual |
Removes the top most clip area from the stack.
| Exception | if the stack is empty. |
Reimplemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Definition at line 65 of file graphics.cpp.
References mClipStack, and fcn::throwException().
Referenced by fcn::Widget::_draw(), fcn::DropDown::draw(), fcn::ImageProgressBar::draw(), fcn::Panel::draw(), fcn::StatusBar::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::popClipArea(), and fcn::sdl3::Graphics::popClipArea().
|
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.
| area | The clip area to be pushed onto the stack. |
Reimplemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Definition at line 25 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::Panel::draw(), fcn::StatusBar::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::sdl3::Graphics::pushClipArea().
|
pure virtual |
Sets the color to use when drawing.
| color | A color. |
Implemented in fcn::opengl::Graphics, and fcn::sdl3::Graphics.
Referenced by fcn::ActivityBar::draw(), fcn::BarGraph::draw(), fcn::Button::draw(), fcn::CheckBox::draw(), fcn::Container::draw(), fcn::CurveGraph::draw(), fcn::DropDown::draw(), fcn::HorizontalBar::draw(), fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::Label::draw(), fcn::LineGraph::draw(), fcn::ListBox::draw(), fcn::MenuBar::draw(), fcn::MenuItem::draw(), fcn::MenuPopup::draw(), fcn::Panel::draw(), fcn::PieGraph::draw(), fcn::PointGraph::draw(), fcn::ScrollArea::draw(), fcn::Slider::draw(), fcn::StatusBar::draw(), fcn::Tab::draw(), fcn::TabbedArea::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Tooltip::draw(), fcn::Window::draw(), fcn::ScrollArea::drawBackground(), fcn::Widget::drawBorder(), fcn::CheckBox::drawBox(), fcn::DropDown::drawButton(), fcn::TextBox::drawCaret(), fcn::TextField::drawCaret(), fcn::ScrollArea::drawDownButton(), fcn::ScrollArea::drawHBar(), fcn::ScrollArea::drawHMarker(), fcn::Window::drawInnerBorder(), fcn::ScrollArea::drawLeftButton(), fcn::Slider::drawMarker(), fcn::Widget::drawOutline(), fcn::CheckBox::drawRhombus(), fcn::ScrollArea::drawRightButton(), fcn::Widget::drawSelectionFrame(), fcn::ScrollArea::drawUpButton(), fcn::ScrollArea::drawVBar(), and fcn::ScrollArea::drawVMarker().
|
virtual |
Sets the font to use when drawing text.
| font | The font to use when drawing. |
Definition at line 91 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::MenuItem::draw(), fcn::Panel::draw(), fcn::StatusBar::draw(), fcn::TextBox::draw(), fcn::TextField::draw(), fcn::Window::draw(), and getColor().
|
protected |
Holds the clip area stack.
Definition at line 421 of file graphics.hpp.
Referenced by fcn::sdl3::Graphics::drawBezier(), fcn::sdl3::Graphics::drawCircle(), fcn::sdl3::Graphics::drawFillCircle(), fcn::sdl3::Graphics::drawHorizontalLine(), fcn::opengl::Graphics::drawImage(), fcn::sdl3::Graphics::drawImage(), fcn::opengl::Graphics::drawLine(), fcn::sdl3::Graphics::drawLine(), fcn::sdl3::Graphics::drawLine(), fcn::opengl::Graphics::drawPoint(), fcn::sdl3::Graphics::drawPoint(), fcn::sdl3::Graphics::drawPolyLine(), fcn::opengl::Graphics::drawRectangle(), fcn::sdl3::Graphics::drawRoundStroke(), fcn::sdl3::Graphics::drawSDLTexture(), fcn::sdl3::Graphics::drawVerticalLine(), fcn::opengl::Graphics::fillRectangle(), fcn::sdl3::Graphics::fillRectangle(), getCurrentClipArea(), popClipArea(), fcn::opengl::Graphics::popClipArea(), fcn::sdl3::Graphics::popClipArea(), pushClipArea(), fcn::opengl::Graphics::pushClipArea(), and fcn::sdl3::Graphics::pushClipArea().
|
protected |
Holds the current font.
Definition at line 426 of file graphics.hpp.
Referenced by drawText(), and setFont().