TGUI  0.10-beta
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 typedef std::shared_ptr<CanvasSFML> Ptr;
72 typedef std::shared_ptr<const CanvasSFML> ConstPtr;
73
74
82 CanvasSFML(const char* typeName = "CanvasSFML", bool initRenderer = true);
83
84
88 CanvasSFML(const CanvasSFML& copy);
89
90
95
96
100 CanvasSFML& operator= (const CanvasSFML& right);
101
102
106 CanvasSFML& operator= (CanvasSFML&& right);
107
108
117 static CanvasSFML::Ptr create(Layout2d size = {"100%", "100%"});
118
119
129
130
137 void setSize(const Layout2d& size) override;
138 using Widget::setSize;
139
140
154 void setView(const sf::View& view);
155
156
162 const sf::View& getView() const;
163
164
172 const sf::View& getDefaultView() const;
173
174
184
185
194 void clear(Color color = Color::Black);
195
196
204 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
205
206
216 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
217 sf::PrimitiveType type, const sf::RenderStates& states = {});
218
219
228 void draw(const tgui::Sprite& sprite, const RenderStates& states = {});
229
230
237 void display();
238
239
247 void draw(BackendRenderTarget& target, RenderStates states) const override;
248
249
256 bool canGainFocus() const override;
257
258
266 sf::RenderTexture& getRenderTexture()
267 {
268 return m_renderTexture;
269 }
270
271
273 protected:
274
276 // Makes a copy of the widget
278 Widget::Ptr clone() const override;
279
280
282 protected:
283
284 sf::RenderTexture m_renderTexture;
285 Vector2u m_usedTextureSize;
286 std::shared_ptr<BackendTextureSFML> m_backendTexture = std::make_shared<BackendTextureSFML>();
287 };
288}
289
291
292#endif // TGUI_CANVAS_SFML_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Definition: CanvasSFML.hpp:68
IntRect getViewport() const
Get the viewport of the currently applied view, applied to this canvas.
CanvasSFML(const CanvasSFML &copy)
Copy constructor.
CanvasSFML(CanvasSFML &&copy)
Move 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:71
sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition: CanvasSFML.hpp:266
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.
static CanvasSFML::Ptr create(Layout2d size={"100%", "100%"})
Creates a new canvas widget.
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.
std::shared_ptr< const CanvasSFML > ConstPtr
Shared constant widget pointer.
Definition: CanvasSFML.hpp:72
void draw(const tgui::Sprite &sprite, const RenderStates &states={})
Draws a TGUI sprite to the canvas.
static CanvasSFML::Ptr copy(CanvasSFML::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.
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
static const Color Black
Black predefined color.
Definition: Color.hpp:253
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Definition: Sprite.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39