xoreos  0.0.5
listbox.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef ENGINES_NWN_GUI_WIDGETS_LISTBOX_H
26 #define ENGINES_NWN_GUI_WIDGETS_LISTBOX_H
27 
28 #include <vector>
29 
30 #include "src/common/types.h"
31 #include "src/common/scopedptr.h"
32 
34 
36 
37 namespace Common {
38  class UString;
39 }
40 
41 namespace Engines {
42 
43 class GUI;
44 
45 namespace NWN {
46 
47 class WidgetButton;
48 class WidgetScrollbar;
49 
51 class WidgetListItem : public NWNWidget {
52 public:
55 
56  bool operator<(const WidgetListItem &item) const;
57  void mouseUp (uint8 state, float x, float y);
58  void mouseWheel(uint8 state, int x, int y);
59 
60  void mouseDblClick(uint8 state, float x, float y);
61 
62  void select();
63 
64  size_t getItemNumber() const;
65 
66 protected:
67  bool getState();
68 
69  virtual bool activate();
70  virtual bool deactivate();
71 
73 
74 private:
75  size_t _itemNumber;
76  bool _state;
77 
78  friend class WidgetListBox;
79 };
80 
83 public:
85  const Common::UString &text, float spacing = 0.0f);
87 
88  void show();
89  void hide();
90 
91  void setPosition(float x, float y, float z);
92 
93  void setUnselectedColor(float r, float g, float b, float a);
94  void setSelectedColor(float r, float g, float b, float a);
95 
96  float getWidth () const;
97  float getHeight() const;
98 
99  void setTag(const Common::UString &tag);
100 
101 protected:
102  bool activate();
103  bool deactivate();
104 
105 private:
107 
108  float _uR, _uG, _uB, _uA;
109  float _sR, _sG, _sB, _sA;
110 
111  float _fontHeight;
112  float _spacing;
113 };
114 
116 class WidgetListBox : public ModelWidget {
117 public:
118  enum Mode {
121  };
122 
123  WidgetListBox(::Engines::GUI &gui, const Common::UString &tag,
124  const Common::UString &model);
125  ~WidgetListBox();
126 
127  Mode getMode() const;
128  void setMode(Mode mode);
129 
130  void show();
131  void hide();
132 
133  void setPosition(float x, float y, float z);
134 
135  float getContentWidth () const;
136  float getContentHeight() const;
137 
138  void lock();
139  void clear();
140  void reserve(size_t n);
141  void add(WidgetListItem *item, bool noTag = false);
142  void remove(WidgetListItem *item);
143  void unlock();
144  void sortByTag();
145 
146  void setText(const Common::UString &font, const Common::UString &text,
147  float spacing = 0.0f);
148 
149  void select(size_t item);
150  size_t getSelected() const;
152  void deselect();
153 
155  void setStartItem(size_t firstItem);
157  size_t getStartItem() const;
158 
160  std::vector<WidgetListItem *>::iterator begin();
162  std::vector<WidgetListItem *>::iterator end();
163 
164  bool wasDblClicked();
165 
166  void mouseDown(uint8 state, float x, float y);
167  void mouseWheel(uint8 state, int x, int y);
168 
169  void subActive(Widget &widget);
170 
171 protected:
172  virtual void updateScrollbarLength();
173  virtual void updateScrollbarPosition();
174 
175  virtual void scrollUp(size_t n);
176  virtual void scrollDown(size_t n);
177 
178  virtual void updateVisible();
179 
180  float _contentX;
181  float _contentY;
182  float _contentZ;
183 
186 
187  std::vector<WidgetListItem *> _items;
188  std::vector<WidgetListItem *> _visibleItems;
189 
190  size_t _startItem;
195 
196  bool _locked;
197 
198 private:
200 
203 
204  void getProperties();
205  void createScrollbar();
206  void itemDblClicked();
207 
208  friend class WidgetListItem;
209 };
210 
211 } // End of namespace NWN
212 
213 } // End of namespace Engines
214 
215 #endif // ENGINES_NWN_GUI_WIDGETS_LISTBOX_H
WidgetButton * _up
Definition: listbox.h:192
float getHeight() const
Get the widget&#39;s height.
Definition: listbox.cpp:201
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
A NWN scrollbar widget.
Definition: scrollbar.h:95
size_t getItemNumber() const
Definition: listbox.cpp:101
void subActive(Widget &widget)
A sub-widget was activated.
Definition: listbox.cpp:670
void add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
uint8_t uint8
Definition: types.h:200
bool operator<(const WidgetListItem &item) const
Definition: listbox.cpp:58
WidgetButton * _down
Definition: listbox.h:193
WidgetListItemTextLine(::Engines::GUI &gui, const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: listbox.cpp:144
Base class for all widgets in NWN.
Definition: nwnwidget.h:45
float getContentWidth() const
Definition: listbox.cpp:373
std::vector< WidgetListItem * >::iterator begin()
Get begin iterator from all the items in WidgetListBox.
Definition: listbox.cpp:654
WidgetListItem * getSelectedItem() const
Definition: listbox.cpp:630
WidgetListItem(::Engines::GUI &gui)
Definition: listbox.cpp:52
void hide()
Hide the widget.
Definition: listbox.cpp:332
An item widget within a NWN listbox widget.
Definition: listbox.h:51
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: listbox.cpp:170
A simple scoped smart pointer template.
virtual void updateVisible()
Definition: listbox.cpp:560
std::vector< WidgetListItem * > _items
Definition: listbox.h:187
void mouseWheel(uint8 state, int x, int y)
A mouse wheel was used on the widget.
Definition: listbox.cpp:725
A NWN button widget.
Definition: button.h:39
A GUI.
Definition: gui.h:43
size_t getSelected() const
Definition: listbox.cpp:626
void setText(const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: listbox.cpp:523
WidgetScrollbar * _scrollbar
Definition: listbox.h:194
A NWN model widget.
virtual void updateScrollbarPosition()
Definition: listbox.cpp:549
Basic Aurora graphics types.
virtual void updateScrollbarLength()
Definition: listbox.cpp:539
void setMode(Mode mode)
Definition: listbox.cpp:313
void setUnselectedColor(float r, float g, float b, float a)
Definition: listbox.cpp:177
WidgetListBox(::Engines::GUI &gui, const Common::UString &tag, const Common::UString &model)
Definition: listbox.cpp:232
std::vector< WidgetListItem * >::iterator end()
Get end iterator from all the items in WidgetListBox.
Definition: listbox.cpp:658
Low-level type definitions to handle fixed width types portably.
A NWN listbox widget.
Definition: listbox.h:116
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: listbox.cpp:347
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
Definition: listbox.cpp:705
virtual bool deactivate()
Definition: listbox.cpp:124
void reserve(size_t n)
Definition: listbox.cpp:405
Common::ScopedPtr< Graphics::Aurora::Text > _text
Definition: listbox.h:106
void mouseDblClick(uint8 state, float x, float y)
A mouse button was double-clicked on the widget.
Definition: listbox.cpp:72
virtual void scrollUp(size_t n)
Definition: listbox.cpp:592
A widget in a GUI.
Definition: widget.h:40
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: listbox.cpp:208
void show()
Show the widget.
Definition: listbox.cpp:162
A NWN model widget.
Definition: modelwidget.h:45
void select(size_t item)
Definition: listbox.cpp:618
void setSelectedColor(float r, float g, float b, float a)
Definition: listbox.cpp:187
float getContentHeight() const
Definition: listbox.cpp:377
void signalGroupMemberActive()
A fellow group member signaled that it is now active.
Definition: listbox.cpp:137
float getWidth() const
Get the widget&#39;s width.
Definition: listbox.cpp:197
void show()
Show the widget.
Definition: listbox.cpp:317
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: listbox.cpp:62
size_t getStartItem() const
Get the first item shown in the list.
Definition: listbox.cpp:650
void mouseWheel(uint8 state, int x, int y)
A mouse wheel was used on the widget.
Definition: listbox.cpp:83
void hide()
Hide the widget.
Definition: listbox.cpp:166
std::vector< WidgetListItem * > _visibleItems
Definition: listbox.h:188
virtual void scrollDown(size_t n)
Definition: listbox.cpp:605
void setStartItem(size_t firstItem)
Set the first item to show in the list.
Definition: listbox.cpp:643
A text line widget within a NWN listbox widget.
Definition: listbox.h:82