TGUI  v0.6.10
ComboBox.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_COMBO_BOX_HPP
27 #define TGUI_COMBO_BOX_HPP
28 
29 
30 #include <TGUI/ListBox.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API ComboBox : public Widget, public WidgetBorders
39  {
40  public:
41 
43 
44 
49  ComboBox();
50 
51 
58  ComboBox(const ComboBox& copy);
59 
60 
65  virtual ~ComboBox();
66 
67 
76  ComboBox& operator= (const ComboBox& right);
77 
78 
81  // Makes a copy of the widget by calling the copy constructor.
82  // This function calls new and if you use this function then you are responsible for calling delete.
84  virtual ComboBox* clone();
85 
86 
96  bool load(const std::string& configFileFilename, const std::string& sectionName = "ComboBox");
97 
98 
106  const std::string& getLoadedConfigFile() const;
107 
108 
118  void setSize(float width, float height);
119 
120 
129  virtual sf::Vector2f getSize() const;
130 
131 
140  virtual sf::Vector2f getFullSize() const;
141 
142 
154  void setItemsToDisplay(unsigned int nrOfItemsInListToDisplay);
155 
156 
168  unsigned int getItemsToDisplay() const;
169 
170 
181  void changeColors(const sf::Color& backgroundColor = sf::Color::White,
182  const sf::Color& textColor = sf::Color::Black,
183  const sf::Color& selectedBackgroundColor = sf::Color(50, 100, 200),
184  const sf::Color& selectedTextColor = sf::Color::White,
185  const sf::Color& borderColor = sf::Color::Black);
186 
193  void setBackgroundColor(const sf::Color& backgroundColor);
194 
201  void setTextColor(const sf::Color& textColor);
202 
209  void setSelectedBackgroundColor(const sf::Color& selectedBackgroundColor);
210 
217  void setSelectedTextColor(const sf::Color& selectedTextColor);
218 
225  void setBorderColor(const sf::Color& borderColor);
226 
227 
234  const sf::Color& getBackgroundColor() const;
235 
242  const sf::Color& getTextColor() const;
243 
250  const sf::Color& getSelectedBackgroundColor() const;
251 
258  const sf::Color& getSelectedTextColor() const;
259 
266  const sf::Color& getBorderColor() const;
267 
268 
278  void setTextFont(const sf::Font& font);
279 
280 
287  const sf::Font* getTextFont() const;
288 
289 
299  virtual void setBorders(unsigned int leftBorder = 0,
300  unsigned int topBorder = 0,
301  unsigned int rightBorder = 0,
302  unsigned int bottomBorder = 0);
303 
304 
323  int addItem(const sf::String& itemName, int id = 0);
324 
325 
343  bool setSelectedItem(const sf::String& itemName);
344 
362  bool setSelectedItem(int index);
363 
364 
371  void deselectItem();
372 
373 
384  bool removeItem(unsigned int index);
385 
386 
397  bool removeItem(const sf::String& itemName);
398 
399 
408  unsigned int removeItemsById(int id);
409 
410 
415  void removeAllItems();
416 
417 
429  sf::String getItem(unsigned int index) const;
430 
431 
445  int getItemIndex(const sf::String& itemName) const;
446 
447 
454  std::vector<sf::String>& getItems() const;
455 
456 
466  sf::String getSelectedItem() const;
467 
468 
480  int getSelectedItemIndex() const;
481 
482 
490  int getSelectedItemId() const;
491 
492 
502  bool changeItem(unsigned int index, const sf::String& newValue);
503 
504 
514  unsigned int changeItems(const sf::String& originalValue, const sf::String& newValue);
515 
516 
526  unsigned int changeItemsById(int id, const sf::String& newValue);
527 
528 
540  bool setScrollbar(const std::string& scrollbarConfigFileFilename);
541 
542 
549  void removeScrollbar();
550 
551 
561  void setMaximumItems(unsigned int maximumItems = 0);
562 
563 
571  unsigned int getMaximumItems() const;
572 
573 
584  virtual void setTransparency(unsigned char transparency);
585 
586 
590  virtual bool mouseOnWidget(float x, float y);
591 
595  virtual void leftMousePressed(float x, float y);
596 
600  virtual void leftMouseReleased(float x, float y);
601 
605  virtual void mouseWheelMoved(int delta, int x, int y);
606 
610  virtual void mouseNoLongerDown();
611 
612 
615  // This function is a (slow) way to set properties on the widget, no matter what type it is.
616  // When the requested property doesn't exist in the widget then the functions will return false.
618  virtual bool setProperty(std::string property, const std::string& value);
619 
622  // This function is a (slow) way to get properties of the widget, no matter what type it is.
623  // When the requested property doesn't exist in the widget then the functions will return false.
625  virtual bool getProperty(std::string property, std::string& value) const;
626 
627 
630  // Returns a list of all properties that can be used in setProperty and getProperty.
631  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
633  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
634 
635 
637  protected:
638 
641  // This function is called when the widget is added to a container.
643  virtual void initialize(Container *const container);
644 
645 
648  // Shows the list of items.
650  void showListBox();
651 
652 
655  // Hides the list of items.
657  void hideListBox();
658 
659 
662  // Called by the internal ListBox when a different item is selected.
664  void newItemSelectedCallbackFunction();
665 
666 
669  // Called by the internal ListBox when it gets unfocused.
671  void listBoxUnfocusedCallbackFunction();
672 
673 
676  // Draws the widget on the render target.
678  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
679 
680 
682  public:
683 
688  {
689  ItemSelected = WidgetCallbacksCount * 1,
690  AllComboBoxCallbacks = WidgetCallbacksCount * 2 - 1,
691  ComboBoxCallbacksCount = WidgetCallbacksCount * 2
692  };
693 
694 
696  protected:
697 
698  std::string m_LoadedConfigFile;
699 
700  bool m_SeparateHoverImage;
701 
702  // The number of items to display. If there is a scrollbar then you can scroll to see the other.
703  // If there is no scrollbar then this will be the maximum amount of items.
704  unsigned int m_NrOfItemsToDisplay;
705 
706  // Internally a list box is used to store all items
707  ListBox::Ptr m_ListBox;
708 
709  // The textures for the arrow image
710  Texture m_TextureArrowUpNormal;
711  Texture m_TextureArrowUpHover;
712  Texture m_TextureArrowDownNormal;
713  Texture m_TextureArrowDownHover;
714 
716  };
717 
719 }
720 
722 
723 #endif // TGUI_COMBO_BOX_HPP
724 
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
The parent class for every widget.
Definition: Widget.hpp:45
Definition: ComboBox.hpp:38
Definition: TextureManager.hpp:52
ComboBoxCallbacks
Defines specific triggers to ComboBox.
Definition: ComboBox.hpp:687
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: SharedWidgetPtr.hpp:44