FifeGUI 0.2.0
A C++ GUI library designed for games.
backends/sdl3/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: 2016 - 2019 Gwilherm Baudic
4// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
5
6#ifndef INCLUDE_FIFECHAN_BACKENDS_SDL_GRAPHICS_HPP_
7#define INCLUDE_FIFECHAN_BACKENDS_SDL_GRAPHICS_HPP_
8
9// Standard library includes
10#include <memory>
11#include <string>
12
13// Platform config include
14#include "fifechan/platform.hpp"
15
16// Third-party library includes
17#include <SDL3/SDL.h>
18
19// Project headers (subdirs before local)
20#include "fifechan/color.hpp"
21#include "fifechan/graphics.hpp"
22
23namespace fcn
24{
25 class Image;
26 class Rectangle;
27} // namespace fcn
28
29namespace fcn::sdl3
30{
38 class FIFEGUI_EXT_API Graphics : public fcn::Graphics
39 {
40 public:
41 Graphics();
42
43 ~Graphics() override;
44
52 virtual void setTarget(SDL_Renderer* renderer, int width, int height);
53
59 virtual SDL_Renderer* getRenderTarget() const;
60
66 virtual void drawSDLTexture(SDL_Texture* texture, SDL_FRect source, SDL_FRect destination);
67
68 // Inherited from Graphics
69
70 void _beginDraw() override;
71 void _endDraw() override;
72 bool pushClipArea(fcn::Rectangle area) override;
73 void popClipArea() override;
74 void drawImage(
75 fcn::Image const * image, int srcX, int srcY, int dstX, int dstY, int width, int height) override;
76 void drawPoint(int x, int y) override;
77 void drawLine(int x1, int y1, int x2, int y2) override;
78 void drawLine(int x1, int y1, int x2, int y2, unsigned int width) override;
79 void drawRoundStroke(int x1, int y1, int x2, int y2, unsigned int width) override;
80
81 void drawRectangle(Rectangle const & rectangle) override;
82 void fillRectangle(Rectangle const & rectangle) override;
83
84 void drawPolyLine(PointVector const & points, unsigned int width) override;
85 void drawBezier(PointVector const & points, int segments, unsigned int width) override;
86
87 void drawCircle(Point const & center, unsigned int radius) override;
88 void drawFillCircle(Point const & center, unsigned int radius) override;
89 void drawCircleSegment(Point const & center, unsigned int radius, int startAngle, int endAngle) override;
91 Point const & center, unsigned int radius, int startAngle, int endAngle) override;
92
93 void setColor(Color const & color) override;
94 Color const & getColor() const override;
95 std::shared_ptr<Font> createFont(std::string const & filename, int size) override;
96
97 protected:
105 void drawHorizontalLine(int x1, int y, int x2);
106
114 void drawVerticalLine(int x, int y1, int y2);
115
120 void saveRenderColor();
121
125 void restoreRenderColor();
126
128 SDL_Renderer* mRenderTarget{};
129
131 int mWidth = 0;
132
134 int mHeight = 0;
135
138
141 Uint8 r{};
143 Uint8 g{};
145 Uint8 b{};
147 Uint8 a{};
148
150 bool mAlpha;
151 };
152} // namespace fcn::sdl3
153
154#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_GRAPHICS_HPP_
Color.
Definition color.hpp:58
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
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
Uint8 a
Previous alpha component from renderer.
void restoreRenderColor()
Restore the rendering color after drawing.
void drawFillCircle(Point const &center, unsigned int radius) override
Draws a filled circle.
void drawPoint(int x, int y) override
Draws a single point/pixel.
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.
void drawRoundStroke(int x1, int y1, int x2, int y2, unsigned int width) override
Draws a round brush stroke along the line segment.
void saveRenderColor()
Save the current rendering color before drawing.
virtual SDL_Renderer * getRenderTarget() const
Gets the target SDL_Renderer.
void drawFillCircleSegment(Point const &center, unsigned int radius, int startAngle, int endAngle) override
Draws a filled circle segment.
Color const & getColor() const override
Gets the color to use when drawing.
void _beginDraw() override
Initializes drawing.
void drawPolyLine(PointVector const &points, unsigned int width) override
Draws lines between points with given width.
SDL_Renderer * mRenderTarget
The SDL_Renderer used for accelerated drawing.
void drawRectangle(Rectangle const &rectangle) override
Draws a simple, non-filled rectangle with a one pixel width.
Uint8 r
Cached renderer color components (previous renderer color).
void _endDraw() override
Deinitializes the drawing process.
void drawLine(int x1, int y1, int x2, int y2) override
Draws a line.
void drawHorizontalLine(int x1, int y, int x2)
Draws a horizontal line.
void drawCircle(Point const &center, unsigned int radius) override
Draws a simple, non-filled circle with a one pixel width.
virtual void drawSDLTexture(SDL_Texture *texture, SDL_FRect source, SDL_FRect destination)
Draws an SDL_Texture on the target surface.
void drawVerticalLine(int x, int y1, int y2)
Draws a vertical line.
void setColor(Color const &color) override
Sets the color to use when drawing.
bool mAlpha
Whether alpha blending is enabled.
bool pushClipArea(fcn::Rectangle area) override
Pushes a clip area onto the stack.
void fillRectangle(Rectangle const &rectangle) override
Draws a filled rectangle.
void popClipArea() override
Removes the top most clip area from the stack.
void drawCircleSegment(Point const &center, unsigned int radius, int startAngle, int endAngle) override
Draws a simple, non-filled circle segment with a one pixel width.
Uint8 b
Previous blue component from renderer.
Uint8 g
Previous green component from renderer.
std::shared_ptr< Font > createFont(std::string const &filename, int size) override
Creates a font for this graphics backend.
void drawBezier(PointVector const &points, int segments, unsigned int width) override
Draws a bezier curve.
Color mColor
Current drawing color.
virtual void setTarget(SDL_Renderer *renderer, int width, int height)
Sets the target SDL_Renderer to use for drawing.
Used replacement tokens by configure_file():
std::vector< Point > PointVector
A list of points.
Definition point.hpp:331