TGUI  0.8-dev
MenuBar.hpp
1 //
3 // TGUI - Texus' 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_MENU_BAR_HPP
27 #define TGUI_MENU_BAR_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 #include <TGUI/Renderers/MenuBarRenderer.hpp>
32 #include <TGUI/Text.hpp>
33 
35 
36 namespace tgui
37 {
41  class TGUI_API MenuBar : public Widget
42  {
43  public:
44 
45  typedef std::shared_ptr<MenuBar> Ptr;
46  typedef std::shared_ptr<const MenuBar> ConstPtr;
47 
48 
50  // Default constructor
52  MenuBar();
53 
54 
61  static MenuBar::Ptr create();
62 
63 
72  static MenuBar::Ptr copy(MenuBar::ConstPtr menuBar);
73 
74 
79  MenuBarRenderer* getSharedRenderer();
80  const MenuBarRenderer* getSharedRenderer() const;
81 
87  MenuBarRenderer* getRenderer();
88  const MenuBarRenderer* getRenderer() const;
89 
90 
99  void setSize(const Layout2d& size) override;
100  using Widget::setSize;
101 
102 
109  void addMenu(const sf::String& text);
110 
111 
129  bool addMenuItem(const sf::String& menu, const sf::String& text);
130 
131 
148  bool addMenuItem(const sf::String& text);
149 
150 
161  bool removeMenu(const sf::String& menu);
162 
163 
168  void removeAllMenus();
169 
170 
180  bool removeMenuItem(const sf::String& menu, const sf::String& menuItem);
181 
182 
190  void setTextSize(unsigned int size);
191 
192 
199  unsigned int getTextSize() const;
200 
201 
211  void setMinimumSubMenuWidth(float minimumWidth);
212 
213 
222  float getMinimumSubMenuWidth() const;
223 
224 
231  void setInvertedMenuDirection(bool invertDirection);
232 
233 
240  bool getInvertedMenuDirection() const;
241 
242 
249  std::map<sf::String, std::vector<sf::String>> getMenus() const;
250 
251 
256  void closeMenu();
257 
258 
264  void setParent(Container* parent) override;
265 
266 
273  bool mouseOnWidget(sf::Vector2f pos) const override;
274 
278  void leftMousePressed(sf::Vector2f pos) override;
279 
283  void leftMouseReleased(sf::Vector2f pos) override;
284 
288  void mouseMoved(sf::Vector2f pos) override;
289 
293  void mouseNoLongerDown() override;
294 
295 
297  private:
298 
300  // This function is called when the mouse leaves the widget. If requested, a callback will be send.
302  void mouseLeftWidget() override;
303 
304 
312  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
313 
314 
316  protected:
317 
327  Signal& getSignal(std::string signalName) override;
328 
329 
336  void rendererChanged(const std::string& property) override;
337 
338 
340  // Makes a copy of the widget
342  Widget::Ptr clone() const override
343  {
344  return std::make_shared<MenuBar>(*this);
345  }
346 
347 
349  public:
350 
355  SignalMenuItem onMenuItemClick = {"MenuItemClicked"};
356 
357 
359  protected:
360 
361  struct Menu
362  {
363  Text text;
364  std::vector<Text> menuItems;
365  int selectedMenuItem = -1;
366  };
367 
368  std::vector<Menu> m_menus;
369 
370  int m_visibleMenu = -1;
371 
372  unsigned int m_textSize = 0;
373 
374  float m_minimumSubMenuWidth = 125;
375 
376  bool m_invertedMenuDirection = false;
377 
378  Sprite m_spriteBackground;
379  Sprite m_spriteItemBackground;
380  Sprite m_spriteSelectedItemBackground;
381 
382  // Cached renderer properties
383  Color m_backgroundColorCached;
384  Color m_selectedBackgroundColorCached;
385  Color m_textColorCached;
386  Color m_selectedTextColorCached;
387  float m_distanceToSideCached = 0;
388 
390  };
391 
393 }
394 
395 
397 
398 #endif // TGUI_MENU_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Definition: MenuBarRenderer.hpp:36
Menu bar widget.
Definition: MenuBar.hpp:41
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:243
The parent class for every widget.
Definition: Widget.hpp:62
Definition: Text.hpp:41
std::shared_ptr< MenuBar > Ptr
Shared widget pointer.
Definition: MenuBar.hpp:45
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:485
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Container widget.
Definition: Container.hpp:47
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: MenuBar.hpp:342
Definition: MenuBar.hpp:361
std::shared_ptr< const MenuBar > ConstPtr
Shared constant widget pointer.
Definition: MenuBar.hpp:46