TGUI  0.10-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
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
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
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}
278
279#endif // TGUI_HAS_BACKEND_SFML_GRAPHICS
280
282
283#endif // TGUI_CANVAS_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Definition: Canvas.hpp:44
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: Canvas.hpp:47
sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition: Canvas.hpp:244
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 rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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: Canvas.hpp:48
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.
Definition: Canvas.hpp:265
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:262
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
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