TGUI  1.0-alpha
Picture.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
35namespace 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
55 Picture(const char* typeName = "Picture", bool initRenderer = true);
56
57
64
65
85 static Picture::Ptr create(const Texture& texture, bool transparentTexture = false);
86
87
97
98
104 const PictureRenderer* getSharedRenderer() const;
105
112
113
122 void setSize(const Layout2d& size) override;
123 using Widget::setSize;
124
125
133 void ignoreMouseEvents(bool ignore = true);
134
135
142
143
150 bool canGainFocus() const override;
151
152
159 bool isMouseOnWidget(Vector2f pos) const override;
160
161
165 void leftMouseReleased(Vector2f pos) override;
166
167
175 void draw(BackendRenderTarget& target, RenderStates states) const override;
176
177
179 protected:
180
190 Signal& getSignal(String signalName) override;
191
192
194 public:
195
196 SignalVector2f onDoubleClick = {"DoubleClicked"};
197
198
200 protected:
201
208 void rendererChanged(const String& property) override;
209
210
214 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
215
216
220 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
221
222
224 // This function is called every frame with the time passed since the last frame.
226 bool updateTime(Duration elapsedTime) override;
227
228
230 // Makes a copy of the widget
232 Widget::Ptr clone() const override;
233
234
236 protected:
237
238 Sprite m_sprite;
239
240 bool m_ignoringMouseEvents = false;
241
242 // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
243 bool m_possibleDoubleClick = false;
244 };
245
247}
248
250
251#endif // TGUI_PICTURE_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Clickable widget.
Definition: ClickableWidget.hpp:40
Wrapper for durations.
Definition: Duration.hpp:52
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Definition: PictureRenderer.hpp:37
Picture widget.
Definition: Picture.hpp:41
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
bool canGainFocus() const override
Returns whether the widget can gain focus.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::shared_ptr< const Picture > ConstPtr
Shared constant widget pointer.
Definition: Picture.hpp:45
bool isIgnoringMouseEvents() const
Returns whether the widget is ignoring mouse events and letting them pass to the widgets behind it.
std::shared_ptr< Picture > Ptr
Shared widget pointer.
Definition: Picture.hpp:44
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
PictureRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setSize(const Layout2d &size) override
Changes the size of the picture.
static Picture::Ptr create(const Texture &texture, bool transparentTexture=false)
Creates a new picture widget.
PictureRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void ignoreMouseEvents(bool ignore=true)
Sets whether the widget should completely ignore mouse events and let them pass to the widgets behind...
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
static Picture::Ptr create()
Creates a new empty picture widget.
static Picture::Ptr copy(Picture::ConstPtr picture)
Makes a copy of another picture.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Definition: Texture.hpp:52
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39