/// <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);
                    }
                }
            }
        }
        /// <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(); };
        }
Exemple #3
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);
            }
        }
        void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
        {
            var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);

            double left = markerGeometry.Bounds.Left;
            double width = extendToRight ? _view.ViewportWidth + _view.MaxTextRightCoordinate : 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);
        }
        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 };
        }
Exemple #7
0
		internal DoorPicture()
		{
			_pen = new Pen(Brushes.Black, 2);
			_pen.Freeze();
			_geometry = new PathGeometry()
			{
				Figures = new PathFigureCollection()
				{
					new PathFigure()
					{
						IsClosed = true,
						IsFilled = true,
						Segments = new PathSegmentCollection()
						{
							new LineSegment(new Point(-40,0),true),
							new LineSegment(new Point(-40,100),true),
							new LineSegment(new Point(0,100),true),
						}
					}
				}
			};
			_geometry.Freeze();
			_geometryDrawing = new GeometryDrawing()
			{
				Brush = new SolidColorBrush(Colors.DarkOrange),
				Pen = _pen,
				Geometry = new PathGeometry()
				{
					Figures = new PathFigureCollection()
					{
						new PathFigure()
						{
							IsClosed = true,
							IsFilled = true,
							Segments = new PathSegmentCollection()
							{
								new LineSegment(new Point(20,40),true),
								new LineSegment(new Point(20,140),true),
								new LineSegment(new Point(0,100),true),
							}
						}
					}
				}
			};
			_geometryDrawing.Freeze();
			_brushes = new Dictionary<Brush, Brush>();
		}
        private void AddMarker(SnapshotSpan span, Geometry markerGeometry, FormatInfo formatInfo)
        {
            GeometryDrawing drawing = new GeometryDrawing(formatInfo.Background, formatInfo.Outline, markerGeometry);
            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, markerGeometry.Bounds.Left);
            Canvas.SetTop(image, markerGeometry.Bounds.Top);

            adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
        }
Exemple #9
0
        // Unlike the LineAdornment extension we do not add a border (a border adds a bit too much
        // visual noise and makes it hard to see the insertion point when it is in the first column).
        private Image DoCreateAdornment(Rect area)
        {
            // Create the brush we'll used to highlight the current line. The color will be
            // the CurrentLine property from the Fonts and Colors panel in the Options dialog.
            if (m_fillBrush == null)
            {
                TextFormattingRunProperties format = m_formatMap.GetTextProperties(m_formatType);
                m_fillBrush = format.BackgroundBrush;
            }

            var drawing = new GeometryDrawing();
            drawing.Brush = m_fillBrush;
            drawing.Geometry = new RectangleGeometry(area, 1.0, 1.0);
            drawing.Freeze();

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

            var image = new Image();
            image.UseLayoutRounding = false;		// work around WPF rounding bug
            image.Source = drawingImage;
            return image;
        }
        private void CreateVisuals(ITextViewLine line)
        {

            {
                var text = line.Extent.GetText();
                if (!regex.IsMatch(text)) return;

            }


            IWpfTextViewLineCollection textViewLines = this.view.TextViewLines;

            // Loop through each character, and place a box around any 'a'
            for (int charIndex = line.Start; charIndex < line.End; charIndex++)
            {
                if (this.view.TextSnapshot[charIndex] == 'a')
                {
                    SnapshotSpan span = new SnapshotSpan(this.view.TextSnapshot, Span.FromBounds(charIndex, charIndex + 1));
                    Geometry geometry = textViewLines.GetMarkerGeometry(span);
                    if (geometry != null)
                    {
                        var drawing = new GeometryDrawing(this.brush, this.pen, geometry);
                        drawing.Freeze();

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

                        var image = new Image
                        {
                            Source = drawingImage,
                        };

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

                        this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
                    }
                }
            }
        }
        public async System.Threading.Tasks.Task Explode()
        {
            if (ParticleCount > MaxParticleCount)
                return;
            ParticleCount++;

            // TODO: rewrite this part for better design & performance
            // store service & package as static member.

            var service = ServiceProvider.GlobalProvider.GetService(typeof(SPowerMode));
            var pm_service = service as IPowerMode;
            var package = pm_service.Package;
            var page = package.General;

            ExplosionParticle.Color = page.Color;
            ExplosionParticle.AlphaRemoveAmount = page.AlphaRemoveAmount;
            ExplosionParticle.bGetColorFromEnvironment = bGetColorFromEnvironment;
            ExplosionParticle.RandomColor = page.RandomColor;
            ExplosionParticle.FrameDelay = page.FrameDelay;
            ExplosionParticle.Gravity = page.Gravity;
            ExplosionParticle.MaxParticleCount = page.MaxParticleCount;
            ExplosionParticle.MaxSideVelocity = page.MaxSideVelocity;
            ExplosionParticle.MaxUpVelocity = page.MaxUpVelocity;
            //ExplosionParticle.ParticlesEnabled = page.ParticlesEnabled;
            //ExplosionParticle.ShakeEnabled = page.ShakeEnabled;
            ExplosionParticle.StartAlpha = page.StartAlpha;

            // End of TODO.

            var alpha = StartAlpha;
            var upVelocity = Random.NextDouble() * MaxUpVelocity;
            var leftVelocity = Random.NextDouble() * MaxSideVelocity * Random.NextSignSwap();
            SolidColorBrush brush = null;
         
            if (bGetColorFromEnvironment)
            {
                var svc = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsUIShell)) as Microsoft.VisualStudio.Shell.Interop.IVsUIShell5;
                brush = new SolidColorBrush(Microsoft.VisualStudio.Shell.VsColors.GetThemedWPFColor(svc, Microsoft.VisualStudio.PlatformUI.EnvironmentColors.PanelTextColorKey));
            }
            else if (RandomColor)
            {
                brush = new SolidColorBrush(Random.NextColor());
            }
            else
            {
                brush = new SolidColorBrush(Color);
            }
            brush.Freeze();
            var drawing = new GeometryDrawing(brush, null, geometry);
            drawing.Freeze();

            var drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();
            var image = new Image
            {
                Source = drawingImage,
            };
            while (alpha >= AlphaRemoveAmount)
            {
                _left -= leftVelocity;
                _top -= upVelocity;
                upVelocity -= Gravity;
                alpha -= AlphaRemoveAmount;

                image.Opacity = alpha;

                Canvas.SetLeft(image, _left);
                Canvas.SetTop(image, _top);
                try
                {
                    // Add the image to the adornment layer and make it relative to the viewport
                    adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative,
                        null,
                        null,
                        image,
                        null);
                    await System.Threading.Tasks.Task.Delay(FrameDelay);
                    adornmentLayer.RemoveAdornment(image);
                }
                catch
                {
                    break;
                }
            }
            try
            {
                adornmentLayer.RemoveAdornment(image);
            }
            catch
            {
                //Ignore all errors, not critical
            }
            ParticleCount--;
        }
        private void CreateAdornment()
        {
            var lines = view.VisualSnapshot.Lines;

            if (codeOrigin == null)
                return;

            var startLine = lines.FirstOrDefault(a => a.LineNumber == codeOrigin.From.Line - 1);
            var endLine = lines.FirstOrDefault(a => a.LineNumber == codeOrigin.To.Line - 1);

            if (startLine == null || endLine == null)
                return;

            var startPosition = startLine.Start + codeOrigin.From.Column - 1;
            var endPosition = endLine.Start + codeOrigin.To.Column - 1;

            var span = new SnapshotSpan(view.TextSnapshot, Span.FromBounds(startPosition, endPosition));

            try
            {
                layer.TextView.ViewScroller.EnsureSpanVisible(span, EnsureSpanVisibleOptions.AlwaysCenter);
            }
            catch (InvalidOperationException)
            {
                // Intentionally ignored.
            }

            var g = view.TextViewLines.GetMarkerGeometry(span);
            if (g != null)
            {
                var drawing = new GeometryDrawing(brush, pen, g);
                drawing.Freeze();

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

                var image = new 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);

                Canvas.SetLeft(achievementUiElement, g.Bounds.Right + 50);
                Canvas.SetTop(achievementUiElement, g.Bounds.Top);

                achievementUiElement.MouseDown += (sender, args) => Reset();

                adornmentVisible = true;

                try
                {

                    layer.AddAdornment(AdornmentPositioningBehavior.TextRelative,
                        span, null, image, (tag, element) => adornmentVisible = false);

                    descriptionLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative,
                        span, null, achievementUiElement, null);
                }
                catch (ArgumentException)
                {
                    // Intentionally ignored.
                }
            }
        }
        /// <summary>
        /// Setta il colore usato dall'evidenziatore.
        /// </summary>
        private static void SetColor()
        {
            // Create the pen and brush to color the box behind the a's
            Brush myBrush = null;
            if (AlmaStyleFixPackage.Page == null)
            {
                myBrush = new SolidColorBrush(Color.FromArgb(0x20, 0x00, 0x00, 0xff));
            }
            else
            {
                myBrush = new SolidColorBrush(Color.FromArgb(
                    Convert.ToByte(AlmaStyleFixPackage.Page.A),
                    Convert.ToByte(AlmaStyleFixPackage.Page.R),
                    Convert.ToByte(AlmaStyleFixPackage.Page.G),
                    Convert.ToByte(AlmaStyleFixPackage.Page.B)));
            }

            // myBrush.Freeze();
            Brush penBrush = new SolidColorBrush(Colors.Red);
            penBrush.Freeze();
            Pen myPen = new Pen(penBrush, 0.5);
            myPen.Freeze();

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

            image = new DrawingImage(drawing);
            image.Freeze();
        }
        private void CreateSensitiveCodeMarkerVisuals(NormalizedSnapshotSpanCollection sensitiveTextSpans, ITextSnapshot newSnapshot)
        {
            _layer.RemoveAllAdornments();

            foreach (var span in sensitiveTextSpans)
            {
                IWpfTextViewLineCollection textViewLines = _view.TextViewLines;

                var geometry = textViewLines.GetMarkerGeometry(span);

                if (geometry != null)
                {
                    var drawing = new GeometryDrawing(_brush, _pen, geometry);
                    drawing.Freeze();

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

                    var image = new Image
                    {
                        Source = drawingImage,
                    };

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

                    _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
                }
            }
        }
Exemple #15
0
        public void ReGenImage(double theight)
        {
            Brush brush = new SolidColorBrush(Colors.LemonChiffon);
            brush.Freeze();
            Brush penBrush = new SolidColorBrush(Colors.White);               //no paddings
            penBrush.Freeze();
            Pen pen = new Pen(penBrush, 0.5);
            pen.Freeze();

            //draw a square with the created brush and pen, specify the start point and width, length of the rect
            System.Windows.Rect r = new System.Windows.Rect(0, 0, _view.ViewportWidth, theight);
            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;
        }
Exemple #16
0
        private void DrawAdornment(IWpfTextViewLineCollection textViewLines, SnapshotSpan span)
        {
            var geometry = textViewLines.GetMarkerGeometry(span);
            if (geometry != null)
            {
                var drawing = new GeometryDrawing(_brush, _pen, geometry);
                drawing.Freeze();

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

                var image = new Image
                {
                    Source = drawingImage,
                };

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

                _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
            }
        }
        private void renderColumns(List<int> columns, Brush brush, Image image)
        {
            GeometryGroup group = new GeometryGroup();
            group.Children.Add(new RectangleGeometry(new Rect(0, 0, 0, 0)));
            renderColumnsForLines(group, columns, _view.TextViewLines);
            group.Freeze();

            Drawing drawing = new GeometryDrawing(brush, _emptyPen, group);
            drawing.Freeze();

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

            image.Source = drawingImage;

            Canvas.SetLeft(image, _view.ViewportLeft + group.Bounds.Left);
            Canvas.SetTop(image, _view.ViewportTop + group.Bounds.Top);
        }
        /// <summary>
        /// Evidenzia le righe con gli errori.
        /// </summary>
        /// <param name="line">
        /// Puntatore al formato grafico della linea da modificare.
        /// </param>
        /// <param name="filePath">
        /// FullName del documento attivo.
        /// </param>
        private void CreateVisuals(ITextViewLine line, string filePath)
        {
            // controllo l'indice della riga corrente                      
            int ind = 0;
            //var appo = this.view.TextSnapshot.Lines.Select((val, i) => new { val, i }).FirstOrDefault(itm => itm.val.Start == line.Start);
            //if (appo != null) ind = appo.i;
            bool found = false;
            foreach (ITextSnapshotLine l in this.view.TextSnapshot.Lines)
            {
                if (l.Start == line.Start)
                {
                    found = true;
                    break;
                }

                ind++;
            }

            // controllo l'indice delle violazioni
            int violationIndex = -1;
            if (found)
            {
                found = false;

                for (int i = 0; i < Violations[filePath].Count; i++)
                {
                    if (Violations[filePath][i].LineNumber == ind)
                    {
                        if (string.IsNullOrEmpty(violations[filePath][i].ErrorMessage))
                        {
                            violations[filePath].RemoveAt(i--);
                        }
                        else
                        {
                            violationIndex = i;
                            found = true;
                            break;
                        }
                    }
                }
            }

            if (!found)
            {
                return;
            }

            // grab a reference to the lines in the current TextView
            IWpfTextViewLineCollection textViewLines = this.view.TextViewLines;
            int start = line.Start;
            int end = line.End;

            // evidenzio a partire dal primo carattere non vuoto
            bool isFirstBlank = true;
            for (int i = start; i < end; ++i)
            {
                if (isFirstBlank && this.view.TextSnapshot[i] == ' ')
                {
                    start++;
                }
                else
                {
                    isFirstBlank = false;
                }
            }

            // eseguo la colorazione del rigo
            SnapshotSpan span = new SnapshotSpan(this.view.TextSnapshot, Span.FromBounds(start, end));
            Geometry g = textViewLines.GetMarkerGeometry(span);

            if (g != null)
            {
                GeometryDrawing drawing = new GeometryDrawing(this.brush, this.pen, g);
                drawing.Freeze();

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

                Image image = new Image();
                image.ToolTip = Violations[filePath][violationIndex].ErrorMessage;
                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);

                this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
            }
        }
        private void Update()
        {
            _layer.RemoveAdornmentsByTag(this);

            var caretPosition = _view.Caret.Position.BufferPosition.Position;
            var snapshot = _view.TextBuffer.CurrentSnapshot;

            if (snapshot.Length == 0)
                return;

            var structureStart = FindStructureStart(snapshot, caretPosition);
            if (!structureStart.HasValue)
                return;

            var structureEnd = FindStructureEnd(snapshot, caretPosition);
            if (!structureEnd.HasValue)
                return;

            {
                var structureStartLine = _view.GetTextViewLineContainingBufferPosition(
                    new SnapshotPoint(snapshot, structureStart.Value));

                if (structureStartLine.VisibilityState < VisibilityState.PartiallyVisible)
                {
                    structureStartLine = _view.TextViewLines.FirstVisibleLine;
                }

                var structureEndLine = _view.GetTextViewLineContainingBufferPosition(
                    new SnapshotPoint(snapshot, structureEnd.Value));

                if (structureEndLine.VisibilityState < VisibilityState.PartiallyVisible)
                {
                    structureEndLine = _view.TextViewLines.LastVisibleLine;
                }

                var drawing = new GeometryDrawing(_brush, null, new RectangleGeometry(
                    new Rect(0, structureStartLine.Top, _view.ViewportWidth, structureEndLine.Bottom - structureStartLine.Top)));
                drawing.Freeze();

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

                var image = new Image { Source = drawingImage };

                Canvas.SetLeft(image, _view.ViewportLeft);
                Canvas.SetTop(image, structureStartLine.Top);

                _layer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, this, image, null);
            }
        }
Exemple #20
0
		void CreateVisuals(ITextViewLine line)
		{
			var text = view.TextSnapshot.GetText(line.Start, line.Length);

			if (hasUsing == false)
				UpdateUsing(text);
			var regex = hasUsing == true ? usingColorRegex : colorRegex;

			var matches = regex.Matches(text);
			foreach (Match match in matches)
			{
				var mode = match.Groups["mode"].Value;

				Func<Match, Eto.Drawing.Color> translateColor;
				if (!colorMatching.TryGetValue(mode, out translateColor))
					continue;

				var color = translateColor(match).ToWpf();
				if (color.A <= 0)
					continue;

				var span = new SnapshotSpan(view.TextSnapshot, line.Start + match.Index, match.Length);
				var geometry = view.TextViewLines.GetMarkerGeometry(span);
				if (geometry == null
					|| !view.TextViewModel.IsPointInVisualBuffer(span.Start, PositionAffinity.Successor)
					|| !view.TextViewModel.IsPointInVisualBuffer(span.End, PositionAffinity.Predecessor))
					continue;

				var pen = GetPen(color);
				var bounds = geometry.Bounds;
				var underline = new LineGeometry(bounds.BottomLeft, bounds.BottomRight);
				underline.Freeze();
				var drawing = new GeometryDrawing(null, pen, underline);
				drawing.Freeze();

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

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

				Canvas.SetLeft(image, geometry.Bounds.Left);
				Canvas.SetTop(image, geometry.Bounds.Bottom - 2);

				layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
			}
		}
        IPixelCanvas RandomSquares__DrawVisual2(int count, int square_size, int canvas_size)
        {
            var rd = new Random();

            var pc = new PixelArrayCanvas(canvas_size, canvas_size);

            var dv = new DrawingVisual();

            var geom = new RectangleGeometry(new System.Windows.Rect(0, 0, square_size, square_size));
            geom.Freeze();

            using (var cx = dv.RenderOpen())
            {
                var canvas = new RectangleGeometry(new Rect(0, 0, canvas_size, canvas_size));
                canvas.Freeze();

                cx.DrawGeometry(Brushes.Transparent, null, canvas);

                var lols = new ConcurrentBag<DrawingWithExtras>();                

                Parallel.For(0, count, i =>
                 {
                     var drawing = new GeometryDrawing(Brushes.Red, new Pen(Brushes.Red, 1), geom);
                     drawing.Freeze();

                     var trans = new TranslateTransform(rd.Next(0, canvas_size - square_size), rd.Next(0, canvas_size - square_size));
                     trans.Freeze();

                     lols.Add(new DrawingWithExtras { drawing = drawing, transform = trans });
                 });

                foreach(var lol in lols)
                {
                    cx.PushTransform(lol.transform);
                    cx.DrawDrawing(lol.drawing);
                    cx.Pop();
                }
            }

            pc.DrawVisual(0, 0, dv, BlendMode.Copy);

            return pc;
        }
        public static DrawingImage CreateImage(PointPattern[] pointPatterns, Size size, Color color)
        {
            if (pointPatterns == null)
                throw new Exception("You must provide a gesture before trying to generate a thumbnail");

            DrawingGroup drawingGroup = new DrawingGroup();
            for (int i = 0; i < pointPatterns.Length; i++)
            {
                PathGeometry pathGeometry = new PathGeometry();

                color.A = (byte)(0xFF - i * 0x55);
                SolidColorBrush brush = new SolidColorBrush(color);
                Pen drawingPen = new Pen(brush, 3 + i * 2) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round };

                if (pointPatterns[i].Points == null) return null;
                for (int j = 0; j < pointPatterns[i].Points.Count; j++)
                {
                    if (pointPatterns[i].Points[j].Count == 1)
                    {
                        Geometry ellipse = new EllipseGeometry(new Point(size.Width * j + size.Width / 2, size.Height / 2),
                            drawingPen.Thickness / 2, drawingPen.Thickness / 2);
                        pathGeometry.AddGeometry(ellipse);
                        continue;
                    }
                    StreamGeometry sg = new StreamGeometry { FillRule = FillRule.EvenOdd };
                    using (StreamGeometryContext sgc = sg.Open())
                    {
                        // Create new size object accounting for pen width
                        Size szeAdjusted = new Size(size.Width - drawingPen.Thickness - 1,
                            (size.Height - drawingPen.Thickness - 1));

                        Size scaledSize;
                        Point[] scaledPoints = ScaleGesture(pointPatterns[i].Points[j], szeAdjusted.Width - 10, szeAdjusted.Height - 10,
                            out scaledSize);

                        // Define size that will mark the offset to center the gesture
                        double iLeftOffset = (size.Width / 2) - (scaledSize.Width / 2);
                        double iTopOffset = (size.Height / 2) - (scaledSize.Height / 2);
                        Vector sizOffset = new Vector(iLeftOffset + j * size.Width, iTopOffset);
                        sgc.BeginFigure(Point.Add(scaledPoints[0], sizOffset), false, false);
                        foreach (Point p in scaledPoints)
                        {
                            sgc.LineTo(Point.Add(p, sizOffset), true, true);
                        }
                        DrawArrow(sgc, scaledPoints, sizOffset, drawingPen.Thickness);
                    }
                    sg.Freeze();
                    pathGeometry.AddGeometry(sg);
                }
                pathGeometry.Freeze();
                GeometryDrawing drawing = new GeometryDrawing(null, drawingPen, pathGeometry);
                drawing.Freeze();
                drawingGroup.Children.Add(drawing);
            }
            //  myPath.Data = sg;
            drawingGroup.Freeze();
            DrawingImage drawingImage = new DrawingImage(drawingGroup);
            drawingImage.Freeze();

            return drawingImage;
        }
Exemple #23
0
        private void DrawIcon(SnapshotSpan span, double x, double y, string toolTipText, FixErrorCallback errorCallback)
        {
            //draw a square with the created brush and pen
            System.Windows.Rect r = new System.Windows.Rect(0, 0, 16, 16);
            Geometry g = new System.Windows.Media.RectangleGeometry(r);
            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.ToolTip = toolTipText;
            _image.Cursor = Cursors.Arrow;
            Helper.Imaging.GetImage(this, _image, "NeosSdiMef.Images.repair.png");
            _image.Stretch = Stretch.Fill;

            _image.MouseLeftButtonDown += new MouseButtonEventHandler(Error_MouseLeftButtonUp);
            _image.Tag = errorCallback;
            Canvas.SetLeft(_image, x);
            Canvas.SetTop(_image, y);

            _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, _image, (t, ui) =>
            {
                rects.Remove(g.Bounds);
            });
        }
        private void HighlightLine(object sender, EventArgs e)
        {
            ITextViewLine containingTextViewLine = _view.Caret.ContainingTextViewLine;
            if (containingTextViewLine != null)
            {
                if (containingTextViewLine.VisibilityState == VisibilityState.Hidden ||
                    containingTextViewLine.VisibilityState == VisibilityState.Unattached ||
                    !_view.Selection.IsEmpty ||
                    !_hasFocus)
                {
                    _image = null;
                    _adornmentLayer.RemoveAllAdornments();
                    return;
                }
                else
                {
                    if (_image == null ||
                        containingTextViewLine.Height != _image.Source.Height ||
                        _view.ViewportWidth + 2 != _image.Source.Width)
                    {
                        _adornmentLayer.RemoveAllAdornments();

                        System.Drawing.Color color;
                        if (_enableIME)
                        {
                            color = Settings.EnableIMEColor;
                        }
                        else
                        {
                            color = Settings.DisableIMEColor;
                        }
                        Brush backgroundBrush = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.G));
                        backgroundBrush.Freeze();

                        Geometry rectangleGeometry = new RectangleGeometry(new Rect(new Size(
                            Settings.Style == AdornmentStyle.Line ? _view.ViewportWidth + 1 : LeftMarkerWidth, //width
                            containingTextViewLine.Height - 1)));
                        GeometryDrawing geometryDrawing = new GeometryDrawing(backgroundBrush, new Pen(backgroundBrush, 1), rectangleGeometry);
                        geometryDrawing.Freeze();
                        DrawingImage drawingImage = new DrawingImage(geometryDrawing);
                        drawingImage.Freeze();
                        _image = new Image();
                        _image.Source = drawingImage;
                        _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, _image, null);
                    }

                    Canvas.SetLeft(_image, Settings.Style == AdornmentStyle.Line ? _view.ViewportLeft + 1 : 1);
                    Canvas.SetTop(_image, containingTextViewLine.Top);
                    return;
                }
            }
        }
		static WrapModeComboBox()
		{
			PolyLineSegment triangleLinesSegment = new PolyLineSegment();
			triangleLinesSegment.Points.Add(new Point(50, 0));
			triangleLinesSegment.Points.Add(new Point(0, 50));
			PathFigure triangleFigure = new PathFigure();
			triangleFigure.IsClosed = true;
			triangleFigure.StartPoint = new Point(0, 0);
			triangleFigure.Segments.Add(triangleLinesSegment);
			PathGeometry triangleGeometry = new PathGeometry();
			triangleGeometry.Figures.Add(triangleFigure);

			triangleDrawing = new GeometryDrawing();
			triangleDrawing.Geometry = triangleGeometry;
			triangleDrawing.Brush = new SolidColorBrush(Color.FromArgb(255, 204, 204, 255));
			Pen trianglePen = new Pen(Brushes.Black, 2);
			triangleDrawing.Pen = trianglePen;
			trianglePen.MiterLimit = 0;
			triangleDrawing.Freeze();
		}
Exemple #26
0
 private void ColorWords()
 {
     if (!XFeatures.Settings.SettingsProvider.IsXhighlighterEnabled())
         return;
     IWpfTextViewLineCollection textViewLines = this._view.TextViewLines;
     foreach (SnapshotSpan bufferSpan in this.SnapShotsToColor)
     {
         try
         {
             Geometry markerGeometry = textViewLines.GetMarkerGeometry(bufferSpan);
             if (markerGeometry != null)
             {
                 GeometryDrawing geometryDrawing = new GeometryDrawing(/*this._brush*/FormatBrush, this._pen, markerGeometry);
                 geometryDrawing.Freeze();
                 DrawingImage drawingImage = new DrawingImage((Drawing)geometryDrawing);
                 drawingImage.Freeze();
                 Image image = new Image();
                 image.Source = (ImageSource)drawingImage;
                 Canvas.SetLeft((UIElement)image, markerGeometry.Bounds.Left);
                 Canvas.SetTop((UIElement)image, markerGeometry.Bounds.Top);
                 this._layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, new SnapshotSpan?(bufferSpan), (object)null, (UIElement)image, (AdornmentRemovedCallback)null);
             }
         }
         catch
         {
         }
     }
 }
        /// <summary>
        /// Creates a colour swatch image with background and border
        /// </summary>
        /// <param name="colourPos">Position in the test where the colour, and what colour it is.</param>
        /// <param name="charSpan">Text that the image will go above</param>
        private Image CreateSwatchImage(Tuple<int, int, Color> colourPos, SnapshotSpan charSpan)
        {
            IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
            Geometry g = textViewLines.GetMarkerGeometry(charSpan);

            Rect r = new Rect(5, 5, 30, 30);
            RectangleGeometry rg = new RectangleGeometry(r);
            Brush brush = new SolidColorBrush(colourPos.Item3);
            brush.Freeze();
            Brush penBrush = new SolidColorBrush(colourPos.Item3);
            penBrush.Freeze();
            Pen pen = new Pen(penBrush, 0.5);
            pen.Freeze();
            GeometryDrawing drawingfront = new GeometryDrawing(brush, pen, rg);
            drawingfront.Freeze();

            Brush penBrushBorder = new SolidColorBrush(Color.FromRgb(0xad, 0xad, 0xad));
            penBrushBorder.Freeze();
            Pen penBorder = new Pen(penBrushBorder, 0.5);
            penBorder.Freeze();

            Rect rWhite = new Rect(0, 0, 20, 40);
            RectangleGeometry rgWhite = new RectangleGeometry(rWhite);
            Brush brushWhite = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            brushWhite.Freeze();
            GeometryDrawing drawingleft = new GeometryDrawing(brushWhite, penBorder, rgWhite);
            drawingleft.Freeze();

            Rect rBlack = new Rect(20, 0, 20, 40);
            RectangleGeometry rgBlack = new RectangleGeometry(rBlack);
            Brush brushBlack = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            brushBlack.Freeze();
            GeometryDrawing drawingright = new GeometryDrawing(brushBlack, penBorder, rgBlack);
            drawingright.Freeze();

            DrawingGroup drawing = new DrawingGroup();
            drawing.Children.Add(drawingleft);
            drawing.Children.Add(drawingright);
            drawing.Children.Add(drawingfront);
            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);

            drawingImage.Freeze();

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

            Canvas.SetLeft(image, g.Bounds.Left - g.Bounds.Width);
            Canvas.SetTop(image, g.Bounds.Top - 40);

            return image;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewportAdornment"/> class.
        /// 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 ViewportAdornment(IWpfTextView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            this.view = view;

            var brush = new SolidColorBrush(Colors.BlueViolet);
            brush.Freeze();
            var penBrush = new SolidColorBrush(Colors.Red);
            penBrush.Freeze();
            var 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, AdornmentWidth, AdornmentHeight);
            var geometry = new RectangleGeometry(r);

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

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

            this.image = new Image
            {
                Source = drawingImage,
            };

            this.adornmentLayer = view.GetAdornmentLayer("ViewportAdornment");

            this.view.ViewportHeightChanged += this.OnSizeChanged;
            this.view.ViewportWidthChanged += this.OnSizeChanged;
        }
Exemple #29
0
        private CaretData CreateCaretData()
        {
            var color = TryCalculateCaretColor();
            var brush = new SolidColorBrush(color ?? Colors.Black);
            brush.Freeze();

            var pen = new Pen(brush, 1.0);
            var tuple = CalculateCaretRectAndDisplayOffset();
            var rect = tuple.Item1;
            var geometry = new RectangleGeometry(rect);
            var drawing = new GeometryDrawing(brush, pen, geometry);
            drawing.Freeze();

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

            var image = new Image { Opacity = _caretOpacity, Source = drawingImage };
            var point = _view.Caret.Position.BufferPosition;
            return new CaretData(_caretDisplay, _caretOpacity, image, color, point, tuple.Item2);
        }
        static SetCardDrawingFactory()
        {
            s_borderPen = new Pen(Brushes.Transparent, 1);
            s_borderPen.Freeze();

            s_greenPen = new Pen(Brushes.Green, 2);
            s_greenPen.Freeze();

            s_redPen = new Pen(Brushes.Red, 2);
            s_redPen.Freeze();

            s_purplePen = new Pen(Brushes.Purple, 2);
            s_purplePen.Freeze();

            s_stripedGreenBrush = GetStripeBrush(Brushes.Green);
            s_stripedGreenBrush.Freeze();

            s_stripedPurpleBrush = GetStripeBrush(Brushes.Purple);
            s_stripedPurpleBrush.Freeze();

            s_stripedRedBrush = GetStripeBrush(Brushes.Red);
            s_stripedRedBrush.Freeze();

            Pen grayPen = new Pen(Brushes.LightGray, 1);
            grayPen.Freeze();

            RectangleGeometry geometry = new RectangleGeometry(new Rect(0, 0, 100, 140), 10, 10);
            s_cardDrawing = new GeometryDrawing(Brushes.White, grayPen, geometry);
            s_cardDrawing.Freeze();
        }