TGUI  1.3.0
Loading...
Searching...
No Matches
CanvasSDL.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_CANVAS_SDL_HPP
27#define TGUI_CANVAS_SDL_HPP
28
29#include <TGUI/Backend/Renderer/SDL_Renderer/BackendTextureSDL.hpp>
30
31#if !TGUI_BUILD_AS_CXX_MODULE
32 #include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
33 #include <TGUI/Widgets/CanvasBase.hpp>
34#endif
35
36#include <TGUI/extlibs/IncludeSDL.hpp>
37
39
40TGUI_MODULE_EXPORT namespace tgui
41{
68 class TGUI_API CanvasSDL : public CanvasBase
69 {
70 public:
71
72 using Ptr = std::shared_ptr<CanvasSDL>;
73 using ConstPtr = std::shared_ptr<const CanvasSDL>;
74
75 static constexpr const char StaticWidgetType[] = "CanvasSDL";
76
77
85 CanvasSDL(const char* typeName = StaticWidgetType, bool initRenderer = true);
86
87
91 CanvasSDL(const CanvasSDL& copy);
92
93
97 CanvasSDL(CanvasSDL&& copy) = default;
98
99
103 CanvasSDL& operator= (const CanvasSDL& right);
104
105
109 CanvasSDL& operator= (CanvasSDL&& right) = default;
110
111
120 TGUI_NODISCARD static CanvasSDL::Ptr create(const Layout2d& size = {"100%", "100%"});
121
122
131 TGUI_NODISCARD static CanvasSDL::Ptr copy(const CanvasSDL::ConstPtr& canvas);
132
133
140 void setSize(const Layout2d& size) override;
141 using Widget::setSize;
142
143
151 void draw(BackendRenderTarget& target, RenderStates states) const override;
152
153
163 TGUI_NODISCARD SDL_Texture* getTextureTarget()
164 {
165 return m_textureTarget;
166 }
167
168
170 protected:
171
173 // Makes a copy of the widget
175 TGUI_NODISCARD Widget::Ptr clone() const override;
176
177
179 protected:
180
181 SDL_Texture* m_textureTarget = nullptr;
182 Vector2u m_textureSize;
183 Vector2u m_usedTextureSize;
184 std::shared_ptr<BackendTextureSDL> m_backendTexture;
185 };
186}
187
189
190#endif // TGUI_CANVAS_SDL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
This class is used as base class for the backend-specific canvas widgets.
Definition CanvasBase.hpp:39
CanvasSDL provides a way to directly render SDL contents on a widget.
Definition CanvasSDL.hpp:69
static TGUI_NODISCARD CanvasSDL::Ptr copy(const CanvasSDL::ConstPtr &canvas)
Makes a copy of another canvas.
void setSize(const Layout2d &size) override
Changes the size of the widget.
std::shared_ptr< const CanvasSDL > ConstPtr
Shared constant widget pointer.
Definition CanvasSDL.hpp:73
std::shared_ptr< CanvasSDL > Ptr
Shared widget pointer.
Definition CanvasSDL.hpp:72
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
CanvasSDL(CanvasSDL &&copy)=default
Default move constructor.
static TGUI_NODISCARD CanvasSDL::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
CanvasSDL(const CanvasSDL &copy)
Copy constructor.
TGUI_NODISCARD SDL_Texture * getTextureTarget()
Access the internal texture on which you can render.
Definition CanvasSDL.hpp:163
Class to store the position or size of a widget.
Definition Layout.hpp:328
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39