mirror of
https://github.com/DarthAffe/ScreenCapture.NET.git
synced 2025-12-13 05:48:39 +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 />
|
/// <inheritdoc />
|
||||||
public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0)
|
public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0)
|
||||||
{
|
{
|
||||||
if (_device == null) throw new ApplicationException("ScreenCapture isn't initialized.");
|
CaptureZoneValidityCheck(x, y, width, height);
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
int unscaledWidth = width;
|
int unscaledWidth = width;
|
||||||
int unscaledHeight = height;
|
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)
|
private void InitializeCaptureZone(in CaptureZone captureZone)
|
||||||
{
|
{
|
||||||
Texture2DDescription stagingTextureDesc = new()
|
Texture2DDescription stagingTextureDesc = new()
|
||||||
|
|||||||
@ -37,10 +37,19 @@ namespace ScreenCapture.NET
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the given <see cref="CaptureScreen"/> from the <see cref="IScreenCapture"/>.
|
/// Removes the given <see cref="CaptureScreen"/> from the <see cref="IScreenCapture"/>.
|
||||||
/// </summary>
|
/// </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>
|
/// <returns><c>true</c> if the <see cref="CaptureScreen"/> was successfully removed; otherwise, <c>false</c>.</returns>
|
||||||
bool UnregisterCaptureZone(CaptureZone captureZone);
|
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>
|
/// <summary>
|
||||||
/// Restarts the <see cref="IScreenCapture"/>.
|
/// Restarts the <see cref="IScreenCapture"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -19,12 +19,12 @@ namespace ScreenCapture.NET
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the x-location of the region on the screen.
|
/// Gets the x-location of the region on the screen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int X { get; }
|
public int X { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the y-location of the region on the screen.
|
/// Gets the y-location of the region on the screen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Y { get; }
|
public int Y { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the width of the region on the screen.
|
/// Gets the width of the region on the screen.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user