mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-03 11:45:55 +00:00
Debug addon and removed old scaling
This commit is contained in:
parent
ed502eb061
commit
ca85765ca2
16 changed files with 1637 additions and 11 deletions
61
addons/DebugGUI/Windows/DebugGUIWindow.cs
Normal file
61
addons/DebugGUI/Windows/DebugGUIWindow.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace WeavUtils
|
||||
{
|
||||
// Draggable window clamped to the corners
|
||||
public abstract partial class DebugGUIWindow : Control
|
||||
{
|
||||
protected const int outOfScreenClampPadding = 30;
|
||||
|
||||
static bool dragInProgress;
|
||||
bool dragged;
|
||||
|
||||
new public virtual Rect2 GetRect()
|
||||
{
|
||||
return base.GetRect();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mb)
|
||||
{
|
||||
if (!dragInProgress && mb.Pressed && mb.ButtonIndex == MouseButton.Middle)
|
||||
{
|
||||
if (GetRect().HasPoint(mb.Position))
|
||||
{
|
||||
dragged = true;
|
||||
dragInProgress = true;
|
||||
}
|
||||
}
|
||||
if (mb.IsReleased() && mb.ButtonIndex == MouseButton.Middle)
|
||||
{
|
||||
if (dragged) dragInProgress = false;
|
||||
dragged = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (@event is InputEventMouseMotion motion)
|
||||
{
|
||||
if (dragged)
|
||||
{
|
||||
Move(motion.Relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Move(Vector2 delta = default)
|
||||
{
|
||||
Position += delta;
|
||||
|
||||
var viewportRect = GetViewportRect();
|
||||
|
||||
// Limit graph window offset so we can't get lost off screen
|
||||
Position = Position.Clamp(
|
||||
-GetRect().Size + Vector2.One * outOfScreenClampPadding,
|
||||
viewportRect.Size - Vector2.One * outOfScreenClampPadding
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue