]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIComboBox.h
13996f0da5ae64d6dd4bf2f22a9a4f7563863e1f
[irrlicht.git] / source / Irrlicht / CGUIComboBox.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_COMBO_BOX_H_INCLUDED__\r
6 #define __C_GUI_COMBO_BOX_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #include "IGUIComboBox.h"\r
10 #include "IGUIStaticText.h"\r
11 #include "irrString.h"\r
12 #include "irrArray.h"\r
13 \r
14 namespace irr\r
15 {\r
16 namespace gui\r
17 {\r
18         class IGUIButton;\r
19         class IGUIListBox;\r
20 \r
21         //! Single line edit box for editing simple text.\r
22         class CGUIComboBox : public IGUIComboBox\r
23         {\r
24         public:\r
25 \r
26                 //! constructor\r
27                 CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,\r
28                         s32 id, core::rect<s32> rectangle);\r
29 \r
30                 //! Returns amount of items in box\r
31                 u32 getItemCount() const override;\r
32 \r
33                 //! returns string of an item. the idx may be a value from 0 to itemCount-1\r
34                 const wchar_t* getItem(u32 idx) const override;\r
35 \r
36                 //! Returns item data of an item. the idx may be a value from 0 to itemCount-1\r
37                 u32 getItemData(u32 idx) const override;\r
38 \r
39                 //! Returns index based on item data\r
40                 s32 getIndexForItemData( u32 data ) const override;\r
41 \r
42                 //! adds an item and returns the index of it\r
43                 u32 addItem(const wchar_t* text, u32 data) override;\r
44 \r
45                 //! Removes an item from the combo box.\r
46                 void removeItem(u32 id) override;\r
47 \r
48                 //! deletes all items in the combo box\r
49                 void clear() override;\r
50 \r
51                 //! returns the text of the currently selected item\r
52                 const wchar_t* getText() const override;\r
53 \r
54                 //! returns id of selected item. returns -1 if no item is selected.\r
55                 s32 getSelected() const override;\r
56 \r
57                 //! sets the selected item. Set this to -1 if no item should be selected\r
58                 void setSelected(s32 idx) override;\r
59 \r
60                 //! sets the text alignment of the text part\r
61                 void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override;\r
62 \r
63                 //! Set the maximal number of rows for the selection listbox\r
64                 void setMaxSelectionRows(u32 max) override;\r
65 \r
66                 //! Get the maximal number of rows for the selection listbox\r
67                 u32 getMaxSelectionRows() const override;\r
68 \r
69                 //! called if an event happened.\r
70                 bool OnEvent(const SEvent& event) override;\r
71 \r
72                 //! draws the element and its children\r
73                 void draw() override;\r
74 \r
75         private:\r
76 \r
77                 void openCloseMenu();\r
78                 void sendSelectionChangedEvent();\r
79                 void updateListButtonWidth(s32 width);\r
80 \r
81                 IGUIButton* ListButton;\r
82                 IGUIStaticText* SelectedText;\r
83                 IGUIListBox* ListBox;\r
84                 IGUIElement *LastFocus;\r
85 \r
86 \r
87                 struct SComboData\r
88                 {\r
89                         SComboData ( const wchar_t * text, u32 data )\r
90                                 : Name (text), Data ( data ) {}\r
91 \r
92                         core::stringw Name;\r
93                         u32 Data;\r
94                 };\r
95                 core::array< SComboData > Items;\r
96 \r
97                 s32 Selected;\r
98                 EGUI_ALIGNMENT HAlign, VAlign;\r
99                 u32 MaxSelectionRows;\r
100                 bool HasFocus;\r
101                 IGUIFont* ActiveFont;\r
102         };\r
103 \r
104 \r
105 } // end namespace gui\r
106 } // end namespace irr\r
107 \r
108 #endif // __C_GUI_COMBO_BOX_H_INCLUDED__\r