TGUI  1.6.1
Loading...
Searching...
No Matches
CanvasRaylib.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_RAYLIB_HPP
26#define TGUI_CANVAS_RAYLIB_HPP
27
28#include <TGUI/Backend/Renderer/Raylib/BackendTextureRaylib.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 <raylib.h>
36
38
39TGUI_MODULE_EXPORT namespace tgui
40{
67 class TGUI_API CanvasRaylib : public CanvasBase
68 {
69 public:
70
71 using Ptr = std::shared_ptr<CanvasRaylib>;
72 using ConstPtr = std::shared_ptr<const CanvasRaylib>;
73
74 static constexpr const char StaticWidgetType[] = "CanvasRaylib";
75
79 ~CanvasRaylib() override;
80
88 CanvasRaylib(const char* typeName = StaticWidgetType, bool initRenderer = true);
89
94
98 CanvasRaylib(CanvasRaylib&& copy) = default;
99
103 CanvasRaylib& operator= (const CanvasRaylib& right);
104
108 CanvasRaylib& operator= (CanvasRaylib&& right) = default;
109
117 TGUI_NODISCARD static CanvasRaylib::Ptr create(const Layout2d& size = {"100%", "100%"});
118
126 TGUI_NODISCARD static CanvasRaylib::Ptr copy(const CanvasRaylib::ConstPtr& canvas);
127
133 void setSize(const Layout2d& size) override;
134 using Widget::setSize;
135
142 void draw(BackendRenderTarget& target, RenderStates states) const override;
143
151 TGUI_NODISCARD RenderTexture2D& getTextureTarget()
152 {
153 return m_textureTarget;
154 }
155
157 protected:
158
160 // Makes a copy of the widget
162 TGUI_NODISCARD Widget::Ptr clone() const override;
163
165 protected:
166
167 RenderTexture2D m_textureTarget;
168 Vector2u m_textureSize;
169 Vector2u m_usedTextureSize;
170 std::shared_ptr<BackendTextureRaylib> m_backendTexture;
171 };
172}
173
175
176#endif // TGUI_CANVAS_RAYLIB_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
CanvasRaylib provides a way to directly render raylib contents on a widget.
Definition CanvasRaylib.hpp:68
std::shared_ptr< CanvasRaylib > Ptr
Shared widget pointer.
Definition CanvasRaylib.hpp:71
static CanvasRaylib::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
static CanvasRaylib::Ptr copy(const CanvasRaylib::ConstPtr &canvas)
Makes a copy of another canvas.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const CanvasRaylib > ConstPtr
Shared constant widget pointer.
Definition CanvasRaylib.hpp:72
CanvasRaylib(const CanvasRaylib &copy)
Copy constructor.
void setSize(const Layout2d &size) override
Changes the size of the widget.
RenderTexture2D & getTextureTarget()
Access the internal render texture to which you can render.
Definition CanvasRaylib.hpp:151
CanvasRaylib(CanvasRaylib &&copy)=default
Default move constructor.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
~CanvasRaylib() override
Destructor.
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