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 
63  Canvas(const Canvas& copy);
64 
65 
74  Canvas& operator= (const Canvas& right);
75 
76 
85  static Canvas::Ptr create(Layout2d size = {100, 100});
86 
87 
96  static Canvas::Ptr copy(Canvas::ConstPtr canvas);
97 
98 
105  virtual void setSize(const Layout2d& size) override;
107 
108 
117  void clear(Color color = sf::Color(0, 0, 0, 255));
118 
119 
127  void draw(const sf::Drawable& drawable, const sf::RenderStates& states = sf::RenderStates::Default);
128 
129 
139  void draw(const sf::Vertex* vertices, std::size_t vertexCount,
140  sf::PrimitiveType type, const sf::RenderStates& states = sf::RenderStates::Default);
141 
142 
151  void display();
152 
153 
161  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
162 
163 
165  protected:
166 
173  virtual void rendererChanged(const std::string& property) override;
174 
175 
177  // Makes a copy of the widget
179  virtual Widget::Ptr clone() const override
180  {
181  return std::make_shared<Canvas>(*this);
182  }
183 
184 
186  protected:
187 
188  sf::RenderTexture m_renderTexture;
189  sf::Sprite m_sprite;
190  };
191 
193 }
194 
196 
197 #endif // TGUI_CANVAS_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:263
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Canvas.hpp:179
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Clickable widget.
Definition: ClickableWidget.hpp:55
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:76
std::shared_ptr< Canvas > Ptr
Shared widget pointer.
Definition: Canvas.hpp:44
Definition: Canvas.hpp:40