DisplayMagician/HeliosPlus.Shared/NVIDIA/SurroundTopologyDisplay.cs

170 lines
6.2 KiB
C#
Raw Normal View History

2017-02-26 19:23:31 +00:00
using System;
using System.Collections.Generic;
2017-02-26 19:23:31 +00:00
using System.Drawing;
using System.Linq;
using EDIDParser;
using EDIDParser.Descriptors;
using EDIDParser.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
2017-02-26 19:23:31 +00:00
using NvAPIWrapper.Mosaic;
namespace HeliosPlus.Shared.NVIDIA
2017-02-26 19:23:31 +00:00
{
public class SurroundTopologyDisplay
2017-02-26 19:23:31 +00:00
{
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();
2018-10-20 00:27:25 +00:00
2017-02-26 19:23:31 +00:00
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))]
2017-02-26 19:23:31 +00:00
public Rotation Rotation { get; set; }
2017-02-26 19:23:31 +00:00
/// <inheritdoc />
public override string ToString()
2017-02-26 19:23:31 +00:00
{
return DisplayName ?? $"SurroundTopologyDisplay #{DisplayId}";
2017-02-26 19:23:31 +00:00
}
public GridTopologyDisplay ToGridTopologyDisplay()
2017-02-26 19:23:31 +00:00
{
return new GridTopologyDisplay(DisplayId, new Overlap(Overlap.X, Overlap.Y), Rotation.ToRotate(), 0,
PixelShift.ToPixelShiftType());
2017-02-26 19:23:31 +00:00
}
// The public override for the Object.Equals
public override bool Equals(object obj)
2017-02-26 19:23:31 +00:00
{
return this.Equals(obj as SurroundTopologyDisplay);
2017-02-26 19:23:31 +00:00
}
// SurroundTopologyDisplay are equal if their contents are equal
public bool Equals(SurroundTopologyDisplay other)
2017-02-26 19:23:31 +00:00
{
// If parameter is null, return false.
if (Object.ReferenceEquals(other, null))
2018-10-20 00:27:25 +00:00
return false;
// Optimization for a common success case.
if (Object.ReferenceEquals(this, other))
2018-10-20 00:27:25 +00:00
return true;
// If run-time types are not exactly the same, return false.
if (this.GetType() != other.GetType())
2018-10-20 00:27:25 +00:00
return false;
// Check whether the SurroundTopologyDisplay properties are equal
// Two SurroundTopologyDisplay are equal only when they have the same data exactly
if (DisplayId == other.DisplayId &&
Overlap.Equals(other.Overlap) &&
PixelShift == other.PixelShift &&
Rotation == other.Rotation)
return true;
else
return false;
2017-02-26 19:23:31 +00:00
}
// If Equals() returns true for this object compared to another
// then GetHashCode() must return the same value for these objects.
2017-02-26 19:23:31 +00:00
public override int GetHashCode()
{
// Get hash code for the DisplayId field if it is not null.
int hashDisplayId = DisplayId.GetHashCode();
2018-10-20 00:27:25 +00:00
// Get hash code for the Overlap field if it is not null.
int hashOverlap = Overlap.GetHashCode();
// Get hash code for the PixelShift field if it is not null.
int hashPixelShift = PixelShift.GetHashCode();
// Get hash code for the Rotation field if it is not null.
int hashRotation = Rotation.GetHashCode();
//Calculate the hash code for the product.
return hashDisplayId ^ hashOverlap ^ hashPixelShift ^ hashRotation;
2017-02-26 19:23:31 +00:00
}
}
// Custom comparer for the ProfileViewportTargetDisplay class
class SurroundTopologyDisplayComparer : IEqualityComparer<SurroundTopologyDisplay>
{
// Products are equal if their names and product numbers are equal.
public bool Equals(SurroundTopologyDisplay x, SurroundTopologyDisplay y)
2017-02-26 19:23:31 +00:00
{
//Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
// Check whether the SurroundTopologyDisplay properties are equal
// Two SurroundTopologyDisplay are equal only when they have the same data exactly
if (x.DisplayId == y.DisplayId &&
x.Overlap.Equals(y.Overlap) &&
x.PixelShift == y.PixelShift &&
x.Rotation == y.Rotation)
return true;
else
return false;
2017-02-26 19:23:31 +00:00
}
// If Equals() returns true for a pair of objects
// then GetHashCode() must return the same value for these objects.
public int GetHashCode(SurroundTopologyDisplay surroundTopologyDisplay)
2017-02-26 19:23:31 +00:00
{
// Check whether the object is null
if (Object.ReferenceEquals(surroundTopologyDisplay, null)) return 0;
// Get hash code for the DisplayId field if it is not null.
int hashDisplayId = surroundTopologyDisplay.DisplayId.GetHashCode();
// Get hash code for the Overlap field if it is not null.
int hashOverlap = surroundTopologyDisplay.Overlap.GetHashCode();
// Get hash code for the PixelShift field if it is not null.
int hashPixelShift = surroundTopologyDisplay.PixelShift.GetHashCode();
// Get hash code for the Rotation field if it is not null.
int hashRotation = surroundTopologyDisplay.Rotation.GetHashCode();
//Calculate the hash code for the product.
return hashDisplayId ^ hashOverlap ^ hashPixelShift ^ hashRotation;
2017-02-26 19:23:31 +00:00
}
2017-02-26 19:23:31 +00:00
}
}