public static void Render(
            this DrawingContext cx,
            double drawingWidth,
            double drawingHeight,
            DrawingRenderInfo drawing)
        {
            // expand drawings to desired size using transparent rectangle
            var canvas = new RectangleGeometry(new Rect(0, 0, drawingWidth, drawingHeight));
            canvas.Freeze();
            cx.DrawGeometry(Brushes.Transparent, null, canvas);

            cx.Render(drawing);
        }
        IPixelCanvas RandomSquares__DrawGeometry(int count, int square_size, int canvas_size)
        {
            var rd = new Random();

            var pc = new PixelArrayCanvas(canvas_size, canvas_size);

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

            for (int i = 0; i < count; i++)
            {
                pc.DrawGeometry(rd.Next(0, canvas_size - square_size), rd.Next(0, canvas_size - square_size), geom, Brushes.Red, new Pen(Brushes.Red, 1));
            }

            return pc;
        }
        public static void Render(
            this DrawingContext cx,
            ParallelOptions parallelOptions,
            double drawingWidth,
            double drawingHeight,
            IEnumerable<DrawingRenderInfo> drawings)
        {
            // expand drawings to desired size using transparent rectangle
            var canvas = new RectangleGeometry(new Rect(0, 0, drawingWidth, drawingHeight));
            canvas.Freeze();
            cx.DrawGeometry(Brushes.Transparent, null, canvas);

            if (parallelOptions.CancellationToken.IsCancellationRequested)
                return;

            cx.Render(parallelOptions, drawings);
        }
예제 #4
0
		protected override void OnRender(DrawingContext drawingContext) {
			base.OnRender(drawingContext);
			if (hexBox.Selection == null || hexBox.VisibleBytesPerLine < 1)
				return;

			ulong selStart = hexBox.Selection.Value.StartOffset;
			ulong selEnd = hexBox.Selection.Value.EndOffset;
			int lines = hexBox.VisibleLinesPerPage;
			ulong bpl = (ulong)hexBox.VisibleBytesPerLine;
			ulong visibleStart = hexBox.TopOffset;
			ulong visibleEnd = NumberUtils.AddUInt64(NumberUtils.AddUInt64(visibleStart, NumberUtils.MulUInt64(bpl, NumberUtils.SubUInt64((ulong)lines, 1))), NumberUtils.SubUInt64(bpl, 1));
			if (selStart > visibleEnd || selEnd < visibleStart)
				return;

			ulong offset = Math.Max(selStart, visibleStart);
			ulong endOffset = Math.Min(selEnd, visibleEnd);
			double x = -hexBox.CharacterWidth * hexBox.LeftColumn;
			double y = (offset - hexBox.TopOffset) / bpl * hexBox.CharacterHeight;
			var path = new PathGeometry();
			double hexByteX = hexBox.GetHexByteColumnIndex() * hexBox.CharacterWidth;
			double asciiX = hexBox.GetAsciiColumnIndex() * hexBox.CharacterWidth;
			while (offset <= endOffset) {
				ulong byteIndex = hexBox.GetLineByteIndex(offset);
				ulong count = Math.Min(bpl - byteIndex, endOffset - offset + 1);

				double dx = byteIndex * hexBox.CharacterWidth;
				var rectGeo = new RectangleGeometry(new Rect(x + dx * 3 + hexByteX + hexBox.CharacterWidth, y, count * hexBox.CharacterWidth * 3 - hexBox.CharacterWidth, hexBox.CharacterHeight));
				rectGeo.Freeze();
				path.AddGeometry(rectGeo);

				if (hexBox.ShowAscii) {
					rectGeo = new RectangleGeometry(new Rect(x + dx + asciiX, y, count * hexBox.CharacterWidth, hexBox.CharacterHeight));
					rectGeo.Freeze();
					path.AddGeometry(rectGeo);
				}

				if (offset + bpl - byteIndex < offset)
					break;
				offset += bpl - byteIndex;
				y += hexBox.CharacterHeight;
			}

			path.Freeze();
			drawingContext.DrawGeometry(Background, null, path);
		}
예제 #5
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length == 3 && values[0] is double && values[1] is double && values[2] is CornerRadius)
            {
                var width = (double)values[0];
                var height = (double)values[1];

                if (width < double.Epsilon || height < double.Epsilon)
                    return Geometry.Empty;

                var radius = (CornerRadius)values[2];

                // Actually we need more complex geometry, when CornerRadius has different values.
                // But let me not to take this into account, and simplify example for a common value.
                var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
                clip.Freeze();

                return clip;
            }

            return DependencyProperty.UnsetValue;
        }
 /// <summary>
 ///     Override of UIElement.GetLayoutClip().  This is a tricky way to ensure we always clip regardless of the value of ClipToBounds. 
 /// </summary>
 protected override Geometry GetLayoutClip(Size layoutSlotSize)
 {
     RectangleGeometry clip = new RectangleGeometry(new Rect(RenderSize)); 
     clip.Freeze();
     return clip; 
 } 
예제 #7
0
      /// <summary>Draws the text glyph in the specified target area.</summary>
      /// <param name="dc">The drawing context to draw on.</param>
      /// <param name="foreground">The text foreground brush.</param>
      /// <param name="targetArea">The target area where the text is to be drawn (according to the specified alignment).</param>
      /// <param name="alignment">Indicates how to align the text with respect to the target area.</param>
      public void Draw(DrawingContext dc, Brush foreground, Rect targetArea, TextAlign alignment) {
         if (IsEmpty || targetArea.IsEmpty || foreground == null) return;

         // compute bounds 
         var bounds = _computeBounds(targetArea, alignment);
         dc.PushTranslate(bounds.X + SharpnessVector.X, bounds.Y + SharpnessVector.Y);

         if (TextOverflow == TextOverflow.Ignore || Width <= bounds.Width) {
            // ignore overflow - use original glyph run and draw it without clipping
            _drawGlyphRun(dc, _fullRun, foreground);

         } else if (TextOverflow == TextOverflow.Clip) {
            // clip overflow - use original glyph run but clip it to fit bounds
            var clipRect = new RectangleGeometry(new Rect(new Point(), bounds.Size));
            clipRect.Freeze();
            dc.PushClip(clipRect);
            _drawGlyphRun(dc, _fullRun, foreground);
            dc.Pop();

         } else {
            // trim overflow - create a trimmed glyph run that fits the bounds and cache it for next invocation 
            // (the caching of the trimmed glyph is effective only if the width does not change - e.g., when drawing the same glyph in a different color)
            if (_trimmedWidth.CertainlyDifferent(bounds.Width)) {
               var result = _buildGlyph(false, bounds.Width);
               _trimmedRun = (result != null ? result.GlyphRun : null);
               _trimmedWidth = bounds.Width;
            }
            _drawGlyphRun(dc, _trimmedRun, foreground);
         }

         dc.Pop();
      }
예제 #8
0
        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry rectGeometry = null;

            int count = _elementsBounds.Count;
            if ( count != 0 )
            {
                // Create a union collection of the element regions.
                for ( int i = 0; i < count; i++ )
                {
                    Rect hatchRect = _elementsBounds[i];

                    if ( hatchRect.IsEmpty )
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if ( hatchGeometry == null )
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();
                        
                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); 
                        line.Freeze();
                        segments.Add(line);
                        
                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); 
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup backgroundGeometry = new GeometryGroup( );
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if ( hatchGeometry != null )
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if ( count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0 )
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
            drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry);
#endif

            // At last, draw the hatch borders
            if ( outlineGeometry != null )
            {
                drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry);
            }
        }
		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="span"/> is <see langword="null"/>.</para>
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="span"/> is less than zero or greater than the buffer length for the associated <see cref="ISourceEditorView"/>.</para>
		/// </exception>
		public Geometry GetMarkerGeometry(Span span)
		{
			if (span == null)
			{
				throw new ArgumentNullException("span");
			}
			if ((span.Start < 0) || (span.End > _editorView.TextBuffer.Length))
			{
				throw new ArgumentOutOfRangeException("span");
			}
			if (span.IsEmpty)
			{
				return null;
			}
			PathGeometry geometry = new PathGeometry();
			geometry.FillRule = FillRule.Nonzero;
			IList<ITextLine> textLines = _editorView.TextLines;
			if (textLines.Count == 0)
			{
				return null;
			}
			if ((span.Start > base.LastRenderedCharacter) || (span.End < base.FirstRenderedCharacter))
			{
				return null;
			}
			ITextLine item = null;
			ITextLine textLineClosestTo = null;
			if (span.Start < base.FirstRenderedCharacter)
			{
				item = textLines[0];
			}
			if (span.End > base.LastRenderedCharacter)
			{
				textLineClosestTo = textLines[textLines.Count - 1];
			}
			if (item == null)
			{
				item = base.GetTextLineClosestTo(span.Start);
			}
			if (textLineClosestTo == null)
			{
				textLineClosestTo = base.GetTextLineClosestTo(span.End);
			}
			if (item == textLineClosestTo)
			{
				foreach (TextBounds bounds in item.GetTextBounds(span))
				{
					RectangleGeometry geometry2 = new RectangleGeometry(new Rect(bounds.Left - 0.2, bounds.Top - 1, bounds.Width + 0.4, bounds.Height + 1), 0.6, 0.6);
					geometry2.Freeze();
					geometry.AddGeometry(geometry2);
				}
			}
			else
			{
				foreach (TextBounds bounds2 in item.GetTextBounds(span))
				{
					RectangleGeometry geometry3 = new RectangleGeometry(new Rect(bounds2.Left - 0.2, bounds2.Top - 1, bounds2.Width + 0.4, bounds2.Height + 1), 0.6, 0.6);
					geometry3.Freeze();
					geometry.AddGeometry(geometry3);
				}
				Int32 num = textLines.IndexOf(item) + 1;
				Int32 index = textLines.IndexOf(textLineClosestTo);
				for (Int32 i = num; i < index; i++)
				{
					ITextLine line3 = textLines[i];
					RectangleGeometry geometry4 = new RectangleGeometry(new Rect(-0.2, line3.VerticalOffset - 0.2, line3.Width, line3.Height + 0.4), 0.6, 0.6);
					geometry4.Freeze();
					geometry.AddGeometry(geometry4);
				}
				foreach (TextBounds bounds3 in textLineClosestTo.GetTextBounds(span))
				{
					RectangleGeometry geometry5 = new RectangleGeometry(new Rect(bounds3.Left - 0.2, bounds3.Top - 1, bounds3.Width + 0.4, bounds3.Height + 1), 0.6, 0.6);
					geometry5.Freeze();
					geometry.AddGeometry(geometry5);
				}
			}
			geometry.Freeze();
			return geometry.GetOutlinedPathGeometry();
		}
예제 #10
0
        /////////////////////////////////////////////////////////////////////
 
        /// <summary>
        /// [TBS] - On UIContext
        /// </summary>
        public DynamicRenderer() : base() 
        {
            _zeroSizedFrozenRect = new RectangleGeometry(new Rect(0,0,0,0)); 
            _zeroSizedFrozenRect.Freeze(); 
        }
        IEnumerable<DrawingRenderInfo> produceSquares(int count, int square_size, int canvas_size)
        {
            Random rd = new Random();

            for(int i = 0; i < count; i++)
            {
                var di = new DrawingRenderInfo();
                di.Transform = new TranslateTransform(rd.Next(0, canvas_size - square_size), rd.Next(0, canvas_size - square_size));
                di.Transform.Freeze();

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

                di.Drawing = new GeometryDrawing(Brushes.Red, null, geom);
                di.Drawing.Freeze();

                yield return di;
            }
        }
        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;
        }
        IPixelCanvas RandomSquares__DrawVisual(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);

                for(int i = 0; i < count; i++)
                {
                    cx.PushTransform(new TranslateTransform(rd.Next(0, canvas_size - square_size), rd.Next(0, canvas_size - square_size)));
                    cx.DrawGeometry(Brushes.Red, new Pen(Brushes.Red, 1), geom);
                    cx.Pop(); 
                }
            }

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

            return pc;
        }
예제 #14
0
 /// <summary>
 /// This method supplies an additional (to the <seealso cref="Clip"/> property) clip geometry
 /// that is used to intersect Clip in case if <seealso cref="ClipToBounds"/> property is set to "true".
 /// Typcally, this is a size of layout space given to the UIElement.
 /// </summary>
 /// <returns>Geometry to use as additional clip if ClipToBounds=true</returns>
 protected virtual Geometry GetLayoutClip(Size layoutSlotSize)
 {
     if(ClipToBounds)
     {
         RectangleGeometry rect = new RectangleGeometry(new Rect(RenderSize));
         rect.Freeze();
         return rect;
     }
     else
         return null;
 }