TGUI  0.8.9
Canvas.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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
30#include <TGUI/Widgets/ClickableWidget.hpp>
31#include <SFML/Graphics/RenderTexture.hpp>
32#include <SFML/Graphics/Sprite.hpp>
33
35
36namespace tgui
37{
39
40 class TGUI_API Canvas : public ClickableWidget
41 {
42 public:
43
44 typedef std::shared_ptr<Canvas> Ptr;
45 typedef std::shared_ptr<const Canvas> ConstPtr;
46
47
54 Canvas(const Layout2d& size = {"100%", "100%"});
55
56
60 Canvas(const Canvas& copy);
61
62
66 Canvas(Canvas&& copy);
67
68
72 Canvas& operator= (const Canvas& right);
73
74
78 Canvas& operator= (Canvas&& right);
79
80
89 static Canvas::Ptr create(Layout2d size = {"100%", "100%"});
90
91
101
102
109 void setSize(const Layout2d& size) override;
110 using Widget::setSize;
111
112
126 void setView(const sf::View& view);
127
128
134 const sf::View& getView() const;
135
136
144 const sf::View& getDefaultView() const;
145
146
155 sf::IntRect getViewport() const;
156
157
166 void clear(Color color = Color::Black);
167
168
176 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = sf::RenderStates::Default);
177
178
188 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
189 sf::PrimitiveType type, const sf::RenderStates& states = sf::RenderStates::Default);
190
191
198 void draw(const tgui::Sprite& sprite, const sf::RenderStates& states = sf::RenderStates::Default);
199
200
209 void display();
210
211
219 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
220
221
228 bool canGainFocus() const override;
229
230
238 sf::RenderTexture& getRenderTexture()
239 {
240 return m_renderTexture;
241 }
242
243
245 protected:
246
253 void rendererChanged(const std::string& property) override;
254
255
257 // Makes a copy of the widget
259 Widget::Ptr clone() const override
260 {
261 return std::make_shared<Canvas>(*this);
262 }
263
264
266 protected:
267
268 sf::RenderTexture m_renderTexture;
269 sf::Sprite m_sprite;
270 };
271
273}
274
276
277#endif // TGUI_CANVAS_HPP
Definition: Canvas.hpp:41
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: Canvas.hpp:238
Canvas(const Layout2d &size={"100%", "100%"})
Default constructor.
sf::IntRect getViewport() const
Get the viewport of the currently applied view, applied to this canvas.
bool canGainFocus() const override
Returns whether the widget can gain focus.
void draw(const tgui::Sprite &sprite, const sf::RenderStates &states=sf::RenderStates::Default)
Draws a TGUI sprite to the canvas.
void draw(const sf::Vertex *vertices, std::size_t vertexCount, sf::PrimitiveType type, const sf::RenderStates &states=sf::RenderStates::Default)
Draws primitives defined by an array of vertices.
void draw(const sf::Drawable &drawable, const sf::RenderStates &states=sf::RenderStates::Default)
Draws a drawable object to the canvas.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
const sf::View & getDefaultView() const
Get the default view of the canvas.
static Canvas::Ptr copy(Canvas::ConstPtr canvas)
Makes a copy of another canvas.
const sf::View & getView() const
Get the view currently in use in the canvas.
void clear(Color color=Color::Black)
Clears the entire canvas with a single color.
Canvas(const Canvas &copy)
Copy constructor.
void display()
Updates the contents of the canvas.
static Canvas::Ptr create(Layout2d size={"100%", "100%"})
Creates a new canvas widget.
Canvas(Canvas &&copy)
Move constructor.
void setView(const sf::View &view)
Change the current active view.
std::shared_ptr< const Canvas > ConstPtr
Shared constant widget pointer.
Definition: Canvas.hpp:45
std::shared_ptr< Canvas > Ptr
Shared widget pointer.
Definition: Canvas.hpp:44
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Canvas.hpp:259
Clickable widget.
Definition: ClickableWidget.hpp:40
Wrapper for colors.
Definition: Color.hpp:49
static const Color Black
Black predefined color.
Definition: Color.hpp:206
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: Sprite.hpp:46
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37