Refactor rendering of editor mentions and modebar

This commit is contained in:
Robert Müller 2023-07-03 20:54:54 +02:00
parent c9642e103f
commit c7c44705e1
2 changed files with 33 additions and 50 deletions

View file

@ -5270,44 +5270,49 @@ void CEditor::ShowFileDialogError(const char *pFormat, ...)
void CEditor::RenderModebar(CUIRect View) void CEditor::RenderModebar(CUIRect View)
{ {
CUIRect Button; CUIRect Mentions, ModeButton;
View.HSplitTop(30.0f, &Mentions, &ModeButton);
ModeButton.VSplitLeft(65.0f, &ModeButton, nullptr);
// mode buttons // mentions
if(m_Mentions)
{ {
View.VSplitLeft(65.0f, &Button, &View); char aBuf[64];
Button.HSplitTop(30.0f, nullptr, &Button); if(m_Mentions == 1)
static int s_Button = 0; str_copy(aBuf, Localize("1 new mention"));
const char *pButName = ""; else if(m_Mentions <= 9)
str_format(aBuf, sizeof(aBuf), Localize("%d new mentions"), m_Mentions);
else
str_copy(aBuf, Localize("9+ new mentions"));
TextRender()->TextColor(ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
UI()->DoLabel(&Mentions, aBuf, 10.0f, TEXTALIGN_MC);
TextRender()->TextColor(TextRender()->DefaultTextColor());
}
// mode button
{
const char *pModeLabel = "";
if(m_Mode == MODE_LAYERS) if(m_Mode == MODE_LAYERS)
pButName = "Layers"; pModeLabel = "Layers";
else if(m_Mode == MODE_IMAGES) else if(m_Mode == MODE_IMAGES)
pButName = "Images"; pModeLabel = "Images";
else if(m_Mode == MODE_SOUNDS) else if(m_Mode == MODE_SOUNDS)
pButName = "Sounds"; pModeLabel = "Sounds";
else
dbg_assert(false, "m_Mode invalid");
int MouseButton = DoButton_Tab(&s_Button, pButName, 0, &Button, 0, "Switch between images, sounds and layers management."); static int s_ModeButton = 0;
const int MouseButton = DoButton_Tab(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management.");
if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0))
{ {
if(m_Mode == MODE_LAYERS) m_Mode = (m_Mode + NUM_MODES - 1) % NUM_MODES;
m_Mode = MODE_SOUNDS;
else if(m_Mode == MODE_IMAGES)
m_Mode = MODE_LAYERS;
else
m_Mode = MODE_IMAGES;
} }
else if(MouseButton == 1 || (Input()->KeyPress(KEY_RIGHT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) else if(MouseButton == 1 || (Input()->KeyPress(KEY_RIGHT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0))
{ {
if(m_Mode == MODE_LAYERS) m_Mode = (m_Mode + 1) % NUM_MODES;
m_Mode = MODE_IMAGES;
else if(m_Mode == MODE_IMAGES)
m_Mode = MODE_SOUNDS;
else
m_Mode = MODE_LAYERS;
} }
} }
View.VSplitLeft(5.0f, nullptr, &View);
} }
void CEditor::RenderStatusbar(CUIRect View) void CEditor::RenderStatusbar(CUIRect View)
@ -6229,7 +6234,7 @@ void CEditor::Render()
// render checker // render checker
RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f); RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f);
CUIRect MenuBar, CModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox; CUIRect MenuBar, ModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox;
m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && UI()->LastActiveItem() != &m_SettingsCommandInput && m_vSelectedLayers.size() == 1; m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && UI()->LastActiveItem() != &m_SettingsCommandInput && m_vSelectedLayers.size() == 1;
if(m_GuiActive) if(m_GuiActive)
@ -6326,34 +6331,12 @@ void CEditor::Render()
RenderBackground(ToolBar, m_BackgroundTexture, 128.0f, Brightness); RenderBackground(ToolBar, m_BackgroundTexture, 128.0f, Brightness);
ToolBar.Margin(2.0f, &ToolBar); ToolBar.Margin(2.0f, &ToolBar);
ToolBar.VSplitLeft(100.0f, &CModeBar, &ToolBar); ToolBar.VSplitLeft(100.0f, &ModeBar, &ToolBar);
RenderBackground(StatusBar, m_BackgroundTexture, 128.0f, Brightness); RenderBackground(StatusBar, m_BackgroundTexture, 128.0f, Brightness);
StatusBar.Margin(2.0f, &StatusBar); StatusBar.Margin(2.0f, &StatusBar);
} }
// show mentions
if(m_GuiActive && m_Mentions)
{
char aBuf[64];
if(m_Mentions == 1)
{
str_copy(aBuf, Localize("1 new mention"));
}
else if(m_Mentions <= 9)
{
str_format(aBuf, sizeof(aBuf), Localize("%d new mentions"), m_Mentions);
}
else
{
str_copy(aBuf, Localize("9+ new mentions"));
}
TextRender()->TextColor(1.0f, 0.0f, 0.0f, 1.0f);
TextRender()->Text(5.0f, 27.0f, 10.0f, aBuf, -1.0f);
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
// do the toolbar // do the toolbar
if(m_Mode == MODE_LAYERS) if(m_Mode == MODE_LAYERS)
DoToolbarLayers(ToolBar); DoToolbarLayers(ToolBar);
@ -6471,8 +6454,7 @@ void CEditor::Render()
if(m_GuiActive) if(m_GuiActive)
{ {
RenderMenubar(MenuBar); RenderMenubar(MenuBar);
RenderModebar(ModeBar);
RenderModebar(CModeBar);
if(!m_ShowPicker) if(!m_ShowPicker)
{ {
if(m_ShowEnvelopeEditor) if(m_ShowEnvelopeEditor)

View file

@ -36,6 +36,7 @@ enum
MODE_LAYERS = 0, MODE_LAYERS = 0,
MODE_IMAGES, MODE_IMAGES,
MODE_SOUNDS, MODE_SOUNDS,
NUM_MODES,
DIALOG_NONE = 0, DIALOG_NONE = 0,
DIALOG_FILE, DIALOG_FILE,