using System;
using System.Drawing;
using WindowsDisplayAPI.Native.DisplayConfig.Structures;
using WindowsDisplayAPI.Native.Structures;
namespace WindowsDisplayAPI.DisplayConfig
{
///
/// Contains information about the target desktop image
///
public class PathTargetDesktopImage : IEquatable
{
///
/// Creates a new PathTargetDesktopImage
///
/// Size of the VidPn source surface that is being displayed on the monitor
///
/// Where the desktop image will be positioned within monitor surface size. Region must be
/// completely inside the bounds of the monitor surface size.
///
///
/// Which part of the desktop image for this clone group will be displayed on this path. This
/// currently must be set to the desktop size.
///
public PathTargetDesktopImage(Size monitorSurfaceSize, Rectangle imageRegion, Rectangle imageClip)
{
ImageClip = imageClip;
ImageRegion = imageRegion;
MonitorSurfaceSize = monitorSurfaceSize;
}
internal PathTargetDesktopImage(DisplayConfigDesktopImageInfo desktopImage)
{
MonitorSurfaceSize = desktopImage.PathSourceSize.ToSize();
ImageRegion = desktopImage.DesktopImageRegion.ToRectangle();
ImageClip = desktopImage.DesktopImageClip.ToRectangle();
}
///
/// Gets part of the desktop image for this clone group that will be displayed on this path. This currently must be set
/// to the desktop size.
///
public Rectangle ImageClip { get; }
///
/// Gets the part that the desktop image will be positioned within monitor surface size. Region must be completely
/// inside the bounds of the monitor surface size.
///
public Rectangle ImageRegion { get; }
///
/// Gets the size of the VidPn source surface that is being displayed on the monitor
///
public Size MonitorSurfaceSize { get; }
///
public bool Equals(PathTargetDesktopImage other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return ImageClip == other.ImageClip &&
ImageRegion == other.ImageRegion &&
MonitorSurfaceSize == other.MonitorSurfaceSize;
}
///
/// Checks for equality of two PathTargetDesktopImage instances
///
/// The first instance
/// The second instance
/// true if both instances are equal, otherwise false
public static bool operator ==(PathTargetDesktopImage left, PathTargetDesktopImage right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
///
/// Checks for inequality of two PathTargetDesktopImage instances
///
/// The first instance
/// The second instance
/// true if both instances are not equal, otherwise false
public static bool operator !=(PathTargetDesktopImage left, PathTargetDesktopImage right)
{
return !(left == right);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return obj.GetType() == GetType() && Equals((PathTargetDesktopImage) obj);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = ImageClip.GetHashCode();
hashCode = (hashCode * 397) ^ ImageRegion.GetHashCode();
hashCode = (hashCode * 397) ^ MonitorSurfaceSize.GetHashCode();
return hashCode;
}
}
///
public override string ToString()
{
return $"{ImageClip} => {ImageRegion} @ {MonitorSurfaceSize}";
}
internal DisplayConfigDesktopImageInfo GetDisplayConfigDesktopImageInfo()
{
return new DisplayConfigDesktopImageInfo(
new PointL(MonitorSurfaceSize),
new RectangleL(ImageRegion),
new RectangleL(ImageClip)
);
}
}
}