-
Notifications
You must be signed in to change notification settings - Fork 33
/
Utility.cs
85 lines (69 loc) · 1.88 KB
/
Utility.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
namespace KSPAdvancedFlyByWire
{
class Utility
{
public static bool RectContainsMouse(Rect windowRect)
{
return windowRect.Contains(GetMousePosition());
}
public static Vector2 GetMousePosition()
{
return new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
}
public static float ApplyChangeAndClamp(float x, float change, float clampMin = -1.0f, float clampMax = 1.0f)
{
x += change;
x = Clamp(x, clampMin, clampMax);
return x;
}
public static float Clamp(float x, float min, float max)
{
return x < min ? min : x > max ? max : x;
}
public static Rect ClampRect(Rect rect, Rect container)
{
Rect item = rect;
if(item.x < container.x)
{
item.x = container.x;
}
else if(item.x + item.width >= container.x + container.width)
{
item.x = container.x + container.width - item.width;
}
if(item.y < container.y)
{
item.y = container.y;
}
else if(item.y + item.height > container.y + container.height)
{
item.y = container.y + container.height - item.height;
}
return item;
}
public static bool CheckXInputSupport()
{
#if LINUX
return false;
#else
return true;
#endif
}
public static bool CheckSDLSupport()
{
return true;
}
public static bool CheckSharpDXSupport()
{
#if LINUX
return false;
#else
return true;
#endif
}
}
}