TGUI  v0.6.10
MenuBar.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_MENU_BAR_HPP
27 #define TGUI_MENU_BAR_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API MenuBar : public Widget
39  {
40  public:
41 
43 
44 
49  MenuBar();
50 
51 
53  // Makes a copy of the widget by calling the copy constructor.
54  // This function calls new and if you use this function then you are responsible for calling delete.
56  virtual MenuBar* clone();
57 
58 
68  bool load(const std::string& configFileFilename, const std::string& sectionName = "MenuBar");
69 
70 
78  const std::string& getLoadedConfigFile() const;
79 
80 
90  virtual void setSize(float width, float height);
91 
92 
102  virtual sf::Vector2f getSize() const;
103 
104 
111  void addMenu(const sf::String& text);
112 
113 
129  bool addMenuItem(const sf::String& menu, const sf::String& text);
130 
131 
142  bool removeMenu(const sf::String& menu);
143 
144 
149  void removeAllMenus();
150 
151 
161  bool removeMenuItem(const sf::String& menu, const sf::String& menuItem);
162 
163 
173  void changeColors(const sf::Color& backgroundColor = sf::Color::White,
174  const sf::Color& textColor = sf::Color::Black,
175  const sf::Color& selectedBackgroundColor = sf::Color(50, 100, 200),
176  const sf::Color& selectedTextColor = sf::Color::White);
177 
178 
185  void setBackgroundColor(const sf::Color& backgroundColor);
186 
187 
194  void setTextColor(const sf::Color& textColor);
195 
196 
203  void setSelectedBackgroundColor(const sf::Color& selectedBackgroundColor);
204 
205 
212  void setSelectedTextColor(const sf::Color& selectedTextColor);
213 
214 
221  const sf::Color& getBackgroundColor() const;
222 
223 
230  const sf::Color& getTextColor() const;
231 
232 
239  const sf::Color& getSelectedBackgroundColor() const;
240 
241 
248  const sf::Color& getSelectedTextColor() const;
249 
250 
260  void setTextFont(const sf::Font& font);
261 
262 
269  const sf::Font* getTextFont() const;
270 
271 
279  void setTextSize(unsigned int size);
280 
281 
288  unsigned int getTextSize() const;
289 
290 
297  void setDistanceToSide(unsigned int distanceToSide);
298 
299 
306  unsigned int getDistanceToSide() const;
307 
308 
318  void setMinimumSubMenuWidth(unsigned int minimumWidth);
319 
320 
329  unsigned int getMinimumSubMenuWidth() const;
330 
331 
335  virtual bool mouseOnWidget(float x, float y);
336 
340  virtual void leftMousePressed(float x, float y);
341 
345  virtual void leftMouseReleased(float x, float y);
346 
350  virtual void mouseMoved(float x, float y);
351 
355  virtual void mouseNoLongerDown();
356 
357 
360  // This function is a (slow) way to set properties on the widget, no matter what type it is.
361  // When the requested property doesn't exist in the widget then the functions will return false.
363  virtual bool setProperty(std::string property, const std::string& value);
364 
367  // This function is a (slow) way to get properties of the widget, no matter what type it is.
368  // When the requested property doesn't exist in the widget then the functions will return false.
370  virtual bool getProperty(std::string property, std::string& value) const;
371 
372 
375  // Returns a list of all properties that can be used in setProperty and getProperty.
376  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
378  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
379 
380 
382  protected:
383 
385  // This function is called when the widget is added to a container.
387  virtual void initialize(Container *const container);
388 
389 
391  // Draws the widget on the render target.
393  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
394 
395 
397  public:
398 
403  {
404  MenuItemClicked = WidgetCallbacksCount * 1,
405  AllMenuBarCallbacks = WidgetCallbacksCount * 2 - 1,
406  MenuBarCallbacksCount = WidgetCallbacksCount * 2
407  };
408 
409 
411  protected:
412 
413  struct Menu
414  {
415  sf::Text text;
416  std::vector<sf::Text> menuItems;
417  int selectedMenuItem;
418  };
419 
420  std::string m_LoadedConfigFile;
421 
422  std::vector<Menu> m_Menus;
423 
424  int m_VisibleMenu;
425 
426  const sf::Font* m_TextFont;
427 
428  sf::Vector2f m_Size;
429 
430  unsigned int m_TextSize;
431 
432  unsigned int m_DistanceToSide;
433 
434  unsigned int m_MinimumSubMenuWidth;
435 
436  sf::Color m_BackgroundColor;
437  sf::Color m_TextColor;
438  sf::Color m_SelectedBackgroundColor;
439  sf::Color m_SelectedTextColor;
440 
442  };
443 
445 }
446 
447 
449 
450 #endif // TGUI_MENU_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Definition: MenuBar.hpp:38
MenuBarCallbacks
Defines specific triggers to MenuBar.
Definition: MenuBar.hpp:402
The parent class for every widget.
Definition: Widget.hpp:45
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: MenuBar.hpp:413
Definition: SharedWidgetPtr.hpp:44