Skip to content

Commit

Permalink
Two usability tweaks
Browse files Browse the repository at this point in the history
1) Added ViewportButtonText color option to themes so it could be different than regular text
2) Added support for using the MMB to pan in VisjectSurfaces.
  • Loading branch information
Radiangames committed Sep 21, 2023
1 parent 97ed46b commit 1c19a52
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions Source/Editor/GUI/StyleValueEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public override void Draw()
-TextBoxBackground
-TextBoxBackgroundSelected
-ProgressNormal
-ViewportButtonText
*/

var size = new Float2(r.Width / 7f, r.Height / 2f);
Expand Down
1 change: 1 addition & 0 deletions Source/Editor/Options/OptionsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public Style CreateDefaultStyle()
TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46),
CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC),
ProgressNormal = Color.FromBgra(0xFF0ad328),
ViewportButtonText = Color.FromBgra(0xFFFFFFFF),

// Fonts
FontTitle = options.Interface.TitleFont.GetFont(),
Expand Down
35 changes: 34 additions & 1 deletion Source/Editor/Surface/VisjectSurface.Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ public override void OnMouseMove(Float2 location)
return;
}

if (_middleMouseDown) {
// Calculate delta
var delta = location - _middleMouseDownPos;
if (delta.LengthSquared > 0.01f) {
// Move view
_mouseMoveAmount += delta.Length;
_rootControl.Location += delta;
_middleMouseDownPos = location;
Cursor = CursorType.SizeAll;
}

// Handled
return;
}

// Check if user is selecting or moving node(s)
if (_leftMouseDown)
{
Expand Down Expand Up @@ -269,6 +284,10 @@ public override void OnLostFocus()
_rightMouseDown = false;
Cursor = CursorType.Default;
}
if (_middleMouseDown) {
_middleMouseDown = false;
Cursor = CursorType.Default;
}
_isMovingSelection = false;
ConnectingEnd(null);

Expand Down Expand Up @@ -380,6 +399,7 @@ public override bool OnMouseDown(Float2 location, MouseButton button)
_isMovingSelection = false;
_rightMouseDown = false;
_leftMouseDown = false;
_middleMouseDown = false;
return true;
}

Expand All @@ -398,6 +418,12 @@ public override bool OnMouseDown(Float2 location, MouseButton button)
{
_rightMouseDown = true;
_rightMouseDownPos = location;
Debug.Log("The right mouse button is down in a window");
}
if (button == MouseButton.Middle) {
_middleMouseDown = true;
_middleMouseDownPos = location;
Debug.Log("The middle mouse button is down in a window");
}

// Check if any node is under the mouse
Expand Down Expand Up @@ -444,7 +470,7 @@ public override bool OnMouseDown(Float2 location, MouseButton button)
Focus();
return true;
}
if (_rightMouseDown)
if (_rightMouseDown || _middleMouseDown)
{
// Start navigating
StartMouseCapture();
Expand Down Expand Up @@ -513,6 +539,12 @@ public override bool OnMouseUp(Float2 location, MouseButton button)
}
_mouseMoveAmount = 0;
}
if (_middleMouseDown && button == MouseButton.Middle) {
_middleMouseDown = false;
EndMouseCapture();
Cursor = CursorType.Default;
_mouseMoveAmount = 0;
}

// Base
bool handled = base.OnMouseUp(location, button);
Expand All @@ -523,6 +555,7 @@ public override bool OnMouseUp(Float2 location, MouseButton button)
// Clear flags
_rightMouseDown = false;
_leftMouseDown = false;
_middleMouseDown = false;
return true;
}

Expand Down
10 changes: 10 additions & 0 deletions Source/Editor/Surface/VisjectSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public partial class VisjectSurface : ContainerControl, IParametersDependantNode
/// </summary>
protected bool _rightMouseDown;

/// <summary>
/// The middle mouse down flag.
/// </summary>
protected bool _middleMouseDown;

/// <summary>
/// The left mouse down position.
/// </summary>
Expand All @@ -69,6 +74,11 @@ public partial class VisjectSurface : ContainerControl, IParametersDependantNode
/// </summary>
protected Float2 _rightMouseDownPos = Float2.Minimum;

/// <summary>
/// The middle mouse down position.
/// </summary>
protected Float2 _middleMouseDownPos = Float2.Minimum;

/// <summary>
/// The mouse position.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Source/Editor/Viewport/Widgets/ViewportWidgetButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ public override void Draw()
if (Icon.IsValid)
{
// Draw icon
Render2D.DrawSprite(Icon, iconRect, style.Foreground);
Render2D.DrawSprite(Icon, iconRect, style.ViewportButtonText);

// Update text rectangle
textRect.Location.X += iconSize;
textRect.Size.X -= iconSize;
}

// Draw text
Render2D.DrawText(style.FontMedium, _text, textRect, style.Foreground * (IsMouseOver ? 1.0f : 0.9f), TextAlignment.Center, TextAlignment.Center);
Render2D.DrawText(style.FontMedium, _text, textRect, style.ViewportButtonText * (IsMouseOver ? 1.0f : 0.9f), TextAlignment.Center, TextAlignment.Center);
}

/// <inheritdoc />
Expand Down
1 change: 1 addition & 0 deletions Source/Engine/Scripting/Scripting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private static void CreateGuiStyle()
BorderNormal = Color.FromBgra(0xFF54545C),
TextBoxBackground = Color.FromBgra(0xFF333337),
ProgressNormal = Color.FromBgra(0xFF0ad328),
ViewportButtonText = Color.FromBgra(0xFFFFFFFF),
TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46),
CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC),
SharedTooltip = new Tooltip(),
Expand Down
6 changes: 6 additions & 0 deletions Source/Engine/UI/GUI/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public Font FontSmall
[EditorOrder(200)]
public Color ProgressNormal;

/// <summary>
/// The color for text of viewport buttons (mouse speed, etc).
/// </summary>
[EditorOrder(205)]
public Color ViewportButtonText;

/// <summary>
/// The arrow right icon.
/// </summary>
Expand Down

0 comments on commit 1c19a52

Please sign in to comment.