void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
        {
            var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);

            double left = 0;
            double width = _view.ViewportWidth + _view.MaxTextRightCoordinate;
            if (markerGeometry != null)
            {
                left = markerGeometry.Bounds.Left;
                if (!extendToRight) width = markerGeometry.Bounds.Width;
            }

            Rect rect = new Rect(left, line.Top, width, line.Height);

            RectangleGeometry geometry = new RectangleGeometry(rect);

            GeometryDrawing drawing = new GeometryDrawing(brush, new Pen(), geometry);
            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            Image image = new Image();
            image.Source = drawingImage;

            Canvas.SetLeft(image, geometry.Bounds.Left);
            Canvas.SetTop(image, geometry.Bounds.Top);

            _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
        }
예제 #2
0
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (null == drawingAttributes)
            {
                throw new ArgumentNullException("drawingAttributes");
            }
            Pen pen = new Pen
            {
                StartLineCap = PenLineCap.Round,
                EndLineCap = PenLineCap.Round,
                Brush = new SolidColorBrush(drawingAttributes.Color),
                Thickness = drawingAttributes.Width
            };

            BrushConverter bc = new BrushConverter();
            Brush BackGround = (Brush)bc.ConvertFromString(drawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor).ToString());
            GeometryConverter gc = new GeometryConverter();
            Geometry geometry = (Geometry)gc.ConvertFromString(string.Format("M {0},{1} {2},{3} {4},{5} Z", StylusPoints[0].X, StylusPoints[1].Y, (Math.Abs(StylusPoints[1].X - StylusPoints[0].X))/2 + StylusPoints[0].X, StylusPoints[0].Y, StylusPoints[1].X, StylusPoints[1].Y));
            GeometryDrawing gd = new GeometryDrawing(BackGround, pen, geometry);
            drawingContext.DrawDrawing(gd);
        }
예제 #3
0
        /// <summary>
        /// Create an Arc geometry drawing of an ellipse or circle
        /// </summary>
        /// <param name="rect">Box to hold the whole ellipse described by the arc</param>
        /// <param name="startDegrees">Start angle of the arc degrees within the ellipse. 0 degrees is a line to the right.</param>
        /// <param name="sweepDegrees">Sweep angle, -ve = Counterclockwise, +ve = Clockwise</param>
        /// <returns>GeometryDrawing object</returns>
        private static GeometryDrawing CreateArcDrawing(Rect rect, double startDegrees, double sweepDegrees)
        {
            // degrees to radians conversion
            double startRadians = startDegrees * Math.PI / 180.0;
            double sweepRadians = sweepDegrees * Math.PI / 180.0;

            // x and y radius
            double dx = rect.Width / 2;
            double dy = rect.Height / 2;

            // determine the start point
            double xs = rect.X + dx + (Math.Cos(startRadians) * dx);
            double ys = rect.Y + dy + (Math.Sin(startRadians) * dy);

            // determine the end point
            double xe = rect.X + dx + (Math.Cos(startRadians + sweepRadians) * dx);
            double ye = rect.Y + dy + (Math.Sin(startRadians + sweepRadians) * dy);

            // draw the arc into a stream geometry
            StreamGeometry streamGeom = new StreamGeometry();
            using (StreamGeometryContext ctx = streamGeom.Open())
            {
                bool isLargeArc = Math.Abs(sweepDegrees) > 180;
                SweepDirection sweepDirection = sweepDegrees < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;

                ctx.BeginFigure(new Point(xs, ys), false, false);
                ctx.ArcTo(new Point(xe, ye), new Size(dx, dy), 0, isLargeArc, sweepDirection, true, false);
            }

            // create the drawing
            GeometryDrawing drawing = new GeometryDrawing();
            drawing.Geometry = streamGeom;
            return drawing;
        }
        /// <summary>
        /// Creates a square image and attaches an event handler to the layout changed event that
        /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
        /// </summary>
        /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
        public TranslationAdornment(IWpfTextView view)
        {
            _view = view;

            Brush brush = new SolidColorBrush(Colors.BlueViolet);
            brush.Freeze();
            Brush penBrush = new SolidColorBrush(Colors.Red);
            penBrush.Freeze();
            Pen pen = new Pen(penBrush, 0.5);
            pen.Freeze();

            //draw a square with the created brush and pen
            System.Windows.Rect r = new System.Windows.Rect(0, 0, 30, 30);
            Geometry g = new RectangleGeometry(r);
            GeometryDrawing drawing = new GeometryDrawing(brush, pen, g);
            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            _image = new Image();
            _image.Source = drawingImage;

            //Grab a reference to the adornment layer that this adornment should be added to
            _adornmentLayer = view.GetAdornmentLayer("TranslationAdornment");

            _view.ViewportHeightChanged += delegate { this.onSizeChange(); };
            _view.ViewportWidthChanged += delegate { this.onSizeChange(); };
        }
예제 #5
0
파일: Pen.cs 프로젝트: osmedile/TypeCobol
 public static Pen CreateErrorPen(Color color)
 {
     var geometry = new StreamGeometry();
     using (var context = geometry.Open())
     {
         context.BeginFigure(new Point(-1, 0), false, false);
         context.PolyLineTo(new[] {
                 new Point(-0.5, 0.4),
                 new Point(0, 0),
                 new Point(0.5, -0.4),
                 new Point(1, 0),
             }, true, true);
     }
     var brushPattern = new GeometryDrawing
     {
         Pen = new Pen(new SolidColorBrush(color), 0.4),
         Geometry = geometry
     };
     var brush = new DrawingBrush(brushPattern)
     {
         TileMode = TileMode.Tile,
         Viewport = new Rect(-1, -1, 2, 2),
         ViewportUnits = BrushMappingMode.Absolute,
         Viewbox = new Rect(-1, -1, 2, 2),
         ViewboxUnits = BrushMappingMode.Absolute,
     };
     var pen = new Pen(brush, 3.0);
     pen.Freeze();
     return pen;
 }
예제 #6
0
        private Brush CreateARectangleWithDrawingBrush()
        {
            // Create a DrawingBrush
            DrawingBrush blackBrush = new DrawingBrush();
            // Create a Geometry with white background
            GeometryDrawing backgroundSquare =
                new GeometryDrawing(
                    Brushes.DarkGray,
                    null,
                    new RectangleGeometry(new Rect(0, 0, 400, 400)));

            // Create a GeometryGroup that will be added to Geometry
            GeometryGroup gGroup = new GeometryGroup();
            gGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 200, 200)));
            gGroup.Children.Add(new RectangleGeometry(new Rect(200, 200, 200, 200)));
            // Create a GeomertyDrawing
            GeometryDrawing checkers = new GeometryDrawing(new SolidColorBrush(Colors.Gray), null, gGroup);

            DrawingGroup checkersDrawingGroup = new DrawingGroup();
            checkersDrawingGroup.Children.Add(backgroundSquare);
            checkersDrawingGroup.Children.Add(checkers);

            blackBrush.Drawing = checkersDrawingGroup;

            // Set Viewport and TimeMode
            blackBrush.Viewport = new Rect(0, 0, 0.1, 0.2);
            blackBrush.TileMode = TileMode.Tile;

            return blackBrush;
        }
예제 #7
0
        public static Sm.Drawing ToGeometryDrawing(this Shape input)
        {
            Sm.GeometryDrawing geometryDrawing = new Sm.GeometryDrawing();
            Sm.GeometryGroup   drawing         = new Sm.GeometryGroup();

            if (input.IsCompound)
            {
                foreach (Geometry geo in input.Geometries)
                {
                    Sm.Geometry geometry = geo.ToGeometry();
                    drawing.Children.Add(geometry);
                }
            }
            else
            {
                Sm.Geometry geometry = input.ToGeometry();
                drawing.Children.Add(geometry);
            }

            geometryDrawing.Geometry = drawing;
            geometryDrawing.Pen      = input.Graphic.Stroke.ToMediaPen();
            geometryDrawing.Brush    = input.Graphic.Fill.ToMediaBrush();

            Sm.DrawingGroup drawingGroup = new Sm.DrawingGroup();
            drawingGroup.Children.Add(geometryDrawing);

            return(drawingGroup);
        }
예제 #8
0
        public void AddDecorationError(BasePropertyDeclarationSyntax _property, string textFull, string toolTipText, FixErrorCallback errorCallback)
        {
            var lineSpan = tree.GetLineSpan(_property.Span, usePreprocessorDirectives: false);
            int lineNumber = lineSpan.StartLinePosition.Line;
            var line = _textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
            var textViewLine = _textView.GetTextViewLineContainingBufferPosition(line.Start);
            int startSpace = textFull.Length - textFull.TrimStart().Length;
            int endSpace = textFull.Length - textFull.TrimEnd().Length;

            SnapshotSpan span = new SnapshotSpan(_textView.TextSnapshot, Span.FromBounds(line.Start.Position + startSpace, line.End.Position - endSpace));
            Geometry g = _textView.TextViewLines.GetMarkerGeometry(span);
            if (g != null)
            {
                rects.Add(g.Bounds);

                GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
                drawing.Freeze();

                DrawingImage drawingImage = new DrawingImage(drawing);
                drawingImage.Freeze();

                Image image = new Image();
                image.Source = drawingImage;
                //image.Visibility = Visibility.Hidden;

                Canvas.SetLeft(image, g.Bounds.Left);
                Canvas.SetTop(image, g.Bounds.Top);
                _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, (t, ui) =>
                {
                    rects.Remove(g.Bounds);
                });

                DrawIcon(span, g.Bounds.Left - 30, g.Bounds.Top, toolTipText, errorCallback);
            }
        }
예제 #9
0
        GeometryDrawing CreateGeometryDrawing()
        {
            //http://msdn.microsoft.com/en-us/library/system.windows.media.geometrydrawing.aspx

            GeometryGroup ellipses = new GeometryGroup();
            ellipses.Children.Add(
                new EllipseGeometry(new Point(200, 200), 45, 20)
                );
            ellipses.Children.Add(
                new EllipseGeometry(new Point(200, 200), 20, 45)
                );

            GeometryDrawing aGeometryDrawing = new GeometryDrawing();
            aGeometryDrawing.Geometry = ellipses;

            // Paint the drawing with a gradient.
            aGeometryDrawing.Brush =
                new LinearGradientBrush(
                    Colors.Blue,
                    Color.FromRgb(204, 204, 255),
                    new Point(0, 0),
                    new Point(1, 1));

            return aGeometryDrawing;
        }
예제 #10
0
 private Drawing createDrawingWithFrameRectangleGeometry()
 {
     GeometryDrawing drawing = new GeometryDrawing();
     drawing.Pen = new Pen(Brushes.Black, 1);
     drawing.Geometry = buildFrameRectangle();
     return drawing;
 }
예제 #11
0
 private Drawing createDrawingWithGroupGemoetry()
 {
     GeometryDrawing drawing = new GeometryDrawing();
     drawing.Pen = new Pen(Brushes.Black, 1);
     drawing.Geometry = buildGeometryGroup();
     return drawing;
 }
예제 #12
0
        public void Init()
        {
            DrawingGroup dg = new DrawingGroup();
            ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight));
            dg.Children.Add(id);

            pointsGeometryGroup = new GeometryGroup();
            linesGeometryGroup = new GeometryGroup();
            middlePointGeoGrp = new GeometryGroup();
            if (points != null)
            {
                SetPointsGeometry();
            }

            GeometryDrawing gd = new GeometryDrawing(Brushes.Blue, null, pointsGeometryGroup);
            dg.Children.Add(gd);

            GeometryDrawing gd2 = new GeometryDrawing(null, new Pen(Brushes.LightGreen,3), linesGeometryGroup);
            dg.Children.Add(gd2);

            GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp);
            dg.Children.Add(gd1);

            Brush b = new SolidColorBrush(Colors.Red);
            b.Opacity = 0.5;
            mousePointGeometryDrwaing = new GeometryDrawing(b, null, null);
            dg.Children.Add(mousePointGeometryDrwaing);

            DrawingImage di = new DrawingImage(dg);
            this.Source = di;

            chosenPoint = -1;
        }
예제 #13
0
파일: AShape.cs 프로젝트: subbuballa/Aegir
        /// <summary>
        /// Create a new abstract shape.
        /// </summary>
        /// <param name="Id">The Id of the shape.</param>
        /// <param name="Latitude">The latitude of the shape center.</param>
        /// <param name="Longitude">The longitude of the shape center.</param>
        /// <param name="Altitude">The altitude of the shape center.</param>
        /// <param name="GeoWidth">The geographical width of the shape center.</param>
        /// <param name="GeoHeight">The geographical height of the shape center.</param>
        public AShape(String[] Geometries, Latitude Latitude, Longitude Longitude, Altitude Altitude, Latitude Latitude2, Longitude Longitude2, Color StrokeColor, Double StrokeThickness, Color FillColor)
        {
            this.Id         = Id;
            this.Latitude   = Latitude;
            this.Longitude  = Longitude;
            this.Altitude   = Altitude;
            this.Latitude2  = Latitude2;
            this.Longitude2 = Longitude2;

            var PathGeometry16 = PathGeometry.Parse(Geometries[8]);

            var GD16 = new GeometryDrawing(new SolidColorBrush(FillColor), new Pen(new SolidColorBrush(StrokeColor), StrokeThickness), PathGeometry16);

            var DrawingGroup = new DrawingGroup();
            DrawingGroup.Children.Add(GD16);

            this.Fill = new DrawingBrush()
            {
                Drawing = DrawingGroup,
                //Viewport = new Rect(0, 0, 1, 1),
                TileMode = TileMode.None,
                Stretch = Stretch.UniformToFill
            };

            Bounds = DrawingGroup.Bounds;
            var w = Bounds.Width;
            var h = Bounds.Height;
        }
예제 #14
0
        /// <summary>
        /// Within the given line add the scarlet box behind the a
        /// </summary>
        private void CreateVisuals(ITextViewLine line)
        {
            //grab a reference to the lines in the current TextView 
            IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
            int start = line.Start;
            int end = line.End;

            //Loop through each character, and place a box around any a 
            for (int i = start; (i < end); ++i)
            {
                if (_view.TextSnapshot[i] == 'a')
                {
                    SnapshotSpan span = new SnapshotSpan(_view.TextSnapshot, Span.FromBounds(i, i + 1));
                    Geometry g = textViewLines.GetMarkerGeometry(span);
                    if (g != null)
                    {
                        GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
                        drawing.Freeze();

                        DrawingImage drawingImage = new DrawingImage(drawing);
                        drawingImage.Freeze();

                        Image image = new Image();
                        image.Source = drawingImage;

                        //Align the image with the top of the bounds of the text geometry
                        Canvas.SetLeft(image, g.Bounds.Left);
                        Canvas.SetTop(image, g.Bounds.Top);

                        _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
                    }
                }
            }
        }
예제 #15
0
        public MainWindow()
        {
            InitializeComponent();

            drawingGroup = new DrawingGroup();

            // Создаем объект для описания геометрической фигуры
            GeometryDrawing geometryDrawing = new GeometryDrawing();

            // Описываем и сохраняем геометрию квадрата
            RectangleGeometry rectGeometry = new RectangleGeometry();
            rectGeometry.Rect = new Rect(0, 0, 10, 10);
            geometryDrawing.Geometry = rectGeometry;

            // Настраиваем перо и кисть
            geometryDrawing.Pen = new Pen(Brushes.Red, 0.005);// Перо рамки
            geometryDrawing.Brush = Brushes.LightBlue;// Кисть закраски

            // Добавляем готовый слой в контейнер отображения
            drawingGroup.Children.Add(geometryDrawing);

            GeometryDrawing ellipsgeomy = new GeometryDrawing();

            EllipseGeometry elgeometry = new EllipseGeometry(new Point(5, 5), 2, 2);

            ellipsgeomy.Geometry = elgeometry;

            ellipsgeomy.Brush = Brushes.White;

            drawingGroup.Children.Add(ellipsgeomy);
        }
예제 #16
0
        public void SetFillBrush()
        {
            DrawingGroup rootDrawingGroup = new DrawingGroup();

            GeometryDrawing aDrawing = new GeometryDrawing();
            aDrawing.Brush = Brushes.Gray.CloneCurrentValue();
            aDrawing.Pen = new Pen(Brushes.Gray, 1);
            aDrawing.Brush.Opacity = .5;

            aDrawing.Geometry = Primitives.PolygonLine(WallElementDetails.StartPoint, WallElementDetails.EndPoint, 10, 10);

            rootDrawingGroup.Children.Add(aDrawing);

            //create a transition line
            GeometryDrawing aCenterLine = new GeometryDrawing();
            aCenterLine.Brush = Brushs.WallBoundaryStroke;
            aCenterLine.Pen = Pens.WallBoundaryStroke;

            aCenterLine.Geometry = Primitives.Line(WallElementDetails.StartPoint, WallElementDetails.EndPoint);

            rootDrawingGroup.Children.Add(aCenterLine);

            DrawingBrush brush = new DrawingBrush(rootDrawingGroup);

            this.Fill = brush;
        }
        public AreaSeries2D()
        {
            // 初始化保存数据点的变量
            _points = new SeriesPointCollection();
            _points.CollectionChanged += _points_CollectionChanged;

            // 初始化绘制曲线的画板
            gStream_Line = new StreamGeometry();
            gStream_Area = new StreamGeometry();

            gDrawing_Line = new GeometryDrawing();
            gDrawing_Line.Brush = null;
            gDrawing_Line.Pen = new Pen()
            {
                Thickness = 1,
                Brush = Brushes.Black
            };
            gDrawing_Line.Geometry = gStream_Line;

            /* 初始化绘制填充色的画板 */
            gDrawing_Area = new GeometryDrawing();
            gDrawing_Area.Brush = Brushes.Red;
            gDrawing_Area.Pen = new Pen()
            {
                Thickness = 0,
                Brush = null
            };
            gDrawing_Area.Geometry = gStream_Area;

            /* 生成绘画组 */
            drawingGroup = new DrawingGroup();
            drawingGroup.Children.Add(gDrawing_Line);
            drawingGroup.Children.Add(gDrawing_Area);
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            

            // allows the points to be rendered as an image that can be further manipulated
            PathGeometry geometry = new PathGeometry();
            this.Siz

            // Add all points to the geometry
            foreach (Points pointXY in _points)
            {
                PathFigure figure = new PathFigure();
                figure.StartPoint = pointXY.FromPoint;
                figure.Segments.Add(new LineSegment(pointXY.ToPoint, true));
                geometry.Figures.Add(figure);
            }

            // Add the first point to close the gap from the graph's end point
            // to graph's start point
            PathFigure lastFigure = new PathFigure();
            lastFigure.StartPoint = _points[_points.Count - 1].FromPoint;
            lastFigure.Segments.Add(new LineSegment(_firstPoint, true));
            geometry.Figures.Add(lastFigure);

            // Create a new drawing and drawing group in order to apply
            // a custom drawing effect
            GeometryDrawing drawing = new GeometryDrawing(this.Pen.Brush, this.Pen, geometry);
            DrawingGroup drawingGroup = new DrawingGroup();
            drawingGroup.Children.Add(drawing);
        }
        private void PaintBackground()
        {
            var backgroundSquare = new GeometryDrawing(Brushes.Black, null, new RectangleGeometry(new Rect(0, 0, 100, 100)));

            var aGeometryGroup = new GeometryGroup();
            aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
            aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));

            var checkerBrush = new LinearGradientBrush();
            checkerBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));
            checkerBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 22, 0), 1.0));

            var checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);

            var checkersDrawingGroup = new DrawingGroup();
            checkersDrawingGroup.Children.Add(backgroundSquare);
            checkersDrawingGroup.Children.Add(checkers);

            var myBrush = new DrawingBrush
            {
                Drawing = checkersDrawingGroup,
                Viewport = new Rect(0, 0, 0.02, 0.02),
                TileMode = TileMode.Tile,
                Opacity = 0.5
            };

            LayoutRoot.Background = myBrush;
        }
예제 #20
0
        public GeometryDrawing Process()
        {
            GeometryDrawing drawing = new GeometryDrawing();
            drawing.Brush = Brushes.Transparent;
            drawing.Geometry = new RectangleGeometry(this.Value);

            return drawing;
        }
예제 #21
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            var ellipse = new EllipseGeometry(new Point(250, 50), 50, 50);
            var drawing = new GeometryDrawing(Brushes.BlueViolet, new Pen(Brushes.Bisque, 2), ellipse);
            drawingContext.DrawDrawing(drawing);
        }
 public static void DrawText(this DrawingGroup drawingGroup, int x, int y, string text)
 {
     var typeface = new Typeface("Arial");
     var formattedText = new FormattedText(text, CultureInfo.CurrentUICulture,
                                  FlowDirection.LeftToRight, typeface, 10, Brushes.Gray);
     var textgeometry = formattedText.BuildGeometry(new Point(x, y));
     var textDrawing = new GeometryDrawing(Brushes.Gray, new Pen(Brushes.Gray, 0), textgeometry);
     drawingGroup.Children.Add(textDrawing);
 }
예제 #23
0
        protected override void HandleDragOver(sw.DragEventArgs e, DragEventArgs args)
        {
            var lastRow = LastDragRow;

            base.HandleDragOver(e, args);
            var info = LastDragInfo = GetDragInfo(args);

            if (args.Effects != DragEffects.None)
            {
                // show drag indicator!
                var row = GetDataGridRow(GetItemAtRow(info.Index));
                if (row != null)
                {
                    // same position, just return
                    if (lastRow != null && lastRow.IsEqual(row, info.InsertIndex))
                    {
                        return;
                    }

                    lastRow?.Revert();
                    LastDragRow = new GridDragRowState(row, info.InsertIndex);

                    if (info.InsertIndex == -1)
                    {
                        row.Background = sw.SystemColors.HighlightBrush;
                        row.Foreground = sw.SystemColors.HighlightTextBrush;
                    }
                    else
                    {
                        var d  = new swm.GeometryDrawing();
                        var gg = new swm.GeometryGroup();
                        gg.Children.Add(new swm.LineGeometry(new sw.Point(0, 0), new sw.Point(row.ActualWidth, 0)));
                        d.Geometry = gg;
                        d.Brush    = sw.SystemColors.HighlightBrush;
                        d.Pen      = new swm.Pen(sw.SystemColors.HighlightBrush, 1);
                        var b = new swm.DrawingBrush {
                            Drawing = d, TileMode = swm.TileMode.None, Stretch = swm.Stretch.None, AlignmentX = swm.AlignmentX.Left
                        };
                        if (info.InsertIndex == row.GetIndex())
                        {
                            b.AlignmentY        = swm.AlignmentY.Top;
                            row.BorderThickness = new sw.Thickness(0, 1, 0, 0);
                        }
                        else
                        {
                            b.AlignmentY        = swm.AlignmentY.Bottom;
                            row.BorderThickness = new sw.Thickness(0, 0, 0, 1);
                        }

                        row.BorderBrush = b;
                    }
                    return;
                }
            }

            ResetDrag();
        }
예제 #24
0
		public static ImageSource GetImageSourceFromAxoColor(AxoColor axoColor, int width, int height)
		{
			var innerRect = new Rect(0, 0, width, height);
			var geometryDrawing = new GeometryDrawing() { Geometry = new RectangleGeometry(innerRect) };
			geometryDrawing.Brush = new SolidColorBrush(GuiHelper.ToWpf(axoColor));
			DrawingImage geometryImage = new DrawingImage(geometryDrawing);
			geometryImage.Freeze(); // Freeze the DrawingImage for performance benefits.
			return geometryImage;
		}
        public static void DrawCircle(this DrawingGroup drawingGroup, Point centerPoint, double radius, SolidColorBrush brush, Pen pen = null)
        {
            if (pen == null)
                pen = new Pen(brush, 1);

            var circle = new EllipseGeometry(centerPoint, radius, radius);
            var circleDrawing = new GeometryDrawing(brush, pen, circle);
            drawingGroup.Children.Add(circleDrawing);
        }
        public static void DrawRectangle(this DrawingGroup drawingGroup, Rect rect, SolidColorBrush brush, Pen pen = null)
        {
            if (pen == null)
                pen = new Pen(brush, 1);

            var rectangleGeometry = new RectangleGeometry(rect);
            var rectangleDrawing = new GeometryDrawing(brush, pen, rectangleGeometry);
            drawingGroup.Children.Add(rectangleDrawing);
        }
예제 #27
0
 public void ShowMidPoint()
 {
     DrawingGroup dg = new DrawingGroup();
     ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight));
     dg.Children.Add(id);
     GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp);
     dg.Children.Add(gd1);
     DrawingImage di = new DrawingImage(dg);
     this.Source = di;
 }
예제 #28
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
 {
     switch (connectionId)
     {
     case 1:
         this.qrDrawing = ((System.Windows.Media.GeometryDrawing)(target));
         return;
     }
     this._contentLoaded = true;
 }
예제 #29
0
        private Image CreateImageToHighlightLine(Geometry geometry, LineResultMarker marker)
        {
            GeometryDrawing backgroundGeometry = new GeometryDrawing(marker.Fill, marker.Outline, geometry);
            backgroundGeometry.Freeze();

            DrawingImage backgroundDrawning = new DrawingImage(backgroundGeometry);
            backgroundDrawning.Freeze();

            return new Image {Source = backgroundDrawning};
        }
        /// <summary>
        /// Freezes and then creates an image object from a GeometryGroup.
        /// </summary>
        /// <param name="brush">The fill brush for the group.</param>
        /// <param name="pen">The Border pen for the group.</param>
        /// <param name="group">The group to create an image from.</param>
        /// <returns>An image object that can be added to the canvas.</returns>
        public static Image CreateImage(this  GeometryGroup group, Brush brush, Pen pen)
        {
            group.Freeze();

            var drawing = new GeometryDrawing(brush, pen, group);
            drawing.Freeze();

            var drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            return new Image { Source = drawingImage };
        }
예제 #31
0
    StackPanel BuildDrawing()
    {
      GeometryDrawing drawing = new GeometryDrawing();

      // Use geometries to describe two overlapping ellipses.
      EllipseGeometry ellipse1 = new EllipseGeometry();
      ellipse1.RadiusX = 20;
      ellipse1.RadiusY = 45;
      ellipse1.Center = new Point(50, 50);
      EllipseGeometry ellipse2 = new EllipseGeometry();
      ellipse2.RadiusX = 45;
      ellipse2.RadiusY = 20;
      ellipse2.Center = new Point(50, 50);
      GeometryGroup ellipses = new GeometryGroup();
      ellipses.Children.Add(ellipse1);
      ellipses.Children.Add(ellipse2);

      // Add the geometry to the drawing.
      drawing.Geometry = ellipses;

      // Specify the drawing's fill.
      drawing.Brush = Brushes.Blue;

      // Specify the drawing's stroke.
      Pen stroke = new Pen();
      stroke.Thickness = 10.0;
      stroke.Brush = new LinearGradientBrush(
          Colors.Black, Colors.Gray, new Point(0, 0), new Point(1, 1));
      drawing.Pen = stroke;

      // Create a DrawingBrush
      DrawingBrush myDrawingBrush = new DrawingBrush();
      myDrawingBrush.Drawing = drawing;

      // Create a Rectangle element.
      Rectangle aRectangle = new Rectangle();
      aRectangle.Width = 150;
      aRectangle.Height = 150;
      aRectangle.Stroke = Brushes.Black;
      aRectangle.StrokeThickness = 1.0;

      // Use the DrawingBrush to paint the rectangle's
      // background.
      aRectangle.Fill = myDrawingBrush;

      StackPanel mainPanel = new StackPanel();
      mainPanel.Children.Add(aRectangle);

      mainPanel.Arrange(new Rect(100, 100, 500, 500));
      //this.drawing2 = mainPanel;
      //this.Content = mainPanel;
      return mainPanel;
    }
예제 #32
0
 public Drawing buildDrawing()
 {
     GeometryDrawing drawing = new GeometryDrawing();
     if (this.penColor.HasValue)
     {
         drawing.Pen = new Pen(new SolidColorBrush(this.penColor.Value), this.penWidth);
     }
     if (this.fillColor.HasValue)
     {
         drawing.Brush = new SolidColorBrush(this.fillColor.Value);
     }
     drawing.Geometry = buildGeometry();
     return drawing;
 }
 private void SelectDrawing( GeometryDrawing drawing, bool select )
 {
     if( select )
     {
         drawing.Brush = Brushes.Red;
         drawing.Pen.Brush = Brushes.Red;
         drawing.Pen.Thickness *= 2;
     }
     else
     {
         drawing.Brush = Brushes.Black;
         drawing.Pen.Brush = Brushes.Black;
         drawing.Pen.Thickness /= 2;
     }
 }
예제 #34
0
        public void Clear(SolidBrush brush)
        {
            var rect = this.ClipBounds;

            if (drawingVisual != null)
            {
                // bitmap
                Control.Close();
                var newbmp = new swmi.RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, swm.PixelFormats.Pbgra32);
                newbmp.Render(visual);

                swm.Geometry maskgeometry;
                if (clipPath != null)
                {
                    maskgeometry = clipPath.ToWpf();
                }
                else
                {
                    maskgeometry = new swm.RectangleGeometry(rect.ToWpf());
                }
                var boundsgeometry = new swm.RectangleGeometry(this.bounds);
                maskgeometry = swm.Geometry.Combine(boundsgeometry, maskgeometry, swm.GeometryCombineMode.Exclude, null);
                var dr = new swm.GeometryDrawing(swm.Brushes.Black, null, maskgeometry);
                var db = new swm.DrawingBrush(dr);
                //db.Transform = new swm.TranslateTransform (0.5, 0.5);

                Control = drawingVisual.RenderOpen();
                PushGuideLines(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                Control.PushOpacityMask(db);
                Control.DrawImage(newbmp, this.bounds);
                Control.Pop();

                TransformStack.PushAll();
                ApplyClip();
            }
            else
            {
                // drawable
                if (brush == null || brush.Color.A < 1.0f)
                {
                    Widget.FillRectangle(Brushes.Black(Generator), rect);
                }
            }
            if (brush != null)
            {
                Widget.FillRectangle(brush, rect);
            }
        }
예제 #35
0
        public void Clear(SolidBrush brush)
        {
            var rect = clipBounds ?? initialClip;

            if (drawingVisual != null)
            {
                // bitmap
                Control.Close();
                var newbmp = new swmi.RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, swm.PixelFormats.Pbgra32);
                newbmp.RenderWithCollect(visual);

                swm.Geometry maskgeometry;
                if (clipPath != null)
                {
                    maskgeometry = clipPath;
                }
                else
                {
                    maskgeometry = new swm.RectangleGeometry(rect.ToWpf());
                }
                var boundsgeometry = new swm.RectangleGeometry(bounds);
                maskgeometry = swm.Geometry.Combine(boundsgeometry, maskgeometry, swm.GeometryCombineMode.Exclude, null);
                var dr = new swm.GeometryDrawing(swm.Brushes.Black, null, maskgeometry);
                var db = new swm.DrawingBrush(dr);
                //db.Transform = new swm.TranslateTransform (0.5, 0.5);

                Control = drawingVisual.RenderOpen();
                Control.PushGuidelineSet(new swm.GuidelineSet(new [] { bounds.Left, bounds.Right }, new [] { bounds.Top, bounds.Bottom }));
                Control.PushOpacityMask(db);
                Control.DrawImage(newbmp, bounds);
                Control.Pop();

                ApplyAll();
            }
            else
            {
                // drawable
                if (brush == null || brush.Color.A < 1.0f)
                {
                    Widget.FillRectangle(Brushes.Black, rect);
                }
            }
            if (brush != null)
            {
                Widget.FillRectangle(brush, rect);
            }
        }
예제 #36
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void BrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children)
            // will promote the property value from a default value to a local value. This is technically a sub-property
            // change because the collection was changed and not a new collection set (GeometryGroup.Children.
            // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled
            // the default value to the compositor. If the property changes from a default value, the new local value
            // needs to be marshalled to the compositor. We detect this scenario with the second condition
            // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be
            // Default and the NewValueSource will be Local.
            if (e.IsASubPropertyChange &&
                (e.OldValueSource == e.NewValueSource))
            {
                return;
            }


            GeometryDrawing target = ((GeometryDrawing)d);


            Brush oldV = (Brush)e.OldValue;
            Brush newV = (Brush)e.NewValue;

            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null)
            {
                DUCE.IResource targetResource = (DUCE.IResource)target;
                using (CompositionEngineLock.Acquire())
                {
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull);
                        target.ReleaseResource(oldV, channel);
                        target.AddRefResource(newV, channel);
                    }
                }
            }

            target.PropertyChanged(BrushProperty);
        }
예제 #37
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] MathInline obj)
        {
            var text = obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            TexFormula formula = null;

            try
            {
                formula = formulaParser.Parse(text);
            }
            catch (Exception)
            {
                renderer.WriteInline(new Run("[!!FORMULA PARSE ERROR!!]")
                {
                    Tag = obj
                });
                return;
            }

            var fontSize        = renderer.CurrentFontSize();
            var formulaRenderer = formula.GetRenderer(TexStyle.Display, fontSize, "Arial");
            var geo             = formulaRenderer.RenderToGeometry(0, 0);
            var geoD            = new System.Windows.Media.GeometryDrawing(Brushes.Black, null, geo);
            var di      = new DrawingImage(geoD);
            var uiImage = new System.Windows.Controls.Image()
            {
                Source = di
            };

            uiImage.Height = formulaRenderer.RenderSize.Height;                                                                         // size image to match rendersize -> get a zoom of 100%
            uiImage.Margin = new System.Windows.Thickness(0, 0, 0, -formulaRenderer.RenderSize.Height * formulaRenderer.RelativeDepth); // Move image so that baseline matches that of text
            var uiInline = new System.Windows.Documents.InlineUIContainer()
            {
                Child             = uiImage,
                Background        = Brushes.Yellow,
                BaselineAlignment = System.Windows.BaselineAlignment.Baseline,
                Tag = obj,
            };

            renderer.WriteInline(uiInline);
        }
예제 #38
0
        protected override void Write([NotNull] WpfRenderer renderer, [NotNull] MathBlock obj)
        {
            string text = string.Empty; // obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            for (int i = 0; i < obj.Lines.Count; ++i)
            {
                var l = obj.Lines.Lines[i];
                text += l.Slice.Text.Substring(l.Slice.Start, l.Slice.Length);
            }

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            TexFormula formula = null;

            try
            {
                formula = formulaParser.Parse(text);
            }
            catch (Exception)
            {
                var paragraph = new Paragraph()
                {
                    Tag = obj
                };
                renderer.Push(paragraph);
                renderer.WriteInline(new Run("[!!FORMULA PARSE ERROR!!]")
                {
                    Tag = obj
                });
                renderer.Pop();
                return;
            }

            var fontSize = renderer.CurrentFontSize();

            if (fontSize <= 0)
            {
                throw new InvalidProgramException();
            }

            var formulaRenderer = formula.GetRenderer(TexStyle.Display, fontSize, "Arial");
            var geo             = formulaRenderer.RenderToGeometry(0, 0);
            var geoD            = new System.Windows.Media.GeometryDrawing(Brushes.Black, null, geo);
            var di      = new DrawingImage(geoD);
            var uiImage = new System.Windows.Controls.Image()
            {
                Source = di
            };

            uiImage.Height = formulaRenderer.RenderSize.Height; // size image to match rendersize -> get a zoom of 100%
            // uiImage.Margin = new System.Windows.Thickness(0, 0, 0, -formulaRenderer.RenderSize.Height * formulaRenderer.RelativeDepth); // Move image so that baseline matches that of text
            var uiBlock = new System.Windows.Documents.BlockUIContainer()
            {
                Child = uiImage,
                Tag   = obj,
            };

            renderer.WriteBlock(uiBlock);
        }
예제 #39
0
        protected override void HandleDragOver(sw.DragEventArgs e, DragEventArgs args)
        {
            var lastRow = LastDragRow;

            base.HandleDragOver(e, args);
            var info = LastDragInfo = GetDragInfo(args);

            if (args.Effects != DragEffects.None)
            {
                // show drag indicator!
                var row = GetDataGridRow(info.Item ?? info.Parent);
                if (row != null)
                {
                    // same position, just return
                    if (lastRow != null && lastRow.IsEqual(row, info.InsertIndex))
                    {
                        return;
                    }

                    lastRow?.Revert();
                    LastDragRow = new GridDragRowState(row, info.InsertIndex);

                    if (info.InsertIndex == -1)
                    {
                        row.Background = sw.SystemColors.HighlightBrush;
                        row.Foreground = sw.SystemColors.HighlightTextBrush;
                    }
                    else
                    {
                        var node = controller.GetNodeAtRow(row.GetIndex());

                        var level = node.Level + 1;                         // indicator to the right of the expanders to align with text
                        var i     = info.Parent as ITreeGridItem;
                        if (info.Position == GridDragPosition.After && ReferenceEquals(info.Item, null))
                        {
                            level++;
                        }

                        level *= 16;
                        var d  = new swm.GeometryDrawing();
                        var gg = new swm.GeometryGroup();
                        gg.Children.Add(new swm.EllipseGeometry(new sw.Point(0, 0), 2, 2));
                        gg.Children.Add(new swm.LineGeometry(new sw.Point(2, 0), new sw.Point(row.ActualWidth - level - 16, 0)));
                        d.Geometry = gg;
                        d.Brush    = sw.SystemColors.HighlightBrush;
                        d.Pen      = new swm.Pen(sw.SystemColors.HighlightBrush, 1);
                        var b = new swm.DrawingBrush {
                            Drawing = d, TileMode = swm.TileMode.None, Stretch = swm.Stretch.None, AlignmentX = swm.AlignmentX.Left
                        };
                        if (info.InsertIndex == node.Index)
                        {
                            b.AlignmentY        = swm.AlignmentY.Top;
                            row.BorderThickness = new sw.Thickness(0, 5, 0, 0);
                        }
                        else
                        {
                            b.AlignmentY        = swm.AlignmentY.Bottom;
                            row.BorderThickness = new sw.Thickness(0, 0, 0, 5);
                        }

                        b.Transform     = new swm.TranslateTransform(level, 0);
                        row.BorderBrush = b;
                    }
                    return;
                }
            }

            ResetDrag();
        }