-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHelpers.cs
77 lines (65 loc) · 2.4 KB
/
Helpers.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
namespace WireMod
{
public static class Helpers
{
public static Vector2 Drift => new Vector2(Main.screenWidth, Main.screenHeight) * (Main.UIScale - 1) * 0.5f;
public static Rectangle GetScreenRect() => new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, (int)(Main.screenWidth * Main.UIScale), (int)(Main.screenHeight * Main.UIScale));
public static Texture2D CreateCircle(int diameter)
{
var texture = new Texture2D(Main.graphics.GraphicsDevice, diameter, diameter);
var colorData = new Color[diameter * diameter];
var radius = diameter / 2f;
for (var x = 0; x < diameter; x++)
{
for (var y = 0; y < diameter; y++)
{
var index = x * diameter + y;
if (new Vector2(x - radius, y - radius).LengthSquared() <= radius * radius)
{
colorData[index] = Color.White;
}
else
{
colorData[index] = Color.Transparent;
}
}
}
texture.SetData(colorData);
return texture;
}
public static Texture2D CreateRectangle(int width, int height)
{
var texture = new Texture2D(Main.graphics.GraphicsDevice, width, height);
var colorData = new Color[width * height];
for (var x = 0; x < width; x++)
{
for (var y = 0; y < height; y++)
{
colorData[x * width + y] = Color.White;
}
}
texture.SetData(colorData);
return texture;
}
public static bool TryParsePoint(string input, out Point16? output)
{
if (string.IsNullOrEmpty(input) || !input.Contains(","))
{
output = null;
return false;
}
var split = input.Split(',');
if (!int.TryParse(split[0], out var x) || !int.TryParse(split[1], out var y))
{
output = null;
return false;
}
output = new Point16(x, y);
return true;
}
}
}