DisplayMagician/HeliosDisplayManagement.Shared/NVIDIA/SurroundTopologyDisplay.cs
temacdonald a9bb295d1f Renamed app to HeliosPlus namespace and more
Renamed app to HeliosPlus namespace so that the updated
changes don't interfere with HeliosDisplayManagement if
that is also installed. The fact that I've changed so much of
the app means that my changes would be unlikely to be
accepted by Soroush, so I'm best to release this work in a
similar way to other projects like Notepad++, by keeping
the same root name, and adding a plus.
    I've also changed the Shortcut form to put all the games
in a single list to reduce the number of clicks a user has to
do in order for them to create a shortcut. I have begun to
prepare the form so that it will support multiple game
libraries, but now I am at a point that I need to fix the Steam
and Uplay game detection mechanisms so that they report
the correct information for the lv_games list view.
2020-04-23 20:16:16 +12:00

128 lines
3.7 KiB
C#

using System;
using System.Drawing;
using System.Linq;
using EDIDParser;
using EDIDParser.Descriptors;
using EDIDParser.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NvAPIWrapper.Mosaic;
namespace HeliosPlus.Shared.NVIDIA
{
public class SurroundTopologyDisplay : IEquatable<SurroundTopologyDisplay>
{
public SurroundTopologyDisplay(GridTopologyDisplay display)
{
DisplayId = display.DisplayDevice.DisplayId;
Rotation = display.Rotation.ToRotation();
Overlap = new Point(display.Overlap.HorizontalOverlap, display.Overlap.VerticalOverlap);
PixelShift = display.PixelShiftType.ToPixelShift();
try
{
var bytes = display.DisplayDevice.PhysicalGPU.ReadEDIDData(display.DisplayDevice.Output);
DisplayName = new EDID(bytes).Descriptors
.Where(descriptor => descriptor is StringDescriptor)
.Cast<StringDescriptor>()
.FirstOrDefault(descriptor => descriptor.Type == StringDescriptorType.MonitorName)?.Value;
}
catch
{
// ignored
}
}
public SurroundTopologyDisplay()
{
}
public uint DisplayId { get; set; }
public string DisplayName { get; set; }
public Point Overlap { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public PixelShift PixelShift { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Rotation Rotation { get; set; }
/// <inheritdoc />
public bool Equals(SurroundTopologyDisplay other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return DisplayId == other.DisplayId &&
Overlap.Equals(other.Overlap) &&
PixelShift == other.PixelShift &&
Rotation == other.Rotation;
}
public static bool operator ==(SurroundTopologyDisplay left, SurroundTopologyDisplay right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
public static bool operator !=(SurroundTopologyDisplay left, SurroundTopologyDisplay right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((SurroundTopologyDisplay) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) DisplayId;
hashCode = (hashCode * 397) ^ Overlap.GetHashCode();
hashCode = (hashCode * 397) ^ (int) PixelShift;
hashCode = (hashCode * 397) ^ (int) Rotation;
return hashCode;
}
}
/// <inheritdoc />
public override string ToString()
{
return DisplayName ?? $"SurroundTopologyDisplay #{DisplayId}";
}
public GridTopologyDisplay ToGridTopologyDisplay()
{
return new GridTopologyDisplay(DisplayId, new Overlap(Overlap.X, Overlap.Y), Rotation.ToRotate(), 0,
PixelShift.ToPixelShiftType());
}
}
}