TGUI  v0.6.10
ChildWindow.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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_CHILD_WINDOW_HPP
27 #define TGUI_CHILD_WINDOW_HPP
28 
29 
30 #include <TGUI/Container.hpp>
31 
33 
34 namespace tgui
35 {
36  class Button;
37 
41  class TGUI_API ChildWindow : public Container, public WidgetBorders
42  {
43  public:
44 
46 
47 
50  {
53 
56 
58  TitleAlignmentRight
59  };
60 
61 
66  ChildWindow();
67 
68 
75  ChildWindow(const ChildWindow& copy);
76 
77 
82  virtual ~ChildWindow();
83 
84 
93  ChildWindow& operator= (const ChildWindow& right);
94 
95 
98  // Makes a copy of the widget by calling the copy constructor.
99  // This function calls new and if you use this function then you are responsible for calling delete.
101  virtual ChildWindow* clone();
102 
103 
113  virtual bool load(const std::string& configFileFilename, const std::string& sectionName = "ChildWindow");
114 
115 
123  const std::string& getLoadedConfigFile() const;
124 
125 
135  void setSize(float width, float height);
136 
137 
146  virtual sf::Vector2f getSize() const;
147 
148 
157  virtual sf::Vector2f getFullSize() const;
158 
159 
171  void setBackgroundTexture(sf::Texture *const texture = nullptr);
172 
173 
181  sf::Texture* getBackgroundTexture();
182 
183 
192  void setTitleBarHeight(unsigned int height);
193 
194 
201  unsigned int getTitleBarHeight() const;
202 
203 
210  void setBackgroundColor(const sf::Color& backgroundColor);
211 
212 
219  const sf::Color& getBackgroundColor() const;
220 
221 
232  virtual void setTransparency(unsigned char transparency);
233 
234 
241  void setTitle(const sf::String& title);
242 
243 
250  const sf::String& getTitle() const;
251 
252 
259  void setTitleColor(const sf::Color& color);
260 
261 
268  const sf::Color& getTitleColor() const;
269 
270 
277  void setBorderColor(const sf::Color& borderColor);
278 
279 
286  const sf::Color& getBorderColor() const;
287 
288 
298  virtual void setBorders(unsigned int leftBorder = 0,
299  unsigned int topBorder = 0,
300  unsigned int rightBorder = 0,
301  unsigned int bottomBorder = 0);
302 
303 
310  void setDistanceToSide(unsigned int distanceToSide);
311 
312 
319  unsigned int getDistanceToSide() const;
320 
321 
328  void setTitleAlignment(TitleAlignment alignment);
329 
330 
337  TitleAlignment getTitleAlignment() const;
338 
339 
348  void setIcon(const std::string& filename);
349 
350 
355  void removeIcon();
356 
357 
367  void destroy();
368 
369 
379  void keepInParent(bool enabled);
380 
381 
391  bool isKeptInParent() const;
392 
393 
401  virtual sf::Vector2f getWidgetsOffset() const;
402 
403 
417  void setPosition(float x, float y);
419 
420 
424  virtual bool mouseOnWidget(float x, float y);
425 
429  virtual void leftMousePressed(float x, float y);
430 
434  virtual void leftMouseReleased(float x, float y);
435 
439  virtual void mouseMoved(float x, float y);
440 
444  virtual void mouseWheelMoved(int delta, int x, int y);
445 
449  virtual void mouseNoLongerDown();
450 
451 
454  // This function is a (slow) way to set properties on the widget, no matter what type it is.
455  // When the requested property doesn't exist in the widget then the functions will return false.
457  virtual bool setProperty(std::string property, const std::string& value);
458 
461  // This function is a (slow) way to get properties of the widget, no matter what type it is.
462  // When the requested property doesn't exist in the widget then the functions will return false.
464  virtual bool getProperty(std::string property, std::string& value) const;
465 
466 
469  // Returns a list of all properties that can be used in setProperty and getProperty.
470  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
472  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
473 
474 
476  protected:
477 
480  // This function is called when the widget is added to a container.
482  virtual void initialize(Container *const container);
483 
484 
487  // Draws the widget on the render target.
489  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
490 
491 
493  public:
494 
499  {
500  LeftMousePressed = WidgetCallbacksCount * 1,
501  Closed = WidgetCallbacksCount * 2,
502  Moved = WidgetCallbacksCount * 4,
503 // Resized = WidgetCallbacksCount * 8,
504  AllChildWindowCallbacks = WidgetCallbacksCount * 16 - 1,
505  ChildWindowCallbacksCount = WidgetCallbacksCount * 16
506  };
507 
508 
510  protected:
511 
512  std::string m_LoadedConfigFile;
513 
514  sf::Vector2f m_Size;
515 
516  sf::Color m_BackgroundColor;
517  sf::Texture* m_BackgroundTexture;
518  sf::Sprite m_BackgroundSprite;
519 
520  Texture m_IconTexture;
521 
522  sf::Text m_TitleText;
523  unsigned int m_TitleBarHeight;
524  bool m_SplitImage;
525  sf::Vector2f m_DraggingPosition;
526  unsigned int m_DistanceToSide;
527  TitleAlignment m_TitleAlignment;
528  sf::Color m_BorderColor;
529  bool m_MouseDownOnTitleBar;
530 
531  Texture m_TextureTitleBar_L;
532  Texture m_TextureTitleBar_M;
533  Texture m_TextureTitleBar_R;
534 
535  Button* m_CloseButton;
536 
537  bool m_KeepInParent;
538 
540  };
541 
543 }
544 
546 
547 #endif // TGUI_CHILD_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Places the title on the left side of the title bar.
Definition: ChildWindow.hpp:52
virtual void setPosition(float x, float y)
Set the position of the widget.
Movable Panel with title bar.
Definition: ChildWindow.hpp:41
ChildWindowCallbacks
Defines specific triggers to ChildWindow.
Definition: ChildWindow.hpp:498
Definition: TextureManager.hpp:52
Parent class for every widget that has borders.
Definition: Widget.hpp:480
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: Button.hpp:40
Places the title in the middle of the title bar.
Definition: ChildWindow.hpp:55
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:49
Definition: SharedWidgetPtr.hpp:44