Ejemplo n.º 1
0
 public Builder(TextViewModel model, Graphics g, StyleStack styleStack, Font defaultFont)
 {
     this.model        = model;
     this.g            = g;
     this.styleStack   = styleStack;
     this.defaultFont  = defaultFont;
     this.visibleLines = new SortedList <float, LayoutLine>();
 }
Ejemplo n.º 2
0
 private StyleStack GetStyleStack()
 {
     if (styleStack == null)
     {
         styleStack = new StyleStack(Services.RequireService <IUiPreferencesService>());
     }
     return(styleStack);
 }
Ejemplo n.º 3
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.º 4
0
 public TextViewPainter(TextViewLayout outer, Graphics g, Color fgColor, Color bgColor, Font defaultFont, StyleStack styleStack)
 {
     this.outer          = outer;
     this.graphics       = g;
     this.defaultFgColor = fgColor;
     this.defaultBgColor = bgColor;
     this.defaultFont    = defaultFont;
     this.styleStack     = styleStack;
     this.useGdiPlus     = false;
 }
Ejemplo n.º 5
0
        public void Stst_Default()
        {
            var stst = new StyleStack(uiPrefs);
            mr.ReplayAll();

            var br = stst.GetBackground(Color.FromArgb(0x12, 0x23, 0x45));
            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x23, br.Color.G);
            Assert.AreEqual(0x45, br.Color.B);
        }
Ejemplo n.º 6
0
 public TextViewPainter(TextViewLayout outer, Graphics g, Color fgColor, Color bgColor, Font defaultFont, StyleStack styleStack)
 {
     this.outer = outer;
     this.graphics = g;
     this.defaultFgColor = fgColor;
     this.defaultBgColor = bgColor;
     this.defaultFont = defaultFont;
     this.styleStack = styleStack;
     this.useGdiPlus = false;
 }
Ejemplo n.º 7
0
 public TextPointer ClientToLogicalPosition(Graphics g, Point pt, StyleStack styleStack)
 {
     foreach (var line in this.visibleLines.Values)
     {
         if (line.Extent.Top <= pt.Y && pt.Y < line.Extent.Bottom)
         {
             return(FindSpanPosition(g, pt, line, styleStack));
         }
     }
     return(new TextPointer(model.EndPosition, 0, 0));
 }
Ejemplo n.º 8
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.º 9
0
 /// <summary>
 /// Generates a TextViewLayout from all the lines in the model.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="g"></param>
 /// <param name="defaultFont"></param>
 /// <param name="styleStack"></param>
 /// <returns></returns>
 public static TextViewLayout AllLines(TextViewModel model, Graphics g, Font defaultFont, StyleStack styleStack)
 {
     model.MoveToLine(model.StartPosition, 0);
     var rcLine = new RectangleF();
     var builder = new Builder(model, g, styleStack, defaultFont);
     for (;;)
     {
         var lines = model.GetLineSpans(1);
         if (lines.Length == 0)
             break;
         builder.AddLayoutLine(lines[0], ref rcLine);
     }
     var layout = builder.Build();
     return layout;
 }
Ejemplo n.º 10
0
        public static TextViewLayout VisibleLines(TextViewModel model, Size size, Graphics g, Font defaultFont, StyleStack styleStack)
        {
            var szClient = new SizeF(size);
            var rcLine = new RectangleF(0, 0, szClient.Width, 0);

            var builder = new Builder(model, g, styleStack, defaultFont);
            while (rcLine.Top < szClient.Height)
            {
                var lines = model.GetLineSpans(1);
                if (lines.Length == 0)
                    break;
                builder.AddLayoutLine(lines[0], ref rcLine);
            }
            return builder.Build();
        }
Ejemplo n.º 11
0
        public void Stst_SingleStyle()
        {
            styles.Add("style1", new UiStyle {
                Background = new SolidBrush(Color.FromArgb(0x12, 0x34, 0x56))
            });
            mr.ReplayAll();

            var stst = new StyleStack(uiPrefs);
            stst.PushStyle("style1");

            var br = stst.GetBackground(Color.Black);
            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x34, br.Color.G);
            Assert.AreEqual(0x56, br.Color.B);
        }
Ejemplo n.º 12
0
        private int GetCharPosition(Graphics g, Point ptClient, LayoutSpan span, StyleStack styleStack)
        {
            var x        = ptClient.X - span.ContentExtent.Left;
            var textStub = span.Text;
            int iLow     = 0;
            int iHigh    = textStub.Length;

            styleStack.PushStyle(span.Style);
            var   font  = styleStack.GetFont(defaultFont);
            var   sz    = MeasureText(g, textStub, font);
            float xLow  = 0;
            float xHigh = sz.Width;

            while (iLow < iHigh - 1)
            {
                int iMid = iLow + (iHigh - iLow) / 2;
                textStub = span.Text.Substring(0, iMid);
                sz       = MeasureText(g, textStub, font);
                if (x < sz.Width)
                {
                    iHigh = iMid;
                    xHigh = sz.Width;
                }
                else
                {
                    iLow = iMid;
                    xLow = sz.Width;
                }
            }
            styleStack.PopStyle();
            var cx = xHigh - xLow;

            if (x - xLow > cx)
            {
                return(iHigh);
            }
            else
            {
                return(iLow);
            }
        }
Ejemplo n.º 13
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.º 14
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.º 15
0
        private TextPointer FindSpanPosition(Graphics g, Point ptClient, LayoutLine line, StyleStack styleStack)
        {
            int iSpan = 0;

            foreach (var span in line.Spans)
            {
                if (span.ContentExtent.Contains(ptClient))
                {
                    int iChar = GetCharPosition(g, ptClient, span, styleStack);
                    return(new TextPointer
                    {
                        Line = line.Position,
                        Span = iSpan,
                        Character = iChar
                    });
                }
                ++iSpan;
            }
            return(new TextPointer {
                Line = line.Position, Span = iSpan, Character = 0
            });
        }
Ejemplo n.º 16
0
 private TextPointer FindSpanPosition(Graphics g, Point ptClient, LayoutLine line, StyleStack styleStack)
 {
     int iSpan = 0;
     foreach (var span in line.Spans)
     {
         if (span.ContentExtent.Contains(ptClient))
         {
             int iChar = GetCharPosition(g, ptClient, span, styleStack);
             return new TextPointer
             {
                 Line = line.Position,
                 Span = iSpan,
                 Character = iChar
             };
         }
         ++iSpan;
     }
     return new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };
 }
Ejemplo n.º 17
0
        public static TextViewLayout VisibleLines(TextViewModel model, Size size, Graphics g, Font defaultFont, StyleStack styleStack)
        {
            var szClient = new SizeF(size);
            var rcLine   = new RectangleF(0, 0, szClient.Width, 0);

            var builder = new Builder(model, g, styleStack, defaultFont);

            while (rcLine.Top < szClient.Height)
            {
                var lines = model.GetLineSpans(1);
                if (lines.Length == 0)
                {
                    break;
                }
                builder.AddLayoutLine(lines[0], ref rcLine);
            }
            return(builder.Build());
        }
Ejemplo n.º 18
0
 private Node CreateGraphNode(Block b)
 {
     var nl = "\n    ";
     var model = GenerateTextModel(b);
     var stack = new StyleStack(uiPreferences);
     var layout = TextViewLayout.AllLines(model, g, defaultFont, stack);
     var blockNode = new CfgBlockNode {
         Block = b,
         TextModel = GenerateTextModel(b),
          Layout = layout,
          UiPreferences = uiPreferences,
     };
     var node = graph.AddNode(b.Name);
     node.Attr.LabelMargin = 5;
     node.UserData = blockNode;
     if (useTextEngine)
     {
         node.Attr.Shape = Shape.DrawFromGeometry;
         node.DrawNodeDelegate = blockNode.DrawNode;
         node.NodeBoundaryDelegate = blockNode.GetNodeBoundary;
     }
     else
     {
         node.Label.FontName = "Lucida Console";
         node.Label.FontSize = 10f;
         node.LabelText =
             b.Name + nl +
             string.Join(nl, b.Statements.Select(s => s.Instruction));
     }
     return node;
 }
Ejemplo n.º 19
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.º 20
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.º 21
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.º 22
0
 private int GetCharPosition(Graphics g, Point ptClient, LayoutSpan span, StyleStack styleStack)
 {
     var x = ptClient.X - span.ContentExtent.Left;
     var textStub = span.Text;
     int iLow = 0;
     int iHigh = textStub.Length;
     styleStack.PushStyle(span.Style);
     var font = styleStack.GetFont(defaultFont);
     var sz = MeasureText(g, textStub, font);
     float xLow = 0;
     float xHigh = sz.Width;
     while (iLow < iHigh - 1)
     {
         int iMid = iLow + (iHigh - iLow) / 2;
         textStub = span.Text.Substring(0, iMid);
         sz = MeasureText(g, textStub, font);
         if (x < sz.Width)
         {
             iHigh = iMid;
             xHigh = sz.Width;
         }
         else
         {
             iLow = iMid;
             xLow = sz.Width;
         }
     }
     styleStack.PopStyle();
     var cx = xHigh - xLow;
     if (x - xLow > cx)
         return iHigh;
     else
         return iLow;
 }
Ejemplo n.º 23
0
 private StyleStack GetStyleStack()
 {
     if (styleStack == null)
         styleStack = new StyleStack(Services.RequireService<IUiPreferencesService>());
     return styleStack;
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Generates a TextViewLayout from all the lines in the model.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="g"></param>
        /// <param name="defaultFont"></param>
        /// <param name="styleStack"></param>
        /// <returns></returns>
        public static TextViewLayout AllLines(TextViewModel model, Graphics g, Font defaultFont, StyleStack styleStack)
        {
            model.MoveToLine(model.StartPosition, 0);
            var rcLine  = new RectangleF();
            var builder = new Builder(model, g, styleStack, defaultFont);

            for (;;)
            {
                var lines = model.GetLineSpans(1);
                if (lines.Length == 0)
                {
                    break;
                }
                builder.AddLayoutLine(lines[0], ref rcLine);
            }
            var layout = builder.Build();

            return(layout);
        }
Ejemplo n.º 25
0
        public void Stst_DoubleStyles()
        {
            styles.Add("style1", new UiStyle
            {
                Background = new SolidBrush(Color.FromArgb(0x12, 0x34, 0x56))
            });
            styles.Add("style2", new UiStyle
            {
                PaddingBottom = 6.0f
            });
            mr.ReplayAll();

            var stst = new StyleStack(uiPrefs);
            stst.PushStyle("style1 style2");

            var br = stst.GetBackground(Color.Black);
            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x34, br.Color.G);
            Assert.AreEqual(0x56, br.Color.B);
            var padding = stst.GetNumber(u => u.PaddingBottom);
            Assert.AreEqual(6.0f, padding);
        }
Ejemplo n.º 26
0
 public Builder(TextViewModel model, Graphics g, StyleStack styleStack, Font defaultFont)
 {
     this.model = model;
     this.g = g;
     this.styleStack = styleStack;
     this.defaultFont = defaultFont;
     this.visibleLines = new SortedList<float, LayoutLine>();
 }
Ejemplo n.º 27
0
 public TextPointer ClientToLogicalPosition(Graphics g, Point pt, StyleStack styleStack)
 {
     foreach (var line in this.visibleLines.Values)
     {
         if (line.Extent.Top <= pt.Y && pt.Y < line.Extent.Bottom)
         {
             return FindSpanPosition(g, pt, line, styleStack);
         }
     }
     return new TextPointer { Line = model.EndPosition, Span = 0, Character = 0 };
 }