예제 #1
0
        public void AddOverlay_WhenOverlayIsNotNull_AddsTheOverlay()
        {
            var overlayManager = new OverlayManager();
            var overlay = new StubOverlay();

            overlayManager.AddOverlay(overlay);

            Assert.AreElementsEqual(new[] { overlay }, overlayManager.Overlays);
        }
예제 #2
0
        public void AddOverlay_WhenOverlayIsNotNullAndIsNotPresent_DoesNothing()
        {
            var overlayManager = new OverlayManager();
            var overlay = new StubOverlay();

            overlayManager.RemoveOverlay(overlay);

            Assert.Count(0, overlayManager.Overlays);
        }
예제 #3
0
        /// <summary>
        /// Creates a screen recorder.
        /// </summary>
        /// <param name="grabber">The screen grabber.</param>
        /// <param name="video">The video to which frames are to be added.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="grabber"/> or
        /// <paramref name="video"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="video"/> size
        /// is not exactly equal to the <paramref name="grabber"/> screenshot size.</exception>
        public ScreenRecorder(ScreenGrabber grabber, Video video)
        {
            if (grabber == null)
                throw new ArgumentNullException("grabber");
            if (video == null)
                throw new ArgumentNullException("video");
            if (video.Parameters.Width != grabber.ScreenshotWidth ||
                video.Parameters.Height != grabber.ScreenshotHeight)
                throw new ArgumentException("The video dimensions must be exactly the same as the screenshots obtained by the grabber.");

            this.grabber = grabber;
            this.video = video;

            overlayManager = new OverlayManager();
        }
예제 #4
0
        /// <summary>
        /// Creates a screen grabber.
        /// </summary>
        /// <param name="parameters">The capture parameters.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is null.</exception>
        public ScreenGrabber(CaptureParameters parameters)
        {
            if (parameters == null)
                throw new ArgumentNullException("parameters");

            this.parameters = parameters;

            Size screenSize = GetScreenSize();
            screenWidth = screenSize.Width;
            screenHeight = screenSize.Height;

            xyScale = Math.Sqrt(parameters.Zoom);
            screenshotWidth = (int) Math.Round(screenWidth * xyScale);
            screenshotHeight = (int) Math.Round(screenHeight * xyScale);

            overlayManager = new OverlayManager();
        }
예제 #5
0
        public void Paint()
        {
            var overlayManager = new OverlayManager();
            var overlay = new CaptionOverlay()
            {
                Text = "This is some text.",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Bottom
            };
            overlayManager.AddOverlay(overlay);

            using (Bitmap bitmap = CreateBitmapWithBackground())
            {
                overlayManager.PaintOverlaysOnImage(bitmap, 0, 0);

                TestLog.WriteLine("Image should contain 'This is some text.' centered at the bottom.");
                TestLog.EmbedImage("Image", bitmap);
            }
        }
예제 #6
0
        /// <summary>
        /// Creates a screen grabber.
        /// </summary>
        /// <param name="parameters">The capture parameters.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is null.</exception>
        public ScreenGrabber(CaptureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            this.parameters = parameters;

            Size screenSize = GetScreenSize();

            screenWidth  = screenSize.Width;
            screenHeight = screenSize.Height;

            xyScale          = Math.Sqrt(parameters.Zoom);
            screenshotWidth  = (int)Math.Round(screenWidth * xyScale);
            screenshotHeight = (int)Math.Round(screenHeight * xyScale);

            overlayManager = new OverlayManager();
        }
예제 #7
0
        /// <summary>
        /// Creates a screen recorder.
        /// </summary>
        /// <param name="grabber">The screen grabber.</param>
        /// <param name="video">The video to which frames are to be added.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="grabber"/> or
        /// <paramref name="video"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="video"/> size
        /// is not exactly equal to the <paramref name="grabber"/> screenshot size.</exception>
        public ScreenRecorder(ScreenGrabber grabber, Video video)
        {
            if (grabber == null)
            {
                throw new ArgumentNullException("grabber");
            }
            if (video == null)
            {
                throw new ArgumentNullException("video");
            }
            if (video.Parameters.Width != grabber.ScreenshotWidth ||
                video.Parameters.Height != grabber.ScreenshotHeight)
            {
                throw new ArgumentException("The video dimensions must be exactly the same as the screenshots obtained by the grabber.");
            }

            this.grabber = grabber;
            this.video   = video;

            overlayManager = new OverlayManager();
        }
예제 #8
0
        public void PaintOverlays_PaintsAllOverlaysAndRestoresGraphicsContextForEachOne()
        {
            var overlayManager = new OverlayManager();
            var overlay1 = new OverlayThatChangesInterpolationMode();
            var overlay2 = new OverlayThatChangesInterpolationMode();
            overlayManager.AddOverlay(overlay1);
            overlayManager.AddOverlay(overlay2);

            using (Bitmap bitmap = new Bitmap(32, 32))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    var request = new OverlayPaintRequest(graphics, new Rectangle(0, 0, 32, 32), 0, 0);

                    overlayManager.PaintOverlays(request);

                    Assert.Multiple(() =>
                    {
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, graphics.InterpolationMode);

                        Assert.IsTrue(overlay1.WasPainted);
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, overlay1.OldInterpolationMode);

                        Assert.IsTrue(overlay2.WasPainted);
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, overlay2.OldInterpolationMode);
                    });
                }
            }
        }
예제 #9
0
        public void PaintOverlays_WhenRequestIsNull_Throws()
        {
            var overlayManager = new OverlayManager();

            Assert.Throws<ArgumentNullException>(() => overlayManager.PaintOverlays(null));
        }
예제 #10
0
        public void RemoveOverlay_WhenOverlayIsNull_Throws()
        {
            var overlayManager = new OverlayManager();

            Assert.Throws<ArgumentNullException>(() => overlayManager.RemoveOverlay(null));
        }
예제 #11
0
        public void ToOverlay_ReturnsACompositeOverlay()
        {
            var overlayManager = new OverlayManager();
            var overlay = new OverlayThatChangesInterpolationMode();
            overlayManager.AddOverlay(overlay);

            Overlay compositeOverlay = overlayManager.ToOverlay();

            var compositeOverlayManager = new OverlayManager();
            compositeOverlayManager.AddOverlay(compositeOverlay);
            using (Bitmap bitmap = new Bitmap(32, 32))
                compositeOverlayManager.PaintOverlaysOnImage(bitmap, 0, 0);
            Assert.IsTrue(overlay.WasPainted);
        }
예제 #12
0
        public void PaintOverlaysOnImage_WhenImageIsNull_Throws()
        {
            var overlayManager = new OverlayManager();

            Assert.Throws<ArgumentNullException>(() => overlayManager.PaintOverlaysOnImage(null, 0, 0));
        }
예제 #13
0
 public CompositeOverlay(OverlayManager overlayManager)
 {
     this.overlayManager = overlayManager;
 }
예제 #14
0
        /// <summary>
        /// Gets the overlay manager for the specified test context.
        /// </summary>
        /// <param name="context">The test context.</param>
        /// <returns>The overlay manager.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is null.</exception>
        public static OverlayManager GetOverlayManager(TestContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            lock (context.Data)
            {
                OverlayManager overlayManager;
                if (! context.Data.TryGetValue(OverlayManagerKey, out overlayManager))
                {
                    overlayManager = new OverlayManager();
                    context.Data.SetValue(OverlayManagerKey, overlayManager);
                }

                return overlayManager;
            }
        }
예제 #15
0
 public CompositeOverlay(OverlayManager overlayManager)
 {
     this.overlayManager = overlayManager;
 }