示例#1
0
        public void DrawRect(Rect bounds, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            if (style.HasFill)
            {
                if (style.CornerRadius.TopLeft > 0)
                {
                    _g.DrawRoundedRectangle(style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect(), new XSize(style.CornerRadius.TopLeft, style.CornerRadius.TopLeft));
                }
                else
                {
                    _g.DrawRectangle(style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect());
                }
            }

            if (style.HasStroke)
            {
                if (style.CornerRadius.TopLeft > 0)
                {
                    _g.DrawRoundedRectangle(new XPen(style.Stroke.ToXColor(), style.StrokeThickness.Left), bounds.ToXRect(), new XSize(style.CornerRadius.TopLeft, style.CornerRadius.TopLeft));
                }
                else
                {
                    _g.DrawRectangle(new XPen(style.Stroke.ToXColor(), style.StrokeThickness.Left), bounds.ToXRect());
                }
            }
        }
示例#2
0
        public override Entity parse(List <string> section)
        {
            gatherCodes(section);
            getCommonCodes();

            //Grab inheiritable values first
            styleName = getCode("  7", styleName);
            style     = new DrawingStyle(parent.styles[styleName]);

            //Get possible local overrides
            style.obliqueAngle = getCode(" 51", style.obliqueAngle);

            int mirrorValue = getCode(" 71", 0);

            style.mirrorX = mirrorValue == 2 || mirrorValue == 6;
            style.mirrorY = mirrorValue == 4 || mirrorValue == 6;

            //Set entity values
            start.X           = getCode(" 10", start.X);
            start.Y           = getCode(" 20", start.Y);
            purePosition.X    = getCode(" 11", purePosition.X);
            purePosition.Y    = getCode(" 21", purePosition.Y);
            text              = getCode("  1", text);
            size              = getCode(" 40", size);
            angle             = getCode(" 50", angle);
            alignmentColIndex = getCode(" 72", alignmentColIndex);
            alignmentRowIndex = getCode(" 73", alignmentRowIndex);

            return(this);
        }
示例#3
0
        public void DrawText(Rect bounds, string text, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            XFontStyle fontStyle = XFontStyle.Regular;

            if (style.FontStyle == FontStyles.Italic)
            {
                fontStyle = XFontStyle.Italic;

                if (style.FontWeight == FontWeights.Bold)
                {
                    fontStyle = XFontStyle.BoldItalic;
                }
            }
            else if (style.FontWeight == FontWeights.Bold)
            {
                fontStyle = XFontStyle.BoldItalic;
            }

            XFont font = new XFont(style.FontFamily.ToString(), style.FontSize, fontStyle);

            _g.DrawString(text, font, style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect(), new XStringFormat());
        }
示例#4
0
        public static void ApplyFill(this SKPaint paint, Rect bounds, DrawingStyle style)
        {
            paint.Style       = SKPaintStyle.Fill;
            paint.IsAntialias = style.EdgeMode == EdgeMode.Unspecified;

            if (style.Fill is SolidColorBrush)
            {
                paint.Color = style.Fill.ToSKColor();
            }
            else
            {
                paint.Shader = style.Fill.ToSkiaShader(bounds.Width, bounds.Height);
            }

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.Transparent.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }

            if (style.Effect != null)
            {
                if (style.Effect is DropShadowEffect)
                {
                    var fx = style.Effect as DropShadowEffect;
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(fx.ShadowDepth.ToFloat(), fx.ShadowDepth.ToFloat(), fx.BlurRadius.ToFloat(), fx.BlurRadius.ToFloat(), fx.Color.ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Draws the specified geometry.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="geometry">The geometry.</param>
        /// <param name="style">The style.</param>
        public void DrawGeometry(Rect bounds, Geometry geometry, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            PathGeometry g = geometry as PathGeometry;

            if (g == null)
            {
                g = (geometry as StreamGeometry).GetWidenedPathGeometry(new Pen(Brushes.Chartreuse, 2d));
            }

            SKPath skPath = g.ToSKPath();

            skPath.Offset(bounds.TopLeft.ToSKPoint());

            if (style.HasFill)
            {
                SKPaint paintFill = new SKPaint();
                paintFill.ApplyFill(bounds, style);

                _canvas.DrawPath(skPath, paintFill);
            }

            if (style.HasStroke)
            {
                SKPaint paintStroke = new SKPaint();
                paintStroke.ApplyStroke(bounds, style);

                _canvas.DrawPath(skPath, paintStroke);
            }

            _canvas.ResetMatrix();
        }
示例#6
0
        /// <summary>
        /// Draws a polygon.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="points">The points.</param>
        /// <param name="style">The style.</param>
        public void DrawPolygon(Rect bounds, Point[] points, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            var    pp   = points.Select(x => x.ToSKPoint()).ToArray();
            SKPath path = new SKPath();

            path.AddPoly(pp, true);
            path.Offset(bounds.Left.ToFloat(), bounds.Top.ToFloat());

            if (style.HasFill)
            {
                SKPaint paintFill = new SKPaint();
                paintFill.ApplyFill(bounds, style);
                _canvas.DrawPath(path, paintFill);
            }

            if (style.HasStroke)
            {
                SKPaint paintStroke = new SKPaint();
                paintStroke.ApplyStroke(bounds, style);
                _canvas.DrawPath(path, paintStroke);
            }

            _canvas.ResetMatrix();
        }
示例#7
0
        public void DrawLine(Rect bounds, Point p1, Point p2, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            _g.DrawLine(new XPen(style.Stroke.ToXColor()), p1.ToXPoint(), p2.ToXPoint());
        }
示例#8
0
        public void DrawImage(Rect bounds, BitmapSource image, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            _g.DrawImage(XImage.FromBitmapSource(image), bounds.ToXRect());
        }
示例#9
0
 public void DrawText(Rect bounds, string text, DrawingStyle style)
 {
     if (style.Fill != null)
     {
         var fill = style.Fill.ToGdiBrush(bounds.Width, bounds.Height);
         _g.DrawString(text, System.Drawing.SystemFonts.DefaultFont, fill, bounds.ToGdiRectF());
         fill.Dispose();
     }
 }
示例#10
0
        public void DrawRect(Rect bounds, DrawingStyle style)
        {
            _context.PushOpacity(style.Opacity);
            _context.DrawRectangle(style.Fill, new Pen(style.Stroke, style.StrokeThickness.Left), bounds);
            _context.Pop();

            if (_hasClip)
            {
                ClipRect(_clipBounds, new CornerRadius());
            }
        }
示例#11
0
        void ChangeStyle(DrawingStyle newStyle)
        {
            DrawingStyler.style = newStyle;
            controller.UpdateStyleNextFrame(newStyle);

            UpdateGraphNowOrNextFrame();

            foreach (MenuItem button in styleButtons)
            {
                button.Checked = false;
            }
        }
示例#12
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Image image = WpfElement as Image;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Opacity = opacity;

            context.DrawImage(bounds, image.Source as BitmapSource, style);
        }
示例#13
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="p1">The p1.</param>
        /// <param name="p2">The p2.</param>
        /// <param name="style">The style.</param>
        public void DrawLine(Rect bounds, Point p1, Point p2, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            SKPaint paint = new SKPaint();

            paint.ApplyStroke(bounds, style);

            _canvas.DrawLine(p1.ToSKPoint(), p2.ToSKPoint(), paint);

            _canvas.ResetMatrix();
        }
示例#14
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Line line = WpfElement as Line;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Stroke          = line.Stroke;
            style.StrokeThickness = new Thickness(line.StrokeThickness);
            style.Opacity         = opacity;

            context.DrawLine(bounds, new Point(line.X1, line.Y1), new Point(line.X2, line.Y2), style);
        }
示例#15
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Rectangle rectangle = WpfElement as Rectangle;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Fill            = rectangle.Fill;
            style.Stroke          = rectangle.Stroke;
            style.StrokeThickness = new Thickness(rectangle.StrokeThickness);
            style.Opacity         = opacity;

            context.DrawRect(bounds, style);
        }
示例#16
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Ellipse ellipse = WpfElement as Ellipse;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Fill            = ellipse.Fill;
            style.Stroke          = ellipse.Stroke;
            style.StrokeThickness = new Thickness(ellipse.StrokeThickness);
            style.Opacity         = opacity;

            context.DrawEllipse(bounds, style);
        }
示例#17
0
        /// <summary>
        /// Draws the specified image.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="image">The image.</param>
        /// <param name="style">The style.</param>
        public void DrawImage(Rect bounds, BitmapSource image, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            SKPaint paint = new SKPaint();

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.White.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }

            _canvas.DrawBitmap(image.ToSKBitmap(), bounds.ToSKRect(), paint);

            _canvas.ResetMatrix();
        }
示例#18
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Path path = WpfElement as Path;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Fill            = path.Fill;
            style.Stroke          = path.Stroke;
            style.StrokeThickness = new Thickness(path.StrokeThickness);
            style.Opacity         = opacity;

            context.DrawGeometry(bounds, path.Data, style);
        }
示例#19
0
 public static T Style <T>(this T shape, DrawingStyle drawingStyle, bool cascades = true, Type type = null) where T : Shape
 {
     if (type != null && !cascades)
     {
         Logger.Fatal($"Setting a type, and cascades = false does nothing!");
     }
     if (type != null)
     {
         shape.SetEnvironment(type, EnvironmentKeys.Shape.DrawingStyle, drawingStyle, true);
     }
     else
     {
         shape.SetEnvironment(EnvironmentKeys.Shape.DrawingStyle, drawingStyle, cascades);
     }
     return(shape);
 }
示例#20
0
        public void DrawRect(Rect bounds, DrawingStyle style)
        {
            if (style.Fill != null)
            {
                var fill = style.Fill.ToGdiBrush(bounds.Width, bounds.Height);
                _g.FillRectangle(fill, bounds.Left.ToFloat(), bounds.Top.ToFloat(), bounds.Width.ToFloat(), bounds.Height.ToFloat());
                fill.Dispose();
            }

            if (style.Stroke != null)
            {
                System.Drawing.Pen pen = new System.Drawing.Pen(style.Stroke.ToGdiBrush(bounds.Width, bounds.Height), style.StrokeThickness.Left.ToFloat());
                _g.DrawRectangle(pen, bounds.Left.ToFloat(), bounds.Top.ToFloat(), bounds.Width.ToFloat(), bounds.Height.ToFloat());
                pen.Dispose();
            }
        }
示例#21
0
        public void DrawEllipse(Rect bounds, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            if (style.HasFill)
            {
                _g.DrawEllipse(style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect());
            }

            if (style.HasStroke)
            {
                _g.DrawEllipse(new XPen(style.Stroke.ToXColor(), style.StrokeThickness.Left), bounds.ToXRect());
            }
        }
示例#22
0
            public void WriteTo(XmlWriter xmlWriter)
            {
                xmlWriter.WriteStartElement("ThreeDProperties");
                {
                    if (Enabled.HasValue)
                    {
                        xmlWriter.WriteElementString("Enabled", Enabled.Value.ToString());
                    }

                    xmlWriter.WriteElementString("ProjectionMode", ProjectionMode.ToString());

                    if (ProjectionMode == ProjectionMode3DForRendering.Perspective)
                    {
                        if (Perspective.HasValue)
                        {
                            xmlWriter.WriteElementString("Perspective", Perspective.ToString());
                        }
                    }

                    if (Rotation.HasValue)
                    {
                        xmlWriter.WriteElementString("Rotation", Rotation.ToString());
                    }

                    if (Inclination.HasValue)
                    {
                        xmlWriter.WriteElementString("Inclination", Inclination.ToString());
                    }

                    xmlWriter.WriteElementString("Shading", Shading.ToString());

                    if (WallThickness.HasValue)
                    {
                        xmlWriter.WriteElementString("WallThickness", WallThickness.ToString());
                    }

                    //if ( chart type is bar OR column)
                    {
                        xmlWriter.WriteElementString("DrawingStyle", DrawingStyle.ToString());
                        if (Clustered.HasValue)
                        {
                            xmlWriter.WriteElementString("Clustered", Clustered.ToString());
                        }
                    }
                }
                xmlWriter.WriteEndElement();
            }
示例#23
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Polygon polygon = WpfElement as Polygon;

            if (polygon.Points != null)
            {
                DrawingStyle style = DrawingStyle.FromElement(this);
                style.Fill            = polygon.Fill;
                style.Stroke          = polygon.Stroke;
                style.StrokeThickness = new Thickness(polygon.StrokeThickness);
                style.Opacity         = opacity;

                context.DrawPolygon(bounds, polygon.Points.ToArray(), style);
            }
        }
示例#24
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            TextBlock textBlock = WpfElement as TextBlock;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.Fill       = textBlock.Foreground;
            style.FontFamily = textBlock.FontFamily;
            style.FontSize   = textBlock.FontSize;
            style.FontStyle  = textBlock.FontStyle;
            style.FontWeight = textBlock.FontWeight;
            style.Opacity    = opacity;

            context.DrawText(bounds, textBlock.Text, style);
        }
示例#25
0
        /// <summary>
        /// Draws the specified text.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="text">The text.</param>
        /// <param name="style">The style.</param>
        public void DrawText(Rect bounds, string text, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            SKFontStyleSlant fontStyle = SKFontStyleSlant.Upright;

            if (style.FontStyle == FontStyles.Italic)
            {
                fontStyle = SKFontStyleSlant.Italic;
            }
            else if (style.FontStyle == FontStyles.Oblique)
            {
                fontStyle = SKFontStyleSlant.Oblique;
            }

            var typeFace = SKTypeface.FromFamilyName(style.FontFamily.ToString(), new SKFontStyle(style.FontWeight.ToOpenTypeWeight(), 1, fontStyle));

            SKPaint paint = new SKPaint();

            paint.Typeface    = typeFace;
            paint.TextSize    = style.FontSize.ToFloat();
            paint.IsAntialias = style.EdgeMode == EdgeMode.Unspecified;

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.White.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }

            if (style.Fill != null)
            {
                if (style.Fill is SolidColorBrush)
                {
                    paint.Color = style.Fill.ToSKColor();
                }
                else
                {
                    paint.Shader = style.Fill.ToSkiaShader(bounds.Width, bounds.Height);
                }
            }

            _canvas.DrawText(text, bounds.Left.ToFloat(), bounds.Bottom.ToFloat(), paint);

            _canvas.ResetMatrix();
        }
示例#26
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (IsPlatformSupported)
            {
                base.OnPaint(e);
            }
            else
            {
                if (FlatStyle != FlatStyle.Standard)
                {
                    FlatStyle = FlatStyle.Standard;
                }

                e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                DrawingStyle.Draw(this, buttonState, e);
            }
        }
示例#27
0
        public void DrawPolygon(Rect bounds, Point[] points, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            _g.TranslateTransform(bounds.Left, bounds.Top);

            if (style.HasFill)
            {
                _g.DrawPolygon(style.Fill.ToXBrush(bounds.Width, bounds.Height), points, XFillMode.Alternate);
            }

            if (style.HasStroke)
            {
                _g.DrawPolygon(new XPen(style.Stroke.ToXColor()), points);
            }

            _g.Restore();
        }
示例#28
0
        public static void ApplyStroke(this SKPaint paint, Rect bounds, DrawingStyle style)
        {
            paint.IsAntialias = style.EdgeMode == EdgeMode.Unspecified;
            paint.Style       = SKPaintStyle.Stroke;
            paint.IsStroke    = true;
            paint.StrokeWidth = style.StrokeThickness.Left.ToFloat();

            if (style.Stroke is SolidColorBrush)
            {
                paint.Color = style.Stroke.ToSKColor();
            }
            else
            {
                paint.Shader = style.Stroke.ToSkiaShader(bounds.Width, bounds.Height);
            }

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.Transparent.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }
        }
示例#29
0
        protected override void OnRender(IDrawingContext context, Rect bounds, double opacity)
        {
            base.OnRender(context, bounds, opacity);

            Border border = WpfElement as Border;

            DrawingStyle style = DrawingStyle.FromElement(this);

            style.CornerRadius    = border.CornerRadius;
            style.Fill            = border.Background;
            style.Stroke          = border.BorderBrush;
            style.StrokeThickness = border.BorderThickness;
            style.Opacity         = opacity;

            context.DrawRect(bounds, style);

            if (border.ClipToBounds)
            {
                context.ClipRect(bounds, border.CornerRadius);
            }
        }
        /// <summary>
        /// Draws results of inspection on image
        /// </summary>
        private void DrawResults(Image ioImage, List <Circle2D> correctCircles, List <Circle2D> incorrectCircles)
        {
            var defaultStyle = new DrawingStyle
            {
                DrawingMode = DrawingMode.HighQuality,
                Filled      = false,
                Opacity     = 1.0f,
                PointShape  = null,
                PointSize   = 2.0f,
                Thickness   = 4.0f
            };

            foreach (var correctCircle in correctCircles)
            {
                AVL.DrawCircle(ioImage, correctCircle, null, Pixel.Green, defaultStyle);
            }

            foreach (var incorrectCircle in incorrectCircles)
            {
                AVL.DrawCircle(ioImage, incorrectCircle, null, Pixel.Red, defaultStyle);
            }
        }