TGUI  1.3-dev
Loading...
Searching...
No Matches
BackendRenderTarget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_BACKEND_RENDER_TARGET_HPP
27#define TGUI_BACKEND_RENDER_TARGET_HPP
28
29#include <TGUI/Rect.hpp>
30#include <TGUI/Color.hpp>
31#include <TGUI/Sprite.hpp>
32#include <TGUI/Text.hpp>
33#include <TGUI/Outline.hpp>
34#include <TGUI/RenderStates.hpp>
35
37
38TGUI_MODULE_EXPORT namespace tgui
39{
40 class Widget;
41 class RootContainer;
42
43
47 class TGUI_API BackendRenderTarget
48 {
49 public:
50
51 // Don't allow copying or moving, because we don't expect derived classes to handle it correctly
54 BackendRenderTarget& operator=(const BackendRenderTarget&) = delete;
55 BackendRenderTarget& operator=(BackendRenderTarget&&) = delete;
56
61
65 virtual ~BackendRenderTarget() = default;
66
71 virtual void setClearColor(const Color& color) = 0;
72
76 virtual void clearScreen() = 0;
77
85 virtual void setView(FloatRect view, FloatRect viewport, Vector2f targetSize);
86
92 virtual void drawGui(const std::shared_ptr<RootContainer>& root) = 0;
93
100 virtual void drawWidget(const RenderStates& states, const std::shared_ptr<Widget>& widget);
101
112 virtual void addClippingLayer(const RenderStates& states, FloatRect rect);
113
119 virtual void removeClippingLayer();
120
129 virtual void drawBorders(const RenderStates& states, const Borders& borders, Vector2f size, Color color);
130
138 virtual void drawFilledRect(const RenderStates& states, Vector2f size, Color color);
139
146 virtual void drawSprite(const RenderStates& states, const Sprite& sprite);
147
154 virtual void drawText(const RenderStates& states, const Text& text);
155
166 virtual void drawTriangle(const RenderStates& states, const Vertex& point1, const Vertex& point2, const Vertex& point3);
167
177 virtual void drawCircle(const RenderStates& states, float size, const Color& backgroundColor, float borderThickness = 0, const Color& borderColor = {});
178
189 virtual void drawRoundedRectangle(const RenderStates& states, const Vector2f& size, const Color& backgroundColor, float radius,
190 const Borders& borders = {0}, const Color& borderColor = Color::Black);
191
202 virtual void drawVertexArray(const RenderStates& states, const Vertex* vertices, std::size_t vertexCount,
203 const unsigned int* indices, std::size_t indexCount, const std::shared_ptr<BackendTexture>& texture) = 0;
204
206 protected:
207
216 virtual void updateClipping(FloatRect clipRect, FloatRect clipViewport) = 0;
217
219 protected:
220
221 FloatRect m_viewRect;
222 FloatRect m_viewport;
223 Vector2f m_targetSize;
224
225 std::vector<std::pair<FloatRect, FloatRect>> m_clipLayers;
226 Vector2f m_pixelsPerPoint = {1, 1};
227 };
228
230}
231
233
234#endif // TGUI_BACKEND_RENDER_TARGET_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
virtual void updateClipping(FloatRect clipRect, FloatRect clipViewport)=0
Called from addClippingLayer and removeClippingLayer to apply the clipping.
virtual void removeClippingLayer()
Removes the last added clipping region.
virtual void setView(FloatRect view, FloatRect viewport, Vector2f targetSize)
Informs the render target about which part of the window is used for rendering.
virtual ~BackendRenderTarget()=default
Virtual destructor.
virtual void drawText(const RenderStates &states, const Text &text)
Draws some text.
virtual void setClearColor(const Color &color)=0
Select the color that will be used by clearScreen.
virtual void drawFilledRect(const RenderStates &states, Vector2f size, Color color)
Draws a colored rectangle.
virtual void drawTriangle(const RenderStates &states, const Vertex &point1, const Vertex &point2, const Vertex &point3)
Draws a single triangles (using the color that is specified in the vertices)
virtual void drawSprite(const RenderStates &states, const Sprite &sprite)
Draws a texture.
virtual void drawVertexArray(const RenderStates &states, const Vertex *vertices, std::size_t vertexCount, const unsigned int *indices, std::size_t indexCount, const std::shared_ptr< BackendTexture > &texture)=0
Draws a vertex array. This is called by the other draw functions when they are not overriden.
virtual void drawWidget(const RenderStates &states, const std::shared_ptr< Widget > &widget)
Draws a widget, if the widget is visible.
virtual void clearScreen()=0
Clears the screen, called at the beginning of each frame when gui.mainLoop() is called.
BackendRenderTarget()=default
Default constructor.
virtual void drawRoundedRectangle(const RenderStates &states, const Vector2f &size, const Color &backgroundColor, float radius, const Borders &borders={0}, const Color &borderColor=Color::Black)
Draws a rounded rectangle.
virtual void drawGui(const std::shared_ptr< RootContainer > &root)=0
Draws the gui and all of its widgets.
virtual void addClippingLayer(const RenderStates &states, FloatRect rect)
Adds another clipping region.
virtual void drawBorders(const RenderStates &states, const Borders &borders, Vector2f size, Color color)
Draws borders inside a provided rectangle.
virtual void drawCircle(const RenderStates &states, float size, const Color &backgroundColor, float borderThickness=0, const Color &borderColor={})
Draws a circle.
Wrapper for colors.
Definition Color.hpp:72
Definition Outline.hpp:39
Definition Sprite.hpp:48
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:50
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39
Definition Vertex.hpp:40