-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathInterfaceHelper.cs
43 lines (38 loc) · 1.46 KB
/
InterfaceHelper.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
using System;
using System.Reflection;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.UI;
namespace MagicStorage
{
public static class InterfaceHelper
{
private static FieldInfo _itemIconCacheTimeInfo;
public static void Initialize()
{
_itemIconCacheTimeInfo = typeof(Main).GetField("_itemIconCacheTime", BindingFlags.NonPublic | BindingFlags.Static);
if (_itemIconCacheTimeInfo is null)
throw new Exception("Reflection value was null (source: InterfaceHelper.Initialize)");
}
public static void HideItemIconCache()
{
_itemIconCacheTimeInfo.SetValue(null, 0);
}
public static Rectangle GetFullRectangle(UIElement element)
{
CalculatedStyle dimensions = element.GetDimensions();
Vector2 vector = new(dimensions.X, dimensions.Y);
Vector2 position = new Vector2(dimensions.Width, dimensions.Height) + vector;
vector = Vector2.Transform(vector, Main.UIScaleMatrix);
position = Vector2.Transform(position, Main.UIScaleMatrix);
Rectangle result = new((int) vector.X, (int) vector.Y, (int) (position.X - vector.X), (int) (position.Y - vector.Y));
int width = Main.spriteBatch.GraphicsDevice.Viewport.Width;
int height = Main.spriteBatch.GraphicsDevice.Viewport.Height;
result.X = Utils.Clamp(result.X, 0, width);
result.Y = Utils.Clamp(result.Y, 0, height);
result.Width = Utils.Clamp(result.Width, 0, width - result.X);
result.Height = Utils.Clamp(result.Height, 0, height - result.Y);
return result;
}
}
}