FifeGUI 0.2.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#include <cstdint>
9#include <iosfwd>
10#include <memory>
11#include <stack>
12#include <string>
13
14#include "fifechan/cliprectangle.hpp"
15#include "fifechan/platform.hpp"
16#include "fifechan/point.hpp"
17
18namespace fcn
19{
20 class Color;
21 class Font;
22 class Image;
23
56 class FIFEGUI_API Graphics
57 {
58 public:
62 enum class Alignment : uint8_t
63 {
64 Left = 0,
65 Center,
66 Right
67 };
68
69 Graphics() = default;
70
71 virtual ~Graphics() = default;
72
73 Graphics(Graphics const &) = delete;
74 Graphics& operator=(Graphics const &) = delete;
75 Graphics(Graphics&&) = delete;
76 Graphics& operator=(Graphics&&) = delete;
77
89 virtual void _beginDraw() { }
90
101 virtual void _endDraw() { }
102
116 virtual bool pushClipArea(Rectangle area);
117
123 virtual void popClipArea();
124
131 virtual ClipRectangle const & getCurrentClipArea();
132
155 virtual void drawImage(Image const * image, int srcX, int srcY, int dstX, int dstY, int width, int height) = 0;
163 virtual void drawImage(Image const * image, int dstX, int dstY);
164
171 virtual void drawPoint(int x, int y) = 0;
172
181 virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
182
192 virtual void drawLine(int x1, int y1, int x2, int y2, unsigned int width) = 0;
193
209 virtual void drawRoundStroke(int x1, int y1, int x2, int y2, unsigned int width)
210 {
211 drawLine(x1, y1, x2, y2, width);
212 }
213
220 virtual void drawPolyLine(PointVector const & points, unsigned int width) = 0;
221
229 virtual void drawBezier(PointVector const & points, int steps, unsigned int width) = 0;
230
236 virtual void drawRectangle(Rectangle const & rectangle) = 0;
237
249 void drawRectangle(int x, int y, int width, int height)
250 {
251 drawRectangle(Rectangle(x, y, width, height));
252 }
253
259 virtual void fillRectangle(Rectangle const & rectangle) = 0;
260
272 void fillRectangle(int x, int y, int width, int height)
273 {
274 fillRectangle(Rectangle(x, y, width, height));
275 }
276
284 virtual void drawCircle(Point const & p, unsigned int radius) = 0;
285
293 virtual void drawFillCircle(Point const & p, unsigned int radius) = 0;
294
305 virtual void drawCircleSegment(Point const & p, unsigned int radius, int sangle, int eangle) = 0;
306
317 virtual void drawFillCircleSegment(Point const & p, unsigned int radius, int sangle, int eangle) = 0;
318
325 virtual void setColor(Color const & color) = 0;
326
333 virtual Color const & getColor() const = 0;
334
340 virtual void setFont(Font* font);
341
351 virtual std::shared_ptr<Font> createFont(std::string const & filename, int size);
352
362 void drawText(std::string const & text, int x, int y)
363 {
364 drawText(text, x, y, Alignment::Left);
365 }
366
376 virtual void drawText(std::string const & text, int x, int y, Alignment alignment);
377
378 protected:
382 std::stack<ClipRectangle> mClipStack;
383
387 Font* mFont{nullptr};
388 };
389} // namespace fcn
390
391#endif // INCLUDE_FIFECHAN_GRAPHICS_HPP_
A rectangle specifically used for clipping rendering regions.
Color.
Definition color.hpp:56
Abstract interface for font rendering.
Definition font.hpp:24
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
virtual void drawPoint(int x, int y)=0
Draws a single point/pixel.
void fillRectangle(int x, int y, int width, int height)
Draws a filled rectangle.
Definition graphics.hpp:272
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:387
Alignment
Alignments for text drawing.
Definition graphics.hpp:63
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:249
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:362
virtual void setFont(Font *font)
Sets the font to use when drawing text.
Definition graphics.cpp:79
virtual std::shared_ptr< Font > createFont(std::string const &filename, int size)
Creates a font for this graphics backend.
Definition graphics.cpp:84
std::stack< ClipRectangle > mClipStack
Holds the clip area stack.
Definition graphics.hpp:382
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void _beginDraw()
Initializes drawing.
Definition graphics.hpp:89
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:209
virtual void _endDraw()
Deinitializes the drawing process.
Definition graphics.hpp:101
Abstract holder for image data.
Definition image.hpp:32
Represents a 2D coordinate (X, Y).
Definition point.hpp:29
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20