TGUI  0.8.0
Picture.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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_PICTURE_HPP
27 #define TGUI_PICTURE_HPP
28 
29 
30 #include <TGUI/Widgets/ClickableWidget.hpp>
31 #include <TGUI/Renderers/PictureRenderer.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API Picture : public ClickableWidget
41  {
42  public:
43 
44  typedef std::shared_ptr<Picture> Ptr;
45  typedef std::shared_ptr<const Picture> ConstPtr;
46 
47 
51  Picture();
52 
53 
61  Picture(const Texture& texture, bool transparentTexture = false);
62 
63 
83  static Picture::Ptr create(const Texture& texture = {}, bool transparentTexture = false);
84 
85 
94  static Picture::Ptr copy(Picture::ConstPtr picture);
95 
96 
101  PictureRenderer* getSharedRenderer();
102  const PictureRenderer* getSharedRenderer() const;
103 
109  PictureRenderer* getRenderer();
110  const PictureRenderer* getRenderer() const;
111 
112 
121  void setSize(const Layout2d& size) override;
122  using Widget::setSize;
123 
124 
132  void ignoreMouseEvents(bool ignore = true);
133 
134 
140  bool isIgnoringMouseEvents() const;
141 
142 
149  bool canGainFocus() const override;
150 
151 
158  bool mouseOnWidget(Vector2f pos) const override;
159 
160 
164  void leftMouseReleased(Vector2f pos) override;
165 
166 
174  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
175 
176 
178  protected:
179 
189  Signal& getSignal(std::string signalName) override;
190 
191 
193  public:
194 
195  SignalVector2f onDoubleClick = {"DoubleClicked"};
196 
197 
199  protected:
200 
207  void rendererChanged(const std::string& property) override;
208 
209 
213  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
214 
215 
219  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
220 
221 
223  // This function is called every frame with the time passed since the last frame.
225  void update(sf::Time elapsedTime) override;
226 
227 
229  // Makes a copy of the widget
231  Widget::Ptr clone() const override
232  {
233  return std::make_shared<Picture>(*this);
234  }
235 
236 
238  protected:
239 
240  Sprite m_sprite;
241 
242  bool m_ignoringMouseEvents = false;
243 
244  // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
245  bool m_possibleDoubleClick = false;
246  };
247 
249 }
250 
252 
253 #endif // TGUI_PICTURE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Definition: Vector2f.hpp:37
Clickable widget.
Definition: ClickableWidget.hpp:39
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
std::shared_ptr< const Picture > ConstPtr
Shared constant widget pointer.
Definition: Picture.hpp:45
Definition: Texture.hpp:40
Definition: PictureRenderer.hpp:36
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Picture.hpp:231
std::shared_ptr< Picture > Ptr
Shared widget pointer.
Definition: Picture.hpp:44
Picture widget.
Definition: Picture.hpp:40