Exemple #1
0
        void drawLine(Context gr, Rectangle cb, int i)
        {
            CodeLine cl        = PrintedLines[i];
            int      lineIndex = buffer.IndexOf(cl);

            double y = cb.Y + fe.Height * i, x = cb.X;

            //Draw line numbering
            Color mgFg = Color.Gray;
            Color mgBg = Color.White;

            if (PrintLineNumbers)
            {
                Rectangle mgR = new Rectangle((int)x, (int)y, leftMargin - leftMarginGap, (int)Math.Ceiling(fe.Height));
                if (cl.exception != null)
                {
                    mgBg = Color.Red;
                    if (buffer.CurrentLine == lineIndex)
                    {
                        mgFg = Color.White;
                    }
                    else
                    {
                        mgFg = Color.LightGray;
                    }
                }
                else if (buffer.CurrentLine == lineIndex)
                {
                    mgFg = Color.Black;
                }
                string strLN = (lineIndex + 1).ToString();
                gr.SetSourceColor(mgBg);
                gr.Rectangle(mgR);
                gr.Fill();
                gr.SetSourceColor(mgFg);

                gr.MoveTo(cb.X + (int)(gr.TextExtents(buffer.LineCount.ToString()).Width - gr.TextExtents(strLN).Width), y + fe.Ascent);
                gr.ShowText(strLN);
                gr.Fill();
            }


            //draw folding
            if (foldingEnabled)
            {
                if (cl.IsFoldable)
                {
                    if (cl.SyntacticNode.StartLine != cl.SyntacticNode.EndLine)
                    {
                        gr.SetSourceColor(Color.Black);
                        Rectangle rFld = new Rectangle(cb.X + leftMargin - leftMarginGap - foldSize, (int)(y + fe.Height / 2.0 - foldSize / 2.0), foldSize, foldSize);
                        gr.Rectangle(rFld, 1.0);
                        if (cl.IsFolded)
                        {
                            gr.MoveTo(rFld.Center.X + 0.5, rFld.Y + 2);
                            gr.LineTo(rFld.Center.X + 0.5, rFld.Bottom - 2);
                        }
                        gr.MoveTo(rFld.Left + 2, rFld.Center.Y + 0.5);
                        gr.LineTo(rFld.Right - 2, rFld.Center.Y + 0.5);
                        gr.Stroke();
                    }
                }
            }

            gr.SetSourceColor(Foreground);
            x += leftMargin;

            if (cl.Tokens == null)
            {
                drawRawCodeLine(gr, x, y, i, lineIndex);
            }
            else
            {
                drawParsedCodeLine(gr, x, y, i, lineIndex);
            }
        }
Exemple #2
0
        void drawLine(Context gr, Rectangle cb, int i)
        {
            CodeLine cl        = PrintedLines[i];
            int      lineIndex = buffer.IndexOf(cl);

            double y = cb.Y + (fe.Ascent + fe.Descent) * i, x = cb.X;

            //Draw line numbering
            Color mgFg = Colors.Jet;
            Color mgBg = Colors.Grey;

            if (PrintLineNumbers)
            {
                Rectangle mgR = new Rectangle((int)x, (int)y, leftMargin - leftMarginGap, (int)Math.Ceiling((fe.Ascent + fe.Descent)));
                if (cl.exception != null)
                {
                    mgBg = Colors.Red;
                    if (buffer.CurrentLine == lineIndex)
                    {
                        mgFg = Colors.White;
                    }
                    else
                    {
                        mgFg = Colors.LightGrey;
                    }
                }
                else if (buffer.CurrentLine == lineIndex && HasFocus)
                {
                    mgFg = Colors.Black;
                    mgBg = Colors.DarkGrey;
                }
                string strLN = (lineIndex + 1).ToString();
                gr.SetSourceColor(mgBg);
                gr.Rectangle(mgR);
                gr.Fill();
                gr.SetSourceColor(mgFg);

                gr.MoveTo(cb.X + (int)(gr.TextExtents(buffer.LineCount.ToString()).Width - gr.TextExtents(strLN).Width), y + fe.Ascent);
                gr.ShowText(strLN);
                gr.Fill();
            }


            //draw folding
            if (foldingEnabled)
            {
                Rectangle rFld = new Rectangle(cb.X + leftMargin - leftMarginGap - foldMargin,
                                               (int)(y + (fe.Ascent + fe.Descent) / 2.0 - foldSize / 2.0), foldSize, foldSize);

                gr.SetSourceColor(Colors.Black);
                gr.LineWidth = 1.0;

                int  level       = 0;
                bool closingNode = false;

                if (currentNode != null)
                {
                    if (cl == currentNode.EndLine)
                    {
                        currentNode = currentNode.Parent;
                        closingNode = true;
                    }
                    if (currentNode != null)
                    {
                        level = currentNode.Level - 1;
                    }
                }

                /*for (int l = 0; l < level; l++) {
                 *      gr.MoveTo (rFld.Center.X + 0.5, y);
                 *      gr.LineTo (rFld.Center.X + 0.5, y + fe.Ascent + fe.Descent);
                 *      rFld.Left += foldHSpace;
                 * }*/
                if (level > 0)
                {
                    gr.MoveTo(rFld.Center.X + 0.5, y);
                    gr.LineTo(rFld.Center.X + 0.5, y + fe.Ascent + fe.Descent);
                }
                if (closingNode)
                {
                    gr.MoveTo(rFld.Center.X + 0.5, y);
                    gr.LineTo(rFld.Center.X + 0.5, y + fe.Ascent / 2 + 0.5);
                    gr.LineTo(rFld.Center.X + 0.5 + foldSize / 2, y + fe.Ascent / 2 + 0.5);
                    closingNode = false;
                }
                gr.SetDash(new double[] { 1.5 }, 0.0);
                gr.SetSourceColor(Colors.Grey);
                gr.Stroke();
                gr.SetDash(new double[] {}, 0.0);

                if (cl.IsFoldable)
                {
                    gr.Rectangle(rFld);
                    gr.SetSourceColor(Colors.White);
                    gr.Fill();
                    gr.SetSourceColor(Colors.Black);
                    gr.Rectangle(rFld, 1.0);
                    if (cl.IsFolded)
                    {
                        gr.MoveTo(rFld.Center.X + 0.5, rFld.Y + 2);
                        gr.LineTo(rFld.Center.X + 0.5, rFld.Bottom - 2);
                    }
                    else
                    {
                        currentNode = cl.SyntacticNode;
                    }

                    gr.MoveTo(rFld.Left + 2, rFld.Center.Y + 0.5);
                    gr.LineTo(rFld.Right - 2, rFld.Center.Y + 0.5);
                    gr.Stroke();
                }
            }

            gr.SetSourceColor(Foreground);
            x += leftMargin;

            if (cl.Tokens == null)
            {
                drawRawCodeLine(gr, x, y, i, lineIndex);
            }
            else
            {
                drawParsedCodeLine(gr, x, y, i, lineIndex);
            }
        }