TGUI  0.7.8
Picture.hpp
1
2//
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
34namespace 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
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
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
Clickable widget.
Definition: ClickableWidget.hpp:56
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Picture widget.
Definition: Picture.hpp:48
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Picture.hpp:279
void setTexture(const Texture &texture, bool fullyClickable=true)
Change the image.
Picture()
Default constructor.
const sf::String & getLoadedFilename() const
Returns the filename of the image that was used to load the widget.
Definition: Picture.hpp:189
Picture(const sf::String &filename, bool fullyClickable=true)
Constructor to creates the picture.
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
Definition: Picture.hpp:246
std::shared_ptr< const Picture > ConstPtr
Shared constant widget pointer.
Definition: Picture.hpp:52
virtual void setSize(const Layout2d &size) override
Changes the size of the picture.
std::shared_ptr< Picture > Ptr
Shared widget pointer.
Definition: Picture.hpp:51
void setSmooth(bool smooth=true)
Enable or disable the smooth filter.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
void setTexture(const sf::String &filename, bool fullyClickable=true)
Change the image.
Picture(const Texture &texture, bool fullyClickable=true)
Constructor to create the picture from an image.
static Picture::Ptr copy(Picture::ConstPtr picture)
Makes a copy of another picture.
static Picture::Ptr create(const char *filename, bool fullyClickable=true)
Creates a new picture widget.
static Picture::Ptr create(const Texture &texture={}, bool fullyClickable=true)
Creates a new picture widget.
Definition: Texture.hpp:45
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34