-
Notifications
You must be signed in to change notification settings - Fork 1
/
OverlayGraphics.cs
132 lines (110 loc) · 4.28 KB
/
OverlayGraphics.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using GameOverlay.Windows;
using SharpDX.Direct2D1;
using Image = GameOverlay.Drawing.Image;
using Font = GameOverlay.Drawing.Font;
using SolidBrush = GameOverlay.Drawing.SolidBrush;
using Graphics = GameOverlay.Drawing.Graphics;
using Rectangle = GameOverlay.Drawing.Rectangle;
using Point = GameOverlay.Drawing.Point;
namespace AutoSaver
{
class OverlayGraphics
{
public GraphicsWindow window;
private readonly Dictionary<string, SolidBrush> brushes;
private readonly Dictionary<string, Font> fonts;
private readonly Dictionary<string, Image> images;
public bool Active = false;
public string TopText = "";
public string SubText = "";
public OverlayGraphics()
{
brushes = new Dictionary<string, SolidBrush>();
fonts = new Dictionary<string, Font>();
images = new Dictionary<string, Image>();
var gfx = new Graphics()
{
MeasureFPS = true,
PerPrimitiveAntiAliasing = true,
TextAntiAliasing = true
};
window = new GraphicsWindow(10, 10, 400, 110, gfx)
{
FPS = 20,
IsTopmost = true,
IsVisible = true
};
window.DestroyGraphics += window_DestroyGraphics;
window.DrawGraphics += window_DrawGraphics;
window.SetupGraphics += window_SetupGraphics;
}
private void window_SetupGraphics(object? sender, SetupGraphicsEventArgs e)
{
var gfx = e.Graphics;
if (e.RecreateResources)
{
foreach (var pair in brushes) pair.Value.Dispose();
foreach (var pair in images) pair.Value.Dispose();
}
brushes["black"] = gfx.CreateSolidBrush(0, 0, 0);
brushes["white"] = gfx.CreateSolidBrush(255, 255, 255);
brushes["red"] = gfx.CreateSolidBrush(255, 0, 0);
brushes["green"] = gfx.CreateSolidBrush(0, 255, 0);
brushes["blue"] = gfx.CreateSolidBrush(0, 0, 255);
brushes["background"] = gfx.CreateSolidBrush(40, 10, 50, 0.8f);
brushes["alpha"] = gfx.CreateSolidBrush(0, 0, 0, 0);
brushes["grid"] = gfx.CreateSolidBrush(255, 255, 255, 0.2f);
brushes["random"] = gfx.CreateSolidBrush(0, 0, 0);
if (e.RecreateResources) return;
images["save"] = gfx.CreateImage(ASResources.save1);
fonts["consolas"] = gfx.CreateFont("Consolas", 14);
fonts["consolasbig"] = gfx.CreateFont("Consolas", 16, true);
}
private void window_DestroyGraphics(object? sender, DestroyGraphicsEventArgs? e)
{
foreach (var pair in brushes) pair.Value.Dispose();
foreach (var pair in fonts) pair.Value.Dispose();
foreach (var pair in images) pair.Value.Dispose();
}
private Point ip = new Point(10, 10);
private Point asp = new Point(30, 10);
private Point ttp = new Point(10, 30);
private Point stp = new Point(10, 50);
private void window_DrawGraphics(object? sender, DrawGraphicsEventArgs e)
{
var gfx = e.Graphics;
gfx.ClearScene(brushes["alpha"]);
if (!Active) return;
gfx.OutlineFillRectangle(brushes["white"], brushes["background"], new Rectangle(0, 0, 400, window.Height), 1);
gfx.DrawImage(images["save"], ip, 1);
gfx.DrawText(fonts["consolasbig"], brushes["white"], asp, "AutoSaver");
gfx.DrawText(fonts["consolas"], brushes["white"], ttp, TopText);
gfx.DrawText(fonts["consolas"], brushes["white"], stp, SubText);
}
public void Run()
{
window.Create();
window.Join();
}
~OverlayGraphics()
{
Dispose(false);
}
#region IDisposable Support
private bool disposedValue;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
window.Dispose();
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}