TGUI  0.9-dev
BackendRenderTarget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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
38namespace tgui
39{
40 class Widget;
41 class RootContainer;
42
43
47 class TGUI_API BackendRenderTarget
48 {
49 public:
50
54 virtual ~BackendRenderTarget() = default;
55
56
61#ifdef TGUI_NEXT
62 virtual void setClearColor(const tgui::Color& color) = 0;
63#else
64 virtual void setClearColor(const tgui::Color& color) { (void)color; }
65#endif
66
70#ifdef TGUI_NEXT
71 virtual void clearScreen() = 0;
72#else
73 virtual void clearScreen() {}
74#endif
75
76#ifndef TGUI_REMOVE_DEPRECATED_CODE
83 TGUI_DEPRECATED("Use setView(view, viewport, targetSize) instead") virtual void setView(FloatRect view, FloatRect viewport);
84#endif
85
93 virtual void setView(FloatRect view, FloatRect viewport, Vector2f targetSize);
94
95
101 virtual void drawGui(const std::shared_ptr<RootContainer>& root) = 0;
102
103
110 virtual void drawWidget(const RenderStates& states, const std::shared_ptr<Widget>& widget);
111
112
123 virtual void addClippingLayer(const RenderStates& states, FloatRect rect);
124
125
131 virtual void removeClippingLayer();
132
133
142 virtual void drawBorders(const RenderStates& states, const Borders& borders, Vector2f size, Color color);
143
144
152 virtual void drawFilledRect(const RenderStates& states, Vector2f size, Color color);
153
154
161 virtual void drawSprite(const RenderStates& states, const Sprite& sprite);
162
163
170 virtual void drawText(const RenderStates& states, const Text& text);
171
172
184 TGUI_DEPRECATED("Use drawVertexArray instead") virtual void drawTriangles(const RenderStates& states, const Vertex* vertices, std::size_t vertexCount, const int* indices = nullptr, std::size_t indexCount = 0);
185
186
196 void drawTriangles(const RenderStates& states, std::initializer_list<Vertex> vertices, std::initializer_list<int> indices = {});
197
198
208 virtual void drawCircle(const RenderStates& states, float size, const Color& backgroundColor, float borderThickness = 0, const Color& borderColor = {});
209
210
221 virtual void drawRoundedRectangle(const RenderStates& states, const Vector2f& size, const Color& backgroundColor, float radius,
222 const Borders& borders = {0}, const Color& borderColor = Color::Black);
223
224
235#ifdef TGUI_NEXT
236 virtual void drawVertexArray(const RenderStates& states, const Vertex* vertices, std::size_t vertexCount,
237 const int* indices, std::size_t indexCount, const std::shared_ptr<BackendTexture>& texture) = 0;
238#else
239 virtual void drawVertexArray(const RenderStates& states, const Vertex* vertices, std::size_t vertexCount,
240 const int* indices, std::size_t indexCount, const std::shared_ptr<BackendTexture>& texture);
241#endif
242
244 protected:
245
254#ifdef TGUI_NEXT
255 virtual void updateClipping(FloatRect clipRect, FloatRect clipViewport) = 0;
256#else
257 virtual void updateClipping(FloatRect clipRect, FloatRect clipViewport) { (void)clipRect; (void)clipViewport; };
258#endif
259
260
262 protected:
263
264 FloatRect m_viewRect;
265 FloatRect m_viewport;
266 Vector2f m_targetSize;
267
268 std::vector<std::pair<FloatRect, FloatRect>> m_clipLayers;
269 };
270
271#ifndef TGUI_REMOVE_DEPRECATED_CODE
272 using BackendRenderTargetBase TGUI_DEPRECATED("BackendRenderTargetBase was renamed to BackendRenderTarget") = BackendRenderTarget;
273#endif
274
276}
277
279
280#endif // TGUI_BACKEND_RENDER_TARGET_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
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 drawFilledRect(const RenderStates &states, Vector2f size, Color color)
Draws a colored rectangle.
virtual void drawSprite(const RenderStates &states, const Sprite &sprite)
Draws a texture.
virtual void clearScreen()
Clears the screen, called at the beginning of each frame when gui.mainLoop() is called.
Definition: BackendRenderTarget.hpp:73
virtual void drawWidget(const RenderStates &states, const std::shared_ptr< Widget > &widget)
Draws a widget, if the widget is visible.
virtual void drawVertexArray(const RenderStates &states, const Vertex *vertices, std::size_t vertexCount, const int *indices, std::size_t indexCount, const std::shared_ptr< BackendTexture > &texture)
Draws a vertex array. This is called by the other draw functions when they are not overriden.
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 updateClipping(FloatRect clipRect, FloatRect clipViewport)
Called from addClippingLayer and removeClippingLayer to apply the clipping.
Definition: BackendRenderTarget.hpp:257
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 setClearColor(const tgui::Color &color)
Select the color that will be used by clearScreen.
Definition: BackendRenderTarget.hpp:64
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:63
static const Color Black
Black predefined color.
Definition: Color.hpp:253
Definition: Outline.hpp:39
Definition: Sprite.hpp:45
Definition: Text.hpp:44
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39
Definition: Vertex.hpp:37