Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CDropDown.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/*
19GUI Object - Drop Down (list)
20
21--Overview--
22
23 Works just like a list-box, but it hides
24 all the elements that aren't selected. They
25 can be brought up by pressing the control.
26*/
27
28#ifndef INCLUDED_CDROPDOWN
29#define INCLUDED_CDROPDOWN
30
31#include "gui/CGUISprite.h"
34#include "maths/Vector2D.h"
35
36#include <string>
37
38/**
39 * Drop Down
40 *
41 * The control can be pressed, but we will not inherent
42 * this behavior from IGUIButtonBehavior, because when
43 * you press this control, the list with elements will
44 * immediately appear, and not first after release
45 * (which is the whole gist of the IGUIButtonBehavior).
46 */
47class CDropDown : public CList
48{
50
51public:
52 CDropDown(CGUI& pGUI);
53 virtual ~CDropDown();
54
55 /**
56 * @see IGUIObject#HandleMessage()
57 */
58 virtual void HandleMessage(SGUIMessage& Message);
59
60 /**
61 * Handle events manually to catch keyboard inputting.
62 */
63 virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev);
64
65 /**
66 * Draws the Button
67 */
68 virtual void Draw(CCanvas2D& canvas);
69
70 // This is one of the few classes we actually need to redefine this function
71 // this is because the size of the control changes whether it is open
72 // or closed.
73 virtual bool IsMouseOver() const;
74
75 virtual float GetBufferedZ() const;
76
77protected:
78 /**
79 * If the size changed, the texts have to be updated as
80 * the word wrapping depends on the size.
81 */
82 virtual void UpdateCachedSize();
83
84 /**
85 * Sets up text, should be called every time changes has been
86 * made that can change the visual.
87 */
88 void SetupText();
89
90 // Sets up the cached GetListRect. Decided whether it should
91 // have a scrollbar, and so on.
92 virtual void SetupListRect();
93
94 // Specify a new List rectangle.
95 virtual CRect GetListRect() const;
96
97 /**
98 * Placement of text.
99 */
101
102 // Is the dropdown opened?
103 bool m_Open;
104
105 // I didn't cache this at first, but it's just as easy as caching
106 // m_CachedActualSize, so I thought, what the heck it's used a lot.
108
109 // Hide scrollbar when it's not needed
111
112 // Not necessarily the element that is selected, this is just
113 // which element should be highlighted. When opening the dropdown
114 // it is set to "selected", but then when moving the mouse it will
115 // change.
117
118 // Stores any text entered by the user for quick access to an element
119 // (ie if you type "acro" it will take you to acropolis).
120 std::string m_InputBuffer;
121
122 // used to know if we want to restart anew or add to m_inputbuffer.
124
125 // Settings
143};
144
145#endif // INCLUDED_CDROPDOWN
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:50
Definition: Canvas2D.h:36
Drop Down.
Definition: CDropDown.h:48
bool m_Open
Definition: CDropDown.h:103
CGUISimpleSetting< CStrW > m_SoundLeave
Definition: CDropDown.h:132
CGUISimpleSetting< CStrW > m_SoundEnter
Definition: CDropDown.h:131
CGUISimpleSetting< float > m_DropDownSize
Definition: CDropDown.h:127
CGUISimpleSetting< CGUISpriteInstance > m_Sprite2Disabled
Definition: CDropDown.h:141
virtual void SetupListRect()
Definition: CDropDown.cpp:354
CGUISimpleSetting< CStrW > m_SoundOpened
Definition: CDropDown.h:133
CGUISimpleSetting< CGUISpriteInstance > m_Sprite2Pressed
Definition: CDropDown.h:140
CGUISimpleSetting< CGUISpriteInstance > m_SpriteOverlayDisabled
Definition: CDropDown.h:135
std::string m_InputBuffer
Definition: CDropDown.h:120
CGUISimpleSetting< CGUISpriteInstance > m_Sprite2Over
Definition: CDropDown.h:139
virtual CRect GetListRect() const
Definition: CDropDown.cpp:409
virtual bool IsMouseOver() const
This function checks if the mouse is hovering the rectangle that the base setting "size" makes.
Definition: CDropDown.cpp:414
double m_TimeOfLastInput
Definition: CDropDown.h:123
virtual InReaction ManuallyHandleKeys(const SDL_Event_ *ev)
Handle events manually to catch keyboard inputting.
Definition: CDropDown.cpp:262
int m_ElementHighlight
Definition: CDropDown.h:116
CGUISimpleSetting< CGUIColor > m_TextColorDisabled
Definition: CDropDown.h:142
CGUISimpleSetting< CStrW > m_SoundClosed
Definition: CDropDown.h:130
virtual void Draw(CCanvas2D &canvas)
Draws the Button.
Definition: CDropDown.cpp:426
void SetupText()
Sets up text, should be called every time changes has been made that can change the visual.
Definition: CDropDown.cpp:64
CGUISimpleSetting< CGUISpriteInstance > m_Sprite2
Definition: CDropDown.h:138
CGUISimpleSetting< float > m_DropDownBuffer
Definition: CDropDown.h:128
CGUISimpleSetting< CGUISpriteInstance > m_SpriteDisabled
Definition: CDropDown.h:134
CVector2D m_TextPos
Placement of text.
Definition: CDropDown.h:100
CGUISimpleSetting< float > m_ButtonWidth
Definition: CDropDown.h:126
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
Definition: CDropDown.cpp:483
virtual ~CDropDown()
Definition: CDropDown.cpp:60
virtual void HandleMessage(SGUIMessage &Message)
Definition: CDropDown.cpp:76
CGUISimpleSetting< CGUISpriteInstance > m_SpriteListOverlay
Definition: CDropDown.h:137
virtual void UpdateCachedSize()
If the size changed, the texts have to be updated as the word wrapping depends on the size.
Definition: CDropDown.cpp:70
CGUISimpleSetting< u32 > m_MinimumVisibleItems
Definition: CDropDown.h:129
CRect m_CachedListRect
Definition: CDropDown.h:107
CDropDown(CGUI &pGUI)
Definition: CDropDown.cpp:30
CGUISimpleSetting< CGUISpriteInstance > m_SpriteList
Definition: CDropDown.h:136
bool m_HideScrollBar
Definition: CDropDown.h:110
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
Rectangle class used for screen rectangles.
Definition: Rect.h:31
Definition: Vector2D.h:32
InReaction
Definition: input.h:35
Definition: libsdl.h:53
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:68