| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | #ifndef GAME_CLIENT_UI_LISTBOX_H |
| 4 | #define GAME_CLIENT_UI_LISTBOX_H |
| 5 | |
| 6 | #include "ui_scrollregion.h" |
| 7 | |
| 8 | struct CListboxItem |
| 9 | { |
| 10 | bool m_Visible; |
| 11 | bool m_Selected; |
| 12 | CUIRect m_Rect; |
| 13 | }; |
| 14 | |
| 15 | // Instances of CListBox must be static, as member addresses are used as UI item IDs |
| 16 | class CListBox : private CUIElementBase |
| 17 | { |
| 18 | private: |
| 19 | CUIRect m_ListBoxView; |
| 20 | CUIRect m_RowView; |
| 21 | float m_ListBoxRowHeight; |
| 22 | int m_ListBoxItemIndex; |
| 23 | int m_ListBoxSelectedIndex; |
| 24 | int m_ListBoxNewSelected; |
| 25 | int m_ListBoxNewSelOffset; |
| 26 | bool m_ListBoxUpdateScroll; |
| 27 | int m_ListBoxNumItems; |
| 28 | int m_ListBoxItemsPerRow; |
| 29 | bool m_ListBoxItemSelected; |
| 30 | bool m_ListBoxItemActivated; |
| 31 | bool m_ScrollbarShown; |
| 32 | float m_AutoSpacing; |
| 33 | CScrollRegion m_ScrollRegion; |
| 34 | int m_BackgroundCorners; |
| 35 | float m_ScrollbarWidth; |
| 36 | float m_ScrollbarMargin; |
| 37 | bool ; |
| 38 | bool m_Active; |
| 39 | |
| 40 | protected: |
| 41 | CListboxItem DoNextRow(); |
| 42 | |
| 43 | public: |
| 44 | CListBox(); |
| 45 | void Reset(); |
| 46 | |
| 47 | void (const CUIRect *pRect, const char *pTitle, float = 20.0f, float Spacing = 2.0f); |
| 48 | void DoAutoSpacing(float Spacing = 20.0f) { m_AutoSpacing = Spacing; } |
| 49 | void DoSpacing(float Spacing = 20.0f); |
| 50 | void DoStart(float RowHeight, int NumItems, int ItemsPerRow, int RowsPerScroll, int SelectedIndex, const CUIRect *pRect = nullptr, bool Background = true, int BackgroundCorners = IGraphics::CORNER_ALL, bool ForceShowScrollbar = false); |
| 51 | void ScrollToSelected() { m_ListBoxUpdateScroll = true; } |
| 52 | CListboxItem DoNextItem(const void *pId, bool Selected = false, float CornerRadius = 5.0f); |
| 53 | CListboxItem (); |
| 54 | int DoEnd(); |
| 55 | |
| 56 | // Active state must be set before calling DoStart. |
| 57 | bool Active() const { return m_Active; } |
| 58 | void SetActive(bool Active) { m_Active = Active; } |
| 59 | |
| 60 | bool WasItemSelected() const { return m_ListBoxItemSelected; } |
| 61 | bool WasItemActivated() const { return m_ListBoxItemActivated; } |
| 62 | |
| 63 | bool ScrollbarShown() const { return m_ScrollbarShown; } |
| 64 | float ScrollbarWidth() const { return ScrollbarShown() ? ScrollbarWidthMax() : 0.0f; } |
| 65 | float ScrollbarWidthMax() const { return m_ScrollbarWidth; } |
| 66 | void SetScrollbarWidth(float Width) { m_ScrollbarWidth = Width; } |
| 67 | float ScrollbarMargin() const { return m_ScrollbarMargin; } |
| 68 | void SetScrollbarMargin(float Margin) { m_ScrollbarMargin = Margin; } |
| 69 | }; |
| 70 | |
| 71 | #endif |
| 72 | |