From f0f631a48b4accf0a736e237eaec6ed94d31ae1a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 30 Nov 2024 23:44:23 +0100 Subject: [PATCH] Add splitter bar for resizing curve editor inside properties panel --- .../Dedicated/CurveObjectEditor.cs | 29 ++++++ Source/Editor/GUI/Splitter.cs | 86 +++++++++++++++++ .../GUI/Timeline/Tracks/CurvePropertyTrack.cs | 96 +++---------------- 3 files changed, 127 insertions(+), 84 deletions(-) create mode 100644 Source/Editor/GUI/Splitter.cs diff --git a/Source/Editor/CustomEditors/Dedicated/CurveObjectEditor.cs b/Source/Editor/CustomEditors/Dedicated/CurveObjectEditor.cs index 065e78bf0..81d826a04 100644 --- a/Source/Editor/CustomEditors/Dedicated/CurveObjectEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/CurveObjectEditor.cs @@ -2,6 +2,7 @@ using FlaxEditor.GUI; using FlaxEngine; +using FlaxEngine.GUI; namespace FlaxEditor.CustomEditors.Dedicated { @@ -13,6 +14,7 @@ namespace FlaxEditor.CustomEditors.Dedicated private bool _isSetting; private int _firstTimeShow; private BezierCurveEditor _curve; + private Splitter _splitter; /// public override void Initialize(LayoutElementsContainer layout) @@ -22,6 +24,13 @@ namespace FlaxEditor.CustomEditors.Dedicated _curve.Height = 120.0f; _curve.Edited += OnCurveEdited; _firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing) + _splitter = new Splitter + { + Moved = OnSplitterMoved, + Parent = _curve, + AnchorPreset = AnchorPresets.HorizontalStretchBottom, + Bounds = new Rectangle(0, _curve.Height - Splitter.DefaultHeight, _curve.Width, Splitter.DefaultHeight), + }; } private void OnCurveEdited() @@ -34,6 +43,11 @@ namespace FlaxEditor.CustomEditors.Dedicated _isSetting = false; } + private void OnSplitterMoved(Float2 location) + { + _curve.Height = Mathf.Clamp(_splitter.PointToParent(location).Y, 50.0f, 1000.0f); + } + /// public override void Refresh() { @@ -54,6 +68,7 @@ namespace FlaxEditor.CustomEditors.Dedicated protected override void Deinitialize() { _curve = null; + _splitter = null; base.Deinitialize(); } @@ -117,6 +132,7 @@ namespace FlaxEditor.CustomEditors.Dedicated private bool _isSetting; private int _firstTimeShow; private LinearCurveEditor _curve; + private Splitter _splitter; /// public override void Initialize(LayoutElementsContainer layout) @@ -126,6 +142,13 @@ namespace FlaxEditor.CustomEditors.Dedicated _curve.Height = 120.0f; _curve.Edited += OnCurveEdited; _firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing) + _splitter = new Splitter + { + Moved = OnSplitterMoved, + Parent = _curve, + AnchorPreset = AnchorPresets.HorizontalStretchBottom, + Bounds = new Rectangle(0, _curve.Height - Splitter.DefaultHeight, _curve.Width, Splitter.DefaultHeight), + }; } private void OnCurveEdited() @@ -138,6 +161,11 @@ namespace FlaxEditor.CustomEditors.Dedicated _isSetting = false; } + private void OnSplitterMoved(Float2 location) + { + _curve.Height = Mathf.Clamp(_splitter.PointToParent(location).Y, 50.0f, 1000.0f); + } + /// public override void Refresh() { @@ -158,6 +186,7 @@ namespace FlaxEditor.CustomEditors.Dedicated protected override void Deinitialize() { _curve = null; + _splitter = null; base.Deinitialize(); } diff --git a/Source/Editor/GUI/Splitter.cs b/Source/Editor/GUI/Splitter.cs new file mode 100644 index 000000000..10a67706e --- /dev/null +++ b/Source/Editor/GUI/Splitter.cs @@ -0,0 +1,86 @@ +// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. + +using System; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.GUI +{ + sealed class Splitter : Control + { + private bool _clicked; + + public Action Moved; + public const float DefaultHeight = 5.0f; + + public override void Draw() + { + var style = Style.Current; + if (IsMouseOver || _clicked) + Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _clicked ? style.BackgroundSelected : style.BackgroundHighlighted); + } + + public override void OnEndMouseCapture() + { + base.OnEndMouseCapture(); + + _clicked = false; + } + + public override void Defocus() + { + base.Defocus(); + + _clicked = false; + } + + public override void OnMouseEnter(Float2 location) + { + base.OnMouseEnter(location); + + Cursor = CursorType.SizeNS; + } + + public override void OnMouseLeave() + { + Cursor = CursorType.Default; + + base.OnMouseLeave(); + } + + public override bool OnMouseDown(Float2 location, MouseButton button) + { + if (button == MouseButton.Left) + { + _clicked = true; + Focus(); + StartMouseCapture(); + return true; + } + + return base.OnMouseDown(location, button); + } + + public override void OnMouseMove(Float2 location) + { + base.OnMouseMove(location); + + if (_clicked) + { + Moved(location); + } + } + + public override bool OnMouseUp(Float2 location, MouseButton button) + { + if (button == MouseButton.Left && _clicked) + { + _clicked = false; + EndMouseCapture(); + return true; + } + + return base.OnMouseUp(location, button); + } + } +} diff --git a/Source/Editor/GUI/Timeline/Tracks/CurvePropertyTrack.cs b/Source/Editor/GUI/Timeline/Tracks/CurvePropertyTrack.cs index 3196879a1..db5fe90e5 100644 --- a/Source/Editor/GUI/Timeline/Tracks/CurvePropertyTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/CurvePropertyTrack.cs @@ -19,87 +19,6 @@ namespace FlaxEditor.GUI.Timeline.Tracks /// public abstract class CurvePropertyTrackBase : MemberTrack, IKeyframesEditorContext { - private sealed class Splitter : Control - { - private bool _clicked; - internal CurvePropertyTrackBase _track; - - public override void Draw() - { - var style = Style.Current; - if (IsMouseOver || _clicked) - Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _clicked ? style.BackgroundSelected : style.BackgroundHighlighted); - } - - public override void OnEndMouseCapture() - { - base.OnEndMouseCapture(); - - _clicked = false; - } - - public override void Defocus() - { - base.Defocus(); - - _clicked = false; - } - - public override void OnMouseEnter(Float2 location) - { - base.OnMouseEnter(location); - - Cursor = CursorType.SizeNS; - } - - public override void OnMouseLeave() - { - Cursor = CursorType.Default; - - base.OnMouseLeave(); - } - - public override bool OnMouseDown(Float2 location, MouseButton button) - { - if (button == MouseButton.Left) - { - _clicked = true; - Focus(); - StartMouseCapture(); - return true; - } - - return base.OnMouseDown(location, button); - } - - public override void OnMouseMove(Float2 location) - { - base.OnMouseMove(location); - - if (_clicked) - { - var height = Mathf.Clamp(PointToParent(location).Y, 40.0f, 1000.0f); - if (!Mathf.NearEqual(height, _track._expandedHeight)) - { - _track.Height = _track._expandedHeight = height; - _track.Timeline.ArrangeTracks(); - } - } - } - - public override bool OnMouseUp(Float2 location, MouseButton button) - { - if (button == MouseButton.Left && _clicked) - { - _clicked = false; - EndMouseCapture(); - return true; - } - - return base.OnMouseUp(location, button); - } - } - private byte[] _curveEditingStartData; private float _expandedHeight = 120.0f; private Splitter _splitter; @@ -251,12 +170,21 @@ namespace FlaxEditor.GUI.Timeline.Tracks { _splitter = new Splitter { - _track = this, + Moved = OnSplitterMoved, Parent = Curve, }; } - var splitterHeight = 5.0f; - _splitter.Bounds = new Rectangle(0, Curve.Height - splitterHeight, Curve.Width, splitterHeight); + _splitter.Bounds = new Rectangle(0, Curve.Height - Splitter.DefaultHeight, Curve.Width, Splitter.DefaultHeight); + } + } + + private void OnSplitterMoved(Float2 location) + { + var height = Mathf.Clamp(PointToParent(location).Y, 40.0f, 1000.0f); + if (!Mathf.NearEqual(height, _expandedHeight)) + { + Height = _expandedHeight = height; + Timeline.ArrangeTracks(); } }