TGUI  0.8-dev
Canvas.hpp
1 //
3 // TGUI - Texus' 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 #include <SFML/Graphics/RenderTexture.hpp>
32 #include <SFML/Graphics/Sprite.hpp>
33 
35 
36 namespace 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 
100  static Canvas::Ptr copy(Canvas::ConstPtr canvas);
101 
102 
109  void setSize(const Layout2d& size) override;
110  using Widget::setSize;
111 
112 
121  void clear(Color color = sf::Color(0, 0, 0, 255));
122 
123 
131  void draw(const sf::Drawable& drawable, const sf::RenderStates& states = sf::RenderStates::Default);
132 
133 
143  void draw(const sf::Vertex* vertices, std::size_t vertexCount,
144  sf::PrimitiveType type, const sf::RenderStates& states = sf::RenderStates::Default);
145 
146 
155  void display();
156 
157 
165  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
166 
167 
169  protected:
170 
177  void rendererChanged(const std::string& property) override;
178 
179 
181  // Makes a copy of the widget
183  Widget::Ptr clone() const override
184  {
185  return std::make_shared<Canvas>(*this);
186  }
187 
188 
190  protected:
191 
192  sf::RenderTexture m_renderTexture;
193  sf::Sprite m_sprite;
194  };
195 
197 }
198 
200 
201 #endif // TGUI_CANVAS_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Clickable widget.
Definition: ClickableWidget.hpp:39
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< const Canvas > ConstPtr
Shared constant widget pointer.
Definition: Canvas.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
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&#39;t know its exact type.
Definition: Canvas.hpp:183
Definition: Canvas.hpp:40