TGUI  0.7.8
Canvas.hpp
1
2//
3// TGUI - Texus's Graphical User Interface
4// Copyright (C) 2012-2017 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
33
34namespace tgui
35{
37
38 class TGUI_API Canvas : public ClickableWidget
39 {
40 public:
41
42 typedef std::shared_ptr<Canvas> Ptr;
43 typedef std::shared_ptr<const Canvas> ConstPtr;
44
45
52 Canvas(const Layout2d& size = {100, 100});
53
54
62 Canvas(const Layout& width, const Layout& height);
63
64
71 Canvas(const Canvas& copy);
72
73
82 Canvas& operator= (const Canvas& right);
83
84
93 static Canvas::Ptr create(Layout2d size = {100, 100});
94
95
105
106
119 virtual void setPosition(const Layout2d& position) override;
121
122
129 virtual void setSize(const Layout2d& size) override;
131
132
141 void clear(const Color& color = sf::Color(0, 0, 0, 255));
142
143
151 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = sf::RenderStates::Default);
152
153
163 void draw(const sf::Vertex* vertices, unsigned int vertexCount,
164 sf::PrimitiveType type, const sf::RenderStates& states = sf::RenderStates::Default);
165
166
175 void display();
176
177
184 virtual void setOpacity(float opacity) override;
185
186
188 protected:
189
191 // Makes a copy of the widget
193 virtual Widget::Ptr clone() const override
194 {
195 return std::make_shared<Canvas>(*this);
196 }
197
198
200 // Draws the widget on the render target.
202 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
203
204
206 protected:
207
208 sf::RenderTexture m_renderTexture;
209 sf::Sprite m_sprite;
210 };
211
213}
214
216
217#endif // TGUI_CANVAS_HPP
Definition: Canvas.hpp:39
void clear(const Color &color=sf::Color(0, 0, 0, 255))
Clear the entire canvas with a single color.
virtual void setSize(const Layout2d &size) override
Changes the size of the widget.
void draw(const sf::Drawable &drawable, const sf::RenderStates &states=sf::RenderStates::Default)
Draw a drawable object to the canvas.
static Canvas::Ptr create(Layout2d size={100, 100})
Creates a new canvas widget.
void draw(const sf::Vertex *vertices, unsigned int vertexCount, sf::PrimitiveType type, const sf::RenderStates &states=sf::RenderStates::Default)
Draw primitives defined by an array of vertices.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
static Canvas::Ptr copy(Canvas::ConstPtr canvas)
Makes a copy of another canvas.
Canvas(const Canvas &copy)
Copy constructor.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
void display()
Update the contents of the canvas.
Canvas(const Layout &width, const Layout &height)
Default constructor.
std::shared_ptr< const Canvas > ConstPtr
Shared constant widget pointer.
Definition: Canvas.hpp:43
std::shared_ptr< Canvas > Ptr
Shared widget pointer.
Definition: Canvas.hpp:42
Canvas(const Layout2d &size={100, 100})
Default constructor.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Canvas.hpp:193
Clickable widget.
Definition: ClickableWidget.hpp:56
Implicit converter for colors.
Definition: Color.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Class to store the left, top, width or height of a widget.
Definition: Layout.hpp:121
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34