-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditorWidgetScalerWidget.cs
More file actions
55 lines (51 loc) · 2.78 KB
/
EditorWidgetScalerWidget.cs
File metadata and controls
55 lines (51 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using TaleWorlds.GauntletUI;
using TaleWorlds.GauntletUI.BaseTypes;
using TaleWorlds.Library;
namespace InGameUIDesigner
{
public class EditorWidgetScalerWidget : Widget
{
private const float _WIDGET_SCALING_MINIMUM_MARGIN = 40f;
public Widget SelectedWidget = null;
public EditorWidgetScalerWidget(UIContext context) : base(context)
{
}
protected override void OnUpdate(float dt)
{
if (UIEditorVM.Instance.WidgetPickerMode)
{
Context.ActiveCursorOfContext = UIContext.MouseCursors.RightClickLink;
return;
}
if (SelectedWidget == null || SelectedWidget.EditorIsLocked()) return;
var localMousePos = GetLocalPoint(Context.EventManager.MousePosition);
if (localMousePos.X < 0 || localMousePos.X > Size.X || localMousePos.Y < 0 || localMousePos.Y > Size.Y) return;
var scalingMarginX = MathF.Min(_WIDGET_SCALING_MINIMUM_MARGIN, Size.X * Context.InverseScale / 4f);
var scalingMarginY = MathF.Min(_WIDGET_SCALING_MINIMUM_MARGIN, Size.Y * Context.InverseScale / 4f);
var canScaleX = SelectedWidget.WidthSizePolicy == SizePolicy.Fixed;
var canScaleY = SelectedWidget.HeightSizePolicy == SizePolicy.Fixed;
if (localMousePos.X < scalingMarginX && canScaleX)
{
if (localMousePos.Y < scalingMarginY && canScaleY)
Context.ActiveCursorOfContext = UIContext.MouseCursors.DiagonalLeftResize;
else if (localMousePos.Y > Size.Y - scalingMarginY && canScaleY)
Context.ActiveCursorOfContext = UIContext.MouseCursors.DiagonalRightResize;
else
Context.ActiveCursorOfContext = UIContext.MouseCursors.HorizontalResize;
}
else if (localMousePos.X > Size.X - scalingMarginX && canScaleX)
{
if (localMousePos.Y < scalingMarginY && canScaleY)
Context.ActiveCursorOfContext = UIContext.MouseCursors.DiagonalRightResize;
else if (localMousePos.Y > Size.Y - scalingMarginY && canScaleY)
Context.ActiveCursorOfContext = UIContext.MouseCursors.DiagonalLeftResize;
else
Context.ActiveCursorOfContext = UIContext.MouseCursors.HorizontalResize;
}
else if (canScaleY && (localMousePos.Y < scalingMarginY || localMousePos.Y > Size.Y - scalingMarginY))
Context.ActiveCursorOfContext = UIContext.MouseCursors.VerticalResize;
else if (localMousePos.X > 0 && localMousePos.X < Size.X && localMousePos.Y > 0 && localMousePos.Y < Size.Y)
Context.ActiveCursorOfContext = UIContext.MouseCursors.Move;
}
}
}