44
55namespace ScreenCapture . NET ;
66
7+ /// <inheritdoc />
78public abstract class AbstractScreenCapture < TColor > : IScreenCapture
89 where TColor : struct , IColor
910{
1011 #region Properties & Fields
1112
1213 private bool _isDisposed ;
1314
15+ /// <summary>
16+ /// Gets a list of <see cref="CaptureZone{TColol}"/> registered on this ScreenCature.
17+ /// </summary>
1418 protected HashSet < CaptureZone < TColor > > CaptureZones { get ; } = new ( ) ;
1519
20+ /// <inheritdoc />
1621 public Display Display { get ; }
1722
1823 #endregion
1924
2025 #region Events
2126
27+ /// <inheritdoc />
2228 public event EventHandler < ScreenCaptureUpdatedEventArgs > ? Updated ;
2329
2430 #endregion
2531
2632 #region Constructors
2733
34+ /// <summary>
35+ /// Initializes a new instance of the <see cref="AbstractScreenCapture{T}"/> class.
36+ /// </summary>
37+ /// <param name="display">The <see cref="Display"/> to duplicate.</param>
2838 protected AbstractScreenCapture ( Display display )
2939 {
3040 this . Display = display ;
@@ -36,6 +46,7 @@ protected AbstractScreenCapture(Display display)
3646
3747 #region Methods
3848
49+ /// <inheritdoc />
3950 public virtual bool CaptureScreen ( )
4051 {
4152 if ( _isDisposed ) throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
@@ -67,10 +78,23 @@ public virtual bool CaptureScreen()
6778 return result ;
6879 }
6980
81+ /// <summary>
82+ /// Performs the actual screen capture.
83+ /// </summary>
84+ /// <returns><c>true</c> if the screen was captured sucessfully; otherwise, <c>false</c>.</returns>
7085 protected abstract bool PerformScreenCapture ( ) ;
7186
87+ /// <summary>
88+ /// Performs an update of the given capture zone.
89+ /// </summary>
90+ /// <param name="captureZone">The capture zone to update.</param>
91+ /// <param name="buffer">The buffer containing the current pixel-data of the capture zone.</param>
7292 protected abstract void PerformCaptureZoneUpdate ( CaptureZone < TColor > captureZone , in Span < byte > buffer ) ;
7393
94+ /// <summary>
95+ /// Raises the <see cref="Updated"/>-event.
96+ /// </summary>
97+ /// <param name="result">A bool indicating whether the update was successful or not.</param>
7498 protected virtual void OnUpdated ( bool result )
7599 {
76100 try
@@ -80,7 +104,10 @@ protected virtual void OnUpdated(bool result)
80104 catch { /**/ }
81105 }
82106
107+ /// <inheritdoc />
83108 ICaptureZone IScreenCapture . RegisterCaptureZone ( int x , int y , int width , int height , int downscaleLevel ) => RegisterCaptureZone ( x , y , width , height , downscaleLevel ) ;
109+
110+ /// <inheritdoc cref="IScreenCapture.RegisterCaptureZone" />
84111 public virtual CaptureZone < TColor > RegisterCaptureZone ( int x , int y , int width , int height , int downscaleLevel = 0 )
85112 {
86113 if ( _isDisposed ) throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
@@ -100,6 +127,15 @@ public virtual CaptureZone<TColor> RegisterCaptureZone(int x, int y, int width,
100127 }
101128 }
102129
130+ /// <summary>
131+ /// Validates the given values of a capture zone.
132+ /// </summary>
133+ /// <param name="x">The X-location of the zone.</param>
134+ /// <param name="y">The Y-location of the zone.</param>
135+ /// <param name="width">The width of the zone.</param>
136+ /// <param name="height">The height of the zone.</param>
137+ /// <param name="downscaleLevel">The downscale-level of the zone.</param>
138+ /// <exception cref="ArgumentException">Throws if some of the provided data is not valid.</exception>
103139 protected virtual void ValidateCaptureZoneAndThrow ( int x , int y , int width , int height , int downscaleLevel )
104140 {
105141 if ( x < 0 ) throw new ArgumentException ( "x < 0" ) ;
@@ -110,6 +146,13 @@ protected virtual void ValidateCaptureZoneAndThrow(int x, int y, int width, int
110146 if ( ( y + height ) > Display . Height ) throw new ArgumentException ( "y + height > Display height" ) ;
111147 }
112148
149+ /// <summary>
150+ /// Calculates the actual size when downscaling is used.
151+ /// </summary>
152+ /// <param name="width">The original width.</param>
153+ /// <param name="height">The original height.</param>
154+ /// <param name="downscaleLevel">The level of downscaling to be used.</param>
155+ /// <returns>A tuple containing the scaled width, the scaled height and the downscale-level used. (This can be smaller then the one provided if the image is not big enough to scale down that often.)</returns>
113156 protected virtual ( int width , int height , int downscaleLevel ) CalculateScaledSize ( int width , int height , int downscaleLevel )
114157 {
115158 if ( downscaleLevel > 0 )
@@ -131,16 +174,22 @@ protected virtual (int width, int height, int downscaleLevel) CalculateScaledSiz
131174 return ( width , height , downscaleLevel ) ;
132175 }
133176
177+ /// <inheritdoc />
134178 bool IScreenCapture . UnregisterCaptureZone ( ICaptureZone captureZone ) => UnregisterCaptureZone ( captureZone as CaptureZone < TColor > ?? throw new ArgumentException ( "Invalid capture-zone." ) ) ;
179+
180+ /// <inheritdoc cref="IScreenCapture.UnregisterCaptureZone" />
135181 public virtual bool UnregisterCaptureZone ( CaptureZone < TColor > captureZone )
136182 {
137183 if ( _isDisposed ) throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
138184
139185 return CaptureZones . Remove ( captureZone ) ;
140186 }
141187
188+ /// <inheritdoc />
142189 void IScreenCapture . UpdateCaptureZone ( ICaptureZone captureZone , int ? x , int ? y , int ? width , int ? height , int ? downscaleLevel )
143190 => UpdateCaptureZone ( captureZone as CaptureZone < TColor > ?? throw new ArgumentException ( "Invalid capture-zone." ) , x , y , width , height , downscaleLevel ) ;
191+
192+ /// <inheritdoc cref="IScreenCapture.UpdateCaptureZone" />
144193 public virtual void UpdateCaptureZone ( CaptureZone < TColor > captureZone , int ? x = null , int ? y = null , int ? width = null , int ? height = null , int ? downscaleLevel = null )
145194 {
146195 if ( _isDisposed ) throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
@@ -169,6 +218,7 @@ public virtual void UpdateCaptureZone(CaptureZone<TColor> captureZone, int? x =
169218 }
170219 }
171220
221+ /// <inheritdoc />
172222 public virtual void Restart ( )
173223 {
174224 if ( _isDisposed ) throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
@@ -190,6 +240,7 @@ public void Dispose()
190240 _isDisposed = true ;
191241 }
192242
243+ /// <inheritdoc cref="Dispose" />
193244 protected virtual void Dispose ( bool disposing ) { }
194245
195246 #endregion
0 commit comments