Pyrogenesis  trunk
CDropDown.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 /*
19 GUI 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 --More info--
28 
29  Check GUI.h
30 
31 */
32 
33 #ifndef INCLUDED_CDROPDOWN
34 #define INCLUDED_CDROPDOWN
35 
36 #include "GUI.h"
37 #include "CList.h"
38 
39 /**
40  * Drop Down
41  *
42  * The control can be pressed, but we will not inherent
43  * this behavior from IGUIButtonBehavior, because when
44  * you press this control, the list with elements will
45  * immediately appear, and not first after release
46  * (which is the whole gist of the IGUIButtonBehavior).
47  */
48 class CDropDown : public CList
49 {
51 
52 public:
53  CDropDown();
54  virtual ~CDropDown();
55 
56 // virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
57 
58  /**
59  * @see IGUIObject#HandleMessage()
60  */
61  virtual void HandleMessage(SGUIMessage& Message);
62 
63  /**
64  * Handle events manually to catch keyboard inputting.
65  */
66  virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev);
67 
68  /**
69  * Draws the Button
70  */
71  virtual void Draw();
72 
73  // This is one of the few classes we actually need to redefine this function
74  // this is because the size of the control changes whether it is open
75  // or closed.
76  virtual bool MouseOver();
77 
78  virtual float GetBufferedZ() const;
79 
80 protected:
81  /**
82  * Sets up text, should be called every time changes has been
83  * made that can change the visual.
84  */
85  void SetupText();
86 
87  // Sets up the cached GetListRect. Decided whether it should
88  // have a scrollbar, and so on.
89  virtual void SetupListRect();
90 
91  // Specify a new List rectangle.
92  virtual CRect GetListRect() const;
93 
94  /**
95  * Placement of text.
96  */
98 
99  // Is the dropdown opened?
100  bool m_Open;
101 
102  // I didn't cache this at first, but it's just as easy as caching
103  // m_CachedActualSize, so I thought, what the heck it's used a lot.
105 
106  // Hide scrollbar when it's not needed
108 
109  // Not necessarily the element that is selected, this is just
110  // which element should be highlighted. When opening the dropdown
111  // it is set to "selected", but then when moving the mouse it will
112  // change.
114 
115  // Stores any text entered by the user for quick access to an element
116  // (ie if you type "acro" it will take you to acropolis).
117  std::string m_InputBuffer;
118 
119  // used to know if we want to restart anew or add to m_inputbuffer.
121 
122 };
123 
124 #endif // INCLUDED_CDROPDOWN
virtual void HandleMessage(SGUIMessage &Message)
Definition: CDropDown.cpp:70
virtual CRect GetListRect() const
Definition: CDropDown.cpp:407
virtual void SetupListRect()
Definition: CDropDown.cpp:385
CPos m_TextPos
Placement of text.
Definition: CDropDown.h:97
bool m_HideScrollBar
Definition: CDropDown.h:107
bool m_Open
Definition: CDropDown.h:100
Definition: libsdl.h:51
void SetupText()
Sets up text, should be called every time changes has been made that can change the visual...
Definition: CDropDown.cpp:63
virtual bool MouseOver()
Checks if mouse is hovering this object.
Definition: CDropDown.cpp:412
InReaction
Definition: input.h:34
virtual void Draw()
Draws the Button.
Definition: CDropDown.cpp:428
std::string m_InputBuffer
Definition: CDropDown.h:117
virtual ~CDropDown()
Definition: CDropDown.cpp:59
Made to represent screen positions and delta values.
Definition: Shapes.h:169
int m_ElementHighlight
Definition: CDropDown.h:113
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
Definition: CDropDown.cpp:510
Create a list of elements, where one can be selected by the user.
Definition: CList.h:32
Drop Down.
Definition: CDropDown.h:48
virtual InReaction ManuallyHandleEvent(const SDL_Event_ *ev)
Handle events manually to catch keyboard inputting.
Definition: CDropDown.cpp:291
CDropDown()
Definition: CDropDown.cpp:28
CRect m_CachedListRect
Definition: CDropDown.h:104
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:91
double m_TimeOfLastInput
Definition: CDropDown.h:120
#define GUI_OBJECT(obj)
Definition: GUIbase.h:48
Rectangle class used for screen rectangles.
Definition: Shapes.h:73