TGUI  v0.7.5
Panel.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_PANEL_HPP
27 #define TGUI_PANEL_HPP
28 
29 
30 #include <TGUI/Container.hpp>
31 
33 
34 namespace tgui
35 {
36  class PanelRenderer;
37 
60  class TGUI_API Panel : public Container
61  {
62  public:
63 
64  typedef std::shared_ptr<Panel> Ptr;
65  typedef std::shared_ptr<const Panel> ConstPtr;
66 
67 
74  Panel(const Layout2d& size = {100, 100});
75 
76 
84  Panel(const Layout& width, const Layout& height);
85 
86 
95  static Panel::Ptr create(Layout2d size = {100, 100});
96 
97 
106  static Panel::Ptr copy(Panel::ConstPtr panel);
107 
108 
115  std::shared_ptr<PanelRenderer> getRenderer() const
116  {
117  return std::static_pointer_cast<PanelRenderer>(m_renderer);
118  }
119 
120 
127  void setBackgroundColor(const Color& backgroundColor)
128  {
129  m_backgroundColor = backgroundColor;
130  }
131 
132 
139  const sf::Color& getBackgroundColor() const
140  {
141  return m_backgroundColor;
142  }
143 
144 
148  virtual bool mouseOnWidget(float x, float y) const override;
149 
153  virtual void leftMousePressed(float x, float y) override;
154 
158  virtual void leftMouseReleased(float x, float y) override;
159 
160 
162  protected:
163 
165  // Makes a copy of the widget
167  virtual Widget::Ptr clone() const override
168  {
169  return std::make_shared<Panel>(*this);
170  }
171 
172 
174  // Draws the widget on the render target.
176  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
177 
178 
180  protected:
181 
182  sf::Color m_backgroundColor = {220, 220, 220};
183 
185 
186 
187  friend class PanelRenderer;
188 
190  };
191 
193 
194  class TGUI_API PanelRenderer : public WidgetRenderer, public WidgetBorders
195  {
196  public:
197 
204  PanelRenderer(Panel* panel) : m_panel{panel} {}
205 
206 
216  virtual void setProperty(std::string property, const std::string& value) override;
217 
218 
229  virtual void setProperty(std::string property, ObjectConverter&& value) override;
230 
231 
241  virtual ObjectConverter getProperty(std::string property) const override;
242 
243 
250  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
251 
252 
264  void setBackgroundColor(const Color& color);
265 
266 
273  void setBorderColor(const Color& color);
274 
275 
277  private:
278 
280  // Makes a copy of the renderer
282  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
283 
284 
286  protected:
287 
288  Panel* m_panel;
289 
290  sf::Color m_borderColor;
291 
292  friend class Panel;
293 
295  };
296 
298 }
299 
301 
302 #endif // TGUI_PANEL_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Implicit converter for colors.
Definition: Color.hpp:39
Class to store the position or size of a widget.
Definition: Layout.hpp:262
The parent class for every widget.
Definition: Widget.hpp:71
PanelRenderer(Panel *panel)
Constructor.
Definition: Panel.hpp:204
void setBackgroundColor(const Color &backgroundColor)
Changes the background color of the panel.
Definition: Panel.hpp:127
Class to store the left, top, width or height of a widget.
Definition: Layout.hpp:120
Definition: Panel.hpp:194
Parent class for every widget that has borders.
Definition: Borders.hpp:136
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Panel widget.
Definition: Panel.hpp:60
Container widget.
Definition: Container.hpp:47
std::shared_ptr< PanelRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: Panel.hpp:115
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Panel.hpp:167
const sf::Color & getBackgroundColor() const
Returns the background color of the panel.
Definition: Panel.hpp:139
Base class for all renderer classes.
Definition: Widget.hpp:682
std::shared_ptr< const Panel > ConstPtr
Shared constant widget pointer.
Definition: Panel.hpp:65
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition: Panel.hpp:64