| [25152] | 1 | /* Copyright (C) 2021 Wildfire Games.
|
|---|
| [27965] | 2 | * This file is part of 0 A.D.
|
|---|
| [6830] | 3 | *
|
|---|
| [27965] | 4 | * 0 A.D. is free software: you can redistribute it and/or modify
|
|---|
| [6830] | 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 | *
|
|---|
| [27965] | 9 | * 0 A.D. is distributed in the hope that it will be useful,
|
|---|
| [6830] | 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
|
|---|
| [27965] | 15 | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| [6830] | 16 | */
|
|---|
| 17 |
|
|---|
| [3802] | 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 |
|
|---|
| [5040] | 28 | #ifndef INCLUDED_CDROPDOWN
|
|---|
| 29 | #define INCLUDED_CDROPDOWN
|
|---|
| [3802] | 30 |
|
|---|
| [23005] | 31 | #include "gui/CGUISprite.h"
|
|---|
| [24352] | 32 | #include "gui/ObjectBases/IGUIObject.h"
|
|---|
| [23028] | 33 | #include "gui/ObjectTypes/CList.h"
|
|---|
| [25152] | 34 | #include "maths/Vector2D.h"
|
|---|
| [3802] | 35 |
|
|---|
| [22941] | 36 | #include <string>
|
|---|
| 37 |
|
|---|
| [3802] | 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 | */
|
|---|
| 47 | class CDropDown : public CList
|
|---|
| 48 | {
|
|---|
| 49 | GUI_OBJECT(CDropDown)
|
|---|
| 50 |
|
|---|
| 51 | public:
|
|---|
| [22741] | 52 | CDropDown(CGUI& pGUI);
|
|---|
| [3802] | 53 | virtual ~CDropDown();
|
|---|
| 54 |
|
|---|
| 55 | /**
|
|---|
| [9340] | 56 | * @see IGUIObject#HandleMessage()
|
|---|
| [3802] | 57 | */
|
|---|
| [16931] | 58 | virtual void HandleMessage(SGUIMessage& Message);
|
|---|
| [3802] | 59 |
|
|---|
| 60 | /**
|
|---|
| 61 | * Handle events manually to catch keyboard inputting.
|
|---|
| 62 | */
|
|---|
| [24215] | 63 | virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev);
|
|---|
| [3802] | 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | * Draws the Button
|
|---|
| 67 | */
|
|---|
| [25588] | 68 | virtual void Draw(CCanvas2D& canvas);
|
|---|
| [3802] | 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.
|
|---|
| [22757] | 73 | virtual bool IsMouseOver() const;
|
|---|
| [3802] | 74 |
|
|---|
| 75 | virtual float GetBufferedZ() const;
|
|---|
| 76 |
|
|---|
| 77 | protected:
|
|---|
| 78 | /**
|
|---|
| [19845] | 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 | /**
|
|---|
| [3802] | 85 | * Sets up text, should be called every time changes has been
|
|---|
| 86 | * made that can change the visual.
|
|---|
| 87 | */
|
|---|
| 88 | void SetupText();
|
|---|
| [16931] | 89 |
|
|---|
| [3802] | 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 | */
|
|---|
| [25152] | 100 | CVector2D m_TextPos;
|
|---|
| [3802] | 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.
|
|---|
| 107 | CRect m_CachedListRect;
|
|---|
| 108 |
|
|---|
| 109 | // Hide scrollbar when it's not needed
|
|---|
| 110 | bool m_HideScrollBar;
|
|---|
| 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.
|
|---|
| 116 | int m_ElementHighlight;
|
|---|
| [16931] | 117 |
|
|---|
| [13556] | 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;
|
|---|
| [16931] | 121 |
|
|---|
| [13556] | 122 | // used to know if we want to restart anew or add to m_inputbuffer.
|
|---|
| 123 | double m_TimeOfLastInput;
|
|---|
| 124 |
|
|---|
| [23005] | 125 | // Settings
|
|---|
| [25392] | 126 | CGUISimpleSetting<float> m_ButtonWidth;
|
|---|
| 127 | CGUISimpleSetting<float> m_DropDownSize;
|
|---|
| 128 | CGUISimpleSetting<float> m_DropDownBuffer;
|
|---|
| 129 | CGUISimpleSetting<u32> m_MinimumVisibleItems;
|
|---|
| 130 | CGUISimpleSetting<CStrW> m_SoundClosed;
|
|---|
| 131 | CGUISimpleSetting<CStrW> m_SoundEnter;
|
|---|
| 132 | CGUISimpleSetting<CStrW> m_SoundLeave;
|
|---|
| 133 | CGUISimpleSetting<CStrW> m_SoundOpened;
|
|---|
| 134 | CGUISimpleSetting<CGUISpriteInstance> m_SpriteDisabled;
|
|---|
| [25587] | 135 | CGUISimpleSetting<CGUISpriteInstance> m_SpriteOverlayDisabled;
|
|---|
| [25392] | 136 | CGUISimpleSetting<CGUISpriteInstance> m_SpriteList;
|
|---|
| [25587] | 137 | CGUISimpleSetting<CGUISpriteInstance> m_SpriteListOverlay;
|
|---|
| [25392] | 138 | CGUISimpleSetting<CGUISpriteInstance> m_Sprite2;
|
|---|
| 139 | CGUISimpleSetting<CGUISpriteInstance> m_Sprite2Over;
|
|---|
| 140 | CGUISimpleSetting<CGUISpriteInstance> m_Sprite2Pressed;
|
|---|
| 141 | CGUISimpleSetting<CGUISpriteInstance> m_Sprite2Disabled;
|
|---|
| 142 | CGUISimpleSetting<CGUIColor> m_TextColorDisabled;
|
|---|
| [3802] | 143 | };
|
|---|
| 144 |
|
|---|
| [16931] | 145 | #endif // INCLUDED_CDROPDOWN
|
|---|