TGUI  1.3.0
Loading...
Searching...
No Matches
CanvasSFML.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_SFML_HPP
27#define TGUI_CANVAS_SFML_HPP
28
29#include <TGUI/Backend/Renderer/SFML-Graphics/BackendTextureSFML.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 <SFML/Graphics/RenderTexture.hpp>
37#include <SFML/Graphics/Sprite.hpp>
38
40
41TGUI_MODULE_EXPORT namespace tgui
42{
69 class TGUI_API CanvasSFML : public CanvasBase
70 {
71 public:
72
73 using Ptr = std::shared_ptr<CanvasSFML>;
74 using ConstPtr = std::shared_ptr<const CanvasSFML>;
75
76 static constexpr const char StaticWidgetType[] = "CanvasSFML";
77
78
86 CanvasSFML(const char* typeName = StaticWidgetType, bool initRenderer = true);
87
88
92 CanvasSFML(const CanvasSFML& copy);
93
94
98 CanvasSFML(CanvasSFML&& copy) noexcept;
99
100
104 CanvasSFML& operator= (const CanvasSFML& right);
105
106
110 CanvasSFML& operator= (CanvasSFML&& right) noexcept;
111
112
121 TGUI_NODISCARD static CanvasSFML::Ptr create(const Layout2d& size = {"100%", "100%"});
122
123
132 TGUI_NODISCARD static CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr& canvas);
133
134
141 void setSize(const Layout2d& size) override;
142 using Widget::setSize;
143
144
158 void setView(const sf::View& view);
159
160
166 TGUI_NODISCARD const sf::View& getView() const;
167
168
176 TGUI_NODISCARD const sf::View& getDefaultView() const;
177
178
187 TGUI_NODISCARD IntRect getViewport() const;
188
189
198 void clear(Color color = Color::Black);
199
200
208 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
209
210
220 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
221 sf::PrimitiveType type, const sf::RenderStates& states = {});
222
223
232 void draw(const Sprite& sprite, const RenderStates& states = {});
233
234
241 void display();
242
243
251 void draw(BackendRenderTarget& target, RenderStates states) const override;
252
253
261 TGUI_NODISCARD sf::RenderTexture& getRenderTexture()
262 {
263 return m_renderTexture;
264 }
265
266
268 protected:
269
271 // Makes a copy of the widget
273 TGUI_NODISCARD Widget::Ptr clone() const override;
274
275
277 protected:
278
279 sf::RenderTexture m_renderTexture;
280 Vector2u m_usedTextureSize;
281 };
282}
283
285
286#endif // TGUI_CANVAS_SFML_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
CanvasSFML provides a way to directly render SFML contents on a widget.
Definition CanvasSFML.hpp:70
TGUI_NODISCARD const sf::View & getDefaultView() const
Get the default view of the canvas.
void draw(const Sprite &sprite, const RenderStates &states={})
Draws a TGUI sprite to the canvas.
CanvasSFML(const CanvasSFML &copy)
Copy constructor.
void setView(const sf::View &view)
Change the current active view.
void setSize(const Layout2d &size) override
Changes the size of the widget.
std::shared_ptr< CanvasSFML > Ptr
Shared widget pointer.
Definition CanvasSFML.hpp:73
static TGUI_NODISCARD CanvasSFML::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
void draw(const sf::Vertex *vertices, std::size_t vertexCount, sf::PrimitiveType type, const sf::RenderStates &states={})
Draws primitives defined by an array of vertices.
void draw(const sf::Drawable &drawable, const sf::RenderStates &states={})
Draws a drawable object to the canvas.
void clear(Color color=Color::Black)
Clears the entire canvas with a single color.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
TGUI_NODISCARD sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition CanvasSFML.hpp:261
TGUI_NODISCARD IntRect getViewport() const
Get the viewport of the currently applied view, applied to this canvas.
static TGUI_NODISCARD CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr &canvas)
Makes a copy of another canvas.
void display()
Updates the contents of the canvas.
CanvasSFML(CanvasSFML &&copy) noexcept
Move constructor.
TGUI_NODISCARD const sf::View & getView() const
Get the view currently in use in the canvas.
std::shared_ptr< const CanvasSFML > ConstPtr
Shared constant widget pointer.
Definition CanvasSFML.hpp:74
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
Wrapper for colors.
Definition Color.hpp:74
Class to store the position or size of a widget.
Definition Layout.hpp:328
Definition Rect.hpp:41
Definition Sprite.hpp:48
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