DDraceNetwork Docs
ui.h
Go to the documentation of this file.
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_H
4#define GAME_CLIENT_UI_H
5
6#include "lineinput.h"
7#include "ui_rect.h"
8
9#include <engine/input.h>
10#include <engine/textrender.h>
11
12#include <chrono>
13#include <set>
14#include <string>
15#include <vector>
16
17class CScrollRegion;
18class IClient;
19class IGraphics;
20class IKernel;
21
22enum class EEditState
23{
24 NONE,
25 START,
26 EDITING,
27 END,
28 ONE_GO
29};
30
31template<typename T>
33{
36};
37
39{
43
44 std::chrono::nanoseconds m_Time;
45 float m_Value;
46
47 float m_XOffset;
48 float m_YOffset;
49 float m_WOffset;
50 float m_HOffset;
51};
52
54{
55public:
56 virtual float ToRelative(int AbsoluteValue, int Min, int Max) const = 0;
57 virtual int ToAbsolute(float RelativeValue, int Min, int Max) const = 0;
58};
60{
61public:
62 float ToRelative(int AbsoluteValue, int Min, int Max) const override
63 {
64 return (AbsoluteValue - Min) / (float)(Max - Min);
65 }
66 int ToAbsolute(float RelativeValue, int Min, int Max) const override
67 {
68 return round_to_int(RelativeValue * (Max - Min) + Min + 0.1f);
69 }
70};
72{
73private:
75
76public:
77 CLogarithmicScrollbarScale(int MinAdjustment)
78 {
79 m_MinAdjustment = maximum(MinAdjustment, 1); // must be at least 1 to support Min == 0 with logarithm
80 }
81 float ToRelative(int AbsoluteValue, int Min, int Max) const override
82 {
83 if(Min < m_MinAdjustment)
84 {
85 AbsoluteValue += m_MinAdjustment;
86 Min += m_MinAdjustment;
87 Max += m_MinAdjustment;
88 }
89 return (std::log(AbsoluteValue) - std::log(Min)) / (float)(std::log(Max) - std::log(Min));
90 }
91 int ToAbsolute(float RelativeValue, int Min, int Max) const override
92 {
93 int ResultAdjustment = 0;
94 if(Min < m_MinAdjustment)
95 {
96 Min += m_MinAdjustment;
97 Max += m_MinAdjustment;
98 ResultAdjustment = -m_MinAdjustment;
99 }
100 return round_to_int(std::exp(RelativeValue * (std::log(Max) - std::log(Min)) + std::log(Min))) + ResultAdjustment;
101 }
102};
103
105{
106public:
107 virtual ColorRGBA GetColor(bool Active, bool Hovered) const = 0;
108};
110{
111public:
112 ColorRGBA GetColor(bool Active, bool Hovered) const override
113 {
114 if(Active)
115 return ColorRGBA(0.15f, 0.15f, 0.15f, 0.25f);
116 else if(Hovered)
117 return ColorRGBA(0.5f, 0.5f, 0.5f, 0.25f);
118 return ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f);
119 }
120};
122{
123public:
124 ColorRGBA GetColor(bool Active, bool Hovered) const override
125 {
126 if(Active)
127 return ColorRGBA(1.0f, 1.0f, 1.0f, 0.4f);
128 else if(Hovered)
129 return ColorRGBA(1.0f, 1.0f, 1.0f, 0.6f);
130 return ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
131 }
132};
134{
135public:
136 ColorRGBA GetColor(bool Active, bool Hovered) const override
137 {
138 if(Active)
139 return ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f);
140 else if(Hovered)
141 return ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
142 return ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f);
143 }
144};
145
146class CUi;
147
149{
150 friend class CUi;
151
153
154 CUIElement(CUi *pUI, int RequestedRectCount) { Init(pUI, RequestedRectCount); }
155
156public:
158 {
160
161 public:
164
165 float m_X;
166 float m_Y;
167 float m_Width;
168 float m_Height;
171
172 std::string m_Text;
174
176
179
181
183
184 void Reset();
185 void Draw(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding);
186 };
187
188protected:
189 CUi *Ui() const { return m_pUI; }
190 std::vector<SUIElementRect> m_vUIRects;
191
192public:
193 CUIElement() = default;
194
195 void Init(CUi *pUI, int RequestedRectCount);
196
197 SUIElementRect *Rect(size_t Index)
198 {
199 return &m_vUIRects[Index];
200 }
201
203 {
204 return !m_vUIRects.empty();
205 }
206
207 void InitRects(int RequestedRectCount);
208};
209
211{
212 float m_MaxWidth = -1;
213 bool m_StopAtEnd = false;
214 bool m_EllipsisAtEnd = false;
216 std::vector<STextColorSplit> m_vColorSplits = {};
217};
218
220{
221 int m_Checked = 0;
224 bool m_UseIconFont = false;
225 bool m_ShowDropDownIcon = false;
227 float m_Rounding = 5.0f;
228 float m_FontFactor = 0.0f;
229 ColorRGBA m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
230};
231
233{
234private:
235 static CUi *s_pUI;
236
237public:
238 static void Init(CUi *pUI) { s_pUI = pUI; }
239
240 IClient *Client() const;
241 IGraphics *Graphics() const;
242 IInput *Input() const;
243 ITextRender *TextRender() const;
244 CUi *Ui() const { return s_pUI; }
245};
246
248{
249};
250
252{
253 bool m_UseScroll = true;
254 int64_t m_Step = 1;
255 float m_Scale = 1.0f;
256 bool m_IsHex = false;
257 int m_HexPrefix = 6;
258 ColorRGBA m_Color = ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f);
259};
260
262{
263 float m_Progress = -1.0f; // between 0.0f and 1.0f, or negative for indeterminate progress
264 ColorRGBA m_Color = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
265 int m_Segments = 64;
266};
267
272{
273};
274
276{
278 ColorRGBA m_BorderColor = ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f);
279 ColorRGBA m_BackgroundColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.75f);
280};
281
282class CUi
283{
284public:
289 {
294
299
304 };
305
316 typedef EPopupMenuFunctionResult (*FPopupMenuFunction)(void *pContext, CUIRect View, bool Active);
317
321 typedef std::function<void()> FPopupMenuClosedCallback;
322
327 {
328 friend class CUi;
329
333
334 public:
335 bool m_AnyPressed = false;
336 bool m_PrimaryPressed = false;
337 bool m_SecondaryPressed = false;
338 vec2 m_PrimaryPosition = vec2(-1.0f, -1.0f);
339 vec2 m_PrimaryDelta = vec2(0.0f, 0.0f);
340 vec2 m_ScrollAmount = vec2(0.0f, 0.0f);
341 };
342
343private:
345
346 const void *m_pHotItem = nullptr;
347 const void *m_pActiveItem = nullptr;
348 const void *m_pLastActiveItem = nullptr; // only used internally to track active CLineInput
349 const void *m_pBecomingHotItem = nullptr;
352 bool m_ActiveItemValid = false;
353
357 {
358 public:
359 const void *m_pLastClickedId = nullptr;
360 float m_LastClickTime = -1.0f;
361 vec2 m_LastClickPos = vec2(-1.0f, -1.0f);
362 };
364 const void *m_pLastEditingItem = nullptr;
368 {
369 public:
370 int m_Button = -1;
371 bool m_DidScroll = false;
372 float m_ScrollValue = 0.0f;
374 const void *m_pLastTextId = nullptr;
375 };
377
378 vec2 m_UpdatedMousePos = vec2(0.0f, 0.0f); // in window screen space
379 vec2 m_UpdatedMouseDelta = vec2(0.0f, 0.0f); // in window screen space
380 vec2 m_MousePos = vec2(0.0f, 0.0f); // in gui space
381 vec2 m_MouseDelta = vec2(0.0f, 0.0f); // in gui space
382 vec2 m_MouseWorldPos = vec2(-1.0f, -1.0f); // in world space
384 unsigned m_MouseButtons = 0;
385 unsigned m_LastMouseButtons = 0;
387 bool m_MouseSlow = false;
388 bool m_MouseLock = false;
389 const void *m_pMouseLockId = nullptr;
390
391 unsigned m_HotkeysPressed = 0;
392
394
395 std::vector<CUIRect> m_vClips;
396 void UpdateClipping();
397
399 {
400 static constexpr float POPUP_BORDER = 1.0f;
401 static constexpr float POPUP_MARGIN = 4.0f;
402
408 };
409 std::vector<SPopupMenu> m_vPopupMenus;
411
412 static CUi::EPopupMenuFunctionResult PopupMessage(void *pContext, CUIRect View, bool Active);
413 static CUi::EPopupMenuFunctionResult PopupConfirm(void *pContext, CUIRect View, bool Active);
414 static CUi::EPopupMenuFunctionResult PopupSelection(void *pContext, CUIRect View, bool Active);
415 static CUi::EPopupMenuFunctionResult PopupColorPicker(void *pContext, CUIRect View, bool Active);
416
421
422 std::vector<CUIElement *> m_vpOwnUIElements; // ui elements maintained by CUi class
423 std::vector<CUIElement *> m_vpUIElements;
424
425public:
431
432 static const float ms_FontmodHeight;
433
434 void Init(IKernel *pKernel);
435 IClient *Client() const { return m_pClient; }
436 IGraphics *Graphics() const { return m_pGraphics; }
437 IInput *Input() const { return m_pInput; }
439
440 CUi();
441 ~CUi();
442
443 enum EHotkey : unsigned
444 {
445 HOTKEY_ENTER = 1 << 0,
447 HOTKEY_UP = 1 << 2,
448 HOTKEY_DOWN = 1 << 3,
449 HOTKEY_LEFT = 1 << 4,
450 HOTKEY_RIGHT = 1 << 5,
452 HOTKEY_TAB = 1 << 7,
455 HOTKEY_PAGE_UP = 1 << 10,
457 HOTKEY_HOME = 1 << 12,
458 HOTKEY_END = 1 << 13,
459 };
460
461 void ResetUIElement(CUIElement &UIElement) const;
462
463 CUIElement *GetNewUIElement(int RequestedRectCount);
464
465 void AddUIElement(CUIElement *pElement);
466 void OnElementsReset();
467 void OnWindowResize();
468 void OnCursorMove(float X, float Y);
469
471 bool Enabled() const { return m_Enabled; }
472 void Update(vec2 MouseWorldPos = vec2(-1.0f, -1.0f));
473 void DebugRender(float X, float Y);
474
475 vec2 MousePos() const { return m_MousePos; }
476 float MouseX() const { return m_MousePos.x; }
477 float MouseY() const { return m_MousePos.y; }
478 vec2 MouseDelta() const { return m_MouseDelta; }
479 float MouseDeltaX() const { return m_MouseDelta.x; }
480 float MouseDeltaY() const { return m_MouseDelta.y; }
482 float MouseWorldX() const { return m_MouseWorldPos.x; }
483 float MouseWorldY() const { return m_MouseWorldPos.y; }
486 int MouseButton(int Index) const { return (m_MouseButtons >> Index) & 1; }
487 int MouseButtonClicked(int Index) const { return MouseButton(Index) && !((m_LastMouseButtons >> Index) & 1); }
489 {
492 return m_MouseLock;
493 }
494 void EnableMouseLock(const void *pId)
495 {
496 m_MouseLock = true;
497 m_pMouseLockId = pId;
498 }
499 void DisableMouseLock() { m_MouseLock = false; }
500
501 void SetHotItem(const void *pId) { m_pBecomingHotItem = pId; }
502 void SetActiveItem(const void *pId)
503 {
504 m_ActiveItemValid = true;
505 m_pActiveItem = pId;
506 if(pId)
507 m_pLastActiveItem = pId;
508 }
509 bool CheckActiveItem(const void *pId)
510 {
511 if(m_pActiveItem == pId)
512 {
513 m_ActiveItemValid = true;
514 return true;
515 }
516 return false;
517 }
519 const void *HotItem() const { return m_pHotItem; }
520 const void *NextHotItem() const { return m_pBecomingHotItem; }
521 const void *ActiveItem() const { return m_pActiveItem; }
523
524 void StartCheck() { m_ActiveItemValid = false; }
526 {
527 if(!m_ActiveItemValid && m_pActiveItem != nullptr)
528 {
529 SetActiveItem(nullptr);
530 m_pHotItem = nullptr;
531 m_pBecomingHotItem = nullptr;
532 }
533 }
534
535 bool MouseInside(const CUIRect *pRect) const;
536 bool MouseInsideClip() const { return !IsClipped() || MouseInside(ClipArea()); }
537 bool MouseHovered(const CUIRect *pRect) const { return MouseInside(pRect) && MouseInsideClip(); }
538 void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const;
539 void UpdateTouchState(CTouchState &State) const;
540 void ResetMouseSlow() { m_MouseSlow = false; }
541
542 bool ConsumeHotkey(EHotkey Hotkey);
544 bool OnInput(const IInput::CEvent &Event);
545
546 constexpr float ButtonColorMulActive() const { return 0.5f; }
547 constexpr float ButtonColorMulHot() const { return 1.5f; }
548 constexpr float ButtonColorMulDefault() const { return 1.0f; }
549 float ButtonColorMul(const void *pId);
550
551 const CUIRect *Screen();
552 void MapScreen();
553 float PixelSize();
554
555 void ClipEnable(const CUIRect *pRect);
556 void ClipDisable();
557 const CUIRect *ClipArea() const;
558 inline bool IsClipped() const { return !m_vClips.empty(); }
559
560 int DoButtonLogic(const void *pId, int Checked, const CUIRect *pRect);
561 int DoDraggableButtonLogic(const void *pId, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted);
562 bool DoDoubleClickLogic(const void *pId);
563 EEditState DoPickerLogic(const void *pId, const CUIRect *pRect, float *pX, float *pY);
564 void DoSmoothScrollLogic(float *pScrollOffset, float *pScrollOffsetChange, float ViewPortSize, float TotalSize, bool SmoothClamp = false, float ScrollSpeed = 10.0f) const;
565 static vec2 CalcAlignedCursorPos(const CUIRect *pRect, vec2 TextSize, int Align, const float *pBiggestCharHeight = nullptr);
566
567 void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}) const;
568
569 void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}, int StrLen = -1, const CTextCursor *pReadCursor = nullptr) const;
570 void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}, int StrLen = -1, const CTextCursor *pReadCursor = nullptr) const;
571
588 bool DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners = IGraphics::CORNER_ALL, const std::vector<STextColorSplit> &vColorSplits = {});
589
606 bool DoClearableEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners = IGraphics::CORNER_ALL, const std::vector<STextColorSplit> &vColorSplits = {});
607
624 bool DoEditBox_Search(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, bool HotkeyEnabled);
625
626 int DoButton_Menu(CUIElement &UIElement, const CButtonContainer *pId, const std::function<const char *()> &GetTextLambda, const CUIRect *pRect, const SMenuButtonProperties &Props = {});
627 // only used for popup menus
628 int DoButton_PopupMenu(CButtonContainer *pButtonContainer, const char *pText, const CUIRect *pRect, float Size, int Align, float Padding = 0.0f, bool TransparentInactive = false, bool Enabled = true);
629
630 // value selector
631 SEditResult<int64_t> DoValueSelectorWithState(const void *pId, const CUIRect *pRect, const char *pLabel, int64_t Current, int64_t Min, int64_t Max, const SValueSelectorProperties &Props = {});
632 int64_t DoValueSelector(const void *pId, const CUIRect *pRect, const char *pLabel, int64_t Current, int64_t Min, int64_t Max, const SValueSelectorProperties &Props = {});
633
634 // scrollbars
635 enum
636 {
640 };
641 float DoScrollbarV(const void *pId, const CUIRect *pRect, float Current);
642 float DoScrollbarH(const void *pId, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner = nullptr);
643 bool DoScrollbarOption(const void *pId, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned Flags = 0u, const char *pSuffix = "");
644
645 // progress bar
646 void RenderProgressBar(CUIRect ProgressBar, float Progress);
647
648 // progress spinner
649 void RenderProgressSpinner(vec2 Center, float OuterRadius, const SProgressSpinnerProperties &Props = {}) const;
650
651 // popup menu
652 void DoPopupMenu(const SPopupMenuId *pId, float X, float Y, float Width, float Height, void *pContext, FPopupMenuFunction pfnFunc, const SPopupMenuProperties &Props = {});
653 void RenderPopupMenus();
654 void ClosePopupMenu(const SPopupMenuId *pId, bool IncludeDescendants = false);
655 void ClosePopupMenus();
656 bool IsPopupOpen() const;
657 bool IsPopupOpen(const SPopupMenuId *pId) const;
658 bool IsPopupHovered() const;
660
662 {
663 static constexpr float POPUP_MAX_WIDTH = 200.0f;
664 static constexpr float POPUP_FONT_SIZE = 10.0f;
665
666 CUi *m_pUI; // set by CUi when popup is shown
667 char m_aMessage[1024];
669
670 void DefaultColor(class ITextRender *pTextRender);
671 void ErrorColor();
672 };
673 void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext);
674
676 {
678 {
679 UNSET = 0,
682 };
683 static constexpr float POPUP_MAX_WIDTH = 200.0f;
684 static constexpr float POPUP_FONT_SIZE = 10.0f;
685 static constexpr float POPUP_BUTTON_HEIGHT = 12.0f;
686 static constexpr float POPUP_BUTTON_SPACING = 5.0f;
687
688 CUi *m_pUI; // set by CUi when popup is shown
691 char m_aMessage[1024];
693
696
698 void Reset();
699 void YesNoButtons();
700 };
701 void ShowPopupConfirm(float X, float Y, SConfirmPopupContext *pContext);
702
704 {
705 CUi *m_pUI; // set by CUi when popup is shown
708 char m_aMessage[256];
709 std::vector<std::string> m_vEntries;
710 std::vector<CButtonContainer> m_vButtonContainers;
711 const std::string *m_pSelection;
717 float m_Width;
720
722 void Reset();
723 };
724 void ShowPopupSelection(float X, float Y, SSelectionPopupContext *pContext);
725
727 {
729 {
734 };
735
736 CUi *m_pUI; // set by CUi when popup is shown
738 bool m_Alpha = false;
739 unsigned int *m_pHslaColor = nullptr; // may be nullptr
743 // UI element IDs
744 const char m_HuePickerId = 0;
745 const char m_ColorPickerId = 0;
746 const char m_aValueSelectorIds[5] = {0};
749 };
750 void ShowPopupColorPicker(float X, float Y, SColorPickerPopupContext *pContext);
751
752 // dropdown menu
754 {
758 bool m_Init = false;
759 };
760 int DoDropDown(CUIRect *pRect, int CurSelection, const char **pStrs, int Num, SDropDownState &State);
761};
762
763#endif
Definition: ui.h:248
Definition: ui.h:110
ColorRGBA GetColor(bool Active, bool Hovered) const override
Definition: ui.h:112
Definition: ui.h:122
ColorRGBA GetColor(bool Active, bool Hovered) const override
Definition: ui.h:124
Definition: lineinput.h:215
Definition: lineinput.h:25
Definition: ui.h:60
float ToRelative(int AbsoluteValue, int Min, int Max) const override
Definition: ui.h:62
int ToAbsolute(float RelativeValue, int Min, int Max) const override
Definition: ui.h:66
Definition: ui.h:72
float ToRelative(int AbsoluteValue, int Min, int Max) const override
Definition: ui.h:81
int ToAbsolute(float RelativeValue, int Min, int Max) const override
Definition: ui.h:91
int m_MinAdjustment
Definition: ui.h:74
CLogarithmicScrollbarScale(int MinAdjustment)
Definition: ui.h:77
Definition: ui.h:134
ColorRGBA GetColor(bool Active, bool Hovered) const override
Definition: ui.h:136
Definition: ui_scrollregion.h:90
Definition: textrender.h:204
Definition: ui.h:233
IClient * Client() const
Definition: ui.cpp:96
IInput * Input() const
Definition: ui.cpp:98
static void Init(CUi *pUI)
Definition: ui.h:238
ITextRender * TextRender() const
Definition: ui.cpp:99
static CUi * s_pUI
Definition: ui.h:235
IGraphics * Graphics() const
Definition: ui.cpp:97
CUi * Ui() const
Definition: ui.h:244
Definition: ui.h:149
CUi * m_pUI
Definition: ui.h:152
bool AreRectsInit()
Definition: ui.h:202
std::vector< SUIElementRect > m_vUIRects
Definition: ui.h:190
SUIElementRect * Rect(size_t Index)
Definition: ui.h:197
CUi * Ui() const
Definition: ui.h:189
CUIElement(CUi *pUI, int RequestedRectCount)
Definition: ui.h:154
void InitRects(int RequestedRectCount)
Definition: ui.cpp:29
void Init(CUi *pUI, int RequestedRectCount)
Definition: ui.cpp:21
CUIElement()=default
Definition: ui_rect.h:11
Definition: ui.h:357
float m_LastClickTime
Definition: ui.h:360
vec2 m_LastClickPos
Definition: ui.h:361
const void * m_pLastClickedId
Definition: ui.h:359
Definition: ui.h:327
bool m_AnyPressed
Definition: ui.h:335
vec2 m_PrimaryDelta
Definition: ui.h:339
float m_SecondaryActivationTime
Definition: ui.h:331
bool m_SecondaryPressedNext
Definition: ui.h:330
bool m_PrimaryPressed
Definition: ui.h:336
bool m_SecondaryPressed
Definition: ui.h:337
vec2 m_PrimaryPosition
Definition: ui.h:338
vec2 m_ScrollAmount
Definition: ui.h:340
vec2 m_SecondaryActivationDelta
Definition: ui.h:332
Definition: ui.h:368
CLineInputNumber m_NumberInput
Definition: ui.h:373
bool m_DidScroll
Definition: ui.h:371
float m_ScrollValue
Definition: ui.h:372
const void * m_pLastTextId
Definition: ui.h:374
int m_Button
Definition: ui.h:370
Definition: ui.h:283
void DoPopupMenu(const SPopupMenuId *pId, float X, float Y, float Width, float Height, void *pContext, FPopupMenuFunction pfnFunc, const SPopupMenuProperties &Props={})
Definition: ui.cpp:1551
void ResetUIElement(CUIElement &UIElement) const
Definition: ui.cpp:143
void ClipEnable(const CUIRect *pRect)
Definition: ui.cpp:459
EEditState DoPickerLogic(const void *pId, const CUIRect *pRect, float *pX, float *pY)
Definition: ui.cpp:617
static const CLogarithmicScrollbarScale ms_LogarithmicScrollbarScale
Definition: ui.h:427
vec2 m_UpdatedMouseDelta
Definition: ui.h:379
void FinishCheck()
Definition: ui.h:525
void RenderProgressSpinner(vec2 Center, float OuterRadius, const SProgressSpinnerProperties &Props={}) const
Definition: ui.cpp:1509
bool OnInput(const IInput::CEvent &Event)
Definition: ui.cpp:387
int DoButton_PopupMenu(CButtonContainer *pButtonContainer, const char *pText, const CUIRect *pRect, float Size, int Align, float Padding=0.0f, bool TransparentInactive=false, bool Enabled=true)
Definition: ui.cpp:1132
CTouchState m_TouchState
Definition: ui.h:386
std::function< void()> FPopupMenuClosedCallback
Definition: ui.h:321
std::vector< SPopupMenu > m_vPopupMenus
Definition: ui.h:409
void EnableMouseLock(const void *pId)
Definition: ui.h:494
vec2 m_MousePos
Definition: ui.h:380
const void * HotItem() const
Definition: ui.h:519
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps={}) const
Definition: ui.cpp:791
void SetPopupMenuClosedCallback(FPopupMenuClosedCallback pfnCallback)
Definition: ui.cpp:1666
bool MouseInside(const CUIRect *pRect) const
Definition: ui.cpp:270
std::vector< CUIElement * > m_vpOwnUIElements
Definition: ui.h:422
void ResetMouseSlow()
Definition: ui.h:540
unsigned m_UpdatedMouseButtons
Definition: ui.h:383
IGraphics * m_pGraphics
Definition: ui.h:418
const void * m_pActiveItem
Definition: ui.h:347
bool IsPopupHovered() const
Definition: ui.cpp:1661
unsigned m_HotkeysPressed
Definition: ui.h:391
constexpr float ButtonColorMulHot() const
Definition: ui.h:547
void SetEnabled(bool Enabled)
Definition: ui.h:470
vec2 MousePos() const
Definition: ui.h:475
void SetActiveItem(const void *pId)
Definition: ui.h:502
EHotkey
Definition: ui.h:444
@ HOTKEY_TAB
Definition: ui.h:452
@ HOTKEY_PAGE_DOWN
Definition: ui.h:456
@ HOTKEY_DELETE
Definition: ui.h:451
@ HOTKEY_SCROLL_UP
Definition: ui.h:453
@ HOTKEY_ESCAPE
Definition: ui.h:446
@ HOTKEY_END
Definition: ui.h:458
@ HOTKEY_SCROLL_DOWN
Definition: ui.h:454
@ HOTKEY_ENTER
Definition: ui.h:445
@ HOTKEY_PAGE_UP
Definition: ui.h:455
@ HOTKEY_LEFT
Definition: ui.h:449
@ HOTKEY_RIGHT
Definition: ui.h:450
@ HOTKEY_DOWN
Definition: ui.h:448
@ HOTKEY_HOME
Definition: ui.h:457
@ HOTKEY_UP
Definition: ui.h:447
int DoDropDown(CUIRect *pRect, int CurSelection, const char **pStrs, int Num, SDropDownState &State)
Definition: ui.cpp:1860
bool IsClipped() const
Definition: ui.h:558
float PixelSize()
Definition: ui.cpp:454
CScrollRegion * m_pBecomingHotScrollRegion
Definition: ui.h:351
static const CLinearScrollbarScale ms_LinearScrollbarScale
Definition: ui.h:426
bool DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners=IGraphics::CORNER_ALL, const std::vector< STextColorSplit > &vColorSplits={})
Definition: ui.cpp:887
bool IsPopupOpen() const
Definition: ui.cpp:1651
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps={}, int StrLen=-1, const CTextCursor *pReadCursor=nullptr) const
Definition: ui.cpp:831
void DebugRender(float X, float Y)
Definition: ui.cpp:261
constexpr float ButtonColorMulDefault() const
Definition: ui.h:548
~CUi()
Definition: ui.cpp:120
void OnCursorMove(float X, float Y)
Definition: ui.cpp:166
static vec2 CalcAlignedCursorPos(const CUIRect *pRect, vec2 TextSize, int Align, const float *pBiggestCharHeight=nullptr)
Definition: ui.cpp:764
vec2 m_MouseWorldPos
Definition: ui.h:382
static CUi::EPopupMenuFunctionResult PopupSelection(void *pContext, CUIRect View, bool Active)
Definition: ui.cpp:1781
vec2 UpdatedMousePos() const
Definition: ui.h:484
int64_t DoValueSelector(const void *pId, const CUIRect *pRect, const char *pLabel, int64_t Current, int64_t Min, int64_t Max, const SValueSelectorProperties &Props={})
Definition: ui.cpp:1144
vec2 m_MouseDelta
Definition: ui.h:381
FPopupMenuClosedCallback m_pfnPopupMenuClosedCallback
Definition: ui.h:410
bool ConsumeHotkey(EHotkey Hotkey)
Definition: ui.cpp:380
int m_ActiveDraggableButtonLogicButton
Definition: ui.h:355
void RenderProgressBar(CUIRect ProgressBar, float Progress)
Definition: ui.cpp:1501
void UpdateTouchState(CTouchState &State) const
Definition: ui.cpp:299
IClient * m_pClient
Definition: ui.h:417
static CUi::EPopupMenuFunctionResult PopupConfirm(void *pContext, CUIRect View, bool Active)
Definition: ui.cpp:1733
IClient * Client() const
Definition: ui.h:435
vec2 MouseWorldPos() const
Definition: ui.h:481
static const CDarkButtonColorFunction ms_DarkButtonColorFunction
Definition: ui.h:428
static const CScrollBarColorFunction ms_ScrollBarColorFunction
Definition: ui.h:430
bool Enabled() const
Definition: ui.h:471
ITextRender * m_pTextRender
Definition: ui.h:420
float MouseWorldX() const
Definition: ui.h:482
bool MouseHovered(const CUIRect *pRect) const
Definition: ui.h:537
unsigned m_MouseButtons
Definition: ui.h:384
IInput * Input() const
Definition: ui.h:437
void MapScreen()
Definition: ui.cpp:448
void DisableMouseLock()
Definition: ui.h:499
void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const
Definition: ui.cpp:275
float MouseY() const
Definition: ui.h:477
float DoScrollbarV(const void *pId, const CUIRect *pRect, float Current)
Definition: ui.cpp:1276
bool m_ActiveItemValid
Definition: ui.h:352
float ButtonColorMul(const void *pId)
Definition: ui.cpp:432
ITextRender * TextRender() const
Definition: ui.h:438
float MouseDeltaY() const
Definition: ui.h:480
void AddUIElement(CUIElement *pElement)
Definition: ui.cpp:138
unsigned m_LastMouseButtons
Definition: ui.h:385
int MouseButton(int Index) const
Definition: ui.h:486
CScrollRegion * m_pHotScrollRegion
Definition: ui.h:350
int m_ActiveButtonLogicButton
Definition: ui.h:354
static CUi::EPopupMenuFunctionResult PopupMessage(void *pContext, CUIRect View, bool Active)
Definition: ui.cpp:1681
const void * m_pLastActiveItem
Definition: ui.h:348
bool MouseInsideClip() const
Definition: ui.h:536
int DoButton_Menu(CUIElement &UIElement, const CButtonContainer *pId, const std::function< const char *()> &GetTextLambda, const CUIRect *pRect, const SMenuButtonProperties &Props={})
Definition: ui.cpp:1030
void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext)
Definition: ui.cpp:1693
void ClosePopupMenu(const SPopupMenuId *pId, bool IncludeDescendants=false)
Definition: ui.cpp:1625
bool DoDoubleClickLogic(const void *pId)
Definition: ui.cpp:602
static const CLightButtonColorFunction ms_LightButtonColorFunction
Definition: ui.h:429
void ClearHotkeys()
Definition: ui.h:543
std::vector< CUIRect > m_vClips
Definition: ui.h:395
IGraphics * Graphics() const
Definition: ui.h:436
float m_ActiveScrollbarOffset
Definition: ui.h:365
void OnWindowResize()
Definition: ui.cpp:161
EPopupMenuFunctionResult(* FPopupMenuFunction)(void *pContext, CUIRect View, bool Active)
Definition: ui.h:316
const void * m_pLastEditingItem
Definition: ui.h:364
void UpdateClipping()
Definition: ui.cpp:491
static CUi::EPopupMenuFunctionResult PopupColorPicker(void *pContext, CUIRect View, bool Active)
Definition: ui.cpp:1904
vec2 UpdatedMouseDelta() const
Definition: ui.h:485
const CScrollRegion * HotScrollRegion() const
Definition: ui.h:522
vec2 m_UpdatedMousePos
Definition: ui.h:378
float MouseDeltaX() const
Definition: ui.h:479
void ShowPopupSelection(float X, float Y, SSelectionPopupContext *pContext)
Definition: ui.cpp:1831
@ SCROLLBAR_OPTION_MULTILINE
Definition: ui.h:639
@ SCROLLBAR_OPTION_INFINITE
Definition: ui.h:637
@ SCROLLBAR_OPTION_NOCLAMPVALUE
Definition: ui.h:638
bool m_MouseSlow
Definition: ui.h:387
void SetHotScrollRegion(CScrollRegion *pId)
Definition: ui.h:518
int MouseButtonClicked(int Index) const
Definition: ui.h:487
const void * ActiveItem() const
Definition: ui.h:521
int DoDraggableButtonLogic(const void *pId, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted)
Definition: ui.cpp:541
const CUIRect * Screen()
Definition: ui.cpp:441
static const float ms_FontmodHeight
Definition: ui.h:432
CUi()
Definition: ui.cpp:112
IInput * m_pInput
Definition: ui.h:419
void ShowPopupConfirm(float X, float Y, SConfirmPopupContext *pContext)
Definition: ui.cpp:1720
float DoScrollbarH(const void *pId, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner=nullptr)
Definition: ui.cpp:1346
std::vector< CUIElement * > m_vpUIElements
Definition: ui.h:423
vec2 MouseDelta() const
Definition: ui.h:478
const void * m_pBecomingHotItem
Definition: ui.h:349
void OnElementsReset()
Definition: ui.cpp:153
const CUIRect * ClipArea() const
Definition: ui.cpp:485
bool CheckActiveItem(const void *pId)
Definition: ui.h:509
CUIRect m_Screen
Definition: ui.h:393
const void * m_pMouseLockId
Definition: ui.h:389
void StartCheck()
Definition: ui.h:524
SEditResult< int64_t > DoValueSelectorWithState(const void *pId, const CUIRect *pRect, const char *pLabel, int64_t Current, int64_t Min, int64_t Max, const SValueSelectorProperties &Props={})
Definition: ui.cpp:1149
void Update(vec2 MouseWorldPos=vec2(-1.0f, -1.0f))
Definition: ui.cpp:177
int DoButtonLogic(const void *pId, int Checked, const CUIRect *pRect)
Definition: ui.cpp:506
constexpr float ButtonColorMulActive() const
Definition: ui.h:546
bool CheckMouseLock()
Definition: ui.h:488
void ClipDisable()
Definition: ui.cpp:478
void Init(IKernel *pKernel)
Definition: ui.cpp:101
EPopupMenuFunctionResult
Definition: ui.h:289
@ POPUP_KEEP_OPEN
Definition: ui.h:293
@ POPUP_CLOSE_CURRENT_AND_DESCENDANTS
Definition: ui.h:303
@ POPUP_CLOSE_CURRENT
Definition: ui.h:298
void SetHotItem(const void *pId)
Definition: ui.h:501
float MouseWorldY() const
Definition: ui.h:483
CUIElement * GetNewUIElement(int RequestedRectCount)
Definition: ui.cpp:129
bool DoEditBox_Search(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, bool HotkeyEnabled)
Definition: ui.cpp:1011
bool DoClearableEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners=IGraphics::CORNER_ALL, const std::vector< STextColorSplit > &vColorSplits={})
Definition: ui.cpp:990
CDoubleClickState m_DoubleClickState
Definition: ui.h:363
bool m_Enabled
Definition: ui.h:344
bool m_MouseLock
Definition: ui.h:388
void DoSmoothScrollLogic(float *pScrollOffset, float *pScrollOffsetChange, float ViewPortSize, float TotalSize, bool SmoothClamp=false, float ScrollSpeed=10.0f) const
Definition: ui.cpp:658
const void * NextHotItem() const
Definition: ui.h:520
void ShowPopupColorPicker(float X, float Y, SColorPickerPopupContext *pContext)
Definition: ui.cpp:2178
const void * m_pHotItem
Definition: ui.h:346
void RenderPopupMenus()
Definition: ui.cpp:1571
CValueSelectorState m_ActiveValueSelectorState
Definition: ui.h:376
void ClosePopupMenus()
Definition: ui.cpp:1640
float m_ProgressSpinnerOffset
Definition: ui.h:366
float MouseX() const
Definition: ui.h:476
bool DoScrollbarOption(const void *pId, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale=&ms_LinearScrollbarScale, unsigned Flags=0u, const char *pSuffix="")
Definition: ui.cpp:1447
Definition: color.h:173
Definition: color.h:203
Definition: color.h:210
Definition: ui.h:105
virtual ColorRGBA GetColor(bool Active, bool Hovered) const =0
Definition: client.h:36
Definition: graphics.h:183
@ CORNER_ALL
Definition: graphics.h:430
Definition: input.h:24
Definition: input.h:20
ECursorType
Definition: input.h:39
Definition: kernel.h:34
Definition: ui.h:54
virtual float ToRelative(int AbsoluteValue, int Min, int Max) const =0
virtual int ToAbsolute(float RelativeValue, int Min, int Max) const =0
Definition: textrender.h:312
T x
Definition: vmath.h:19
T y
Definition: vmath.h:23
constexpr int round_to_int(float f)
Definition: math.h:14
constexpr T maximum(T a, T b)
Definition: math.h:130
Definition: ui.h:158
CUIElement * m_pParent
Definition: ui.h:159
float m_Y
Definition: ui.h:166
CTextCursor m_Cursor
Definition: ui.h:175
float m_Height
Definition: ui.h:168
float m_Width
Definition: ui.h:167
ColorRGBA m_TextColor
Definition: ui.h:177
int m_ReadCursorGlyphCount
Definition: ui.h:173
int m_UIRectQuadContainer
Definition: ui.h:162
ColorRGBA m_TextOutlineColor
Definition: ui.h:178
void Draw(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding)
Definition: ui.cpp:57
std::string m_Text
Definition: ui.h:172
SUIElementRect()
Definition: ui.cpp:37
float m_Rounding
Definition: ui.h:169
void Reset()
Definition: ui.cpp:39
STextContainerIndex m_UITextContainer
Definition: ui.h:163
ColorRGBA m_QuadColor
Definition: ui.h:182
int m_Corners
Definition: ui.h:170
float m_X
Definition: ui.h:165
Definition: ui.h:727
EColorPickerMode m_ColorMode
Definition: ui.h:737
CUi * m_pUI
Definition: ui.h:736
EColorPickerMode
Definition: ui.h:729
@ MODE_UNSET
Definition: ui.h:730
@ MODE_HSVA
Definition: ui.h:731
@ MODE_HSLA
Definition: ui.h:733
@ MODE_RGBA
Definition: ui.h:732
const char m_HuePickerId
Definition: ui.h:744
bool m_Alpha
Definition: ui.h:738
const char m_ColorPickerId
Definition: ui.h:745
ColorRGBA m_RgbaColor
Definition: ui.h:741
EEditState m_State
Definition: ui.h:748
CButtonContainer m_aModeButtons[(int) MODE_HSLA+1]
Definition: ui.h:747
const char m_aValueSelectorIds[5]
Definition: ui.h:746
ColorHSLA m_HslaColor
Definition: ui.h:742
unsigned int * m_pHslaColor
Definition: ui.h:739
ColorHSVA m_HsvaColor
Definition: ui.h:740
Definition: ui.h:676
static constexpr float POPUP_FONT_SIZE
Definition: ui.h:684
static constexpr float POPUP_BUTTON_SPACING
Definition: ui.h:686
static constexpr float POPUP_MAX_WIDTH
Definition: ui.h:683
EConfirmationResult
Definition: ui.h:678
@ CONFIRMED
Definition: ui.h:680
@ CANCELED
Definition: ui.h:681
@ UNSET
Definition: ui.h:679
char m_aNegativeButtonLabel[128]
Definition: ui.h:690
static constexpr float POPUP_BUTTON_HEIGHT
Definition: ui.h:685
CButtonContainer m_ConfirmButton
Definition: ui.h:695
char m_aPositiveButtonLabel[128]
Definition: ui.h:689
CUi * m_pUI
Definition: ui.h:688
void Reset()
Definition: ui.cpp:1709
char m_aMessage[1024]
Definition: ui.h:691
CButtonContainer m_CancelButton
Definition: ui.h:694
SConfirmPopupContext()
Definition: ui.cpp:1704
EConfirmationResult m_Result
Definition: ui.h:692
void YesNoButtons()
Definition: ui.cpp:1714
Definition: ui.h:754
CUIElement m_UiElement
Definition: ui.h:756
CButtonContainer m_ButtonContainer
Definition: ui.h:757
bool m_Init
Definition: ui.h:758
SSelectionPopupContext m_SelectionPopupContext
Definition: ui.h:755
Definition: ui.h:662
void ErrorColor()
Definition: ui.cpp:1676
static constexpr float POPUP_MAX_WIDTH
Definition: ui.h:663
char m_aMessage[1024]
Definition: ui.h:667
ColorRGBA m_TextColor
Definition: ui.h:668
CUi * m_pUI
Definition: ui.h:666
void DefaultColor(class ITextRender *pTextRender)
Definition: ui.cpp:1671
static constexpr float POPUP_FONT_SIZE
Definition: ui.h:664
Definition: ui.h:399
void * m_pContext
Definition: ui.h:406
static constexpr float POPUP_MARGIN
Definition: ui.h:401
const SPopupMenuId * m_pId
Definition: ui.h:403
static constexpr float POPUP_BORDER
Definition: ui.h:400
CUIRect m_Rect
Definition: ui.h:405
FPopupMenuFunction m_pfnFunc
Definition: ui.h:407
SPopupMenuProperties m_Props
Definition: ui.h:404
Definition: ui.h:704
float m_AlignmentHeight
Definition: ui.h:718
int m_SelectionIndex
Definition: ui.h:712
float m_EntryHeight
Definition: ui.h:713
float m_EntrySpacing
Definition: ui.h:715
bool m_TransparentButtons
Definition: ui.h:719
char m_aMessage[256]
Definition: ui.h:708
const std::string * m_pSelection
Definition: ui.h:711
SSelectionPopupContext()
Definition: ui.cpp:1759
float m_EntryPadding
Definition: ui.h:714
void Reset()
Definition: ui.cpp:1764
std::vector< CButtonContainer > m_vButtonContainers
Definition: ui.h:710
CUi * m_pUI
Definition: ui.h:705
SPopupMenuProperties m_Props
Definition: ui.h:707
float m_Width
Definition: ui.h:717
std::vector< std::string > m_vEntries
Definition: ui.h:709
float m_FontSize
Definition: ui.h:716
CScrollRegion * m_pScrollRegion
Definition: ui.h:706
Definition: ui.h:33
T m_Value
Definition: ui.h:35
EEditState m_State
Definition: ui.h:34
Definition: ui.h:211
float m_MaxWidth
Definition: ui.h:212
std::vector< STextColorSplit > m_vColorSplits
Definition: ui.h:216
bool m_StopAtEnd
Definition: ui.h:213
bool m_EllipsisAtEnd
Definition: ui.h:214
bool m_EnableWidthCheck
Definition: ui.h:215
Definition: ui.h:220
ColorRGBA m_Color
Definition: ui.h:229
bool m_UseIconFont
Definition: ui.h:224
bool m_ShowDropDownIcon
Definition: ui.h:225
bool m_HintRequiresStringCheck
Definition: ui.h:222
bool m_HintCanChangePositionOrSize
Definition: ui.h:223
float m_FontFactor
Definition: ui.h:228
float m_Rounding
Definition: ui.h:227
int m_Corners
Definition: ui.h:226
int m_Checked
Definition: ui.h:221
Definition: ui.h:272
Definition: ui.h:276
ColorRGBA m_BackgroundColor
Definition: ui.h:279
int m_Corners
Definition: ui.h:277
ColorRGBA m_BorderColor
Definition: ui.h:278
Definition: ui.h:262
int m_Segments
Definition: ui.h:265
ColorRGBA m_Color
Definition: ui.h:264
float m_Progress
Definition: ui.h:263
Definition: textrender.h:293
Definition: ui.h:39
std::chrono::nanoseconds m_Time
Definition: ui.h:44
bool m_ScaleLabel
Definition: ui.h:41
float m_Value
Definition: ui.h:45
float m_XOffset
Definition: ui.h:47
bool m_Active
Definition: ui.h:40
float m_HOffset
Definition: ui.h:50
float m_WOffset
Definition: ui.h:49
bool m_RepositionLabel
Definition: ui.h:42
float m_YOffset
Definition: ui.h:48
Definition: ui.h:252
int64_t m_Step
Definition: ui.h:254
ColorRGBA m_Color
Definition: ui.h:258
float m_Scale
Definition: ui.h:255
int m_HexPrefix
Definition: ui.h:257
bool m_UseScroll
Definition: ui.h:253
bool m_IsHex
Definition: ui.h:256
EEditState
Definition: ui.h:23
vector2_base< float > vec2
Definition: vmath.h:158