|
FifeGUI 0.2.0
A C++ GUI library designed for games.
|
#include <graphics.hpp>
Public Types | |
| enum class | Alignment : uint8_t { Left = 0 , Center , Right } |
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 56 of file graphics.hpp.
|
strong |
Alignments for text drawing.
Definition at line 62 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.
NOTE: You will never need to call this function yourself, unless you use a Graphics object outside the library.
Reimplemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.
Definition at line 89 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().
NOTE: You generally won't need to call this function yourself unless you are using a Graphics object outside of the library.
Reimplemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.
Definition at line 101 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::sdl2::Graphics.
Definition at line 84 of file graphics.cpp.
Referenced by getColor().
|
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::sdl2::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::sdl2::Graphics.
|
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.
| 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::sdl2::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::sdl2::Graphics.
Referenced by fcn::PointGraph::draw(), and fcn::CheckBox::drawDot().
|
pure virtual |
Draws a filled circle segment.
Note: The start angle must be less than the end angle. 0 angle is right side.
| 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::sdl2::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. It is equivalent to calling:
Reimplemented in fcn::opengl::Graphics.
Definition at line 74 of file graphics.cpp.
References drawImage(), fcn::Image::getHeight(), and fcn::Image::getWidth().
|
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:
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).
| 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::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().
|
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::sdl2::Graphics.
Referenced by fcn::DropDown::draw(), fcn::LineGraph::draw(), fcn::PointGraph::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::sdl2::Graphics.
|
pure virtual |
Draws a single point/pixel.
| x | The x coordinate. |
| y | The y coordinate. |
Implemented in fcn::opengl::Graphics, and fcn::sdl2::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::sdl2::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 249 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::sdl2::Graphics.
Referenced by fcn::DropDown::draw(), fcn::Tab::draw(), fcn::TextField::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::sdl2::Graphics.
Definition at line 209 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 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().
|
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 91 of file graphics.cpp.
References mFont.
|
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 272 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::sdl2::Graphics.
Referenced by fcn::BarGraph::draw(), fcn::Button::draw(), fcn::Container::draw(), fcn::CurveGraph::draw(), fcn::DropDown::draw(), fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::LineGraph::draw(), fcn::ListBox::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::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::sdl2::Graphics.
References createFont(), and setFont().
Referenced by fcn::sdl2::TrueTypeFont::drawString().
|
virtual |
Gets the current clip area.
Useful if you want to do drawing bypassing Graphics.
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().
|
virtual |
Removes the top most clip area from the stack.
| Exception | if the stack is empty. |
Reimplemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.
Definition at line 55 of file graphics.cpp.
References mClipStack.
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(), and fcn::sdl2::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::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().
|
pure virtual |
Sets the color to use when drawing.
| color | A color. |
Implemented in fcn::opengl::Graphics, and fcn::sdl2::Graphics.
Referenced by fcn::BarGraph::draw(), fcn::Button::draw(), fcn::CheckBox::draw(), fcn::Container::draw(), fcn::CurveGraph::draw(), fcn::DropDown::draw(), fcn::Icon::draw(), fcn::IconProgressBar::draw(), fcn::ImageButton::draw(), fcn::ImageProgressBar::draw(), fcn::Label::draw(), fcn::LineGraph::draw(), fcn::ListBox::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::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 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().
|
protected |
Holds the clip area stack.
Definition at line 382 of file graphics.hpp.
Referenced by fcn::sdl2::Graphics::drawBezier(), fcn::sdl2::Graphics::drawCircle(), fcn::sdl2::Graphics::drawCircleSegment(), fcn::sdl2::Graphics::drawFillCircle(), fcn::sdl2::Graphics::drawFillCircleSegment(), fcn::sdl2::Graphics::drawHorizontalLine(), fcn::opengl::Graphics::drawImage(), fcn::sdl2::Graphics::drawImage(), fcn::opengl::Graphics::drawLine(), fcn::sdl2::Graphics::drawLine(), fcn::sdl2::Graphics::drawLine(), fcn::opengl::Graphics::drawPoint(), fcn::sdl2::Graphics::drawPoint(), fcn::sdl2::Graphics::drawPolyLine(), fcn::opengl::Graphics::drawRectangle(), fcn::sdl2::Graphics::drawRoundStroke(), fcn::sdl2::Graphics::drawSDLTexture(), fcn::sdl2::Graphics::drawVerticalLine(), fcn::opengl::Graphics::fillRectangle(), fcn::sdl2::Graphics::fillRectangle(), getCurrentClipArea(), popClipArea(), fcn::opengl::Graphics::popClipArea(), fcn::sdl2::Graphics::popClipArea(), pushClipArea(), fcn::opengl::Graphics::pushClipArea(), and fcn::sdl2::Graphics::pushClipArea().
|
protected |
Holds the current font.
Definition at line 387 of file graphics.hpp.
Referenced by drawText(), and setFont().