Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CList.h
Go to the documentation of this file.
1/* Copyright (C) 2021 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 "gui/CGUISprite.h"
26
27#include <vector>
28
29/**
30 * Create a list of elements, where one can be selected
31 * by the user. The control will use a pre-processed
32 * text-object for each element, which will be managed
33 * by the IGUITextOwner structure.
34 *
35 * A scroll-bar will appear when needed. This will be
36 * achieved with the IGUIScrollBarOwner structure.
37 */
38class CList : public IGUIObject, public IGUIScrollBarOwner, public IGUITextOwner
39{
41public:
42 CList(CGUI& pGUI);
43 virtual ~CList();
44
45 /**
46 * @see IGUIObject#ResetStates()
47 */
48 virtual void ResetStates();
49
50 /**
51 * @see IGUIObject#UpdateCachedSize()
52 */
53 virtual void UpdateCachedSize();
54
55 /**
56 * Adds an item last to the list.
57 */
58 virtual void AddItem(const CGUIString& str, const CGUIString& data);
59
60 /**
61 * Add an item where both parameters are identical.
62 */
63 void AddItem(const CGUIString& strAndData);
64
65protected:
66 /**
67 * Sets up text, should be called every time changes has been
68 * made that can change the visual.
69 * @param append - if true, we assume we only need to render the new element at the end of the list.
70 */
71 virtual void SetupText();
72 virtual void SetupText(bool append);
73
74 /**
75 * @see IGUIObject#HandleMessage()
76 */
77 virtual void HandleMessage(SGUIMessage& Message);
78
79 /**
80 * Handle events manually to catch keyboard inputting.
81 */
82 virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev);
83
84 /**
85 * Draws the List box
86 */
87 virtual void Draw(CCanvas2D& canvas);
88
89 virtual void CreateJSObject();
90
91 /**
92 * Easy select elements functions
93 */
94 virtual void SelectNextElement();
95 virtual void SelectPrevElement();
96 virtual void SelectFirstElement();
97 virtual void SelectLastElement();
98
99 /**
100 * Handle the <item> tag.
101 */
102 virtual bool HandleAdditionalChildren(const XMBData& xmb, const XMBElement& child);
103
104 // Called every time the auto-scrolling should be checked.
105 void UpdateAutoScroll();
106
107 // Extended drawing interface, this is so that classes built on the this one
108 // can use other sprite names.
109 virtual void DrawList(CCanvas2D& canvas, const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& spriteOverlay,
110 const CGUISpriteInstance& spriteSelectArea, const CGUISpriteInstance& spriteSelectAreaOverlay, const CGUIColor& textColor);
111
112 // Get the area of the list. This is so that it can easily be changed, like in CDropDown
113 // where the area is not equal to m_CachedActualSize.
114 virtual CRect GetListRect() const { return m_CachedActualSize; }
115
116 // Returns whether SetupText() has run since the last message was received
117 // (and thus whether list items have possibly changed).
118 virtual bool GetModified() const { return m_Modified; }
119
120 /**
121 * List of each element's relative y position. Will be
122 * one larger than m_Items, because it will end with the
123 * bottom of the last element. First element will always
124 * be zero, but still stored for easy handling.
125 */
126 std::vector<float> m_ItemsYPositions;
127
128 virtual int GetHoveredItem();
129
148
149private:
150 static const CStr EventNameSelectionChange;
151 static const CStr EventNameHoverChange;
154
155 // Whether the list's items have been modified since last handling a message.
157
158 // Used for doubleclick registration
160
161 // Last time a click on an item was issued
163};
164
165#endif // INCLUDED_CLIST
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:50
Definition: Canvas2D.h:36
Definition: CGUISprite.h:134
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
Definition: CGUIString.h:42
The main object that represents a whole GUI page.
Definition: CGUI.h:61
Create a list of elements, where one can be selected by the user.
Definition: CList.h:39
CGUISimpleSetting< CGUISpriteInstance > m_SpriteSelectAreaOverlay
Definition: CList.h:140
CGUISimpleSetting< CStr > m_ScrollBarStyle
Definition: CList.h:133
virtual int GetHoveredItem()
Definition: CList.cpp:469
virtual void SelectLastElement()
Definition: CList.cpp:439
CGUISimpleSetting< bool > m_ScrollBottom
Definition: CList.h:134
CGUISimpleSetting< CGUIColor > m_TextColor
Definition: CList.h:141
CGUISimpleSetting< CGUISpriteInstance > m_Sprite
Definition: CList.h:137
virtual ~CList()
Definition: CList.cpp:68
virtual void SelectPrevElement()
Definition: CList.cpp:424
virtual void CreateJSObject()
Creates the JS object representing this page upon first use.
CGUISimpleSetting< bool > m_ScrollBar
Definition: CList.h:132
CGUISimpleSetting< CStrW > m_SoundSelected
Definition: CList.h:136
virtual void DrawList(CCanvas2D &canvas, const int &selected, const CGUISpriteInstance &sprite, const CGUISpriteInstance &spriteOverlay, const CGUISpriteInstance &spriteSelectArea, const CGUISpriteInstance &spriteSelectAreaOverlay, const CGUIColor &textColor)
Definition: CList.cpp:307
static const CStr EventNameHoverChange
Definition: CList.h:151
CGUISimpleSetting< CGUISpriteInstance > m_SpriteOverlay
Definition: CList.h:138
CGUISimpleSetting< CGUIList > m_List
Definition: CList.h:146
CGUISimpleSetting< bool > m_AutoScroll
Definition: CList.h:144
std::vector< float > m_ItemsYPositions
List of each element's relative y position.
Definition: CList.h:126
static const CStr EventNameMouseLeftDoubleClickItem
Definition: CList.h:153
void UpdateAutoScroll()
Definition: CList.cpp:447
int m_PrevSelectedItem
Definition: CList.h:159
CGUISimpleSetting< CStrW > m_SoundDisabled
Definition: CList.h:135
CGUISimpleSetting< i32 > m_Hovered
Definition: CList.h:145
static const CStr EventNameMouseLeftClickItem
Definition: CList.h:152
CGUISimpleSetting< CGUISpriteInstance > m_SpriteSelectArea
Definition: CList.h:139
virtual void ResetStates()
Definition: CList.cpp:143
virtual void HandleMessage(SGUIMessage &Message)
Definition: CList.cpp:155
virtual InReaction ManuallyHandleKeys(const SDL_Event_ *ev)
Handle events manually to catch keyboard inputting.
Definition: CList.cpp:250
virtual void SelectFirstElement()
Definition: CList.cpp:433
CGUISimpleSetting< CGUIList > m_ListData
Definition: CList.h:147
virtual void SelectNextElement()
Easy select elements functions.
Definition: CList.cpp:415
static const CStr EventNameSelectionChange
Definition: CList.h:150
CGUISimpleSetting< i32 > m_Selected
Definition: CList.h:143
virtual bool GetModified() const
Definition: CList.h:118
bool m_Modified
Definition: CList.h:156
CGUISimpleSetting< float > m_BufferZone
Definition: CList.h:130
CGUISimpleSetting< CStrW > m_Font
Definition: CList.h:131
double m_LastItemClickTime
Definition: CList.h:162
virtual void Draw(CCanvas2D &canvas)
Draws the List box.
Definition: CList.cpp:302
CGUISimpleSetting< CGUIColor > m_TextColorSelected
Definition: CList.h:142
virtual void UpdateCachedSize()
Definition: CList.cpp:149
virtual CRect GetListRect() const
Definition: CList.h:114
virtual bool HandleAdditionalChildren(const XMBData &xmb, const XMBElement &child)
Handle the <item> tag.
Definition: CList.cpp:400
CList(CGUI &pGUI)
Definition: CList.cpp:34
virtual void SetupText()
Sets up text, should be called every time changes has been made that can change the visual.
Definition: CList.cpp:72
virtual void AddItem(const CGUIString &str, const CGUIString &data)
Adds an item last to the list.
Definition: CList.cpp:386
Rectangle class used for screen rectangles.
Definition: Rect.h:31
GUI object such as a button or an input-box.
Definition: IGUIObject.h:60
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Definition: IGUIObject.h:380
Base-class this if you want an object to contain one, or several, scroll-bars.
Definition: IGUIScrollBarOwner.h:37
Framework for handling Output text.
Definition: IGUITextOwner.h:53
Definition: XMBData.h:96
Definition: XMBData.h:136
InReaction
Definition: input.h:35
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:30
Definition: libsdl.h:53
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:68