mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add generic popup message to editor (e.g. for error message popups)
Add `CEditor::ShowPopupMessage` function to show a generic message in a popup. The message text and color are configurable with the `SMessagePopupContext` argument object. Instances of this class must have a static memory location, as the message needs to be available after the `ShowPopupMessage` function returns, and the address of this object is used to uniquely identify it in the UI.
This commit is contained in:
parent
8d7442e328
commit
7079925966
|
@ -1099,6 +1099,19 @@ public:
|
|||
static int PopupColorPicker(CEditor *pEditor, CUIRect View, void *pContext);
|
||||
static int PopupEntities(CEditor *pEditor, CUIRect View, void *pContext);
|
||||
|
||||
struct SMessagePopupContext
|
||||
{
|
||||
static constexpr float POPUP_MAX_WIDTH = 200.0f;
|
||||
static constexpr float POPUP_FONT_SIZE = 10.0f;
|
||||
char m_aMessage[256];
|
||||
ColorRGBA m_TextColor;
|
||||
|
||||
void DefaultColor(class ITextRender *pTextRender);
|
||||
void ErrorColor();
|
||||
};
|
||||
static int PopupMessage(CEditor *pEditor, CUIRect View, void *pContext);
|
||||
void ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext);
|
||||
|
||||
static void CallbackOpenMap(const char *pFileName, int StorageType, void *pUser);
|
||||
static void CallbackAppendMap(const char *pFileName, int StorageType, void *pUser);
|
||||
static void CallbackSaveMap(const char *pFileName, int StorageType, void *pUser);
|
||||
|
|
|
@ -1870,3 +1870,34 @@ int CEditor::PopupEntities(CEditor *pEditor, CUIRect View, void *pContext)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CEditor::SMessagePopupContext::DefaultColor(ITextRender *pTextRender)
|
||||
{
|
||||
m_TextColor = pTextRender->DefaultTextColor();
|
||||
}
|
||||
|
||||
void CEditor::SMessagePopupContext::ErrorColor()
|
||||
{
|
||||
m_TextColor = ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
int CEditor::PopupMessage(CEditor *pEditor, CUIRect View, void *pContext)
|
||||
{
|
||||
SMessagePopupContext *pMessagePopup = static_cast<SMessagePopupContext *>(pContext);
|
||||
|
||||
CTextCursor Cursor;
|
||||
pEditor->TextRender()->SetCursor(&Cursor, View.x, View.y, SMessagePopupContext::POPUP_FONT_SIZE, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = View.w;
|
||||
pEditor->TextRender()->TextColor(pMessagePopup->m_TextColor);
|
||||
pEditor->TextRender()->TextEx(&Cursor, pMessagePopup->m_aMessage, -1);
|
||||
pEditor->TextRender()->TextColor(pEditor->TextRender()->DefaultTextColor());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CEditor::ShowPopupMessage(float X, float Y, SMessagePopupContext *pContext)
|
||||
{
|
||||
const float TextWidth = minimum(TextRender()->TextWidth(nullptr, SMessagePopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, -1, -1.0f), SMessagePopupContext::POPUP_MAX_WIDTH);
|
||||
const int LineCount = TextRender()->TextLineCount(nullptr, SMessagePopupContext::POPUP_FONT_SIZE, pContext->m_aMessage, TextWidth);
|
||||
UiInvokePopupMenu(pContext, 0, X, Y, TextWidth + 10.0f, LineCount * SMessagePopupContext::POPUP_FONT_SIZE + 10.0f, PopupMessage, pContext);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue