Pyrogenesis  trunk
CList.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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 #ifndef INCLUDED_CLIST
19 #define INCLUDED_CLIST
20 
21 #include "IGUIScrollBar.h"
22 
23 /**
24  * Create a list of elements, where one can be selected
25  * by the user. The control will use a pre-processed
26  * text-object for each element, which will be managed
27  * by the IGUITextOwner structure.
28  *
29  * A scroll-bar will appear when needed. This will be
30  * achieved with the IGUIScrollBarOwner structure.
31  */
32 class CList : public IGUIScrollBarOwner, public IGUITextOwner
33 {
35 
36 public:
37  CList();
38  virtual ~CList();
39 
40  /**
41  * @see IGUIObject#ResetStates()
42  */
44 
45  /**
46  * Adds an item last to the list.
47  */
48  virtual void AddItem(const CStrW& str, const CStrW& data);
49 
50 protected:
51  /**
52  * Sets up text, should be called every time changes has been
53  * made that can change the visual.
54  */
55  virtual void SetupText();
56 
57  /**
58  * @see IGUIObject#HandleMessage()
59  */
60  virtual void HandleMessage(SGUIMessage& Message);
61 
62  /**
63  * Handle events manually to catch keyboard inputting.
64  */
65  virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev);
66 
67  /**
68  * Draws the List box
69  */
70  virtual void Draw();
71 
72  /**
73  * Easy select elements functions
74  */
75  virtual void SelectNextElement();
76  virtual void SelectPrevElement();
77  virtual void SelectFirstElement();
78  virtual void SelectLastElement();
79 
80  /**
81  * Handle the <item> tag.
82  */
83  virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile);
84 
85  // Called every time the auto-scrolling should be checked.
86  void UpdateAutoScroll();
87 
88  // Extended drawing interface, this is so that classes built on the this one
89  // can use other sprite names.
90  virtual void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
91 
92  // Get the area of the list. This is so that it can easily be changed, like in CDropDown
93  // where the area is not equal to m_CachedActualSize.
94  virtual CRect GetListRect() const { return m_CachedActualSize; }
95 
96  // Returns whether SetupText() has run since the last message was received
97  // (and thus whether list items have possibly changed).
98  virtual bool GetModified() const { return m_Modified; }
99 
100  /**
101  * List of each element's relative y position. Will be
102  * one larger than m_Items, because it will end with the
103  * bottom of the last element. First element will always
104  * be zero, but still stored for easy handling.
105  */
106  std::vector<float> m_ItemsYPositions;
107 
108 private:
109  // Whether the list's items have been modified since last handling a message.
111 
112  // Used for doubleclick registration
114 
115  // Last time a click on an item was issued
117 };
118 
119 #endif // INCLUDED_CLIST
double m_LastItemClickTime
Definition: CList.h:116
virtual InReaction ManuallyHandleEvent(const SDL_Event_ *ev)
Handle events manually to catch keyboard inputting.
Definition: CList.cpp:254
virtual void DrawList(const int &selected, const CStr &_sprite, const CStr &_sprite_selected, const CStr &_textcolor)
Definition: CList.cpp:314
int m_PrevSelectedItem
Definition: CList.h:113
virtual void AddItem(const CStrW &str, const CStrW &data)
Adds an item last to the list.
Definition: CList.cpp:403
Definition: XeroXMB.h:160
virtual void SetupText()
Sets up text, should be called every time changes has been made that can change the visual...
Definition: CList.cpp:69
virtual void HandleMessage(SGUIMessage &Message)
Definition: CList.cpp:146
Definition: libsdl.h:51
virtual void Draw()
Draws the List box.
Definition: CList.cpp:306
virtual bool GetModified() const
Definition: CList.h:98
virtual void ResetStates()
Definition: CList.h:43
Framework for handling Output text.
Definition: IGUITextOwner.h:45
CList()
Definition: CList.cpp:30
InReaction
Definition: input.h:34
std::vector< float > m_ItemsYPositions
List of each element&#39;s relative y position.
Definition: CList.h:106
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Definition: IGUIObject.h:415
Definition: Xeromyces.h:42
virtual ~CList()
Definition: CList.cpp:65
virtual CRect GetListRect() const
Definition: CList.h:94
Create a list of elements, where one can be selected by the user.
Definition: CList.h:32
virtual void ResetStates()
Definition: IGUIScrollBarOwner.cpp:32
virtual void SelectNextElement()
Easy select elements functions.
Definition: CList.cpp:435
virtual void SelectLastElement()
Definition: CList.cpp:479
virtual void SelectFirstElement()
Definition: CList.cpp:470
virtual bool HandleAdditionalChildren(const XMBElement &child, CXeromyces *pFile)
Handle the <item> tag.
Definition: CList.cpp:422
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:91
Base-class this if you want an object to contain one, or several, scroll-bars.
Definition: IGUIScrollBarOwner.h:33
void UpdateAutoScroll()
Definition: CList.cpp:491
bool m_Modified
Definition: CList.h:110
#define GUI_OBJECT(obj)
Definition: GUIbase.h:48
virtual void SelectPrevElement()
Definition: CList.cpp:454
Rectangle class used for screen rectangles.
Definition: Shapes.h:73