TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
ListBox.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_LISTBOX_INCLUDED_
27 #define _TGUI_LISTBOX_INCLUDED_
28 
30 
32 
33 namespace tgui
34 {
36 
37  struct TGUI_API ListBox : public OBJECT, OBJECT_BORDERS
38  {
42  ListBox();
43 
44 
48  ListBox(const ListBox& copy);
49 
50 
54  virtual ~ListBox();
55 
56 
60  ListBox& operator= (const ListBox& right);
61 
62 
66  virtual void initialize();
67 
68 
72  virtual ListBox* clone();
73 
74 
91  virtual bool load(unsigned int width,
92  unsigned int height,
93  const std::string& scrollbarPathname = "",
94  unsigned int itemHeight = 0);
95 
96 
103  virtual void setSize(float width, float height);
104 
105 
109  virtual Vector2u getSize() const;
110 
111 
115  virtual Vector2f getScaledSize() const;
116 
117 
123  virtual std::string getLoadedScrollbarPathname() const;
124 
125 
135  virtual void changeColors(const sf::Color& backgroundColor = sf::Color::White,
136  const sf::Color& textColor = sf::Color::Black,
137  const sf::Color& selectedBackgroundColor = sf::Color(50, 100, 200),
138  const sf::Color& selectedTextColor = sf::Color::White,
139  const sf::Color& borderColor = sf::Color::Black);
140 
146  virtual void setBackgroundColor(const sf::Color& backgroundColor);
147 
153  virtual void setTextColor(const sf::Color& textColor);
154 
160  virtual void setSelectedBackgroundColor(const sf::Color& selectedBackgroundColor);
161 
167  virtual void setSelectedTextColor(const sf::Color& selectedTextColor);
168 
174  virtual void setBorderColor(const sf::Color& borderColor);
175 
176 
180  virtual const sf::Color& getBackgroundColor() const;
181 
185  virtual const sf::Color& getTextColor() const;
186 
190  virtual const sf::Color& getSelectedBackgroundColor() const;
191 
195  virtual const sf::Color& getSelectedTextColor() const;
196 
200  virtual const sf::Color& getBorderColor() const;
201 
202 
209  virtual void setTextFont(const sf::Font& font);
210 
211 
215  virtual const sf::Font* getTextFont() const;
216 
217 
232  virtual unsigned int addItem(const sf::String& itemName);
233 
234 
248  virtual bool setSelectedItem(const sf::String& itemName);
249 
264  virtual bool setSelectedItem(unsigned int id);
265 
266 
270  virtual void removeItem(unsigned int id);
271 
272 
276  virtual void removeItem(const sf::String& itemName);
277 
278 
282  virtual void removeAllItems();
283 
284 
292  virtual sf::String getItem(unsigned int id) const;
293 
294 
304  virtual unsigned int getItemID(const sf::String& itemName) const;
305 
306 
310  virtual std::vector<sf::String>& getItems();
311 
312 
320  virtual sf::String getSelectedItem() const;
321 
322 
332  virtual unsigned int getSelectedItemID() const;
333 
334 
338  virtual bool setScrollbar(const std::string& scrollbarPathname);
339 
340 
346  virtual void removeScrollbar();
347 
348 
355  virtual void setItemHeight(unsigned int itemHeight);
356 
360  virtual unsigned int getItemHeight() const;
361 
362 
369  virtual void setMaximumItems(unsigned int maximumItems = 0);
370 
374  virtual unsigned int getMaximumItems() const;
375 
376 
385  virtual void setBorders(unsigned int leftBorder = 0,
386  unsigned int topBorder = 0,
387  unsigned int rightBorder = 0,
388  unsigned int bottomBorder = 0);
389 
390 
392  // These functions are used to receive callback from the EventManager.
393  // You normally don't need them, but you can use them to simulate an event.
395  virtual bool mouseOnObject(float x, float y);
396  virtual void leftMousePressed(float x, float y);
397  virtual void leftMouseReleased(float x, float y);
398  virtual void mouseMoved(float x, float y);
399  virtual void mouseWheelMoved(int delta);
400  virtual void mouseNotOnObject();
401  virtual void mouseNoLongerDown();
402 
403 
405  protected:
406 
408  // Because this struct is derived from sf::Drawable, you can just call the draw function from your sf::RenderTarget.
409  // This function will be called and it will draw the list box on the render target.
411  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
412 
413 
415  protected:
416 
417  // This contains the different items in the list box
418  std::vector<sf::String> m_Items;
419 
420  // What is the id of the selected item?
421  unsigned int m_SelectedItem;
422 
423  // The size must be stored
424  Vector2u m_Size;
425  unsigned int m_ItemHeight;
426 
427  unsigned int m_TextSize;
428 
429  // This will store the maximum number of items in the list box (zero by default, meaning that there is no limit)
430  unsigned int m_MaxItems;
431 
432  // When there are too many items a scrollbar will be shown
433  Scrollbar* m_Scroll;
434 
435  // The pathname of the loaded scrollbar (if there is one)
436  std::string m_LoadedScrollbarPathname;
437 
438  // These colors are used to draw the list box
439  sf::Color m_BackgroundColor;
440  sf::Color m_TextColor;
441  sf::Color m_SelectedBackgroundColor;
442  sf::Color m_SelectedTextColor;
443  sf::Color m_BorderColor;
444 
445  // The font used to draw the text
446  sf::Font m_TextFont;
447 
448  // ComboBox contains a list box internally and it should be able to adjust it.
449  friend struct ComboBox;
450 
452  };
453 
455 }
456 
458 
459 #endif //_TGUI_LISTBOX_INCLUDED_
The parent struct for every object.
Definition: Objects.hpp:36
Definition: Scrollbar.hpp:35
Parent struct for every object that has borders.
Definition: Objects.hpp:299
Definition: ListBox.hpp:37
Definition: ComboBox.hpp:35