TGUI  0.7.8
MenuBar.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_MENU_BAR_HPP
27#define TGUI_MENU_BAR_HPP
28
29
30#include <TGUI/Widgets/Label.hpp>
31
33
34namespace tgui
35{
36 class MenuBarRenderer;
37
50 class TGUI_API MenuBar : public Widget
51 {
52 public:
53
54 typedef std::shared_ptr<MenuBar> Ptr;
55 typedef std::shared_ptr<const MenuBar> ConstPtr;
56
57
59 // Default constructor
61 MenuBar();
62
63
71
72
82
83
90 std::shared_ptr<MenuBarRenderer> getRenderer() const
91 {
92 return std::static_pointer_cast<MenuBarRenderer>(m_renderer);
93 }
94
95
108 virtual void setPosition(const Layout2d& position) override;
110
111
120 virtual void setSize(const Layout2d& size) override;
122
123
132 virtual void setFont(const Font& font) override;
133
134
141 void addMenu(const sf::String& text);
142
143
159 bool addMenuItem(const sf::String& menu, const sf::String& text);
160
161
176 bool addMenuItem(const sf::String& text);
177
178
189 bool removeMenu(const sf::String& menu);
190
191
197
198
208 bool removeMenuItem(const sf::String& menu, const sf::String& menuItem);
209
210
218 void setTextSize(unsigned int size);
219
220
227 unsigned int getTextSize() const
228 {
229 return m_textSize;
230 }
231
232
242 void setMinimumSubMenuWidth(float minimumWidth);
243
244
254 {
255 return m_minimumSubMenuWidth;
256 }
257
258
263 void closeMenu();
264
265
272 virtual void setOpacity(float opacity) override;
273
274
280 virtual void setParent(Container* parent) override;
281
282
286 virtual bool mouseOnWidget(float x, float y) const override;
287
291 virtual void leftMousePressed(float x, float y) override;
292
296 virtual void leftMouseReleased(float x, float y) override;
297
301 virtual void mouseMoved(float x, float y) override;
302
306 virtual void mouseNoLongerDown() override;
307
308
310 private:
311
313 // This function is called when the mouse leaves the widget. If requested, a callback will be send.
315 virtual void mouseLeftWidget() override;
316
317
319 protected:
320
321
323 // Makes a copy of the widget
325 virtual Widget::Ptr clone() const override
326 {
327 return std::make_shared<MenuBar>(*this);
328 }
329
330
343 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
344
345
347 // Draws the widget on the render target.
349 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
350
351
353 protected:
354
355 struct Menu
356 {
357 Label text;
358 std::vector<Label> menuItems;
359 int selectedMenuItem = -1;
360 };
361
362 std::vector<Menu> m_menus;
363
364 int m_visibleMenu = -1;
365
366 unsigned int m_textSize = 0;
367
368 float m_minimumSubMenuWidth = 125;
369
370 friend class MenuBarRenderer;
371
373 };
374
375
377
378 class TGUI_API MenuBarRenderer : public WidgetRenderer
379 {
380 public:
381
388 MenuBarRenderer(MenuBar* menuBar) : m_menuBar{menuBar} {}
389
390
401 virtual void setProperty(std::string property, const std::string& value) override;
402
403
415 virtual void setProperty(std::string property, ObjectConverter&& value) override;
416
417
427 virtual ObjectConverter getProperty(std::string property) const override;
428
429
436 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
437
438
445 void setBackgroundColor(const Color& backgroundColor);
446
447
454 void setTextColor(const Color& textColor);
455
456
463 void setSelectedBackgroundColor(const Color& selectedBackgroundColor);
464
465
472 void setSelectedTextColor(const Color& selectedTextColor);
473
474
481 void setDistanceToSide(float distanceToSide);
482
483
492 void setBackgroundTexture(const Texture& texture);
493
494
503 void setItemBackgroundTexture(const Texture& texture);
504
505
515
516
518 // Draws the widget on the render target.
520 void draw(sf::RenderTarget& target, sf::RenderStates states) const;
521
522
524 private:
525
527 // Makes a copy of the renderer
529 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
530
531
533 protected:
534
535 MenuBar* m_menuBar;
536
537 float m_distanceToSide = 0;
538
539 sf::Color m_textColor;
540 sf::Color m_selectedTextColor;
541
542 sf::Color m_backgroundColor;
543 sf::Color m_selectedBackgroundColor;
544
545 Texture m_backgroundTexture;
546 Texture m_itemBackgroundTexture;
547 Texture m_selectedItemBackgroundTexture;
548
549 friend class MenuBar;
550
552 };
553
555}
556
557
559
560#endif // TGUI_MENU_BAR_HPP
Implicit converter for colors.
Definition: Color.hpp:40
Container widget.
Definition: Container.hpp:48
Definition: Font.hpp:38
Label widget.
Definition: Label.hpp:50
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Definition: MenuBar.hpp:379
MenuBarRenderer(MenuBar *menuBar)
Constructor.
Definition: MenuBar.hpp:388
void setBackgroundColor(const Color &backgroundColor)
Set the background color that will be used inside the menu bar.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setDistanceToSide(float distanceToSide)
Changes the distance between the text and the side of the menu item.
void setSelectedItemBackgroundTexture(const Texture &texture)
Change the image that is used as background of the selected menu item.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setItemBackgroundTexture(const Texture &texture)
Change the image that is displayed when the tab is not selected.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
void setSelectedBackgroundColor(const Color &selectedBackgroundColor)
Set the background color of the selected text that will be used inside the menu bar.
void setSelectedTextColor(const Color &selectedTextColor)
Set the text color of the selected text that will be used inside the menu bar.
void setTextColor(const Color &textColor)
Set the text color that will be used inside the menu bar.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setBackgroundTexture(const Texture &texture)
Change the image that is used to fill the entire menu bar.
Menu bar widget.
Definition: MenuBar.hpp:51
void addMenu(const sf::String &text)
Adds a new menu.
std::shared_ptr< MenuBarRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: MenuBar.hpp:90
float getMinimumSubMenuWidth() const
Returns the distance between the text and the side of the menu item.
Definition: MenuBar.hpp:253
void closeMenu()
Closes the open menu when one of the menus is open.
std::shared_ptr< const MenuBar > ConstPtr
Shared constant widget pointer.
Definition: MenuBar.hpp:55
bool addMenuItem(const sf::String &menu, const sf::String &text)
Adds a new menu item.
bool removeMenuItem(const sf::String &menu, const sf::String &menuItem)
Removes a menu item.
void setTextSize(unsigned int size)
Changes the character size of the text.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: MenuBar.hpp:325
void removeAllMenus()
Removes all menus.
bool removeMenu(const sf::String &menu)
Removes a menu.
static MenuBar::Ptr copy(MenuBar::ConstPtr menuBar)
Makes a copy of another menu bar.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
std::shared_ptr< MenuBar > Ptr
Shared widget pointer.
Definition: MenuBar.hpp:54
void setMinimumSubMenuWidth(float minimumWidth)
Changes the minimum width of the submenus.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
static MenuBar::Ptr create()
Creates a new menu bar widget.
unsigned int getTextSize() const
Returns the character size of the text.
Definition: MenuBar.hpp:227
bool addMenuItem(const sf::String &text)
Adds a new menu item to the last added menu.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
virtual void setSize(const Layout2d &size) override
Changes the size of the menu bar.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
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
Base class for all renderer classes.
Definition: Widget.hpp:683
The parent class for every widget.
Definition: Widget.hpp:72
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34
Definition: MenuBar.hpp:356