FifeGUI 0.2.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
virtual int getTargetPlaneHeight () const
virtual int getTargetPlaneWidth () const
 Graphics ()
 Graphics (Graphics &&)=delete
 Graphics (Graphics const &)=delete
 Graphics (int width, int height)
Graphicsoperator= (Graphics &&)=delete
Graphicsoperator= (Graphics const &)=delete
void popClipArea () override
bool pushClipArea (Rectangle area) override
void setColor (Color const &color) override
virtual 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 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 }

Detailed Description

OpenGL-specific implementation of the Graphics interface.

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

Constructor & Destructor Documentation

◆ Graphics() [1/2]

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

Constructor.

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

References setTargetPlane().

◆ 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 27 of file backends/opengl/graphics.cpp.

References setTargetPlane().

◆ ~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 34 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 71 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 230 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 269 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 279 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 274 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 284 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.

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.

Implements fcn::Graphics.

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

References fcn::Graphics::mClipStack, 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(), and setColor().

◆ 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. It is equivalent to calling:

drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), \
image->getHeight());

Reimplemented from fcn::Graphics.

Definition at line 163 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 192 of file backends/opengl/graphics.cpp.

References fcn::Graphics::mClipStack, 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 220 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 175 of file backends/opengl/graphics.cpp.

References fcn::Graphics::mClipStack, 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 225 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 235 of file backends/opengl/graphics.cpp.

References fcn::Rectangle::height, fcn::Graphics::mClipStack, 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 252 of file backends/opengl/graphics.cpp.

References fcn::Rectangle::height, fcn::Graphics::mClipStack, 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 305 of file backends/opengl/graphics.cpp.

References mColor.

Referenced by drawImage().

◆ getTargetPlaneHeight()

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

Gets the target plane height.

Returns
The target plane height.

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

References mHeight.

◆ getTargetPlaneWidth()

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

Gets the target plane width.

Returns
The target plane width.

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

References mWidth.

◆ 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 100 of file backends/opengl/graphics.cpp.

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

Referenced by _endDraw(), and popClipArea().

◆ 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 87 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 289 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 )
virtual

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 115 of file backends/opengl/graphics.cpp.

References mHeight, and mWidth.

Referenced by Graphics(), and Graphics().

Member Data Documentation

◆ mAlpha

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

Whether alpha blending is enabled.

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

Referenced by setColor().

◆ mColor

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

Current drawing color.

Definition at line 135 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 129 of file backends/opengl/graphics.hpp.

Referenced by _beginDraw(), getTargetPlaneHeight(), popClipArea(), pushClipArea(), and setTargetPlane().

◆ mWidth

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

Width of the logical target plane.

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

Referenced by _beginDraw(), getTargetPlaneWidth(), and setTargetPlane().


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