TGUI  0.9-dev
Canvas.hpp
1 //
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 
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 
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  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 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
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:72
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Class to store the position or size of a widget.
Definition: Layout.hpp:258
Definition: Canvas.hpp:40
std::shared_ptr< Canvas > Ptr
Shared widget pointer.
Definition: Canvas.hpp:44
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:70
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Canvas.hpp:259
std::shared_ptr< const Canvas > ConstPtr
Shared constant widget pointer.
Definition: Canvas.hpp:45
sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition: Canvas.hpp:238
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
static const Color Black
Black predefined color.
Definition: Color.hpp:221
Clickable widget.
Definition: ClickableWidget.hpp:39