TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
ComboBox.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
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_INCLUDED_
27 #define _TGUI_COMBO_BOX_INCLUDED_
28 
30 
31 namespace tgui
32 {
34 
35  struct TGUI_API ComboBox : public OBJECT, OBJECT_BORDERS
36  {
40  ComboBox();
41 
42 
46  ComboBox(const ComboBox& copy);
47 
48 
52  virtual ~ComboBox();
53 
54 
58  ComboBox& operator= (const ComboBox& right);
59 
60 
64  virtual void initialize();
65 
66 
70  virtual ComboBox* clone();
71 
72 
91  virtual bool load(const std::string& comboBoxPathname,
92  float width,
93  float height,
94  unsigned int nrOfItemsInListToDisplay = 10,
95  const std::string& scrollbarPathname = "");
96 
97 
104  virtual void setSize(float width, float height);
105 
106 
110  virtual Vector2u getSize() const;
111 
112 
116  virtual Vector2f getScaledSize() const;
117 
118 
124  virtual std::string getLoadedPathname() const;
125 
126 
132  virtual std::string getLoadedScrollbarPathname() const;
133 
134 
141  virtual void setItemsToDisplay(unsigned int nrOfItemsInListToDisplay);
142 
149  virtual unsigned int getItemsToDisplay() const;
150 
151 
161  virtual void changeColors(const sf::Color& backgroundColor = sf::Color::White,
162  const sf::Color& textColor = sf::Color::Black,
163  const sf::Color& selectedBackgroundColor = sf::Color(50, 100, 200),
164  const sf::Color& selectedTextColor = sf::Color::White,
165  const sf::Color& borderColor = sf::Color::Black);
166 
172  virtual void setBackgroundColor(const sf::Color& backgroundColor);
173 
179  virtual void setTextColor(const sf::Color& textColor);
180 
186  virtual void setSelectedBackgroundColor(const sf::Color& selectedBackgroundColor);
187 
193  virtual void setSelectedTextColor(const sf::Color& selectedTextColor);
194 
200  virtual void setBorderColor(const sf::Color& borderColor);
201 
202 
206  virtual const sf::Color& getBackgroundColor() const;
207 
211  virtual const sf::Color& getTextColor() const;
212 
216  virtual const sf::Color& getSelectedBackgroundColor() const;
217 
221  virtual const sf::Color& getSelectedTextColor() const;
222 
226  virtual const sf::Color& getBorderColor() const;
227 
228 
232  virtual void setTextFont(const sf::Font& font);
233 
237  virtual const sf::Font* getTextFont() const;
238 
239 
248  virtual void setBorders(unsigned int leftBorder = 0,
249  unsigned int topBorder = 0,
250  unsigned int rightBorder = 0,
251  unsigned int bottomBorder = 0);
252 
253 
270  virtual unsigned int addItem(const sf::String& itemName);
271 
272 
287  virtual bool setSelectedItem(const sf::String& itemName);
288 
304  virtual bool setSelectedItem(unsigned int id);
305 
306 
310  virtual void removeItem(unsigned int id);
311 
312 
316  virtual void removeItem(const sf::String& itemName);
317 
318 
322  virtual void removeAllItems();
323 
324 
332  virtual sf::String getItem(unsigned int id) const;
333 
334 
344  virtual unsigned int getItemID(const sf::String& itemName) const;
345 
346 
350  virtual std::vector<sf::String>& getItems() const;
351 
352 
360  virtual sf::String getSelectedItem() const;
361 
362 
372  virtual unsigned int getSelectedItemID() const;
373 
374 
378  virtual bool setScrollbar(const std::string& scrollbarPathname);
379 
380 
386  virtual void removeScrollbar();
387 
388 
395  virtual void setMaximumItems(unsigned int maximumItems = 0);
396 
403  virtual unsigned int getMaximumItems() const;
404 
405 
407  // These functions are used to receive callback from EventManager.
408  // You normally don't need them, but you can use them to simulate an event.
410  virtual bool mouseOnObject(float x, float y);
411  virtual void leftMousePressed(float x, float y);
412  virtual void leftMouseReleased(float x, float y);
413  virtual void mouseMoved(float x, float y);
414  virtual void mouseWheelMoved(int delta);
415  virtual void mouseNoLongerDown();
416 
417 
419  protected:
420 
421 
423  // Because this struct is derived from sf::Drawable, you can just call the Draw function from your sf::RenderTarget.
424  // This function will be called and it will draw the object on the render target.
426  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
427 
428 
430  protected:
431 
432  // This boolean becomes true when you clicked on the combo box, when the list should be shown
433  bool m_ShowList;
434 
435  // When the mouse is on top of the object, it might be on the list box part.
436  bool m_MouseOnListBox;
437 
438  // The number of items to display. If there is a scrollbar then you can scroll to see the other.
439  // If there is no scrollbar then this will be the maximum amount of items.
440  unsigned int m_NrOfItemsToDisplay;
441 
442  // Internally a list box is used to store all items
443  ListBox* m_ListBox;
444 
445  // The pathname of the loaded scrollbar (if there is one)
446  std::string m_LoadedScrollbarPathname;
447 
448  // The textures for the arrow image
449  sf::Texture* m_TextureNormal;
450  sf::Texture* m_TextureHover;
451 
452  // The sprites for the arrow image
453  sf::Sprite m_SpriteNormal;
454  sf::Sprite m_SpriteHover;
455 
456  // The pathname that was used to load the combo box
457  std::string m_LoadedPathname;
458 
460  };
461 
463 }
464 
466 
467 #endif //_TGUI_COMBO_BOX_INCLUDED_
468 
The parent struct for every object.
Definition: Objects.hpp:36
Parent struct for every object that has borders.
Definition: Objects.hpp:299
Definition: ListBox.hpp:37
Definition: ComboBox.hpp:35