Skip to content

Commit

Permalink
Render editor status bar except tooltip behind popups
Browse files Browse the repository at this point in the history
So that buttons in the status bar cannot be used while a popup or the file dialog is open.

The tooltip still has to be rendered after popup menus, as popup menus can set the tooltip, which would otherwise not be shown.
  • Loading branch information
Robyt3 committed Jul 25, 2023
1 parent b412153 commit 177f748
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/game/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5511,7 +5511,7 @@ void CEditor::RenderModebar(CUIRect View)
}
}

void CEditor::RenderStatusbar(CUIRect View)
void CEditor::RenderStatusbar(CUIRect View, CUIRect *pTooltipRect)
{
CUIRect Button;
View.VSplitRight(60.0f, &View, &Button);
Expand All @@ -5531,20 +5531,24 @@ void CEditor::RenderStatusbar(CUIRect View)
m_ShowServerSettingsEditor ^= 1;
}

if(m_pTooltip)
{
char aBuf[512];
if(ms_pUiGotContext && ms_pUiGotContext == UI()->HotItem())
str_format(aBuf, sizeof(aBuf), "%s Right click for context menu.", m_pTooltip);
else
str_copy(aBuf, m_pTooltip);
View.VSplitRight(10.0f, pTooltipRect, nullptr);
}

View.VSplitRight(10.0f, &View, nullptr);
SLabelProperties Props;
Props.m_MaxWidth = View.w;
Props.m_EllipsisAtEnd = true;
UI()->DoLabel(&View, aBuf, 10.0f, TEXTALIGN_ML, Props);
}
void CEditor::RenderTooltip(CUIRect TooltipRect)
{
if(m_pTooltip == nullptr)
return;

char aBuf[512];
if(ms_pUiGotContext && ms_pUiGotContext == UI()->HotItem())
str_format(aBuf, sizeof(aBuf), "%s Right click for context menu.", m_pTooltip);
else
str_copy(aBuf, m_pTooltip);

SLabelProperties Props;
Props.m_MaxWidth = TooltipRect.w;
Props.m_EllipsisAtEnd = true;
UI()->DoLabel(&TooltipRect, aBuf, 10.0f, TEXTALIGN_ML, Props);
}

bool CEditor::IsEnvelopeUsed(int EnvelopeIndex) const
Expand Down Expand Up @@ -7147,6 +7151,7 @@ void CEditor::Render()

UI()->MapScreen();

CUIRect TooltipRect;
if(m_GuiActive)
{
RenderMenubar(MenuBar);
Expand All @@ -7162,6 +7167,7 @@ void CEditor::Render()
}
s_ShowServerSettingsEditorLast = m_ShowServerSettingsEditor;
}
RenderStatusbar(StatusBar, &TooltipRect);
}

RenderPressedKeys(View);
Expand Down Expand Up @@ -7194,13 +7200,12 @@ void CEditor::Render()

UpdateZoomWorld();

// Popup menus must be rendered before the statusbar, because UI elements in
// popup menus can set tooltips, which are rendered in the status bar.
UI()->RenderPopupMenus();
FreeDynamicPopupMenus();

// The tooltip can be set in popup menus so we have to render the tooltip after the popup menus.
if(m_GuiActive)
RenderStatusbar(StatusBar);
RenderTooltip(TooltipRect);

RenderMousePointer();
}
Expand Down
3 changes: 2 additions & 1 deletion src/game/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,8 @@ class CEditor : public IEditor
void RenderSelectedImage(CUIRect View);
void RenderSounds(CUIRect Toolbox);
void RenderModebar(CUIRect View);
void RenderStatusbar(CUIRect View);
void RenderStatusbar(CUIRect View, CUIRect *pTooltipRect);
void RenderTooltip(CUIRect TooltipRect);

void RenderEnvelopeEditor(CUIRect View);
void RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast);
Expand Down

0 comments on commit 177f748

Please sign in to comment.