add highlight when actor reference is single clicked

This commit is contained in:
xxSeys1
2024-12-11 17:11:00 +01:00
parent 0cf31395b5
commit 1e61abdfef
2 changed files with 84 additions and 0 deletions

View File

@@ -23,10 +23,17 @@ namespace FlaxEditor.GUI.Tree
/// </summary>
public const float DefaultNodeOffsetY = 0;
private const float _targetHighlightScale = 1.25f;
private const float _highlightScaleAnimDuration = 0.85f;
private Tree _tree;
private bool _opened, _canChangeOrder;
private float _animationProgress, _cachedHeight;
private bool _isHightlighted;
private float _targetHighlightTimeSec;
private float _currentHighlightTimeSec;
private float _highlightScale;
private bool _mouseOverArrow, _mouseOverHeader;
private float _xOffset, _textWidth;
private float _headerHeight = 16.0f;
@@ -605,9 +612,44 @@ namespace FlaxEditor.GUI.Tree
}
}
/// <summary>
/// Adds a box around the text to highlight the node.
/// </summary>
/// <param name="durationSec">The duration of the highlight in seconds.</param>
public void StartHighlight(float durationSec = 3)
{
_isHightlighted = true;
_targetHighlightTimeSec = durationSec;
_currentHighlightTimeSec = 0;
_highlightScale = 2f;
}
/// <summary>
/// Stops any current highlight.
/// </summary>
public void StopHighlight()
{
_isHightlighted = false;
_targetHighlightTimeSec = 0;
_currentHighlightTimeSec = 0;
}
/// <inheritdoc />
public override void Update(float deltaTime)
{
// Highlight animations
if (_isHightlighted)
{
_currentHighlightTimeSec += deltaTime;
// In the first second, animate the highlight to shrink into it's resting position
if (_currentHighlightTimeSec < _highlightScaleAnimDuration)
_highlightScale = Mathf.Lerp(_highlightScale, _targetHighlightScale, _currentHighlightTimeSec);
if (_currentHighlightTimeSec >= _targetHighlightTimeSec)
_isHightlighted = false;
}
// Drop/down animation
if (_animationProgress < 1.0f)
{
@@ -676,6 +718,18 @@ namespace FlaxEditor.GUI.Tree
textRect.Width -= 18.0f;
}
float textWidth = TextFont.GetFont().MeasureText(_text).X;
Rectangle trueTextRect = textRect;
trueTextRect.Width = textWidth;
trueTextRect.Scale(_highlightScale);
if (_isHightlighted)
{
Color highlightBackgroundColor = Editor.Instance.Options.Options.Visual.HighlightColor;
highlightBackgroundColor = highlightBackgroundColor.AlphaMultiplied(0.3f);
Render2D.FillRectangle(trueTextRect, highlightBackgroundColor);
}
// Draw text
Color textColor = CacheTextColor();
Render2D.DrawText(TextFont.GetFont(), _text, textRect, textColor, TextAlignment.Near, TextAlignment.Center);
@@ -730,6 +784,12 @@ namespace FlaxEditor.GUI.Tree
}
}
if (_isHightlighted)
{
// Draw highlights
Render2D.DrawRectangle(trueTextRect, Editor.Instance.Options.Options.Visual.HighlightColor, 3);
}
// Base
if (_opened)
{