TGUI  0.9-dev
Canvas.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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_HPP
27#define TGUI_CANVAS_HPP
28
29#include <TGUI/Config.hpp>
30
31#if TGUI_HAS_BACKEND_SFML_GRAPHICS
32
33#include <TGUI/Widgets/ClickableWidget.hpp>
34#include <SFML/Graphics/RenderTexture.hpp>
35#include <SFML/Graphics/Sprite.hpp>
36
38
39namespace tgui
40{
42
43 class TGUI_API CanvasSFML : public ClickableWidget
44 {
45 public:
46
47 typedef std::shared_ptr<CanvasSFML> Ptr;
48 typedef std::shared_ptr<const CanvasSFML> ConstPtr;
49
50
58 CanvasSFML(const char* typeName = "Canvas", bool initRenderer = true);
59
60
64 CanvasSFML(const CanvasSFML& copy);
65
66
70 CanvasSFML(CanvasSFML&& copy);
71
72
76 CanvasSFML& operator= (const CanvasSFML& right);
77
78
82 CanvasSFML& operator= (CanvasSFML&& right);
83
84
93 static CanvasSFML::Ptr create(Layout2d size = {"100%", "100%"});
94
95
104 static CanvasSFML::Ptr copy(CanvasSFML::ConstPtr canvas);
105
106
113 void setSize(const Layout2d& size) override;
114 using Widget::setSize;
115
116
130 void setView(const sf::View& view);
131
132
138 const sf::View& getView() const;
139
140
148 const sf::View& getDefaultView() const;
149
150
159 IntRect getViewport() const;
160
161
170 void clear(Color color = Color::Black);
171
172
180 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
181
182
192 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
193 sf::PrimitiveType type, const sf::RenderStates& states = {});
194
195
204 void draw(const tgui::Sprite& sprite, const RenderStates& states = {});
205
206
215 void display();
216
217
225 void draw(BackendRenderTarget& target, RenderStates states) const override;
226
227
234 bool canGainFocus() const override;
235
236
244 sf::RenderTexture& getRenderTexture()
245 {
246 return m_renderTexture;
247 }
248
249
251 protected:
252
259 void rendererChanged(const String& property) override;
260
261
263 // Makes a copy of the widget
265 Widget::Ptr clone() const override
266 {
267 return std::make_shared<CanvasSFML>(*this);
268 }
269
270
272 protected:
273
274 sf::RenderTexture m_renderTexture;
275 Sprite m_sprite;
276 };
277
279
280 using Canvas = CanvasSFML;
281}
282
283#endif // TGUI_HAS_BACKEND_SFML_GRAPHICS
284
286
287#endif // TGUI_CANVAS_HPP
static const Color Black
Black predefined color.
Definition: Color.hpp:253
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