This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
/
Scene.cs
131 lines (116 loc) · 4.36 KB
/
Scene.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
using System;
namespace GameOverlay.Drawing
{
/// <summary>
/// Represents a Scene / frame of a Graphics surface.
/// </summary>
public class Scene : IDisposable
{
/// <summary>
/// The Graphics surface.
/// </summary>
public Graphics Device { get; }
private Scene()
{
}
/// <summary>
/// Initializes a new Scene using a Graphics surface
/// </summary>
/// <param name="device">A Graphics surface</param>
public Scene(Graphics device)
{
Device = device ?? throw new ArgumentNullException(nameof(device));
device.BeginScene();
}
/// <summary>
/// Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
/// </summary>
~Scene() => Dispose(false);
/// <summary>
/// Returns a value indicating whether this instance and a specified <see cref="T:System.Object" /> represent the same type and value.
/// </summary>
/// <param name="obj">The object to compare with this instance.</param>
/// <returns><see langword="true" /> if <paramref name="obj" /> is a Scene and equal to this instance; otherwise, <see langword="false" />.</returns>
public override bool Equals(object obj)
{
if (obj is Scene scene)
{
return scene.Device.Equals(Device);
}
else
{
return false;
}
}
/// <summary>
/// Returns a value indicating whether two specified instances of Scene represent the same value.
/// </summary>
/// <param name="value">An object to compare to this instance.</param>
/// <returns><see langword="true" /> if <paramref name="value" /> is equal to this instance; otherwise, <see langword="false" />.</returns>
public bool Equals(Scene value)
{
return value != null
&& value.Device == Device;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return Device.GetHashCode();
}
/// <summary>
/// Converts this Scene to a human-readable string.
/// </summary>
/// <returns>A string representation of this Scene.</returns>
public override string ToString()
{
return OverrideHelper.ToString(
"Scene", GetHashCode().ToString(),
"Device", Device.ToString());
}
#region IDisposable Support
private bool disposedValue = false;
/// <summary>
/// Releases all resources used by this Scene.
/// </summary>
/// <param name="disposing">A Boolean value indicating whether this is called from the destructor.</param>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
Device.EndScene();
disposedValue = true;
}
}
/// <summary>
/// Releases all resources used by this Scene.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
/// <summary>
/// Converts a Scene to a Graphics surface.
/// </summary>
/// <param name="scene">The Scene object.</param>
public static implicit operator Graphics(Scene scene)
{
if (scene.Device == null) throw new InvalidOperationException(nameof(scene.Device) + " is null");
return scene.Device;
}
/// <summary>
/// Returns a value indicating whether two specified instances of Scene represent the same value.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns> <see langword="true" /> if <paramref name="left" /> and <paramref name="right" /> are equal; otherwise, <see langword="false" />.</returns>
public static bool Equals(Scene left, Scene right)
{
return left?.Equals(right) == true;
}
}
}