mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Allow adjusting popup border/background color
Add `SPopupMenuProperties` parameter object for `DoPopupMenu`.
This commit is contained in:
parent
09835ed342
commit
f0bb4a45d0
|
@ -1273,7 +1273,7 @@ void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect,
|
|||
*pOption = Value;
|
||||
}
|
||||
|
||||
void CUI::DoPopupMenu(const SPopupMenuId *pID, int X, int Y, int Width, int Height, void *pContext, FPopupMenuFunction pfnFunc, int Corners)
|
||||
void CUI::DoPopupMenu(const SPopupMenuId *pID, int X, int Y, int Width, int Height, void *pContext, FPopupMenuFunction pfnFunc, const SPopupMenuProperties &Props)
|
||||
{
|
||||
constexpr float Margin = SPopupMenu::POPUP_BORDER + SPopupMenu::POPUP_MARGIN;
|
||||
if(X + Width > Screen()->w - Margin)
|
||||
|
@ -1284,11 +1284,11 @@ void CUI::DoPopupMenu(const SPopupMenuId *pID, int X, int Y, int Width, int Heig
|
|||
m_vPopupMenus.emplace_back();
|
||||
SPopupMenu *pNewMenu = &m_vPopupMenus.back();
|
||||
pNewMenu->m_pID = pID;
|
||||
pNewMenu->m_Props = Props;
|
||||
pNewMenu->m_Rect.x = X;
|
||||
pNewMenu->m_Rect.y = Y;
|
||||
pNewMenu->m_Rect.w = Width;
|
||||
pNewMenu->m_Rect.h = Height;
|
||||
pNewMenu->m_Corners = Corners;
|
||||
pNewMenu->m_pContext = pContext;
|
||||
pNewMenu->m_pfnFunc = pfnFunc;
|
||||
}
|
||||
|
@ -1322,9 +1322,9 @@ void CUI::RenderPopupMenus()
|
|||
}
|
||||
|
||||
CUIRect PopupRect = PopupMenu.m_Rect;
|
||||
PopupRect.Draw(ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f), PopupMenu.m_Corners, 3.0f);
|
||||
PopupRect.Draw(PopupMenu.m_Props.m_BorderColor, PopupMenu.m_Props.m_Corners, 3.0f);
|
||||
PopupRect.Margin(SPopupMenu::POPUP_BORDER, &PopupRect);
|
||||
PopupRect.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.75f), PopupMenu.m_Corners, 3.0f);
|
||||
PopupRect.Draw(PopupMenu.m_Props.m_BackgroundColor, PopupMenu.m_Props.m_Corners, 3.0f);
|
||||
PopupRect.Margin(SPopupMenu::POPUP_MARGIN, &PopupRect);
|
||||
|
||||
EPopupMenuFunctionResult Result = PopupMenu.m_pfnFunc(PopupMenu.m_pContext, PopupRect, Active);
|
||||
|
|
|
@ -244,6 +244,13 @@ struct SPopupMenuId
|
|||
{
|
||||
};
|
||||
|
||||
struct SPopupMenuProperties
|
||||
{
|
||||
int m_Corners = IGraphics::CORNER_ALL;
|
||||
ColorRGBA m_BorderColor = ColorRGBA(0.5f, 0.5f, 0.5f, 0.75f);
|
||||
ColorRGBA m_BackgroundColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.75f);
|
||||
};
|
||||
|
||||
class CUI
|
||||
{
|
||||
public:
|
||||
|
@ -321,8 +328,8 @@ private:
|
|||
static constexpr float POPUP_MARGIN = 4.0f;
|
||||
|
||||
const SPopupMenuId *m_pID;
|
||||
SPopupMenuProperties m_Props;
|
||||
CUIRect m_Rect;
|
||||
int m_Corners;
|
||||
void *m_pContext;
|
||||
FPopupMenuFunction m_pfnFunc;
|
||||
};
|
||||
|
@ -510,7 +517,7 @@ public:
|
|||
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, const char *pSuffix = "");
|
||||
|
||||
// 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 DoPopupMenu(const SPopupMenuId *pID, int X, int Y, int Width, int Height, void *pContext, FPopupMenuFunction pfnFunc, const SPopupMenuProperties &Props = {});
|
||||
void RenderPopupMenus();
|
||||
void ClosePopupMenu(const SPopupMenuId *pID, bool IncludeDescendants = false);
|
||||
void ClosePopupMenus();
|
||||
|
|
|
@ -5962,13 +5962,16 @@ void CEditor::RenderExtraEditorDragBar(CUIRect View, float *pSplit)
|
|||
|
||||
void CEditor::RenderMenubar(CUIRect MenuBar)
|
||||
{
|
||||
SPopupMenuProperties PopupProperties;
|
||||
PopupProperties.m_Corners = IGraphics::CORNER_R | IGraphics::CORNER_B;
|
||||
|
||||
CUIRect FileButton;
|
||||
static int s_FileButton = 0;
|
||||
MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar);
|
||||
if(DoButton_Menu(&s_FileButton, "File", 0, &FileButton, 0, nullptr))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuFileId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuFileId, FileButton.x, FileButton.y + FileButton.h - 1.0f, 120.0f, 174.0f, this, PopupMenuFile, IGraphics::CORNER_R | IGraphics::CORNER_B);
|
||||
UI()->DoPopupMenu(&s_PopupMenuFileId, FileButton.x, FileButton.y + FileButton.h - 1.0f, 120.0f, 174.0f, this, PopupMenuFile, PopupProperties);
|
||||
}
|
||||
|
||||
MenuBar.VSplitLeft(5.0f, nullptr, &MenuBar);
|
||||
|
@ -5979,7 +5982,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
|
|||
if(DoButton_Menu(&s_ToolsButton, "Tools", 0, &ToolsButton, 0, nullptr))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuToolsId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuToolsId, ToolsButton.x, ToolsButton.y + ToolsButton.h - 1.0f, 200.0f, 50.0f, this, PopupMenuTools, IGraphics::CORNER_R | IGraphics::CORNER_B);
|
||||
UI()->DoPopupMenu(&s_PopupMenuToolsId, ToolsButton.x, ToolsButton.y + ToolsButton.h - 1.0f, 200.0f, 50.0f, this, PopupMenuTools, PopupProperties);
|
||||
}
|
||||
|
||||
MenuBar.VSplitLeft(5.0f, nullptr, &MenuBar);
|
||||
|
@ -5990,7 +5993,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
|
|||
if(DoButton_Menu(&s_SettingsButton, "Settings", 0, &SettingsButton, 0, nullptr))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuEntitiesId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuEntitiesId, SettingsButton.x, SettingsButton.y + SettingsButton.h - 1.0f, 200.0f, 64.0f, this, PopupMenuSettings, IGraphics::CORNER_R | IGraphics::CORNER_B);
|
||||
UI()->DoPopupMenu(&s_PopupMenuEntitiesId, SettingsButton.x, SettingsButton.y + SettingsButton.h - 1.0f, 200.0f, 64.0f, this, PopupMenuSettings, PopupProperties);
|
||||
}
|
||||
|
||||
CUIRect Info, Close;
|
||||
|
|
Loading…
Reference in a new issue