Merge branch 'better-looking-states' of https://github.com/Tryibion/FlaxEngine into Tryibion-better-looking-states

This commit is contained in:
Wojtek Figat
2023-03-14 09:35:21 +01:00

View File

@@ -291,6 +291,8 @@ namespace FlaxEditor.Surface.Archetypes
private bool _isMouseDown;
private Rectangle _textRect;
private Rectangle _dragAreaRect;
private bool _cursorChanged = false;
private bool _textRectHovered = false;
/// <summary>
/// Gets or sets the first state node identifier for the state machine pointed by the entry node.
@@ -339,7 +341,8 @@ namespace FlaxEditor.Surface.Archetypes
var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0);
titleSize.X += 8.0f;
_dragAreaRect = new Rectangle((Size - titleSize) * 0.5f, titleSize);
var padding = new Float2(8, 8);
_dragAreaRect = new Rectangle(padding, Size - padding * 2);
}
/// <inheritdoc />
@@ -348,10 +351,19 @@ namespace FlaxEditor.Surface.Archetypes
var style = Style.Current;
// Paint Background
BackgroundColor = _isSelected ? Color.OrangeRed : style.BackgroundNormal;
if (_isSelected)
Render2D.DrawRectangle(_textRect, Color.Orange);
BackgroundColor = style.BackgroundNormal;
var dragAreaColor = BackgroundColor / 2.0f;
if (IsMouseOver)
BackgroundColor *= 1.2f;
if (_textRectHovered)
BackgroundColor *= 1.2f;
Render2D.FillRectangle(_textRect, BackgroundColor);
Render2D.FillRectangle(_dragAreaRect, dragAreaColor);
// Push clipping mask
if (ClipChildren)
@@ -385,6 +397,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = true;
Cursor = CursorType.Hand;
_cursorChanged = true;
Focus();
return true;
}
@@ -402,6 +415,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = false;
Cursor = CursorType.Default;
_cursorChanged = false;
Surface.ConnectingEnd(this);
}
@@ -415,6 +429,25 @@ namespace FlaxEditor.Surface.Archetypes
public override void OnMouseMove(Float2 location)
{
Surface.ConnectingOver(this);
if (_dragAreaRect.Contains(location) && !_cursorChanged && !Input.GetMouseButton(MouseButton.Left))
{
Cursor = CursorType.SizeAll;
_cursorChanged = true;
}
else if (!_dragAreaRect.Contains(location) && _cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRect.Contains(location) && !_dragAreaRect.Contains(location) && !_textRectHovered)
{
_textRectHovered = true;
}
else if (_textRectHovered && (!_textRect.Contains(location) || _dragAreaRect.Contains(location)))
{
_textRectHovered = false;
}
base.OnMouseMove(location);
}
@@ -423,6 +456,15 @@ namespace FlaxEditor.Surface.Archetypes
{
base.OnMouseLeave();
if (_cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRectHovered)
_textRectHovered = false;
if (_isMouseDown)
{
_isMouseDown = false;
@@ -609,6 +651,8 @@ namespace FlaxEditor.Surface.Archetypes
private Rectangle _textRect;
private Rectangle _dragAreaRect;
private Rectangle _renameButtonRect;
private bool _cursorChanged = false;
private bool _textRectHovered = false;
/// <summary>
/// The transitions list from this state to the others.
@@ -714,7 +758,8 @@ namespace FlaxEditor.Surface.Archetypes
var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0);
titleSize.X += 8.0f;
_dragAreaRect = new Rectangle((Size - titleSize) * 0.5f, titleSize);
var padding = new Float2(8, 8);
_dragAreaRect = new Rectangle(padding, Size - padding * 2);
}
/// <inheritdoc />
@@ -1141,10 +1186,19 @@ namespace FlaxEditor.Surface.Archetypes
var style = Style.Current;
// Paint Background
BackgroundColor = _isSelected ? Color.OrangeRed : style.BackgroundNormal;
if (_isSelected)
Render2D.DrawRectangle(_textRect, Color.Orange);
BackgroundColor = style.BackgroundNormal;
var dragAreaColor = BackgroundColor / 2.0f;
if (IsMouseOver)
BackgroundColor *= 1.2f;
if (_textRectHovered)
BackgroundColor *= 1.2f;
Render2D.FillRectangle(_textRect, BackgroundColor);
Render2D.FillRectangle(_dragAreaRect, dragAreaColor);
// Push clipping mask
if (ClipChildren)
@@ -1197,6 +1251,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = true;
Cursor = CursorType.Hand;
_cursorChanged = true;
Focus();
return true;
}
@@ -1214,6 +1269,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = false;
Cursor = CursorType.Default;
_cursorChanged = false;
Surface.ConnectingEnd(this);
}
@@ -1234,6 +1290,26 @@ namespace FlaxEditor.Surface.Archetypes
public override void OnMouseMove(Float2 location)
{
Surface.ConnectingOver(this);
if (_dragAreaRect.Contains(location) && !_cursorChanged && !_renameButtonRect.Contains(location) && !_closeButtonRect.Contains(location) && !Input.GetMouseButton(MouseButton.Left))
{
Cursor = CursorType.SizeAll;
_cursorChanged = true;
}
else if ((!_dragAreaRect.Contains(location) || _renameButtonRect.Contains(location) || _closeButtonRect.Contains(location)) && _cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRect.Contains(location) && !_dragAreaRect.Contains(location) && !_textRectHovered)
{
_textRectHovered = true;
}
else if (_textRectHovered && (!_textRect.Contains(location) || _dragAreaRect.Contains(location)))
{
_textRectHovered = false;
}
base.OnMouseMove(location);
}
@@ -1242,6 +1318,15 @@ namespace FlaxEditor.Surface.Archetypes
{
base.OnMouseLeave();
if (_cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRectHovered)
_textRectHovered = false;
if (_isMouseDown)
{
_isMouseDown = false;