|
FifeGUI 0.2.0
A C++ GUI library designed for games.
|
#include <graphics.hpp>
Public Member Functions | |
| void | _beginDraw () override |
| void | _endDraw () override |
| std::shared_ptr< Font > | createFont (std::string const &filename, int size) override |
| void | drawBezier (PointVector const &points, int segments, unsigned int width) override |
| void | drawCircle (Point const ¢er, unsigned int radius) override |
| void | drawCircleSegment (Point const ¢er, unsigned int radius, int startAngle, int endAngle) override |
| void | drawFillCircle (Point const ¢er, unsigned int radius) override |
| void | drawFillCircleSegment (Point const ¢er, 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_Rect source, SDL_Rect destination) |
| void | fillRectangle (Rectangle const &rectangle) override |
| Color const & | getColor () const override |
| virtual SDL_Renderer * | getRenderTarget () const |
| Graphics (Graphics &&)=delete | |
| Graphics (Graphics const &)=delete | |
| Graphics & | operator= (Graphics &&)=delete |
| Graphics & | operator= (Graphics const &)=delete |
| 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< ClipRectangle > | mClipStack |
| Font * | mFont {nullptr} |
Additional Inherited Members | |
| Public Types inherited from fcn::Graphics | |
| enum class | Alignment : uint8_t { Left = 0 , Center , Right } |
SDL2 renderer-specific implementation of the Graphics interface.
This is the primary graphics backend - it uses SDL_Renderer for all drawing operations.
Definition at line 33 of file backends/sdl2/graphics.hpp.
| fcn::sdl2::Graphics::Graphics | ( | ) |
Definition at line 27 of file backends/sdl2/graphics.cpp.
|
overridevirtualdefault |
Reimplemented from fcn::Graphics.
|
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.
Reimplemented from fcn::Graphics.
Definition at line 31 of file backends/sdl2/graphics.cpp.
References _beginDraw(), fcn::Rectangle::height, mHeight, mWidth, pushClipArea(), fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.
Referenced by _beginDraw().
|
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.
Reimplemented from fcn::Graphics.
Definition at line 41 of file backends/sdl2/graphics.cpp.
References _endDraw(), and popClipArea().
Referenced by _endDraw().
|
overridevirtual |
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 from fcn::Graphics.
Definition at line 670 of file backends/sdl2/graphics.cpp.
References createFont().
Referenced by createFont().
|
overridevirtual |
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. |
Implements fcn::Graphics.
Definition at line 612 of file backends/sdl2/graphics.cpp.
References drawBezier(), drawLine(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), and saveRenderColor().
Referenced by drawBezier().
|
overridevirtual |
Draws a simple, non-filled circle with a one pixel width.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
Implements fcn::Graphics.
Definition at line 498 of file backends/sdl2/graphics.cpp.
References drawCircle(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawCircle().
|
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.
| 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. |
Implements fcn::Graphics.
Definition at line 540 of file backends/sdl2/graphics.cpp.
References drawCircleSegment(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawCircleSegment().
|
overridevirtual |
Draws a filled circle.
| p | The circle center coordinate as point. |
| radius | The circle radius. |
Implements fcn::Graphics.
Definition at line 397 of file backends/sdl2/graphics.cpp.
References drawFillCircle(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawFillCircle().
|
overridevirtual |
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. |
Implements fcn::Graphics.
Definition at line 446 of file backends/sdl2/graphics.cpp.
References drawFillCircleSegment(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawFillCircleSegment().
|
protected |
Draws a horizontal line.
| x1 | the start coordinate of the line. |
| y | the y coordinate of the line. |
| x2 | the end coordinate of the line. |
Definition at line 180 of file backends/sdl2/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().
|
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:
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. |
Implements fcn::Graphics.
Definition at line 95 of file backends/sdl2/graphics.cpp.
References drawImage(), fcn::sdl2::Image::getTexture(), fcn::Graphics::mClipStack, mRenderTarget, fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawImage().
|
overridevirtual |
Draws a line.
| x1 | The first x coordinate. |
| y1 | The first y coordinate. |
| x2 | The second x coordinate. |
| y2 | The second y coordinate. |
Implements fcn::Graphics.
Definition at line 280 of file backends/sdl2/graphics.cpp.
References drawLine(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawBezier(), drawLine(), drawLine(), drawPolyLine(), and drawRoundStroke().
|
overridevirtual |
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. |
Implements fcn::Graphics.
Definition at line 301 of file backends/sdl2/graphics.cpp.
References drawLine(), drawRoundStroke(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
|
overridevirtual |
Draws a single point/pixel.
| x | The x coordinate. |
| y | The y coordinate. |
Implements fcn::Graphics.
Definition at line 157 of file backends/sdl2/graphics.cpp.
References drawPoint(), fcn::Rectangle::isContaining(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawPoint().
|
overridevirtual |
Draws lines between points with given width.
| points | Contains the points that are used for drawing. |
| width | The line width. |
Implements fcn::Graphics.
Definition at line 636 of file backends/sdl2/graphics.cpp.
References drawLine(), drawPolyLine(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), and saveRenderColor().
Referenced by drawPolyLine().
|
overridevirtual |
Draws a simple, non-filled rectangle with a one pixel width.
| rectangle | The rectangle to draw. |
Implements fcn::Graphics.
Definition at line 266 of file backends/sdl2/graphics.cpp.
References drawHorizontalLine(), drawRectangle(), drawVerticalLine(), fcn::Rectangle::height, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.
Referenced by drawRectangle().
|
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).
| 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 from fcn::Graphics.
Definition at line 345 of file backends/sdl2/graphics.cpp.
References drawLine(), drawRoundStroke(), fcn::Graphics::mClipStack, mColor, mRenderTarget, restoreRenderColor(), saveRenderColor(), fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawLine(), and drawRoundStroke().
|
virtual |
Draws an SDL_Texture on the target surface.
NOTE: The clip areas will be taken into account.
Definition at line 675 of file backends/sdl2/graphics.cpp.
References drawSDLTexture(), fcn::Graphics::mClipStack, mRenderTarget, fcn::ClipRectangle::xOffset, and fcn::ClipRectangle::yOffset.
Referenced by drawSDLTexture().
|
protected |
Draws a vertical line.
| x | the x coordinate of the line. |
| y1 | the start coordinate of the line. |
| y2 | the end coordinate of the line. |
Definition at line 223 of file backends/sdl2/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().
|
overridevirtual |
Draws a filled rectangle.
| rectangle | The filled rectangle to draw. |
Implements fcn::Graphics.
Definition at line 127 of file backends/sdl2/graphics.cpp.
References fillRectangle(), fcn::Rectangle::height, fcn::Rectangle::isIntersecting(), 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 fillRectangle().
|
overridevirtual |
Gets the color to use when drawing.
Implements fcn::Graphics.
Definition at line 665 of file backends/sdl2/graphics.cpp.
References getColor(), and mColor.
Referenced by getColor().
|
virtual |
Gets the target SDL_Renderer.
Definition at line 90 of file backends/sdl2/graphics.cpp.
References getRenderTarget(), and mRenderTarget.
Referenced by getRenderTarget().
|
overridevirtual |
Removes the top most clip area from the stack.
| Exception | if the stack is empty. |
Reimplemented from fcn::Graphics.
Definition at line 71 of file backends/sdl2/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().
|
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.
| area | The clip area to be pushed onto the stack. |
Reimplemented from fcn::Graphics.
Definition at line 53 of file backends/sdl2/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().
|
protected |
Restore the rendering color after drawing.
Definition at line 698 of file backends/sdl2/graphics.cpp.
References a, b, g, mRenderTarget, r, and restoreRenderColor().
Referenced by drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawHorizontalLine(), drawLine(), drawLine(), drawPoint(), drawPolyLine(), drawRoundStroke(), drawVerticalLine(), fillRectangle(), and restoreRenderColor().
|
protected |
Save the current rendering color before drawing.
Does not affect the mColor attribute.
Definition at line 693 of file backends/sdl2/graphics.cpp.
References a, b, g, mRenderTarget, r, and saveRenderColor().
Referenced by drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawHorizontalLine(), drawLine(), drawLine(), drawPoint(), drawPolyLine(), drawRoundStroke(), drawVerticalLine(), fillRectangle(), and saveRenderColor().
|
overridevirtual |
Sets the color to use when drawing.
| color | A color. |
Implements fcn::Graphics.
Definition at line 658 of file backends/sdl2/graphics.cpp.
References fcn::Color::a, mAlpha, mColor, and setColor().
Referenced by setColor().
|
virtual |
Sets the target SDL_Renderer to use for drawing.
Preferably done only once.
| renderer | the SDL_Renderer to use for drawing. |
| width | screen width |
| height | screen height |
Definition at line 46 of file backends/sdl2/graphics.cpp.
References mHeight, mRenderTarget, mWidth, and setTarget().
Referenced by setTarget().
|
protected |
Previous alpha component from renderer.
Definition at line 146 of file backends/sdl2/graphics.hpp.
Referenced by restoreRenderColor(), and saveRenderColor().
|
protected |
Previous blue component from renderer.
Definition at line 144 of file backends/sdl2/graphics.hpp.
Referenced by restoreRenderColor(), and saveRenderColor().
|
protected |
Previous green component from renderer.
Definition at line 142 of file backends/sdl2/graphics.hpp.
Referenced by restoreRenderColor(), and saveRenderColor().
|
protected |
Whether alpha blending is enabled.
Definition at line 149 of file backends/sdl2/graphics.hpp.
Referenced by setColor().
|
protected |
Current drawing color.
Definition at line 136 of file backends/sdl2/graphics.hpp.
Referenced by drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawHorizontalLine(), drawLine(), drawLine(), drawPoint(), drawPolyLine(), drawRoundStroke(), drawVerticalLine(), fillRectangle(), getColor(), and setColor().
|
protected |
Screen height.
Definition at line 133 of file backends/sdl2/graphics.hpp.
Referenced by _beginDraw(), and setTarget().
|
protected |
The SDL_Renderer used for accelerated drawing.
Definition at line 127 of file backends/sdl2/graphics.hpp.
Referenced by drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawHorizontalLine(), drawImage(), drawLine(), drawLine(), drawPoint(), drawPolyLine(), drawRoundStroke(), drawSDLTexture(), drawVerticalLine(), fillRectangle(), getRenderTarget(), popClipArea(), pushClipArea(), restoreRenderColor(), saveRenderColor(), and setTarget().
|
protected |
Screen width.
Definition at line 130 of file backends/sdl2/graphics.hpp.
Referenced by _beginDraw(), and setTarget().
|
protected |
Cached renderer color components (previous renderer color).
Previous red component from renderer.
Definition at line 140 of file backends/sdl2/graphics.hpp.
Referenced by restoreRenderColor(), and saveRenderColor().