Skip to content

Commit c87a9ef

Browse files
committed
Added directx, refactored to prefered resharper settings
-Added directx, -Refactored to my resharper settings
1 parent 954f01e commit c87a9ef

28 files changed

+1797
-132
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Linq;
3+
using Overlay.NET.Common;
4+
using Process.NET;
5+
using Process.NET.Memory;
6+
7+
namespace Overlay.NET.Demo.Directx
8+
{
9+
public class DirectXOverlayDemo
10+
{
11+
DirectxOverlayPluginExample _directXoverlayPluginExample;
12+
ProcessSharp _processSharp;
13+
14+
public void StartDemo()
15+
{
16+
Log.Debug(@"Please type the process name of the window you want to attach to, e.g 'notepad.");
17+
Log.Debug("Note: If there is more than one process found, the first will be used.");
18+
19+
var processName = Console.ReadLine();
20+
21+
var process = System.Diagnostics.Process.GetProcessesByName(processName).FirstOrDefault();
22+
if (process == null)
23+
{
24+
Log.Warn($"No process by the name of {processName} was found.");
25+
Log.Warn("Please open one or use a different name and restart the demo.");
26+
Console.ReadLine();
27+
return;
28+
}
29+
30+
_directXoverlayPluginExample = new DirectxOverlayPluginExample();
31+
_processSharp = new ProcessSharp(process, MemoryType.Remote);
32+
33+
_directXoverlayPluginExample.Initialize(_processSharp.WindowFactory.MainWindow);
34+
_directXoverlayPluginExample.Enable();
35+
Log.Info("Close the console to end the demo.");
36+
37+
while (true)
38+
{
39+
_directXoverlayPluginExample.Update();
40+
}
41+
42+
Log.Info("Close the console to end the demo.");
43+
Log.Debug("Demo complete.");
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Drawing;
4+
using Overlay.NET.Common;
5+
using Overlay.NET.Demo.Internals;
6+
using Overlay.NET.Directx;
7+
using Process.NET.Windows;
8+
9+
namespace Overlay.NET.Demo.Directx
10+
{
11+
[RegisterPlugin("DirectXverlayDemo-1", "Jacob Kemple", "DirectXOverlayDemo", "0.0",
12+
"A basic demo of the DirectXoverlay.")]
13+
public class DirectxOverlayPluginExample : DirectXOverlayPlugin
14+
{
15+
readonly ISettings<DemoOverlaySettings> _settings = new SerializableSettings<DemoOverlaySettings>();
16+
readonly TickEngine _tickEngine = new TickEngine();
17+
int _displayFps;
18+
int _font;
19+
int _hugeFont;
20+
int _i;
21+
int _interiorBrush;
22+
int _redBrush;
23+
int _redOpacityBrush;
24+
float _rotation;
25+
Stopwatch _watch;
26+
27+
public override void Initialize(IWindow targetWindow)
28+
{
29+
// Set target window by calling the base method
30+
base.Initialize(targetWindow);
31+
32+
OverlayWindow = new DirectXOverlayWindow(targetWindow.Handle, false);
33+
34+
// For demo, show how to use settings
35+
var current = _settings.Current;
36+
var type = GetType();
37+
38+
current.UpdateRate = 1000/60;
39+
current.Author = GetAuthor(type);
40+
current.Description = GetDescription(type);
41+
current.Identifier = GetIdentifier(type);
42+
current.Name = GetName(type);
43+
current.Version = GetVersion(type);
44+
45+
// File is made from above info
46+
_settings.Save();
47+
_settings.Load();
48+
Console.Title = @"OverlayExample";
49+
50+
OverlayWindow = new DirectXOverlayWindow(targetWindow.Handle, false);
51+
_watch = Stopwatch.StartNew();
52+
53+
_redBrush = OverlayWindow.Graphics.CreateBrush(0x7FFF0000);
54+
_redOpacityBrush = OverlayWindow.Graphics.CreateBrush(Color.FromArgb(80, 255, 0, 0));
55+
_interiorBrush = OverlayWindow.Graphics.CreateBrush(0x7FFFFF00);
56+
57+
_font = OverlayWindow.Graphics.CreateFont("Arial", 20);
58+
_hugeFont = OverlayWindow.Graphics.CreateFont("Arial", 50, true);
59+
60+
_rotation = 0.0f;
61+
_displayFps = 0;
62+
_i = 0;
63+
// Set up update interval and register events for the tick engine.
64+
_tickEngine.Interval = _settings.Current.UpdateRate.Milliseconds();
65+
_tickEngine.PreTick += OnPreTick;
66+
_tickEngine.Tick += OnTick;
67+
}
68+
69+
void OnTick(object sender, EventArgs e)
70+
{
71+
if (OverlayWindow.IsVisible)
72+
{
73+
OverlayWindow.SetBounds(TargetWindow.X, TargetWindow.Y, TargetWindow.Width, TargetWindow.Height);
74+
InternalRender();
75+
}
76+
}
77+
78+
void OnPreTick(object sender, EventArgs e)
79+
{
80+
var activated = TargetWindow.IsActivated;
81+
var visible = OverlayWindow.IsVisible;
82+
83+
// Ensure window is shown or hidden correctly prior to updating
84+
if (!activated && visible)
85+
{
86+
OverlayWindow.Hide();
87+
}
88+
89+
else if (activated && !visible)
90+
{
91+
OverlayWindow.Show();
92+
}
93+
}
94+
95+
// ReSharper disable once RedundantOverriddenMember
96+
public override void Enable()
97+
{
98+
_tickEngine.IsTicking = true;
99+
base.Enable();
100+
}
101+
102+
// ReSharper disable once RedundantOverriddenMember
103+
public override void Disable()
104+
{
105+
_tickEngine.IsTicking = false;
106+
base.Disable();
107+
}
108+
109+
public override void Update()
110+
{
111+
_tickEngine.Pulse();
112+
base.Update();
113+
}
114+
115+
protected void InternalRender()
116+
{
117+
OverlayWindow.Graphics.BeginScene();
118+
OverlayWindow.Graphics.ClearScene();
119+
120+
//first row
121+
OverlayWindow.Graphics.DrawText("DrawBarH", _font, _redBrush, 50, 40);
122+
OverlayWindow.Graphics.DrawBarH(50, 70, 20, 100, 80, 2, _redBrush, _interiorBrush);
123+
124+
OverlayWindow.Graphics.DrawText("DrawBarV", _font, _redBrush, 200, 40);
125+
OverlayWindow.Graphics.DrawBarV(200, 120, 100, 20, 80, 2, _redBrush, _interiorBrush);
126+
127+
OverlayWindow.Graphics.DrawText("DrawBox2D", _font, _redBrush, 350, 40);
128+
OverlayWindow.Graphics.DrawBox2D(350, 70, 50, 100, 2, _redBrush, _redOpacityBrush);
129+
130+
OverlayWindow.Graphics.DrawText("DrawBox3D", _font, _redBrush, 500, 40);
131+
OverlayWindow.Graphics.DrawBox3D(500, 80, 50, 100, 10, 2, _redBrush, _redOpacityBrush);
132+
133+
OverlayWindow.Graphics.DrawText("DrawCircle3D", _font, _redBrush, 650, 40);
134+
OverlayWindow.Graphics.DrawCircle(700, 120, 35, 2, _redBrush);
135+
136+
OverlayWindow.Graphics.DrawText("DrawEdge", _font, _redBrush, 800, 40);
137+
OverlayWindow.Graphics.DrawEdge(800, 70, 50, 100, 10, 2, _redBrush);
138+
139+
OverlayWindow.Graphics.DrawText("DrawLine", _font, _redBrush, 950, 40);
140+
OverlayWindow.Graphics.DrawLine(950, 70, 1000, 200, 2, _redBrush);
141+
142+
//second row
143+
OverlayWindow.Graphics.DrawText("DrawPlus", _font, _redBrush, 50, 250);
144+
OverlayWindow.Graphics.DrawPlus(70, 300, 15, 2, _redBrush);
145+
146+
OverlayWindow.Graphics.DrawText("DrawRectangle", _font, _redBrush, 200, 250);
147+
OverlayWindow.Graphics.DrawRectangle(200, 300, 50, 100, 2, _redBrush);
148+
149+
OverlayWindow.Graphics.DrawText("DrawRectangle3D", _font, _redBrush, 350, 250);
150+
OverlayWindow.Graphics.DrawRectangle3D(350, 320, 50, 100, 10, 2, _redBrush);
151+
152+
OverlayWindow.Graphics.DrawText("FillCircle", _font, _redBrush, 800, 250);
153+
OverlayWindow.Graphics.FillCircle(850, 350, 50, _redBrush);
154+
155+
OverlayWindow.Graphics.DrawText("FillRectangle", _font, _redBrush, 950, 250);
156+
OverlayWindow.Graphics.FillRectangle(950, 300, 50, 100, _redBrush);
157+
158+
_rotation += 0.03f; //related to speed
159+
160+
if (_rotation > 50.0f) //size of the swastika
161+
{
162+
_rotation = -50.0f;
163+
}
164+
165+
if (_watch.ElapsedMilliseconds > 1000)
166+
{
167+
_i = _displayFps;
168+
_displayFps = 0;
169+
_watch.Restart();
170+
}
171+
172+
else
173+
{
174+
_displayFps++;
175+
}
176+
177+
OverlayWindow.Graphics.DrawText("FPS: " + _i, _hugeFont, _redBrush, 400, 600, false);
178+
179+
OverlayWindow.Graphics.EndScene();
180+
}
181+
182+
public override void Dispose()
183+
{
184+
OverlayWindow.Dispose();
185+
base.Dispose();
186+
}
187+
}
188+
}

src/Overlay.NET.Demo/Internals/WpfDemoOverlaySettings.cs renamed to src/Overlay.NET.Demo/Internals/DemoOverlaySettings.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace Overlay.NET.Demo.Internals
22
{
33
// Example settings
4-
public class WpfDemoOverlaySettings
4+
public class DemoOverlaySettings
55
{
66
// 60 frames/sec roughly
7-
public int UpdateRate { get; set; }
7+
public int UpdateRate { get; set; }
88

99
public string Author { get; set; }
1010
public string Description { get; set; }

src/Overlay.NET.Demo/Overlay.NET.Demo.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@
4141
</Reference>
4242
<Reference Include="System" />
4343
<Reference Include="System.Core" />
44+
<Reference Include="System.Drawing" />
4445
<Reference Include="System.Xaml" />
4546
<Reference Include="WindowsBase" />
4647
</ItemGroup>
4748
<ItemGroup>
49+
<Compile Include="Directx\DirectXOverlayDemo.cs" />
4850
<Compile Include="Internals\ConsoleLog.cs" />
51+
<Compile Include="Directx\DirectxOverlayPluginExample.cs" />
4952
<Compile Include="Program.cs" />
5053
<Compile Include="Properties\AssemblyInfo.cs" />
51-
<Compile Include="Internals\WpfDemoOverlaySettings.cs" />
52-
<Compile Include="Internals\WpfOverlayDemo.cs" />
54+
<Compile Include="Internals\DemoOverlaySettings.cs" />
55+
<Compile Include="Wpf\WpfOverlayDemoExample.cs" />
56+
<Compile Include="Wpf\WpfOverlayExampleDemo.cs" />
5357
</ItemGroup>
5458
<ItemGroup>
5559
<None Include="App.config" />

src/Overlay.NET.Demo/Program.cs

+28-51
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,53 @@
11
using System;
2-
using System.Linq;
32
using Overlay.NET.Common;
3+
using Overlay.NET.Demo.Directx;
44
using Overlay.NET.Demo.Internals;
5+
using Overlay.NET.Demo.Wpf;
56
using Process.NET;
6-
using Process.NET.Memory;
77

88
namespace Overlay.NET.Demo
99
{
10+
/// <summary>
11+
/// </summary>
1012
public static class Program
1113
{
12-
private static OverlayPlugin _overlay;
13-
private static ProcessSharp _processSharp;
14-
private static bool _work;
15-
14+
/// <summary>
15+
/// Defines the entry point of the application.
16+
/// </summary>
1617
[STAThread]
1718
public static void Main()
1819
{
1920
Log.Register("Console", new ConsoleLog());
21+
Log.Debug("Enter 1 to run WPF overlay demo");
22+
Log.Debug("Enter 2 to run DirectX overlay demo");
23+
24+
var result = Console.ReadLine();
25+
int oneOrTwo;
2026

21-
Log.Debug(@"Please type the process name of the window you want to attach to, e.g 'notepad.");
22-
Log.Debug("Note: If there is more than one process found, the first will be used.");
27+
var parsed = int.TryParse(result, out oneOrTwo);
2328

24-
// Set up objects/overlay
25-
var processName = Console.ReadLine();
26-
var process = System.Diagnostics.Process.GetProcessesByName(processName).FirstOrDefault();
27-
if (process == null)
29+
if (!parsed)
2830
{
29-
Log.Warn($"No process by the name of {processName} was found.");
30-
Log.Warn("Please open one or use a different name and restart the demo.");
31-
Console.ReadLine();
31+
Log.Debug("Unable to read your input, make sure it consist of '1' or '2' only and try again");
3232
return;
3333
}
3434

35-
_processSharp = new ProcessSharp(process, MemoryType.Remote);
36-
_overlay = new WpfOverlayDemo();
37-
38-
var wpfOverlay = (WpfOverlayDemo) _overlay;
39-
40-
// This is done to focus on the fact the Init method
41-
// is overriden in the wpf overlay demo in order to set the
42-
// wpf overlay window instance
43-
wpfOverlay.Initialize(_processSharp.WindowFactory.MainWindow);
44-
wpfOverlay.Enable();
45-
46-
_work = true;
47-
48-
// Log some info about the overlay.
49-
Log.Debug("Starting update loop (open notepad and drag around)");
50-
Log.Debug("Update rate: " + wpfOverlay.Settings.Current.UpdateRate.Milliseconds());
51-
52-
var info = wpfOverlay.Settings.Current;
53-
54-
Log.Debug($"Author: {info.Author}");
55-
Log.Debug($"Description: {info.Description}");
56-
Log.Debug($"Name: {info.Name}");
57-
Log.Debug($"Identifier: {info.Identifier}");
58-
Log.Debug($"Version: {info.Version}");
59-
60-
Log.Info("Note: Settings are saved to a settings folder in your main app folder.");
61-
62-
63-
Log.Info("Give your window focus to enable the overlay (and unfocus to disable..)");
64-
65-
Log.Info("Close the console to end the demo.");
66-
67-
// Do work
68-
while (_work)
35+
// ReSharper disable once SwitchStatementMissingSomeCases
36+
switch (oneOrTwo)
6937
{
70-
_overlay.Update();
38+
case 1:
39+
var wpfDemo = new WpfOverlayExampleDemo();
40+
wpfDemo.StartDemo();
41+
Log.WriteLine("Demo running..");
42+
break;
43+
case 2:
44+
var directXDemo = new DirectXOverlayDemo();
45+
directXDemo.StartDemo();
46+
Log.WriteLine("Demo running..");
47+
break;
7148
}
7249

73-
Log.Debug("Demo complete.");
50+
Console.ReadLine();
7451
}
7552
}
7653
}

0 commit comments

Comments
 (0)