Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CList.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19 GUI Object - List [box]
20 
21 --Overview--
22 
23  GUI Object for creating lists of information, wherein one
24  of the elements can be selected. A scroll-bar will aid
25  when there's too much information to be displayed at once.
26 
27 --More info--
28 
29  Check GUI.h
30 
31 */
32 
33 #ifndef INCLUDED_CLIST
34 #define INCLUDED_CLIST
35 
36 //--------------------------------------------------------
37 // Includes / Compiler directives
38 //--------------------------------------------------------
39 
40 #include "IGUIScrollBar.h"
41 
42 //--------------------------------------------------------
43 // Macros
44 //--------------------------------------------------------
45 
46 //--------------------------------------------------------
47 // Types
48 //--------------------------------------------------------
49 
50 //--------------------------------------------------------
51 // Declarations
52 //--------------------------------------------------------
53 
54 
55 /**
56  * Create a list of elements, where one can be selected
57  * by the user. The control will use a pre-processed
58  * text-object for each element, which will be managed
59  * by the IGUITextOwner structure.
60  *
61  * A scroll-bar will appear when needed. This will be
62  * achieve with the IGUIScrollBarOwner structure.
63  *
64  */
65 
66 class CList : public IGUIScrollBarOwner, public IGUITextOwner
67 {
69 
70 public:
71  CList();
72  virtual ~CList();
73 
74  /**
75  * @see IGUIObject#ResetStates()
76  */
78 
79  /**
80  * Adds an item last to the list.
81  */
82  virtual void AddItem(const CStrW& str, const CStrW& data);
83 
84 protected:
85  /**
86  * Sets up text, should be called every time changes has been
87  * made that can change the visual.
88  */
89  void SetupText();
90 
91  /**
92  * @see IGUIObject#HandleMessage()
93  */
94  virtual void HandleMessage(SGUIMessage &Message);
95 
96  /**
97  * Handle events manually to catch keyboard inputting.
98  */
99  virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev);
100 
101  /**
102  * Draws the List box
103  */
104  virtual void Draw();
105 
106  /**
107  * Easy select elements functions
108  */
109  virtual void SelectNextElement();
110  virtual void SelectPrevElement();
111  virtual void SelectFirstElement();
112  virtual void SelectLastElement();
113 
114  /**
115  * Handle the <item> tag.
116  */
117  virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile);
118 
119  // Called every time the auto-scrolling should be checked.
120  void UpdateAutoScroll();
121 
122  // Extended drawing interface, this is so that classes built on the this one
123  // can use other sprite names.
124  void DrawList(const int &selected, const CStr& _sprite,
125  const CStr& _sprite_selected, const CStr& _textcolor);
126 
127  // Get the area of the list. This is so that it can easily be changed, like in CDropDown
128  // where the area is not equal to m_CachedActualSize.
129  virtual CRect GetListRect() const { return m_CachedActualSize; }
130 
131  // Returns whether SetupText() has run since the last message was received
132  // (and thus whether list items have possibly changed).
133  virtual bool GetModified() const { return m_Modified; }
134 
135  // List of items.
136  //CGUIList m_List;
137 
138  /**
139  * List of each element's relative y position. Will be
140  * one larger than m_Items, because it will end with the
141  * bottom of the last element. First element will always
142  * be zero, but still stored for easy handling.
143  */
144  std::vector<float> m_ItemsYPositions;
145 
146 private:
147  // Whether the list's items have been modified since last handling a message.
149 };
150 
151 #endif
virtual InReaction ManuallyHandleEvent(const SDL_Event_ *ev)
Handle events manually to catch keyboard inputting.
Definition: CList.cpp:278
void DrawList(const int &selected, const CStr &_sprite, const CStr &_sprite_selected, const CStr &_textcolor)
Definition: CList.cpp:327
virtual void AddItem(const CStrW &str, const CStrW &data)
Adds an item last to the list.
Definition: CList.cpp:425
void SetupText()
Sets up text, should be called every time changes has been made that can change the visual...
Definition: CList.cpp:77
virtual void HandleMessage(SGUIMessage &Message)
Definition: CList.cpp:155
virtual void Draw()
Draws the List box.
Definition: CList.cpp:319
virtual bool GetModified() const
Definition: CList.h:133
virtual void ResetStates()
Definition: CList.h:77
Framework for handling Output text.
Definition: IGUITextOwner.h:60
CList()
Definition: CList.cpp:36
InReaction
Definition: input.h:34
std::vector< float > m_ItemsYPositions
List of each element&#39;s relative y position.
Definition: CList.h:144
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Definition: IGUIObject.h:434
virtual ~CList()
Definition: CList.cpp:73
virtual CRect GetListRect() const
Definition: CList.h:129
Create a list of elements, where one can be selected by the user.
Definition: CList.h:66
virtual void ResetStates()
virtual void SelectNextElement()
Easy select elements functions.
Definition: CList.cpp:459
virtual void SelectLastElement()
Definition: CList.cpp:505
virtual void SelectFirstElement()
Definition: CList.cpp:494
virtual bool HandleAdditionalChildren(const XMBElement &child, CXeromyces *pFile)
Handle the &lt;item&gt; tag.
Definition: CList.cpp:443
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:106
Base-class this if you want an object to contain one, or several, scroll-bars.
void UpdateAutoScroll()
Definition: CList.cpp:519
bool m_Modified
Definition: CList.h:148
#define GUI_OBJECT(obj)
Definition: GUIbase.h:62
virtual void SelectPrevElement()
Definition: CList.cpp:478
Rectangle class used for screen rectangles.
Definition: Overlay.h:71