6544: make envelope editor resizeable by dragging r=def- a=Marmare314


![resizeable-editor](https://user-images.githubusercontent.com/49279081/235273201-5ee620c3-3784-49d1-ac0c-3bc3d5aca440.gif)


## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: marmare314 <49279081+Marmare314@users.noreply.github.com>
This commit is contained in:
bors[bot] 2023-04-29 09:05:05 +00:00 committed by GitHub
commit dc804f88ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 18 deletions

View file

@ -336,6 +336,8 @@ ColorRGBA CEditor::GetButtonColor(const void *pID, int Checked)
switch(Checked)
{
case 8: // invisible
return ColorRGBA(0, 0, 0, 0);
case 7: // selected + game layers
if(UI()->HotItem() == pID)
return ColorRGBA(1, 0, 0, 0.4f);
@ -5221,14 +5223,9 @@ void CEditor::RenderStatusbar(CUIRect View)
CUIRect Button;
View.VSplitRight(60.0f, &View, &Button);
static int s_EnvelopeButton = 0;
int MouseButton = DoButton_Editor(&s_EnvelopeButton, "Envelopes", m_ShowEnvelopeEditor, &Button, 0, "Toggles the envelope editor.");
if(MouseButton == 2)
m_ShowEnvelopeEditor = (m_ShowEnvelopeEditor + 3) % 4;
else if(MouseButton == 1)
m_ShowEnvelopeEditor = (m_ShowEnvelopeEditor + 1) % 4;
if(MouseButton)
if(DoButton_Editor(&s_EnvelopeButton, "Envelopes", m_ShowEnvelopeEditor, &Button, 0, "Toggles the envelope editor."))
{
m_ShowEnvelopeEditor ^= 1;
m_ShowServerSettingsEditor = false;
}
@ -5237,7 +5234,7 @@ void CEditor::RenderStatusbar(CUIRect View)
static int s_SettingsButton = 0;
if(DoButton_Editor(&s_SettingsButton, "Server settings", m_ShowServerSettingsEditor, &Button, 0, "Toggles the server settings editor."))
{
m_ShowEnvelopeEditor = 0;
m_ShowEnvelopeEditor = false;
m_ShowServerSettingsEditor ^= 1;
}
@ -5321,6 +5318,12 @@ 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);
@ -5329,6 +5332,47 @@ 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;
@ -6066,14 +6110,7 @@ void CEditor::Render()
View.HSplitBottom(16.0f, &View, &StatusBar);
if(m_ShowEnvelopeEditor && !m_ShowPicker)
{
float Size = 125.0f;
if(m_ShowEnvelopeEditor == 2)
Size *= 2.0f;
else if(m_ShowEnvelopeEditor == 3)
Size *= 3.0f;
View.HSplitBottom(Size, &View, &ExtraEditor);
}
View.HSplitBottom(m_EnvelopeEditorSplit, &View, &ExtraEditor);
if(m_ShowServerSettingsEditor && !m_ShowPicker)
View.HSplitBottom(250.0f, &View, &ExtraEditor);

View file

@ -808,7 +808,8 @@ public:
m_AnimateTime = 0;
m_AnimateSpeed = 1;
m_ShowEnvelopeEditor = 0;
m_ShowEnvelopeEditor = false;
m_EnvelopeEditorSplit = 250.0f;
m_ShowServerSettingsEditor = false;
m_ShowEnvelopePreview = SHOWENV_NONE;
@ -1060,7 +1061,8 @@ public:
float m_AnimateTime;
float m_AnimateSpeed;
int m_ShowEnvelopeEditor;
bool m_ShowEnvelopeEditor;
float m_EnvelopeEditorSplit;
enum EShowEnvelope
{