Exemplo n.º 1
0
        protected override void OnRender(System.Windows.Media.DrawingContext ctx)
        {
            double x = 0;
            double y = 0;

            ctx.PushClip(new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight)));//restrict drawing to textbox
            ctx.DrawRectangle(Brushes.White, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));//Draw Background

            int startLine = this.firstLine;
            int count = (int)(this.ActualHeight / CodeBox.GetLineHeight());

            int lastLine = Math.Min(startLine + count, this.LineInfos.Length);
            string[] lines = this.LineInfos.Skip(startLine).Take(count).Select(f => f.TextLine).ToArray();
            FormattedText text = CodeBox.GetFormatText(string.Join(Environment.NewLine, lines), Brushes.White);

            int lineIndex = 0;
            for (int i = startLine; i < lastLine; ++i)
            {
                var lineInfo = this.LineInfos[i];
                int index = 0;

                double h = text.Height;// +text.LineHeight;
                // Draw for each segment.
                foreach (var seg in lineInfo.Segments)
                {
                    if (seg.StartIndex != index)
                    {
                        text.SetForegroundBrush(Brushes.Black, index + lineIndex, seg.StartIndex - index);
                    }
                    text.SetForegroundBrush(seg.Foreground, seg.StartIndex + lineIndex, seg.Length);

                    index = seg.StartIndex + seg.Length;
                }

                if (lineInfo.TextLine.Length != index)
                {
                    text.SetForegroundBrush(Brushes.Black, index + lineIndex, lineInfo.TextLine.Length - index);
                }

                lineIndex += lineInfo.TextLine.Length + Environment.NewLine.Length;
            }

            FormattedText hide = CodeBox.GetFormatText(text.Text.Substring(0, firstCharCol), Brushes.White);

            ctx.DrawText(text, new Point(x - hide.WidthIncludingTrailingWhitespace, y));
        }
Exemplo n.º 2
0
        public void Draw(System.Windows.Media.DrawingContext context, DrawingArgs args)
        {
            double lineWidth = 1;
            context.PushClip(new RectangleGeometry(args.RenderBounds));

            var transformdPos = args.Transform.Transform(new Point(0, Position)).X;

            Point start = new Point(transformdPos, args.RenderBounds.Top);
            Point end = new Point(transformdPos, args.RenderBounds.Bottom);

            var offset = lineWidth / 2;
            context.PushGuidelineSet(new GuidelineSet(
                new[] { start.X + offset, end.X + offset },
                new[] { start.Y + offset, end.Y + offset }));

            context.DrawLine(new Pen(new SolidColorBrush(Color), lineWidth), start, end);

            context.Pop();
        }
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     if (_bitmap != null)
     {
         drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
         drawingContext.DrawImage(_bitmap, new Rect(new Size(_bitmap.Width, _bitmap.Height)));
         drawingContext.Pop();
     }
 }