FifeGUI 0.3.0
A C++ GUI library designed for games.
fcn::opengl::Graphics Class Reference

#include <graphics.hpp>

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

Public Member Functions

void _beginDraw () override
void _endDraw () override
void drawBezier (PointVector const &points, int steps, unsigned int width) override
void drawCircle (Point const &p, unsigned int radius) override
void drawCircleSegment (Point const &p, unsigned int radius, int sangle, int eangle) override
void drawFillCircle (Point const &p, unsigned int radius) override
void drawFillCircleSegment (Point const &p, unsigned int radius, int sangle, int eangle) override
void drawImage (fcn::Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height) override
void drawImage (fcn::opengl::Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height)
virtual void drawImage (Image const *image, int dstX, int dstY)
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 fillRectangle (Rectangle const &rectangle) override
Color const & getColor () const override
 Graphics ()
 Graphics (int width, int height)
void popClipArea () override
bool pushClipArea (Rectangle area) override
void setColor (Color const &color) override
void setTargetPlane (int width, int height)
Public Member Functions inherited from fcn::Graphics
virtual std::shared_ptr< FontcreateFont (std::string const &filename, int size)
void drawRectangle (int x, int y, int width, int height)
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 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

virtual int getTargetPlaneHeight () const
virtual int getTargetPlaneWidth () const
virtual void setTargetPlaneImpl (int width, int height)

Protected Attributes

bool mAlpha {}
Color mColor
int mHeight {}
int mWidth {}
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

OpenGL-specific implementation of the Graphics interface.

Definition at line 23 of file backends/opengl/graphics.hpp.

Constructor & Destructor Documentation

◆ Graphics() [1/2]

fcn::opengl::Graphics::Graphics ( )

Constructor.

Definition at line 28 of file backends/opengl/graphics.cpp.

References mHeight, and mWidth.

◆ Graphics() [2/2]

fcn::opengl::Graphics::Graphics ( int width,
int height )

Constructor.

Parameters
widththe width of the logical drawing surface. Should be the same as the screen resolution.
heightthe height ot the logical drawing surface. Should be the same as the screen resolution.

Definition at line 32 of file backends/opengl/graphics.cpp.

References mHeight, and mWidth.

◆ ~Graphics()

fcn::opengl::Graphics::~Graphics ( )
overridevirtualdefault

Reimplemented from fcn::Graphics.

Member Function Documentation

◆ _beginDraw()

void fcn::opengl::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 43 of file backends/opengl/graphics.cpp.

References mHeight, mWidth, and pushClipArea().

◆ _endDraw()

void fcn::opengl::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 80 of file backends/opengl/graphics.cpp.

References popClipArea().

◆ drawBezier()

void fcn::opengl::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 239 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawCircle()

void fcn::opengl::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 278 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawCircleSegment()

void fcn::opengl::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 288 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawFillCircle()

void fcn::opengl::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 283 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawFillCircleSegment()

void fcn::opengl::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 293 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawImage() [1/3]

void fcn::opengl::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 130 of file backends/opengl/graphics.cpp.

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

◆ drawImage() [2/3]

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

Draws an OpenGL-specific image.

Parameters
imagePointer to the OpenGL image to draw.
srcXSource X coordinate.
srcYSource Y coordinate.
dstXDestination X coordinate.
dstYDestination Y coordinate.
widthWidth of the region to draw.
heightHeight of the region to draw.

References drawBezier(), drawCircle(), drawCircleSegment(), drawFillCircle(), drawFillCircleSegment(), drawLine(), drawPoint(), drawPolyLine(), drawRectangle(), fillRectangle(), getColor(), getTargetPlaneHeight(), getTargetPlaneWidth(), setColor(), and setTargetPlaneImpl().

◆ drawImage() [3/3]

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.

Example
It is equivalent to calling:
drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight());
Parameters
imageThe image to draw.
dstXThe destination x coordinate.
dstYThe destination y coordinate.

Reimplemented from fcn::Graphics.

Definition at line 200 of file graphics.cpp.

◆ drawLine() [1/2]

void fcn::opengl::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 201 of file backends/opengl/graphics.cpp.

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

Referenced by drawImage().

◆ drawLine() [2/2]

void fcn::opengl::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 229 of file backends/opengl/graphics.cpp.

◆ drawPoint()

void fcn::opengl::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 184 of file backends/opengl/graphics.cpp.

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

Referenced by drawImage().

◆ drawPolyLine()

void fcn::opengl::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 234 of file backends/opengl/graphics.cpp.

Referenced by drawImage().

◆ drawRectangle()

void fcn::opengl::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 244 of file backends/opengl/graphics.cpp.

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

Referenced by drawImage().

◆ fillRectangle()

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

Draws a filled rectangle.

Parameters
rectangleThe filled rectangle to draw.

Implements fcn::Graphics.

Definition at line 261 of file backends/opengl/graphics.cpp.

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

Referenced by drawImage().

◆ getColor()

Color const & fcn::opengl::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 314 of file backends/opengl/graphics.cpp.

References mColor.

Referenced by drawImage().

◆ getTargetPlaneHeight()

int fcn::opengl::Graphics::getTargetPlaneHeight ( ) const
protectedvirtual

Gets the target plane height.

Returns
The target plane height.

Definition at line 324 of file backends/opengl/graphics.cpp.

References mHeight.

Referenced by drawImage().

◆ getTargetPlaneWidth()

int fcn::opengl::Graphics::getTargetPlaneWidth ( ) const
protectedvirtual

Gets the target plane width.

Returns
The target plane width.

Definition at line 319 of file backends/opengl/graphics.cpp.

References mWidth.

Referenced by drawImage().

◆ popClipArea()

void fcn::opengl::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 109 of file backends/opengl/graphics.cpp.

References fcn::Graphics::mClipStack, mHeight, and fcn::Graphics::popClipArea().

Referenced by _endDraw().

◆ pushClipArea()

bool fcn::opengl::Graphics::pushClipArea ( 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 96 of file backends/opengl/graphics.cpp.

References fcn::Graphics::mClipStack, mHeight, and fcn::Graphics::pushClipArea().

Referenced by _beginDraw().

◆ setColor()

void fcn::opengl::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 298 of file backends/opengl/graphics.cpp.

References fcn::Color::a, fcn::Color::b, fcn::Color::g, mAlpha, mColor, and fcn::Color::r.

Referenced by drawImage().

◆ setTargetPlane()

void fcn::opengl::Graphics::setTargetPlane ( int width,
int height )

Sets the target plane on where to draw.

Parameters
widththe width of the logical drawing surface. Should be the same as the screen resolution.
heightthe height ot the logical drawing surface. Should be the same as the screen resolution.

Definition at line 36 of file backends/opengl/graphics.cpp.

References setTargetPlaneImpl().

◆ setTargetPlaneImpl()

void fcn::opengl::Graphics::setTargetPlaneImpl ( int width,
int height )
protectedvirtual

Backend hook that actually applies the logical target plane size.

Subclasses may override to update platform or API specific state.

Parameters
widthLogical plane width in pixels.
heightLogical plane height in pixels.

Definition at line 124 of file backends/opengl/graphics.cpp.

References mHeight, and mWidth.

Referenced by drawImage(), and setTargetPlane().

Member Data Documentation

◆ mAlpha

bool fcn::opengl::Graphics::mAlpha {}
protected

Whether alpha blending is enabled.

Definition at line 140 of file backends/opengl/graphics.hpp.

Referenced by setColor().

◆ mColor

Color fcn::opengl::Graphics::mColor
protected

Current drawing color.

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

Referenced by getColor(), and setColor().

◆ mHeight

int fcn::opengl::Graphics::mHeight {}
protected

Height of the logical target plane.

Definition at line 137 of file backends/opengl/graphics.hpp.

Referenced by _beginDraw(), getTargetPlaneHeight(), Graphics(), Graphics(), popClipArea(), pushClipArea(), and setTargetPlaneImpl().

◆ mWidth

int fcn::opengl::Graphics::mWidth {}
protected

Width of the logical target plane.

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

Referenced by _beginDraw(), getTargetPlaneWidth(), Graphics(), Graphics(), and setTargetPlaneImpl().


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