Make server settings editor height adjustable by dragging

Same as for the envelope editor. Extract `RenderExtraEditorDragBar` function to reduce duplicate code.

Fix height being changed by repeated clicking on the draggable element by also resetting `s_Operation` when `Clicked` is `true`.
This commit is contained in:
Robert Müller 2023-05-29 12:00:08 +02:00
parent 57f1b1a8c6
commit 90ae59a666
2 changed files with 51 additions and 49 deletions

View file

@ -5226,6 +5226,8 @@ void CEditor::RemoveUnusedEnvelopes()
void CEditor::RenderEnvelopeEditor(CUIRect View)
{
RenderExtraEditorDragBar(View, &m_EnvelopeEditorSplit);
if(m_SelectedEnvelope < 0)
m_SelectedEnvelope = 0;
if(m_SelectedEnvelope >= (int)m_Map.m_vpEnvelopes.size())
@ -5235,12 +5237,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
if(m_SelectedEnvelope >= 0 && m_SelectedEnvelope < (int)m_Map.m_vpEnvelopes.size())
pEnvelope = m_Map.m_vpEnvelopes[m_SelectedEnvelope];
CUIRect DragBar = {
View.x,
View.y - 2.0f, // use margin
View.w,
22.0f,
};
CUIRect ToolBar, CurveBar, ColorBar;
View.HSplitTop(15.0f, &ToolBar, &View);
View.HSplitTop(15.0f, &CurveBar, &View);
@ -5249,47 +5245,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
bool CurrentEnvelopeSwitched = false;
// do the dragbar
{
enum
{
OP_NONE,
OP_DRAG_HEADER,
OP_CLICK_HEADER
};
static int s_Operation = 0;
static float s_InitialMouseY = 0.0f;
static float s_InitialMouseOffsetY = 0.0f;
static int s_DragBar = 0;
bool Clicked;
bool Abrupted;
if(int Result = DoButton_DraggableEx(&s_DragBar, "", 8, &DragBar, &Clicked, &Abrupted, 0, "Change the size of the editor by dragging."))
{
if(s_Operation == OP_NONE && Result == 1)
{
s_InitialMouseY = UI()->MouseY();
s_InitialMouseOffsetY = UI()->MouseY() - DragBar.y;
s_Operation = OP_CLICK_HEADER;
}
if(Abrupted)
s_Operation = OP_NONE;
if(s_Operation == OP_CLICK_HEADER && absolute(UI()->MouseY() - s_InitialMouseY) > 5)
s_Operation = OP_DRAG_HEADER;
if(s_Operation == OP_DRAG_HEADER)
{
if(Clicked)
s_Operation = OP_NONE;
m_EnvelopeEditorSplit = s_InitialMouseOffsetY + View.y + View.h - UI()->MouseY();
m_EnvelopeEditorSplit = clamp(m_EnvelopeEditorSplit, 100.0f, 400.0f);
}
}
}
// do the toolbar
{
CUIRect Button;
@ -5818,6 +5773,8 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast)
{
RenderExtraEditorDragBar(View, &m_ServerSettingsEditorSplit);
static int s_CommandSelectedIndex = -1;
CUIRect ToolBar;
@ -5963,6 +5920,47 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd
s_ScrollRegion.End();
}
void CEditor::RenderExtraEditorDragBar(CUIRect View, float *pSplit)
{
const CUIRect DragBar = {
View.x,
View.y - 2.0f, // use margin
View.w,
22.0f,
};
enum EDragOperation
{
OP_NONE,
OP_DRAGGING,
OP_CLICKED
};
static EDragOperation s_Operation = OP_NONE;
static float s_InitialMouseY = 0.0f;
static float s_InitialMouseOffsetY = 0.0f;
bool Clicked;
bool Abrupted;
if(int Result = DoButton_DraggableEx(&s_Operation, "", 8, &DragBar, &Clicked, &Abrupted, 0, "Change the size of the editor by dragging."))
{
if(s_Operation == OP_NONE && Result == 1)
{
s_InitialMouseY = UI()->MouseY();
s_InitialMouseOffsetY = UI()->MouseY() - DragBar.y;
s_Operation = OP_CLICKED;
}
if(Clicked || Abrupted)
s_Operation = OP_NONE;
if(s_Operation == OP_CLICKED && absolute(UI()->MouseY() - s_InitialMouseY) > 5.0f)
s_Operation = OP_DRAGGING;
if(s_Operation == OP_DRAGGING)
*pSplit = clamp(s_InitialMouseOffsetY + View.y + View.h - UI()->MouseY(), 100.0f, 400.0f);
}
}
void CEditor::RenderMenubar(CUIRect MenuBar)
{
CUIRect FileButton;
@ -6049,7 +6047,7 @@ void CEditor::Render()
View.HSplitBottom(m_EnvelopeEditorSplit, &View, &ExtraEditor);
if(m_ShowServerSettingsEditor && !m_ShowPicker)
View.HSplitBottom(250.0f, &View, &ExtraEditor);
View.HSplitBottom(m_ServerSettingsEditorSplit, &View, &ExtraEditor);
}
else
{

View file

@ -810,6 +810,7 @@ public:
m_ShowEnvelopeEditor = false;
m_EnvelopeEditorSplit = 250.0f;
m_ShowServerSettingsEditor = false;
m_ServerSettingsEditorSplit = 250.0f;
m_ShowEnvelopePreview = SHOWENV_NONE;
m_SelectedQuadEnvelope = -1;
@ -1073,6 +1074,8 @@ public:
bool m_ShowEnvelopeEditor;
float m_EnvelopeEditorSplit;
bool m_ShowServerSettingsEditor;
float m_ServerSettingsEditorSplit;
enum EShowEnvelope
{
@ -1081,7 +1084,6 @@ public:
SHOWENV_ALL
};
EShowEnvelope m_ShowEnvelopePreview;
bool m_ShowServerSettingsEditor;
bool m_ShowPicker;
std::vector<int> m_vSelectedLayers;
@ -1234,8 +1236,10 @@ public:
void RenderSounds(CUIRect Toolbox);
void RenderModebar(CUIRect View);
void RenderStatusbar(CUIRect View);
void RenderEnvelopeEditor(CUIRect View);
void RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast);
void RenderExtraEditorDragBar(CUIRect View, float *pSplit);
void RenderMenubar(CUIRect Menubar);
void RenderFileDialog();