Ejemplo n.º 1
0
            public Painter(TextView outer, Graphics g, StyleStack styleStack)
            {
                this.outer = outer;
                this.graphics = g;
                this.styleStack = styleStack;

                selStart = outer.GetStartSelection();
                selEnd = outer.GetEndSelection();
            }
Ejemplo n.º 2
0
        public bool DrawNode(Node node, object graphics)
        {
            Graphics g = (Graphics)graphics;

            var m = g.Transform;
            var saveM = g.Transform.Clone();
            //      g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));

            // This is supposed to flip the text around its center

            var c = (float)node.GeometryNode.Center.Y;
            using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
            {
                m.Multiply(m2);
            }

            m.Translate(
                (float)node.GeometryNode.Center.X,
                (float)node.GeometryNode.Center.Y);

            g.Transform = m;

            var styleStack = GetStyleStack();
            var painter = new TextViewPainter(
                Layout, g,
                SystemColors.WindowText,
                SystemColors.Window,
                SystemFonts.DefaultFont, styleStack);
            var ptr = new TextPointer { Character = 0, Span = 0, Line = TextModel.StartPosition };
            painter.SetSelection(ptr, ptr);
            painter.PaintGdiPlus();
            g.Transform = saveM;
            g.ResetClip();

            saveM.Dispose();
       //     m.Dispose();
            return true;//returning false would enable the default rendering
        }
Ejemplo n.º 3
0
        private RectangleF CharPositionToClient(Graphics g, TextPointer pos, LayoutSpan span, StyleStack styleStack)
        {
            var iChar = pos.Character;

            styleStack.PushStyle(span.Style);
            var font = styleStack.GetFont(defaultFont);

            var textStub = span.Text.Substring(0, iChar);
            var sz = MeasureText(g, textStub, font);
            var x = sz.Width + span.ContentExtent.Left;
            var width = 1;

            styleStack.PopStyle();

            return new RectangleF(x, span.ContentExtent.Top, width, span.ContentExtent.Height);
        }
Ejemplo n.º 4
0
 private RectangleF SpanPositionToClient(Graphics g, TextPointer pos, LayoutLine line, StyleStack styleStack)
 {
     var iSpan = pos.Span;
     if (iSpan < 0 || iSpan >= line.Spans.Length)
         return line.Extent;
     var span = line.Spans[iSpan];
     return CharPositionToClient(g, pos, span, styleStack);
 }
Ejemplo n.º 5
0
 public RectangleF LogicalPositionToClient(Graphics g, TextPointer pos, StyleStack styleStack)
 {
     foreach (var line in this.visibleLines.Values)
     {
         if (line.Position == pos.Line)
         {
             return SpanPositionToClient(g, pos, line, styleStack);
         }
     }
     return new RectangleF(new PointF(0, 0), CalculateExtent());
 }
Ejemplo n.º 6
0
 internal bool IsInsideSelection(TextPointer pos)
 {
     return
         (layout.ComparePositions(GetStartSelection(), pos) <= 0 &&
          layout.ComparePositions(pos, GetEndSelection()) < 0);
 }
Ejemplo n.º 7
0
 internal bool IsInsideSelection(TextPointer pos)
 {
     return
         ComparePositions(GetStartSelection(), pos) <= 0 &&
         ComparePositions(pos, GetEndSelection()) < 0;
 }
Ejemplo n.º 8
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if (Capture)
     {
         var pos = ClientToLogicalPosition(e.Location);
         if (dragging)
         {
             cursorPos = anchorPos = pos;
             var span = GetSpan(e.Location);
             if (span != null && span.Tag != null)
             {
                 Navigate.Fire(this, new EditorNavigationArgs(span.Tag));
             }
             Invalidate();
         }
         else
         {
             if (IsSelectionEmpty())
             {
                 var span = GetSpan(e.Location);
                 if (span != null && span.Tag != null)
                 {
                     Navigate.Fire(this, new EditorNavigationArgs(span.Tag));
                 }
             }
             SelectionChanged.Fire(this);
         }
         Capture = false;
     }
     base.OnMouseUp(e);
 }
Ejemplo n.º 9
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Capture = true;
            var pos = ClientToLogicalPosition(e.Location);
            if (!IsSelectionEmpty() &&
                IsInsideSelection(pos))
            {
                // if down-click is done on a selection, the user may want 
                // to drag it.
                dragging = true;
            }
            else if (ComparePositions(pos, cursorPos) != 0)
            {
                Focus();

                // User clicked somewhere other than the current cursor
                // position, so we need to move it.
                dragging = false;
                this.cursorPos = pos;
                if ((Control.ModifierKeys & Keys.Shift) == 0)
                    this.anchorPos = pos;
                SetCaret();
                Invalidate();
            }
            base.OnMouseDown(e);
        }
Ejemplo n.º 10
0
 public void SetSelection(TextPointer start, TextPointer end)
 {
     this.selStart = start;
     this.selEnd = end;
 }
Ejemplo n.º 11
0
 protected virtual void OnModelChanged(EventArgs e)
 {
     this.cursorPos = new TextPointer
     {
         Line = model.CurrentPosition,
         Span = 0,
         Character = 0
     };
     this.anchorPos = cursorPos;
     ChangeLayout();
     UpdateScrollbar();
     ModelChanged.Fire(this);
 }
Ejemplo n.º 12
0
 private RectangleF LogicalPositionToClient(TextPointer pos)
 {
     using (var g = CreateGraphics())
     {
         GetStyleStack().PushStyle(StyleClass);
         var ptr = layout.LogicalPositionToClient(g, pos, styleStack);
         styleStack.PopStyle();
         return ptr;
     }
 }
Ejemplo n.º 13
0
 public void ClearSelection()
 {
     anchorPos = cursorPos;
     Invalidate();
 }
Ejemplo n.º 14
0
 public void ClearSelection()
 {
     anchorPos = cursorPos;
     Invalidate();
 }
Ejemplo n.º 15
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     Capture = true;
     var pos = ClientToLogicalPosition(e.Location);
     if (!IsSelectionEmpty() &&
         IsInsideSelection(pos))
     {
         dragging = true;
     }
     else if (ComparePositions(pos, cursorPos) != 0)
     {
         dragging = false;
         this.cursorPos = pos;
         if ((Control.ModifierKeys & Keys.Shift) == 0)
             this.anchorPos = pos;
         Focus();
         SetCaret();
         Invalidate();
     }
     base.OnMouseDown(e);
 }
Ejemplo n.º 16
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (Capture && !dragging)
     {
         var pos = ClientToLogicalPosition(e.Location);
         if (ComparePositions(cursorPos, pos) != 0)
         {
             this.cursorPos = pos;
             Invalidate();
         }
     }
     else
     {
         var span = GetSpan(e.Location);
         if (span != null)
         {
             this.Cursor = GetCursor(span.Style);
         }
         else
         {
             this.Cursor = Cursors.Default;
         }
     }
     base.OnMouseMove(e);
 }
Ejemplo n.º 17
0
            private void PaintLine(LayoutLine line)
            {
                // Paint the last piece of the line
                RectangleF rcTrailer = line.Extent;
                float xMax = 0;
                if (line.Spans.Length > 0)
                {
                    xMax = line.Spans[line.Spans.Length - 1].Extent.Right;
                }
                var cx = outer.ClientRectangle.Right - xMax;
                if (cx > 0)
                {
                    rcTrailer.X = xMax;
                    rcTrailer.Width = cx;
                    graphics.FillRectangle(
                        styleStack.GetBackground(outer),
                        rcTrailer);
                }

                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    this.styleStack.PushStyle(span.Style);
                    var pos = new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg = styleStack.GetForegroundColor(outer);
                    this.bg = styleStack.GetBackground(outer);
                    this.font = styleStack.GetFont(outer);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                DrawTrailingTextSegment(selEnd.Character, false);
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

#if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
#endif
                    styleStack.PopStyle();
                }
            }
Ejemplo n.º 18
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (Capture && !dragging)
     {
         // We're extending the selection
         var pos = ClientToLogicalPosition(e.Location);
         if (ComparePositions(cursorPos, pos) != 0)
         {
             this.cursorPos = pos;
             Invalidate();
         }
     }
     else
     {
         // Not captured, so rat is just floating over us.
         // Show the right cursor.
         var span = GetSpan(e.Location);
         if (span != null)
         {
             GetStyleStack().PushStyle(StyleClass);
             styleStack.PushStyle(span.Style);
             this.Cursor = styleStack.GetCursor(this);
             styleStack.PopStyle();
             styleStack.PopStyle();
         }
         else
         {
             this.Cursor = Cursors.Default;
         }
     }
     base.OnMouseMove(e);
 }
Ejemplo n.º 19
0
            public Painter(TextView outer, Graphics g)
            {
                this.outer = outer;
                this.graphics = g;

                selStart = outer.GetStartSelection();
                selEnd = outer.GetEndSelection();
            }
Ejemplo n.º 20
0
 private int ComparePositions(TextPointer a, TextPointer b)
 {
     var d = model.ComparePositions(a.Line, b.Line);
     if (d != 0)
         return d;
     d = a.Span.CompareTo(b.Span);
     if (d != 0)
         return d;
     return a.Character.CompareTo(b.Character);
 }
Ejemplo n.º 21
0
            private void PaintLine(LayoutLine line)
            {
                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    var pos = new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg = outer.GetForegroundColor(span.Style);
                    this.bg = outer.GetBackground(span.Style);
                    this.font = outer.GetFont(span.Style);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                if (selEnd.Character < span.Text.Length)
                                {
                                    // If there is trailing unselected text, display that.
                                    DrawTrailingTextSegment(selEnd.Character, false);
                                }
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

                #if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                #endif
                }
            }
Ejemplo n.º 22
0
 protected virtual void OnModelChanged(EventArgs e)
 {
     this.cursorPos = new TextPointer
     {
         Line = model.StartPosition,
         Span = 0,
         Character = 0
     };
     this.anchorPos = cursorPos;
     vScroll.Value = 0;
     ChangeLayout();
     ModelChanged.Fire(this);
 }
Ejemplo n.º 23
0
            private void PaintLine(LayoutLine line)
            {
                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    var pos = new TextPointer {
                        Line = line.Position, Span = iSpan, Character = 0
                    };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg   = outer.GetForegroundColor(span.Style);
                    this.bg   = outer.GetBackground(span.Style);
                    this.font = outer.GetFont(span.Style);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                if (selEnd.Character < span.Text.Length)
                                {
                                    // If there is trailing unselected text, display that.
                                    DrawTrailingTextSegment(selEnd.Character, false);
                                }
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

#if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz       = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz       = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
#endif
                }
            }