// ReSharper disable MemberCanBePrivate.Global
using System;
namespace ScreenCapture
{
///
/// Represents a duplicated region on the screen.
///
public sealed class CaptureZone
{
#region Properties & Fields
///
/// Gets the unique id of this .
///
public int Id { get; }
///
/// Gets the x-location of the region on the screen.
///
public int X { get; }
///
/// Gets the y-location of the region on the screen.
///
public int Y { get; }
///
/// Gets the width of the region on the screen.
///
public int Width { get; }
///
/// Gets the height of the region on the screen.
///
public int Height { get; }
///
/// Gets the level of downscaling applied to the image of this region before copying to local memory. The calculation is (width and height)/2^downscaleLevel.
///
public int DownscaleLevel { get; }
///
/// Gets the original width of the region (this equals if is 0).
///
public int UnscaledWidth { get; }
///
/// Gets the original height of the region (this equals if is 0).
///
public int UnscaledHeight { get; }
///
/// Gets the actually captured width of the region (this can be greated than due to size-constraints on the GPU).
///
public int CaptureWidth { get; }
///
/// Gets the actually captured height of the region (this can be greated than due to size-constraints on the GPU).
///
public int CaptureHeight { get; }
///
/// Gets the width of the buffer the capture is saved to.
/// Equals most of the time but can be bigger.
///
public int BufferWidth { get; }
///
/// Gets the height of the buffer the capture is saved to.
/// Equals most of the time but can be bigger.
///
public int BufferHeight { get; }
///
/// Gets the buffer containing the image data. Format depends on the specific capture but is most likely BGRA32.
///
public byte[] Buffer { get; }
///
/// Gets the config for black-bar detection.
///
public BlackBarDetection BlackBars { get; }
///
/// Gets or sets if the should be automatically updated on every captured frame.
///
public bool AutoUpdate { get; set; } = true;
///
/// Gets if an update for the is requested on the next captured frame.
///
public bool IsUpdateRequested { get; private set; }
#endregion
#region Events
///
/// Occurs when the is updated.
///
public event EventHandler? Updated;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The unique id of this .
/// The x-location of the region on the screen.
/// The y-location of the region on the screen.
/// The width of the region on the screen.
/// The height of the region on the screen.
/// The level of downscaling applied to the image of this region before copying to local memory.
/// The original width of the region.
/// The original height of the region
/// The actually captured width of the region.
/// The actually captured height of the region.
/// The width of the buffer the capture is saved to.
/// The height of the buffer the capture is saved to.
/// The buffer containing the image data.
public CaptureZone(int id, int x, int y, int width, int height, int downscaleLevel, int unscaledWidth, int unscaledHeight, int captureWidth, int captureHeight, int bufferWidth, int bufferHeight, byte[] buffer)
{
this.Id = id;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.UnscaledWidth = unscaledWidth;
this.UnscaledHeight = unscaledHeight;
this.DownscaleLevel = downscaleLevel;
this.CaptureWidth = captureWidth;
this.CaptureHeight = captureHeight;
this.BufferWidth = bufferWidth;
this.BufferHeight = bufferHeight;
this.Buffer = buffer;
BlackBars = new BlackBarDetection(this);
}
#endregion
#region Methods
///
/// Requests to update this when the next frame is captured.
/// Only necessary if is set to false.
///
public void RequestUpdate() => IsUpdateRequested = true;
///
/// Marks the as updated.
/// WARNING: This should not be called outside of an !
///
public void SetUpdated()
{
IsUpdateRequested = false;
BlackBars.InvalidateCache();
Updated?.Invoke(this, new EventArgs());
}
///
/// Determines whether this equals the given one.
///
/// The to compare.
/// true if the specified object is equal to the current object; otherwise, false.
public bool Equals(CaptureZone other) => Id == other.Id;
///
public override bool Equals(object? obj) => obj is CaptureZone other && Equals(other);
///
public override int GetHashCode() => Id;
#endregion
}
}