コード例 #1
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            margin  = newToken.GetProperty <Int32Property>(PropertyNames.Margin).Value;
            spread  = newToken.GetProperty <Int32Property>(PropertyNames.Spread).Value;
            blur    = newToken.GetProperty <Int32Property>(PropertyNames.Blur).Value;
            color   = ColorBgra.FromUInt32(unchecked ((uint)newToken.GetProperty <Int32Property>(PropertyNames.Color).Value));
            offsetX = newToken.GetProperty <Int32Property>(PropertyNames.OffsetX).Value;
            offsetY = newToken.GetProperty <Int32Property>(PropertyNames.OffsetY).Value;

            if (shadowSurface == null)
            {
                shadowSurface = new Surface(srcArgs.Surface.Size);
            }
            else
            {
                shadowSurface.Clear(Color.Transparent);
            }

            // Setup for calling the Gaussian Blur effect
            PropertyCollection             blurProps      = blurEffect.CreatePropertyCollection();
            PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps);

            BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, blur);
            blurEffect.SetRenderInfo(BlurParameters, dstArgs, new RenderArgs(shadowSurface));

            Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();

            PointF topStart    = new PointF(selection.Left, selection.Top + (margin + spread + offsetY) / 2f);
            PointF topEnd      = new PointF(selection.Right, selection.Top + (margin + spread + offsetY) / 2f);
            PointF rightStart  = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Top);
            PointF rightEnd    = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Bottom);
            PointF bottomStart = new PointF(selection.Left, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF bottomEnd   = new PointF(selection.Right, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF leftStart   = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Top);
            PointF leftEnd     = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Bottom);

            using (Graphics shadow = new RenderArgs(shadowSurface).Graphics)
                using (Pen shadowPen = new Pen(color))
                {
                    shadowPen.Width = margin + spread + offsetX;
                    shadow.DrawLine(shadowPen, leftStart, leftEnd);

                    shadowPen.Width = margin + spread - offsetX;
                    shadow.DrawLine(shadowPen, rightStart, rightEnd);

                    shadowPen.Width = margin + spread + offsetY;
                    shadow.DrawLine(shadowPen, topStart, topEnd);

                    shadowPen.Width = margin + spread - offsetY;
                    shadow.DrawLine(shadowPen, bottomStart, bottomEnd);
                }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
コード例 #2
0
ファイル: Tartan.cs プロジェクト: toehead2001/pdn-tartan
        protected override void OnSetRenderInfo(TartanConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            Color backColor = newToken.BackColor;
            IReadOnlyCollection <Item> horLines = newToken.HorLines;
            IReadOnlyCollection <Item> verLines = newToken.OneSet ? newToken.HorLines : newToken.VerLines;

            Rectangle selection = EnvironmentParameters.SelectionBounds;

            if (tartanSurface == null)
            {
                tartanSurface = new Surface(SrcArgs.Size);
            }

            using (Graphics tartanGraphics = new RenderArgs(tartanSurface).Graphics)
            {
                // Fill in background color
                using (SolidBrush backBrush = new SolidBrush(backColor))
                {
                    tartanGraphics.FillRectangle(backBrush, selection);
                }

                if (horLines.Count > 0)
                {
                    int yOffset = selection.Top;
                    while (yOffset <= selection.Bottom)
                    {
                        foreach (Item lineItem in horLines)
                        {
                            // Create points that define line.
                            Point pointA = new Point(selection.Left, lineItem.Width / 2 + yOffset);
                            Point pointB = new Point(selection.Right, lineItem.Width / 2 + yOffset);

                            // Draw line to screen.
                            using (Pen lineItemPen = GetItemPen(lineItem.Style, lineItem.Color, lineItem.Width, false))
                            {
                                tartanGraphics.DrawLine(lineItemPen, pointA, pointB);
                            }

                            yOffset += lineItem.Width + lineItem.Spacing;
                        }
                    }
                }

                if (verLines.Count > 0)
                {
                    int xOffset = selection.Left;
                    while (xOffset <= selection.Right)
                    {
                        foreach (Item lineItem in verLines)
                        {
                            // Create points that define line.
                            Point pointA = new Point(lineItem.Width / 2 + xOffset, selection.Top);
                            Point pointB = new Point(lineItem.Width / 2 + xOffset, selection.Bottom);

                            // Draw line to screen.
                            using (Pen lineItemPen = GetItemPen(lineItem.Style, lineItem.Color, lineItem.Width, true))
                            {
                                tartanGraphics.DrawLine(lineItemPen, pointA, pointB);
                            }

                            xOffset += lineItem.Width + lineItem.Spacing;
                        }
                    }
                }
            }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }