mirror of
https://github.com/DarthAffe/ScreenCapture.NET.git
synced 2025-12-12 13:28:35 +00:00
Added functionality to reposition CaptureZones, without having to recreate the CaptureZone from scratch.
This commit is contained in:
parent
e9d09277de
commit
520c4a98fc
@ -203,14 +203,7 @@ namespace ScreenCapture.NET
|
||||
/// <inheritdoc />
|
||||
public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0)
|
||||
{
|
||||
if (_device == null) throw new ApplicationException("ScreenCapture isn't initialized.");
|
||||
|
||||
if (x < 0) throw new ArgumentException("x < 0");
|
||||
if (y < 0) throw new ArgumentException("y < 0");
|
||||
if (width <= 0) throw new ArgumentException("with <= 0");
|
||||
if (height <= 0) throw new ArgumentException("height <= 0");
|
||||
if ((x + width) > Display.Width) throw new ArgumentException("x + width > Display width");
|
||||
if ((y + height) > Display.Height) throw new ArgumentException("y + height > Display height");
|
||||
CaptureZoneValidityCheck(x, y, width, height);
|
||||
|
||||
int unscaledWidth = width;
|
||||
int unscaledHeight = height;
|
||||
@ -252,6 +245,33 @@ namespace ScreenCapture.NET
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RepositionCaptureZone(CaptureZone captureZone, int x, int y)
|
||||
{
|
||||
CaptureZoneValidityCheck(x, y, captureZone.UnscaledWidth, captureZone.UnscaledHeight);
|
||||
|
||||
lock (_captureZones)
|
||||
{
|
||||
if (!_captureZones.ContainsKey(captureZone))
|
||||
throw new ArgumentException("Non registered CaptureZone", nameof(captureZone));
|
||||
}
|
||||
|
||||
captureZone.X = x;
|
||||
captureZone.Y = y;
|
||||
}
|
||||
|
||||
private void CaptureZoneValidityCheck(int x, int y, int width, int height)
|
||||
{
|
||||
if (_device == null) throw new ApplicationException("ScreenCapture isn't initialized.");
|
||||
|
||||
if (x < 0) throw new ArgumentException("x < 0");
|
||||
if (y < 0) throw new ArgumentException("y < 0");
|
||||
if (width <= 0) throw new ArgumentException("with <= 0");
|
||||
if (height <= 0) throw new ArgumentException("height <= 0");
|
||||
if ((x + width) > Display.Width) throw new ArgumentException("x + width > Display width");
|
||||
if ((y + height) > Display.Height) throw new ArgumentException("y + height > Display height");
|
||||
}
|
||||
|
||||
private void InitializeCaptureZone(in CaptureZone captureZone)
|
||||
{
|
||||
Texture2DDescription stagingTextureDesc = new()
|
||||
|
||||
@ -37,10 +37,19 @@ namespace ScreenCapture.NET
|
||||
/// <summary>
|
||||
/// Removes the given <see cref="CaptureScreen"/> from the <see cref="IScreenCapture"/>.
|
||||
/// </summary>
|
||||
/// <param name="captureZone">The previosly registered <see cref="CaptureScreen"/>.</param>
|
||||
/// <param name="captureZone">The previously registered <see cref="CaptureScreen"/>.</param>
|
||||
/// <returns><c>true</c> if the <see cref="CaptureScreen"/> was successfully removed; otherwise, <c>false</c>.</returns>
|
||||
bool UnregisterCaptureZone(CaptureZone captureZone);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the position of the given <see cref="CaptureScreen"/>.
|
||||
/// </summary>
|
||||
/// <param name="captureZone">The previously registered <see cref="CaptureScreen"/>.</param>
|
||||
/// <param name="x">The new x-location of the region on the screen.</param>
|
||||
/// <param name="y">The new y-location of the region on the screen</param>
|
||||
/// <returns><c>true</c> if the <see cref="CaptureScreen"/> was successfully repositioned; otherwise, <c>false</c>.</returns>
|
||||
void RepositionCaptureZone(CaptureZone captureZone, int x, int y);
|
||||
|
||||
/// <summary>
|
||||
/// Restarts the <see cref="IScreenCapture"/>.
|
||||
/// </summary>
|
||||
|
||||
@ -19,12 +19,12 @@ namespace ScreenCapture.NET
|
||||
/// <summary>
|
||||
/// Gets the x-location of the region on the screen.
|
||||
/// </summary>
|
||||
public int X { get; }
|
||||
public int X { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the y-location of the region on the screen.
|
||||
/// </summary>
|
||||
public int Y { get; }
|
||||
public int Y { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the region on the screen.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user