TGUI  1.1
Loading...
Searching...
No Matches
CanvasSDL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 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 import tgui;
33#else
34 #include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
35 #include <TGUI/Widgets/ClickableWidget.hpp>
36#endif
37
38#include <TGUI/extlibs/IncludeSDL.hpp>
39
41
42TGUI_MODULE_EXPORT namespace tgui
43{
70 class TGUI_API CanvasSDL : public ClickableWidget
71 {
72 public:
73
74 using Ptr = std::shared_ptr<CanvasSDL>;
75 using ConstPtr = std::shared_ptr<const CanvasSDL>;
76
77 static constexpr const char StaticWidgetType[] = "CanvasSDL";
78
79
87 CanvasSDL(const char* typeName = StaticWidgetType, bool initRenderer = true);
88
89
93 CanvasSDL(const CanvasSDL& copy);
94
95
99 CanvasSDL(CanvasSDL&& copy) = default;
100
101
105 CanvasSDL& operator= (const CanvasSDL& right);
106
107
111 CanvasSDL& operator= (CanvasSDL&& right) = default;
112
113
122 TGUI_NODISCARD static CanvasSDL::Ptr create(const Layout2d& size = {"100%", "100%"});
123
124
133 TGUI_NODISCARD static CanvasSDL::Ptr copy(const CanvasSDL::ConstPtr& canvas);
134
135
142 void setSize(const Layout2d& size) override;
143 using Widget::setSize;
144
145
153 void draw(BackendRenderTarget& target, RenderStates states) const override;
154
155
162 TGUI_NODISCARD bool canGainFocus() const override;
163
164
174 TGUI_NODISCARD SDL_Texture* getTextureTarget()
175 {
176 return m_textureTarget;
177 }
178
179
181 protected:
182
184 // Makes a copy of the widget
186 TGUI_NODISCARD Widget::Ptr clone() const override;
187
188
190 protected:
191
192 SDL_Texture* m_textureTarget = nullptr;
193 Vector2u m_textureSize;
194 Vector2u m_usedTextureSize;
195 std::shared_ptr<BackendTextureSDL> m_backendTexture;
196 };
197}
198
200
201#endif // TGUI_CANVAS_SDL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Definition CanvasSDL.hpp:71
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:75
std::shared_ptr< CanvasSDL > Ptr
Shared widget pointer.
Definition CanvasSDL.hpp:74
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:174
TGUI_NODISCARD bool canGainFocus() const override
Returns whether the widget can gain focus.
Clickable widget.
Definition ClickableWidget.hpp:40
Class to store the position or size of a widget.
Definition Layout.hpp:305
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