FifeGUI 0.3.0
A C++ GUI library designed for games.
graphics.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_GRAPHICS_HPP_
6#define INCLUDE_FIFECHAN_GRAPHICS_HPP_
7
8// Standard library includes
9#include <cstdint>
10#include <iosfwd>
11#include <memory>
12#include <stack>
13#include <string>
14
15// Project headers (subdirs before local)
16#include "fifechan/cliprectangle.hpp"
17#include "fifechan/point.hpp"
18
19namespace fcn
20{
21 class Color;
22 class Font;
23 class Image;
24
57 class FIFEGUI_API Graphics
58 {
59 public:
63 enum class Alignment : uint8_t
64 {
65 Left = 0,
66 Center,
67 Right
68 };
69
73 enum class VerticalAlignment : uint8_t
74 {
75 Top = 0,
76 Center,
77 Bottom
78 };
79
80 Graphics() = default;
81
82 virtual ~Graphics() = default;
83
84 Graphics(Graphics const &) = delete;
85 Graphics& operator=(Graphics const &) = delete;
86 Graphics(Graphics&&) = delete;
87 Graphics& operator=(Graphics&&) = delete;
88
103 virtual void _beginDraw()
104 {
105 }
106
118 virtual void _endDraw()
119 {
120 }
121
137 virtual bool pushClipArea(Rectangle area);
138
144 virtual void popClipArea();
145
153 virtual ClipRectangle const & getCurrentClipArea();
154
181 virtual void drawImage(
182 Image const * image, int srcX, int srcY, int dstX, int dstY, int width, int height) = 0;
183
200 virtual void drawImage(Image const * image, int dstX, int dstY);
201
208 virtual void drawPoint(int x, int y) = 0;
209
218 virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
219
229 virtual void drawLine(int x1, int y1, int x2, int y2, unsigned int width) = 0;
230
246 virtual void drawRoundStroke(int x1, int y1, int x2, int y2, unsigned int width)
247 {
248 drawLine(x1, y1, x2, y2, width);
249 }
250
257 virtual void drawPolyLine(PointVector const & points, unsigned int width) = 0;
258
266 virtual void drawBezier(PointVector const & points, int steps, unsigned int width) = 0;
267
273 virtual void drawRectangle(Rectangle const & rectangle) = 0;
274
285 void drawRectangle(int x, int y, int width, int height)
286 {
287 drawRectangle(Rectangle(x, y, width, height));
288 }
289
295 virtual void fillRectangle(Rectangle const & rectangle) = 0;
296
307 void fillRectangle(int x, int y, int width, int height)
308 {
309 fillRectangle(Rectangle(x, y, width, height));
310 }
311
318 virtual void drawCircle(Point const & p, unsigned int radius) = 0;
319
326 virtual void drawFillCircle(Point const & p, unsigned int radius) = 0;
327
340 virtual void drawCircleSegment(Point const & p, unsigned int radius, int sangle, int eangle) = 0;
341
354 virtual void drawFillCircleSegment(Point const & p, unsigned int radius, int sangle, int eangle) = 0;
355
362 virtual void setColor(Color const & color) = 0;
363
370 virtual Color const & getColor() const = 0;
371
377 virtual void setFont(Font* font);
378
388 virtual std::shared_ptr<Font> createFont(std::string const & filename, int size);
389
401 void drawText(std::string const & text, int x, int y)
402 {
403 drawText(text, x, y, Alignment::Left);
404 }
405
415 virtual void drawText(std::string const & text, int x, int y, Alignment alignment);
416
417 protected:
421 std::stack<ClipRectangle> mClipStack;
422
426 Font* mFont{nullptr};
427 };
428} // namespace fcn
429
430#endif // INCLUDE_FIFECHAN_GRAPHICS_HPP_
A rectangle specifically used for clipping rendering regions.
Color.
Definition color.hpp:58
Abstract interface for font rendering.
Definition font.hpp:26
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
virtual void drawPoint(int x, int y)=0
Draws a single point/pixel.
VerticalAlignment
Vertical alignments for text drawing.
Definition graphics.hpp:74
void fillRectangle(int x, int y, int width, int height)
Draws a filled rectangle.
Definition graphics.hpp:307
virtual void drawPolyLine(PointVector const &points, unsigned int width)=0
Draws lines between points with given width.
Font * mFont
Holds the current font.
Definition graphics.hpp:426
Alignment
Horizontal alignments for text drawing.
Definition graphics.hpp:64
virtual void drawBezier(PointVector const &points, int steps, unsigned int width)=0
Draws a bezier curve.
virtual void drawFillCircleSegment(Point const &p, unsigned int radius, int sangle, int eangle)=0
Draws a filled circle segment.
virtual void drawLine(int x1, int y1, int x2, int y2, unsigned int width)=0
Draws a thick line.
virtual void drawCircleSegment(Point const &p, unsigned int radius, int sangle, int eangle)=0
Draws a simple, non-filled circle segment with a one pixel width.
virtual void drawImage(Image const *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
Draws a part of an image.
void drawRectangle(int x, int y, int width, int height)
Draws a simple, non-filled rectangle with a one pixel width.
Definition graphics.hpp:285
virtual void drawCircle(Point const &p, unsigned int radius)=0
Draws a simple, non-filled circle with a one pixel width.
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
Definition graphics.hpp:401
virtual void setFont(Font *font)
Sets the font to use when drawing text.
Definition graphics.cpp:91
virtual std::shared_ptr< Font > createFont(std::string const &filename, int size)
Creates a font for this graphics backend.
Definition graphics.cpp:96
std::stack< ClipRectangle > mClipStack
Holds the clip area stack.
Definition graphics.hpp:421
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void _beginDraw()
Initializes drawing.
Definition graphics.hpp:103
virtual void drawFillCircle(Point const &p, unsigned int radius)=0
Draws a filled circle.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void drawRectangle(Rectangle const &rectangle)=0
Draws a simple, non-filled rectangle with a one pixel width.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
virtual Color const & getColor() const =0
Gets the color to use when drawing.
virtual void drawRoundStroke(int x1, int y1, int x2, int y2, unsigned int width)
Draws a round brush stroke along the line segment.
Definition graphics.hpp:246
virtual void _endDraw()
Deinitializes the drawing process.
Definition graphics.hpp:118
Abstract holder for image data.
Definition image.hpp:34
Represents a 2D coordinate (X, Y).
Definition point.hpp:34
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
Used replacement tokens by configure_file():
std::vector< Point > PointVector
A list of points.
Definition point.hpp:331