示例#1
0
        /// <inheritdoc />
        protected override void PaintImpl(OverlayPaintRequest request)
        {
            if (text.Length == 0)
            {
                return;
            }

            Rectangle layoutRect = new Rectangle(
                request.FramesBounds.Left + Margin,
                request.FramesBounds.Top + Margin,
                request.FramesBounds.Width - Margin * 2,
                request.FramesBounds.Height - Margin * 2);

            StringFormat format = new StringFormat(StringFormat.GenericDefault)
            {
                Alignment     = ToStringAlignment(HorizontalAlignment),
                LineAlignment = ToStringAlignment(VerticalAlignment)
            };

            GraphicsPath path = new GraphicsPath();

            path.AddString(text, FontFamily.GenericSansSerif, (int)FontStyle.Regular, fontSize, layoutRect, format);

            Brush fillBrush  = Brushes.Black;
            Pen   outlinePen = new Pen(Brushes.White, fontSize / 2.0f);

            outlinePen.Alignment = PenAlignment.Outset;

            request.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            request.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            request.Graphics.DrawPath(outlinePen, path);
            request.Graphics.FillPath(fillBrush, path);
        }
示例#2
0
        /// <summary>
        /// Paints the overlay.
        /// </summary>
        /// <param name="request">The paint request.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="request"/> is null.</exception>
        public void Paint(OverlayPaintRequest request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            PaintImpl(request);
        }
示例#3
0
        /// <summary>
        /// Paints the overlay.
        /// </summary>
        /// <param name="request">The paint request.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="request"/> is null.</exception>
        public void Paint(OverlayPaintRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            PaintImpl(request);
        }
示例#4
0
        /// <summary>
        /// Asks all overlays to paint themselves.
        /// </summary>
        /// <param name="request">The paint request.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="request"/> is null.</exception>
        public void PaintOverlays(OverlayPaintRequest request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            foreach (Overlay overlay in overlays)
            {
                GraphicsState originalState = request.Graphics.Save();
                try
                {
                    overlay.Paint(request);
                }
                finally
                {
                    request.Graphics.Restore(originalState);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Asks all overlays to paint themselves.
        /// </summary>
        /// <param name="request">The paint request.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="request"/> is null.</exception>
        public void PaintOverlays(OverlayPaintRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            foreach (Overlay overlay in overlays)
            {
                GraphicsState originalState = request.Graphics.Save();
                try
                {
                    overlay.Paint(request);
                }
                finally
                {
                    request.Graphics.Restore(originalState);
                }
            }
        }
        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);
                    });
                }
            }
        }
            protected override void PaintImpl(OverlayPaintRequest request)
            {
                OldInterpolationMode = request.Graphics.InterpolationMode;
                WasPainted = true;

                request.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            }
 protected override void PaintImpl(OverlayPaintRequest request)
 {
     throw new NotImplementedException();
 }
示例#9
0
 protected override void PaintImpl(OverlayPaintRequest request)
 {
     overlayManager.PaintOverlays(request);
 }
示例#10
0
 /// <summary>
 /// Paints the overlay.
 /// </summary>
 /// <param name="request">The paint request, not null.</param>
 protected abstract void PaintImpl(OverlayPaintRequest request);
示例#11
0
        /// <inheritdoc />
        protected override void PaintImpl(OverlayPaintRequest request)
        {
            if (text.Length == 0)
                return;

            Rectangle layoutRect = new Rectangle(
                request.FramesBounds.Left + Margin,
                request.FramesBounds.Top + Margin,
                request.FramesBounds.Width - Margin * 2,
                request.FramesBounds.Height - Margin * 2);

            StringFormat format = new StringFormat(StringFormat.GenericDefault)
            {
                Alignment = ToStringAlignment(HorizontalAlignment),
                LineAlignment = ToStringAlignment(VerticalAlignment)
            };

            GraphicsPath path = new GraphicsPath();
            path.AddString(text, FontFamily.GenericSansSerif, (int) FontStyle.Regular, fontSize, layoutRect, format);

            Brush fillBrush = Brushes.Black;
            Pen outlinePen = new Pen(Brushes.White, fontSize / 2.0f);
            outlinePen.Alignment = PenAlignment.Outset;

            request.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            request.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            request.Graphics.DrawPath(outlinePen, path);
            request.Graphics.FillPath(fillBrush, path);
        }
示例#12
0
 /// <summary>
 /// Paints the overlay.
 /// </summary>
 /// <param name="request">The paint request, not null.</param>
 protected abstract void PaintImpl(OverlayPaintRequest request);
示例#13
0
 protected override void PaintImpl(OverlayPaintRequest request)
 {
     overlayManager.PaintOverlays(request);
 }