TGUI  v0.7.5
Picture.hpp
1 //
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_PICTURE_HPP
27 #define TGUI_PICTURE_HPP
28 
29 
30 #include <TGUI/Widgets/ClickableWidget.hpp>
31 
33 
34 namespace tgui
35 {
47  class TGUI_API Picture : public ClickableWidget
48  {
49  public:
50 
51  typedef std::shared_ptr<Picture> Ptr;
52  typedef std::shared_ptr<const Picture> ConstPtr;
53 
54 
58  Picture();
59 
60 
71  Picture(const sf::String& filename, bool fullyClickable = true);
72 
73 
90  Picture(const Texture& texture, bool fullyClickable = true);
91 
92 
103  void setTexture(const sf::String& filename, bool fullyClickable = true);
104 
105 
122  void setTexture(const Texture& texture, bool fullyClickable = true);
123 
124 
145  static Picture::Ptr create(const char* filename, bool fullyClickable = true);
146 
147 
168  static Picture::Ptr create(const Texture& texture = {}, bool fullyClickable = true);
169 
170 
179  static Picture::Ptr copy(Picture::ConstPtr picture);
180 
181 
189  const sf::String& getLoadedFilename() const
190  {
191  return m_loadedFilename;
192  }
193 
194 
207  virtual void setPosition(const Layout2d& position) override;
209 
210 
219  virtual void setSize(const Layout2d& size) override;
221 
222 
235  void setSmooth(bool smooth = true);
236 
237 
246  bool isSmooth() const
247  {
248  return m_texture.isSmooth();
249  }
250 
251 
258  virtual void setOpacity(float opacity) override;
259 
260 
264  virtual bool mouseOnWidget(float x, float y) const override;
265 
266 
270  virtual void leftMouseReleased(float x, float y) override;
271 
272 
274  protected:
275 
277  // Makes a copy of the widget
279  virtual Widget::Ptr clone() const override
280  {
281  return std::make_shared<Picture>(*this);
282  }
283 
284 
286  // This function is called every frame with the time passed since the last frame.
288  virtual void update(sf::Time elapsedTime) override;
289 
290 
292  // Draws the widget on the render target.
294  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
295 
296 
298  protected:
299 
300  sf::String m_loadedFilename;
301 
302  Texture m_texture;
303 
304  // Set to false when clicks on transparent parts of the picture should go to the widgets behind the picture
305  bool m_fullyClickable = true;
306 
307  // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
308  bool m_possibleDoubleClick = false;
309  };
310 
312 }
313 
315 
316 #endif // TGUI_PICTURE_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Class to store the position or size of a widget.
Definition: Layout.hpp:262
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Clickable widget.
Definition: ClickableWidget.hpp:55
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
const sf::String & getLoadedFilename() const
Returns the filename of the image that was used to load the widget.
Definition: Picture.hpp:189
std::shared_ptr< const Picture > ConstPtr
Shared constant widget pointer.
Definition: Picture.hpp:52
Definition: Texture.hpp:44
std::shared_ptr< Picture > Ptr
Shared widget pointer.
Definition: Picture.hpp:51
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Picture.hpp:279
Picture widget.
Definition: Picture.hpp:47
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
Definition: Picture.hpp:246