TGUI  1.6.1
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#ifndef TGUI_CANVAS_SDL_HPP
26#define TGUI_CANVAS_SDL_HPP
27
28#include <TGUI/Backend/Renderer/SDL_Renderer/BackendTextureSDL.hpp>
29
30#if !TGUI_BUILD_AS_CXX_MODULE
31 #include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
32 #include <TGUI/Widgets/CanvasBase.hpp>
33#endif
34
35#include <TGUI/extlibs/IncludeSDL.hpp>
36
38
39TGUI_MODULE_EXPORT namespace tgui
40{
67 class TGUI_API CanvasSDL : public CanvasBase
68 {
69 public:
70
71 using Ptr = std::shared_ptr<CanvasSDL>;
72 using ConstPtr = std::shared_ptr<const CanvasSDL>;
73
74 static constexpr const char StaticWidgetType[] = "CanvasSDL";
75
83 CanvasSDL(const char* typeName = StaticWidgetType, bool initRenderer = true);
84
88 CanvasSDL(const CanvasSDL& copy);
89
93 CanvasSDL(CanvasSDL&& copy) = default;
94
98 CanvasSDL& operator= (const CanvasSDL& right);
99
103 CanvasSDL& operator= (CanvasSDL&& right) = default;
104
112 TGUI_NODISCARD static CanvasSDL::Ptr create(const Layout2d& size = {"100%", "100%"});
113
121 TGUI_NODISCARD static CanvasSDL::Ptr copy(const CanvasSDL::ConstPtr& canvas);
122
128 void setSize(const Layout2d& size) override;
129 using Widget::setSize;
130
137 void draw(BackendRenderTarget& target, RenderStates states) const override;
138
148 TGUI_NODISCARD SDL_Texture* getTextureTarget()
149 {
150 return m_textureTarget;
151 }
152
154 protected:
155
157 // Makes a copy of the widget
159 TGUI_NODISCARD Widget::Ptr clone() const override;
160
162 protected:
163
164 SDL_Texture* m_textureTarget = nullptr;
165 Vector2u m_textureSize;
166 Vector2u m_usedTextureSize;
167 std::shared_ptr<BackendTextureSDL> m_backendTexture;
168 };
169}
170
172
173#endif // TGUI_CANVAS_SDL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
This class is used as base class for the backend-specific canvas widgets.
Definition CanvasBase.hpp:38
CanvasSDL provides a way to directly render SDL contents on a widget.
Definition CanvasSDL.hpp:68
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:72
std::shared_ptr< CanvasSDL > Ptr
Shared widget pointer.
Definition CanvasSDL.hpp:71
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
CanvasSDL(CanvasSDL &&copy)=default
Default move constructor.
static CanvasSDL::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
static CanvasSDL::Ptr copy(const CanvasSDL::ConstPtr &canvas)
Makes a copy of another canvas.
SDL_Texture * getTextureTarget()
Access the internal texture on which you can render.
Definition CanvasSDL.hpp:148
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
CanvasSDL(const CanvasSDL &copy)
Copy constructor.
Class to store the position or size of a widget.
Definition Layout.hpp:323
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
States used for drawing.
Definition RenderStates.hpp:38