TGUI  1.0-beta
Loading...
Searching...
No Matches
CanvasSFML.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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/Config.hpp>
30#include <TGUI/Backend/Renderer/SFML-Graphics/BackendTextureSFML.hpp>
31#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
32#include <TGUI/Widgets/ClickableWidget.hpp>
33
34#include <SFML/Graphics/RenderTexture.hpp>
35#include <SFML/Graphics/Sprite.hpp>
36
38
39namespace tgui
40{
67 class TGUI_API CanvasSFML : public ClickableWidget
68 {
69 public:
70
71 using Ptr = std::shared_ptr<CanvasSFML>;
72 using ConstPtr = std::shared_ptr<const CanvasSFML>;
73
74 static constexpr const char StaticWidgetType[] = "CanvasSFML";
75
76
84 CanvasSFML(const char* typeName = StaticWidgetType, bool initRenderer = true);
85
86
90 CanvasSFML(const CanvasSFML& copy);
91
92
96 CanvasSFML(CanvasSFML&& copy) noexcept;
97
98
102 CanvasSFML& operator= (const CanvasSFML& right);
103
104
108 CanvasSFML& operator= (CanvasSFML&& right) noexcept;
109
110
119 static CanvasSFML::Ptr create(const Layout2d& size = {"100%", "100%"});
120
121
131
132
139 void setSize(const Layout2d& size) override;
140 using Widget::setSize;
141
142
156 void setView(const sf::View& view);
157
158
164 const sf::View& getView() const;
165
166
174 const sf::View& getDefaultView() const;
175
176
186
187
196 void clear(Color color = Color::Black);
197
198
206 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
207
208
218 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
219 sf::PrimitiveType type, const sf::RenderStates& states = {});
220
221
230 void draw(const tgui::Sprite& sprite, const RenderStates& states = {});
231
232
239 void display();
240
241
249 void draw(BackendRenderTarget& target, RenderStates states) const override;
250
251
258 bool canGainFocus() const override;
259
260
268 sf::RenderTexture& getRenderTexture()
269 {
270 return m_renderTexture;
271 }
272
273
275 protected:
276
278 // Makes a copy of the widget
280 Widget::Ptr clone() const override;
281
282
284 protected:
285
286 sf::RenderTexture m_renderTexture;
287 Vector2u m_usedTextureSize;
288 std::shared_ptr<BackendTextureSFML> m_backendTexture = std::make_shared<BackendTextureSFML>();
289 };
290}
291
293
294#endif // TGUI_CANVAS_SFML_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Definition: CanvasSFML.hpp:68
static CanvasSFML::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
IntRect getViewport() const
Get the viewport of the currently applied view, applied to this canvas.
CanvasSFML(const CanvasSFML &copy)
Copy constructor.
void setView(const sf::View &view)
Change the current active view.
static CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr &canvas)
Makes a copy of another canvas.
void setSize(const Layout2d &size) override
Changes the size of the widget.
sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition: CanvasSFML.hpp:268
std::shared_ptr< CanvasSFML > Ptr
Shared widget pointer.
Definition: CanvasSFML.hpp:71
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.
const sf::View & getView() const
Get the view currently in use in the canvas.
void draw(const sf::Drawable &drawable, const sf::RenderStates &states={})
Draws a drawable object to the canvas.
const sf::View & getDefaultView() const
Get the default view of the canvas.
void clear(Color color=Color::Black)
Clears the entire canvas with a single color.
void display()
Updates the contents of the canvas.
bool canGainFocus() const override
Returns whether the widget can gain focus.
void draw(const tgui::Sprite &sprite, const RenderStates &states={})
Draws a TGUI sprite to the canvas.
CanvasSFML(CanvasSFML &&copy) noexcept
Move constructor.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const CanvasSFML > ConstPtr
Shared constant widget pointer.
Definition: CanvasSFML.hpp:72
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
Clickable widget.
Definition: ClickableWidget.hpp:40
Wrapper for colors.
Definition: Color.hpp:63
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Definition: Rect.hpp:41
Definition: Sprite.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39