2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_CLIENT_UI_H
|
|
|
|
#define GAME_CLIENT_UI_H
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2022-07-08 15:56:06 +00:00
|
|
|
#include "ui_rect.h"
|
|
|
|
|
2022-06-06 20:03:24 +00:00
|
|
|
#include <engine/input.h>
|
2020-10-12 10:29:47 +00:00
|
|
|
#include <engine/textrender.h>
|
2022-05-18 16:00:05 +00:00
|
|
|
|
|
|
|
#include <chrono>
|
2023-03-27 15:22:17 +00:00
|
|
|
#include <set>
|
2020-10-12 10:29:47 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-08-10 21:00:25 +00:00
|
|
|
class IClient;
|
2022-08-07 20:03:34 +00:00
|
|
|
class IGraphics;
|
|
|
|
class IKernel;
|
|
|
|
|
2020-10-26 01:10:55 +00:00
|
|
|
struct SUIAnimator
|
|
|
|
{
|
2020-10-26 02:48:05 +00:00
|
|
|
bool m_Active;
|
|
|
|
bool m_ScaleLabel;
|
2020-10-26 03:10:58 +00:00
|
|
|
bool m_RepositionLabel;
|
2020-10-26 02:48:05 +00:00
|
|
|
|
2022-05-18 16:00:05 +00:00
|
|
|
std::chrono::nanoseconds m_Time;
|
2020-10-26 01:10:55 +00:00
|
|
|
float m_Value;
|
2020-10-26 02:48:05 +00:00
|
|
|
|
|
|
|
float m_XOffset;
|
|
|
|
float m_YOffset;
|
|
|
|
float m_WOffset;
|
|
|
|
float m_HOffset;
|
2020-10-26 01:10:55 +00:00
|
|
|
};
|
|
|
|
|
2022-08-07 20:03:34 +00:00
|
|
|
class IScrollbarScale
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual float ToRelative(int AbsoluteValue, int Min, int Max) const = 0;
|
|
|
|
virtual int ToAbsolute(float RelativeValue, int Min, int Max) const = 0;
|
|
|
|
};
|
|
|
|
class CLinearScrollbarScale : public IScrollbarScale
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float ToRelative(int AbsoluteValue, int Min, int Max) const override
|
|
|
|
{
|
|
|
|
return (AbsoluteValue - Min) / (float)(Max - Min);
|
|
|
|
}
|
|
|
|
int ToAbsolute(float RelativeValue, int Min, int Max) const override
|
|
|
|
{
|
|
|
|
return round_to_int(RelativeValue * (Max - Min) + Min + 0.1f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
class CLogarithmicScrollbarScale : public IScrollbarScale
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_MinAdjustment;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLogarithmicScrollbarScale(int MinAdjustment)
|
|
|
|
{
|
|
|
|
m_MinAdjustment = maximum(MinAdjustment, 1); // must be at least 1 to support Min == 0 with logarithm
|
|
|
|
}
|
|
|
|
float ToRelative(int AbsoluteValue, int Min, int Max) const override
|
|
|
|
{
|
|
|
|
if(Min < m_MinAdjustment)
|
|
|
|
{
|
|
|
|
AbsoluteValue += m_MinAdjustment;
|
|
|
|
Min += m_MinAdjustment;
|
|
|
|
Max += m_MinAdjustment;
|
|
|
|
}
|
2023-02-28 20:31:40 +00:00
|
|
|
return (std::log(AbsoluteValue) - std::log(Min)) / (float)(std::log(Max) - std::log(Min));
|
2022-08-07 20:03:34 +00:00
|
|
|
}
|
|
|
|
int ToAbsolute(float RelativeValue, int Min, int Max) const override
|
|
|
|
{
|
|
|
|
int ResultAdjustment = 0;
|
|
|
|
if(Min < m_MinAdjustment)
|
|
|
|
{
|
|
|
|
Min += m_MinAdjustment;
|
|
|
|
Max += m_MinAdjustment;
|
|
|
|
ResultAdjustment = -m_MinAdjustment;
|
|
|
|
}
|
2023-02-28 20:31:40 +00:00
|
|
|
return round_to_int(std::exp(RelativeValue * (std::log(Max) - std::log(Min)) + std::log(Min))) + ResultAdjustment;
|
2022-08-07 20:03:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SUIExEditBoxProperties
|
|
|
|
{
|
|
|
|
bool m_SelectText = false;
|
|
|
|
const char *m_pEmptyText = "";
|
|
|
|
};
|
|
|
|
|
2020-10-12 10:29:47 +00:00
|
|
|
class CUI;
|
|
|
|
|
|
|
|
class CUIElement
|
|
|
|
{
|
|
|
|
friend class CUI;
|
|
|
|
|
2022-07-09 21:35:00 +00:00
|
|
|
CUI *m_pUI;
|
|
|
|
|
2021-09-13 21:48:10 +00:00
|
|
|
CUIElement(CUI *pUI, int RequestedRectCount) { Init(pUI, RequestedRectCount); }
|
2020-10-12 10:29:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct SUIElementRect
|
|
|
|
{
|
2022-07-09 21:35:00 +00:00
|
|
|
CUIElement *m_pParent;
|
|
|
|
|
2020-10-12 10:29:47 +00:00
|
|
|
public:
|
|
|
|
int m_UIRectQuadContainer;
|
|
|
|
int m_UITextContainer;
|
|
|
|
|
|
|
|
float m_X;
|
|
|
|
float m_Y;
|
|
|
|
float m_Width;
|
|
|
|
float m_Height;
|
|
|
|
|
|
|
|
std::string m_Text;
|
|
|
|
|
|
|
|
CTextCursor m_Cursor;
|
|
|
|
|
2022-07-01 04:42:36 +00:00
|
|
|
ColorRGBA m_TextColor;
|
|
|
|
ColorRGBA m_TextOutlineColor;
|
2020-11-08 18:41:16 +00:00
|
|
|
|
2020-11-25 12:05:53 +00:00
|
|
|
SUIElementRect();
|
2021-09-13 21:48:10 +00:00
|
|
|
|
|
|
|
ColorRGBA m_QuadColor;
|
|
|
|
|
|
|
|
void Reset();
|
2022-07-09 21:35:00 +00:00
|
|
|
void Draw(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding);
|
2020-10-12 10:29:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2022-07-09 21:35:00 +00:00
|
|
|
CUI *UI() const { return m_pUI; }
|
2022-06-11 19:38:18 +00:00
|
|
|
std::vector<SUIElementRect> m_vUIRects;
|
2020-10-12 10:29:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CUIElement() = default;
|
|
|
|
|
2021-09-13 21:48:10 +00:00
|
|
|
void Init(CUI *pUI, int RequestedRectCount);
|
2020-10-12 10:29:47 +00:00
|
|
|
|
2022-08-13 09:40:04 +00:00
|
|
|
SUIElementRect *Rect(size_t Index)
|
2020-10-12 10:29:47 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
return &m_vUIRects[Index];
|
2020-10-12 10:29:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 21:48:10 +00:00
|
|
|
bool AreRectsInit()
|
2020-10-12 10:29:47 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
return !m_vUIRects.empty();
|
2020-10-12 10:29:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 21:48:10 +00:00
|
|
|
void InitRects(int RequestedRectCount);
|
2020-10-12 10:29:47 +00:00
|
|
|
};
|
|
|
|
|
2022-03-11 16:34:48 +00:00
|
|
|
struct SLabelProperties
|
|
|
|
{
|
|
|
|
float m_MaxWidth = -1;
|
|
|
|
int m_AlignVertically = 1;
|
|
|
|
bool m_StopAtEnd = false;
|
|
|
|
class CTextCursor *m_pSelCursor = nullptr;
|
|
|
|
bool m_EnableWidthCheck = true;
|
|
|
|
};
|
|
|
|
|
2022-08-13 11:58:11 +00:00
|
|
|
class CUIElementBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static CUI *s_pUI;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void Init(CUI *pUI) { s_pUI = pUI; }
|
|
|
|
|
|
|
|
IClient *Client() const;
|
|
|
|
IGraphics *Graphics() const;
|
|
|
|
IInput *Input() const;
|
|
|
|
ITextRender *TextRender() const;
|
|
|
|
CUI *UI() const { return s_pUI; }
|
|
|
|
};
|
|
|
|
|
2022-07-16 13:32:06 +00:00
|
|
|
class CButtonContainer
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2023-03-27 15:22:17 +00:00
|
|
|
/**
|
|
|
|
* Type safe UI ID for popup menus.
|
|
|
|
*/
|
|
|
|
struct SPopupMenuId
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
class CUI
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2023-03-27 15:22:17 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* These enum values are returned by popup menu functions to specify the behavior.
|
|
|
|
*/
|
|
|
|
enum EPopupMenuFunctionResult
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The current popup menu will be kept open.
|
|
|
|
*/
|
|
|
|
POPUP_KEEP_OPEN = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current popup menu will be closed.
|
|
|
|
*/
|
|
|
|
POPUP_CLOSE_CURRENT = 1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current popup menu and all popup menus above it will be closed.
|
|
|
|
*/
|
|
|
|
POPUP_CLOSE_CURRENT_AND_DESCENDANTS = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback that draws a popup menu.
|
|
|
|
*
|
|
|
|
* @param pContext The context object of the popup menu.
|
|
|
|
* @param View The UI rect where the popup menu's contents should be drawn.
|
|
|
|
* @param Active Whether this popup is active (the top-most popup).
|
|
|
|
* Only the active popup should handle key and mouse events.
|
|
|
|
*
|
|
|
|
* @return Value from the @link EPopupMenuFunctionResult @endlink enum.
|
|
|
|
*/
|
|
|
|
typedef EPopupMenuFunctionResult (*FPopupMenuFunction)(void *pContext, CUIRect View, bool Active);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback that is called when one or more popups are closed.
|
|
|
|
*/
|
|
|
|
typedef std::function<void()> FPopupMenuClosedCallback;
|
|
|
|
|
|
|
|
private:
|
2022-05-27 16:14:31 +00:00
|
|
|
bool m_Enabled;
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
const void *m_pHotItem;
|
|
|
|
const void *m_pActiveItem;
|
|
|
|
const void *m_pLastActiveItem;
|
2021-11-22 17:26:13 +00:00
|
|
|
const void *m_pBecomingHotItem;
|
2022-04-07 07:46:02 +00:00
|
|
|
const void *m_pActiveTooltipItem;
|
2022-05-27 08:55:32 +00:00
|
|
|
bool m_ActiveItemValid = false;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_MouseX, m_MouseY; // in gui space
|
2020-12-14 00:51:31 +00:00
|
|
|
float m_MouseDeltaX, m_MouseDeltaY; // in gui space
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_MouseWorldX, m_MouseWorldY; // in world space
|
2009-10-27 14:38:53 +00:00
|
|
|
unsigned m_MouseButtons;
|
|
|
|
unsigned m_LastMouseButtons;
|
2022-08-07 20:03:34 +00:00
|
|
|
bool m_MouseSlow = false;
|
|
|
|
|
|
|
|
IInput::CEvent *m_pInputEventsArray;
|
|
|
|
int *m_pInputEventCount;
|
2022-08-21 11:17:09 +00:00
|
|
|
unsigned m_HotkeysPressed = 0;
|
2022-08-07 20:03:34 +00:00
|
|
|
|
|
|
|
bool m_MouseIsPress = false;
|
|
|
|
bool m_HasSelection = false;
|
|
|
|
|
|
|
|
int m_MousePressX = 0;
|
|
|
|
int m_MousePressY = 0;
|
|
|
|
int m_MouseCurX = 0;
|
|
|
|
int m_MouseCurY = 0;
|
|
|
|
int m_CurSelStart = 0;
|
|
|
|
int m_CurSelEnd = 0;
|
|
|
|
const void *m_pSelItem = nullptr;
|
|
|
|
|
|
|
|
int m_CurCursor = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
CUIRect m_Screen;
|
2022-05-13 18:20:04 +00:00
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
std::vector<CUIRect> m_vClips;
|
2022-05-13 18:20:04 +00:00
|
|
|
void UpdateClipping();
|
|
|
|
|
2023-03-27 15:22:17 +00:00
|
|
|
struct SPopupMenu
|
|
|
|
{
|
|
|
|
static constexpr float POPUP_BORDER = 1.0f;
|
|
|
|
static constexpr float POPUP_MARGIN = 4.0f;
|
|
|
|
|
|
|
|
const SPopupMenuId *m_pID;
|
|
|
|
CUIRect m_Rect;
|
|
|
|
int m_Corners;
|
|
|
|
void *m_pContext;
|
|
|
|
FPopupMenuFunction m_pfnFunc;
|
|
|
|
};
|
|
|
|
std::vector<SPopupMenu> m_vPopupMenus;
|
|
|
|
FPopupMenuClosedCallback m_pfnPopupMenuClosedCallback = nullptr;
|
|
|
|
|
|
|
|
static CUI::EPopupMenuFunctionResult PopupMessage(void *pContext, CUIRect View, bool Active);
|
|
|
|
static CUI::EPopupMenuFunctionResult PopupConfirm(void *pContext, CUIRect View, bool Active);
|
|
|
|
static CUI::EPopupMenuFunctionResult PopupSelection(void *pContext, CUIRect View, bool Active);
|
|
|
|
|
2022-08-10 21:00:25 +00:00
|
|
|
IClient *m_pClient;
|
2022-08-07 20:03:34 +00:00
|
|
|
IGraphics *m_pGraphics;
|
|
|
|
IInput *m_pInput;
|
|
|
|
ITextRender *m_pTextRender;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
std::vector<CUIElement *> m_vpOwnUIElements; // ui elements maintained by CUI class
|
|
|
|
std::vector<CUIElement *> m_vpUIElements;
|
2020-10-12 10:29:47 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
2022-08-07 20:03:34 +00:00
|
|
|
static const CLinearScrollbarScale ms_LinearScrollbarScale;
|
|
|
|
static const CLogarithmicScrollbarScale ms_LogarithmicScrollbarScale;
|
|
|
|
|
2021-12-03 18:49:22 +00:00
|
|
|
static float ms_FontmodHeight;
|
|
|
|
|
2022-08-07 20:03:34 +00:00
|
|
|
void Init(IKernel *pKernel);
|
|
|
|
void InitInputs(IInput::CEvent *pInputEventsArray, int *pInputEventCount);
|
2022-08-10 21:00:25 +00:00
|
|
|
IClient *Client() const { return m_pClient; }
|
2022-08-07 20:03:34 +00:00
|
|
|
IGraphics *Graphics() const { return m_pGraphics; }
|
|
|
|
IInput *Input() const { return m_pInput; }
|
|
|
|
ITextRender *TextRender() const { return m_pTextRender; }
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
CUI();
|
2020-10-12 10:29:47 +00:00
|
|
|
~CUI();
|
|
|
|
|
2022-08-21 11:17:09 +00:00
|
|
|
enum EHotkey : unsigned
|
|
|
|
{
|
|
|
|
HOTKEY_ENTER = 1 << 0,
|
|
|
|
HOTKEY_ESCAPE = 1 << 1,
|
|
|
|
HOTKEY_UP = 1 << 2,
|
|
|
|
HOTKEY_DOWN = 1 << 3,
|
|
|
|
HOTKEY_DELETE = 1 << 4,
|
|
|
|
HOTKEY_TAB = 1 << 5,
|
|
|
|
HOTKEY_SCROLL_UP = 1 << 6,
|
|
|
|
HOTKEY_SCROLL_DOWN = 1 << 7,
|
2023-01-05 19:38:30 +00:00
|
|
|
HOTKEY_PAGE_UP = 1 << 8,
|
|
|
|
HOTKEY_PAGE_DOWN = 1 << 9,
|
|
|
|
HOTKEY_HOME = 1 << 10,
|
|
|
|
HOTKEY_END = 1 << 11,
|
2022-08-21 11:17:09 +00:00
|
|
|
};
|
|
|
|
|
2020-10-12 10:29:47 +00:00
|
|
|
void ResetUIElement(CUIElement &UIElement);
|
|
|
|
|
2021-09-13 21:48:10 +00:00
|
|
|
CUIElement *GetNewUIElement(int RequestedRectCount);
|
2020-10-12 10:29:47 +00:00
|
|
|
|
|
|
|
void AddUIElement(CUIElement *pElement);
|
|
|
|
void OnElementsReset();
|
|
|
|
void OnWindowResize();
|
|
|
|
void OnLanguageChange();
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2022-05-27 16:14:31 +00:00
|
|
|
void SetEnabled(bool Enabled) { m_Enabled = Enabled; }
|
|
|
|
bool Enabled() const { return m_Enabled; }
|
|
|
|
void Update(float MouseX, float MouseY, float MouseWorldX, float MouseWorldY);
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2020-12-14 00:51:31 +00:00
|
|
|
float MouseDeltaX() const { return m_MouseDeltaX; }
|
|
|
|
float MouseDeltaY() const { return m_MouseDeltaY; }
|
2009-10-27 14:38:53 +00:00
|
|
|
float MouseX() const { return m_MouseX; }
|
|
|
|
float MouseY() const { return m_MouseY; }
|
|
|
|
float MouseWorldX() const { return m_MouseWorldX; }
|
|
|
|
float MouseWorldY() const { return m_MouseWorldY; }
|
2020-09-26 19:41:58 +00:00
|
|
|
int MouseButton(int Index) const { return (m_MouseButtons >> Index) & 1; }
|
2021-02-08 21:26:26 +00:00
|
|
|
int MouseButtonClicked(int Index) const { return MouseButton(Index) && !((m_LastMouseButtons >> Index) & 1); }
|
|
|
|
int MouseButtonReleased(int Index) const { return ((m_LastMouseButtons >> Index) & 1) && !MouseButton(Index); }
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2021-11-22 17:26:13 +00:00
|
|
|
void SetHotItem(const void *pID) { m_pBecomingHotItem = pID; }
|
2020-09-26 19:41:58 +00:00
|
|
|
void SetActiveItem(const void *pID)
|
|
|
|
{
|
2022-05-27 08:55:32 +00:00
|
|
|
m_ActiveItemValid = true;
|
2020-09-26 19:41:58 +00:00
|
|
|
m_pActiveItem = pID;
|
|
|
|
if(pID)
|
|
|
|
m_pLastActiveItem = pID;
|
|
|
|
}
|
2022-05-27 08:55:32 +00:00
|
|
|
bool CheckActiveItem(const void *pID)
|
|
|
|
{
|
|
|
|
if(m_pActiveItem == pID)
|
|
|
|
{
|
|
|
|
m_ActiveItemValid = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-07 07:46:02 +00:00
|
|
|
void SetActiveTooltipItem(const void *pID) { m_pActiveTooltipItem = pID; }
|
2022-05-27 08:55:32 +00:00
|
|
|
void ClearLastActiveItem() { m_pLastActiveItem = nullptr; }
|
2009-10-27 14:38:53 +00:00
|
|
|
const void *HotItem() const { return m_pHotItem; }
|
2021-11-22 17:26:13 +00:00
|
|
|
const void *NextHotItem() const { return m_pBecomingHotItem; }
|
2009-10-27 14:38:53 +00:00
|
|
|
const void *ActiveItem() const { return m_pActiveItem; }
|
2022-04-07 07:46:02 +00:00
|
|
|
const void *ActiveTooltipItem() const { return m_pActiveTooltipItem; }
|
2009-10-27 14:38:53 +00:00
|
|
|
const void *LastActiveItem() const { return m_pLastActiveItem; }
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2022-05-27 08:55:32 +00:00
|
|
|
void StartCheck() { m_ActiveItemValid = false; }
|
|
|
|
void FinishCheck()
|
|
|
|
{
|
2022-05-27 17:00:03 +00:00
|
|
|
if(!m_ActiveItemValid && m_pActiveItem != nullptr)
|
|
|
|
{
|
2022-05-27 08:55:32 +00:00
|
|
|
SetActiveItem(nullptr);
|
2022-05-27 17:00:03 +00:00
|
|
|
m_pHotItem = nullptr;
|
|
|
|
m_pBecomingHotItem = nullptr;
|
|
|
|
}
|
2022-05-27 08:55:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:55:31 +00:00
|
|
|
bool MouseInside(const CUIRect *pRect) const;
|
2022-05-13 18:24:10 +00:00
|
|
|
bool MouseInsideClip() const { return !IsClipped() || MouseInside(ClipArea()); }
|
|
|
|
bool MouseHovered(const CUIRect *pRect) const { return MouseInside(pRect) && MouseInsideClip(); }
|
2022-06-06 20:03:24 +00:00
|
|
|
void ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType) const;
|
2022-08-07 20:03:34 +00:00
|
|
|
void ResetMouseSlow() { m_MouseSlow = false; }
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2022-08-21 11:17:09 +00:00
|
|
|
bool ConsumeHotkey(EHotkey Hotkey);
|
|
|
|
void ClearHotkeys() { m_HotkeysPressed = 0; }
|
|
|
|
bool OnInput(const IInput::CEvent &Event);
|
|
|
|
|
2023-03-27 15:22:17 +00:00
|
|
|
constexpr float ButtonColorMulActive() const { return 0.5f; }
|
|
|
|
constexpr float ButtonColorMulHot() const { return 1.5f; }
|
|
|
|
constexpr float ButtonColorMulDefault() const { return 1.0f; }
|
2021-11-26 20:55:31 +00:00
|
|
|
float ButtonColorMul(const void *pID);
|
|
|
|
|
2023-04-07 09:50:30 +00:00
|
|
|
const CUIRect *Screen();
|
2021-09-22 19:48:55 +00:00
|
|
|
void MapScreen();
|
2012-01-10 22:13:19 +00:00
|
|
|
float PixelSize();
|
2022-05-13 18:20:04 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void ClipEnable(const CUIRect *pRect);
|
2009-10-27 14:38:53 +00:00
|
|
|
void ClipDisable();
|
2022-05-13 18:20:04 +00:00
|
|
|
const CUIRect *ClipArea() const;
|
2022-06-11 19:38:18 +00:00
|
|
|
inline bool IsClipped() const { return !m_vClips.empty(); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-10-12 10:29:47 +00:00
|
|
|
int DoButtonLogic(const void *pID, int Checked, const CUIRect *pRect);
|
2023-03-15 17:15:43 +00:00
|
|
|
int DoDraggableButtonLogic(const void *pID, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted);
|
2015-08-17 12:10:08 +00:00
|
|
|
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
|
2022-08-10 21:00:25 +00:00
|
|
|
void DoSmoothScrollLogic(float *pScrollOffset, float *pScrollOffsetChange, float ViewPortSize, float TotalSize, float ScrollSpeed = 10.0f);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-03-11 16:34:48 +00:00
|
|
|
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {});
|
2020-10-12 10:29:47 +00:00
|
|
|
|
Mark parameters as `const` when possible
According to cppchecker's `constParameter` error:
```
src\engine\gfx\image_manipulation.cpp:7:58: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void Dilate(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest, unsigned char AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD)
^
src\engine\gfx\image_manipulation.cpp:58:67: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void CopyColorValues(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest)
^
src\engine\shared\network_conn.cpp:241:42: style: Parameter 'Addr' can be declared as reference to const [constParameter]
void CNetConnection::DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup)
^
src\base\system.cpp:4060:71: style: Parameter 'random' can be declared as pointer to const [constParameter]
void generate_password(char *buffer, unsigned length, unsigned short *random, unsigned random_length)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:263:38: style: Parameter 'AllocatedMemory' can be declared as reference to const [constParameter]
void Free(SMemoryHeapQueueElement &AllocatedMemory)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:1708:47: style: Parameter 'ImgExtent' can be declared as reference to const [constParameter]
static size_t ImageMipLevelCount(VkExtent3D &ImgExtent)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2801:29: style: Parameter 'Image' can be declared as reference to const [constParameter]
void ImageBarrier(VkImage &Image, size_t MipMapBase, size_t MipMapCount, size_t LayerBase, size_t LayerCount, VkFormat Format, VkImageLayout OldLayout, VkImageLayout NewLayout)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6495:46: style: Parameter 'ExecBuffer' can be declared as reference to const [constParameter]
void Cmd_Clear(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_Clear *pCommand)
^
src\game\client\components\skins.cpp:83:72: style: Parameter 'pImg' can be declared as pointer to const [constParameter]
static void CheckMetrics(CSkin::SSkinMetricVariable &Metrics, uint8_t *pImg, int ImgWidth, int ImgX, int ImgY, int CheckWidth, int CheckHeight)
^
src\game\client\prediction\entities\character.h:106:37: style: Parameter 'pNewInput' can be declared as pointer to const [constParameter]
void SetInput(CNetObj_PlayerInput *pNewInput)
^
src\game\client\prediction\gameworld.cpp:245:106: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:245:151: style: Parameter 'pThisOnly' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:283:116: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
std::list<class CCharacter *> CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, class CEntity *pNotThis)
^
src\game\client\ui.cpp:522:180: style: Parameter 'pReadCursor' can be declared as pointer to const [constParameter]
void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, CTextCursor *pReadCursor)
^
src\game\client\ui_scrollregion.cpp:23:86: style: Parameter 'pParams' can be declared as pointer to const [constParameter]
void CScrollRegion::Begin(CUIRect *pClipRect, vec2 *pOutOffset, CScrollRegionParams *pParams)
^
src\game\server\scoreworker.h:239:29: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void Set(float Time, float aTimeCp[NUM_CHECKPOINTS])
^
src\game\server\score.cpp:135:80: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible)
^
src\game\server\teeinfo.cpp:40:57: style: Parameter 'pUseCustomColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
src\game\server\teeinfo.cpp:40:80: style: Parameter 'pSkinPartColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
```
2022-11-13 14:32:53 +00:00
|
|
|
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);
|
|
|
|
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, const CTextCursor *pReadCursor = nullptr);
|
2022-08-07 20:03:34 +00:00
|
|
|
|
|
|
|
bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {});
|
|
|
|
bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = IGraphics::CORNER_ALL, const SUIExEditBoxProperties &Properties = {});
|
|
|
|
|
2023-03-27 15:22:17 +00:00
|
|
|
int DoButton_PopupMenu(CButtonContainer *pButtonContainer, const char *pText, const CUIRect *pRect, int Align);
|
|
|
|
|
2022-08-07 20:03:34 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SCROLLBAR_OPTION_INFINITE = 1,
|
|
|
|
SCROLLBAR_OPTION_NOCLAMPVALUE = 2,
|
|
|
|
};
|
|
|
|
float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current);
|
|
|
|
float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner = nullptr);
|
|
|
|
void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned Flags = 0u);
|
|
|
|
void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char **ppLabels, int NumLabels, const IScrollbarScale *pScale = &ms_LinearScrollbarScale);
|
2023-03-27 15:22:17 +00:00
|
|
|
|
|
|
|
// popup menu
|
|
|
|
void DoPopupMenu(const SPopupMenuId *pID, int X, int Y, int Width, int Height, void *pContext, FPopupMenuFunction pfnFunc, int Corners = IGraphics::CORNER_ALL);
|
|
|
|
void RenderPopupMenus();
|
|
|
|
void ClosePopupMenu(const SPopupMenuId *pID, bool IncludeDescendants = false);
|
|
|
|
void ClosePopupMenus();
|
|
|
|
bool IsPopupOpen() const;
|
|
|
|
bool IsPopupOpen(const SPopupMenuId *pID) const;
|
|
|
|
bool IsPopupHovered() const;
|
|
|
|
void SetPopupMenuClosedCallback(FPopupMenuClosedCallback pfnCallback);
|
|
|
|
|
|
|
|
struct SMessagePopupContext : public SPopupMenuId
|
|
|
|
{
|
|
|
|
static constexpr float POPUP_MAX_WIDTH = 200.0f;
|
|
|
|
static constexpr float POPUP_FONT_SIZE = 10.0f;
|
|
|
|
|
|
|
|
CUI *m_pUI; // set by CUI when popup is shown
|
|
|
|
char m_aMessage[1024];
|
|
|
|
ColorRGBA m_TextColor;
|
|
|
|
|
|
|
|
void DefaultColor(class ITextRender *pTextRender);
|
|
|
|
void ErrorColor();
|
|
|
|
};
|
|
|
|
void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext);
|
|
|
|
|
|
|
|
struct SConfirmPopupContext : public SPopupMenuId
|
|
|
|
{
|
|
|
|
enum EConfirmationResult
|
|
|
|
{
|
|
|
|
UNSET = 0,
|
|
|
|
CONFIRMED,
|
|
|
|
CANCELED,
|
|
|
|
};
|
|
|
|
static constexpr float POPUP_MAX_WIDTH = 200.0f;
|
|
|
|
static constexpr float POPUP_FONT_SIZE = 10.0f;
|
|
|
|
static constexpr float POPUP_BUTTON_HEIGHT = 12.0f;
|
|
|
|
static constexpr float POPUP_BUTTON_SPACING = 5.0f;
|
|
|
|
|
|
|
|
CUI *m_pUI; // set by CUI when popup is shown
|
|
|
|
char m_aPositiveButtonLabel[128];
|
|
|
|
char m_aNegativeButtonLabel[128];
|
|
|
|
char m_aMessage[1024];
|
|
|
|
EConfirmationResult m_Result;
|
|
|
|
|
|
|
|
SConfirmPopupContext();
|
|
|
|
void Reset();
|
|
|
|
void YesNoButtons();
|
|
|
|
};
|
|
|
|
void ShowPopupConfirm(float X, float Y, SConfirmPopupContext *pContext);
|
|
|
|
|
|
|
|
struct SSelectionPopupContext : public SPopupMenuId
|
|
|
|
{
|
|
|
|
static constexpr float POPUP_MAX_WIDTH = 300.0f;
|
|
|
|
static constexpr float POPUP_FONT_SIZE = 10.0f;
|
|
|
|
static constexpr float POPUP_ENTRY_HEIGHT = 12.0f;
|
|
|
|
static constexpr float POPUP_ENTRY_SPACING = 5.0f;
|
|
|
|
|
|
|
|
CUI *m_pUI; // set by CUI when popup is shown
|
|
|
|
char m_aMessage[256];
|
|
|
|
std::set<std::string> m_Entries;
|
|
|
|
std::vector<CButtonContainer> m_vButtonContainers;
|
|
|
|
const std::string *m_pSelection;
|
|
|
|
|
|
|
|
SSelectionPopupContext();
|
|
|
|
void Reset();
|
|
|
|
};
|
|
|
|
void ShowPopupSelection(float X, float Y, SSelectionPopupContext *pContext);
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
#endif
|