⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 painter_gdi.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
📖 第 1 页 / 共 3 页
字号:
                    if (this.Control.ContainsFocus)
                        GFX.SelectionBuffer.Clear(Control.SelectionBackColor);
                    else
                        GFX.SelectionBuffer.Clear(Control.InactiveSelectionBackColor);

                    RenderSelectedText(RowIndex);
                }
            }


            if (this.Control.ContainsFocus || Control.View.Action ==
                XTextAction.xtDragText)
            {
                RenderCaret(RowIndex, RowPos * Control.View.RowHeight + this.yOffset);
            }

            RenderSelection(RowIndex, true);
            RenderMargin(RowIndex);
            if (Control.Document.Folding)
                RenderExpansion(RowIndex);

            RowPaintEventArgs e = new RowPaintEventArgs();
            
            Rectangle rec = new Rectangle(0, 0, this.Control.Width,
                                          Control.View.RowHeight);
            e.Graphics = Graphics.FromHdc(bbuff.hDC);
            e.Bounds = rec;
            e.Row = null;
            if (RowIndex >= 0 && RowIndex < Control.Document.Count)
                e.Row = Control.Document[RowIndex];

            this.Control._CodeEditor.OnRenderRow(e);
            e.Graphics.Dispose();

            bbuff.Flush();
            bbuff.RenderToControl(0, RowPos * Control.View.RowHeight + this.yOffset)
                ;

            //GFX.SelectionBuffer.RenderToControl (0,RowPos*Control.View.RowHeight+this.yOffset);


            if (found)
                bg.Dispose();
        }

        private void SetFont(bool Bold, bool Italic, bool Underline, GDISurface
            bbuff)
        {
            if (Bold)
                if (Italic)
                    if (Underline)
                        bbuff.Font = GFX.FontBoldItalicUnderline;
                    else
                        bbuff.Font = GFX.FontBoldItalic;
                else if (Underline)
                    bbuff.Font = GFX.FontBoldUnderline;
                else
                    bbuff.Font = GFX.FontBold;
            else if (Italic)
                if (Underline)
                    bbuff.Font = GFX.FontItalicUnderline;
                else
                    bbuff.Font = GFX.FontItalic;
            else if (Underline)
                bbuff.Font = GFX.FontUnderline;
            else
                bbuff.Font = GFX.FontNormal;

        }

        private void SetStringFont(bool Bold, bool Italic, bool Underline)
        {
            GDISurface bbuff = GFX.StringBuffer;
            if (Bold)
                if (Italic)
                    if (Underline)
                        bbuff.Font = GFX.FontBoldItalicUnderline;
                    else
                        bbuff.Font = GFX.FontBoldItalic;
                else if (Underline)
                    bbuff.Font = GFX.FontBoldUnderline;
                else
                    bbuff.Font = GFX.FontBold;
            else if (Italic)
                if (Underline)
                    bbuff.Font = GFX.FontItalicUnderline;
                else
                    bbuff.Font = GFX.FontItalic;
            else if (Underline)
                bbuff.Font = GFX.FontUnderline;
            else
                bbuff.Font = GFX.FontNormal;

        }

        private void RenderCollapsedSelectedText(int RowIndex, int xPos)
        {
            GDISurface bbuff = GFX.SelectionBuffer;
            bbuff.Font = GFX.FontBold;
            bbuff.FontTransparent = true;

            if (this.Control.ContainsFocus)
                bbuff.TextForeColor = Control.SelectionForeColor;
            else
                bbuff.TextForeColor = Control.InactiveSelectionForeColor;

            //bbuff.TextForeColor =Color.DarkBlue;
            Row r = Control.Document[RowIndex];
            string str = "";
            str = r.CollapsedText;


            xPos++;
            int taborig = -Control.View.FirstVisibleColumn * Control.View.CharWidth
                + Control.View.TextMargin;
            GFX.StringBuffer.Font = GFX.FontBold;
            int wdh = GFX.StringBuffer.DrawTabbedString(str, xPos + 1, 0, taborig,
                                                        Control.PixelTabSize).Width;

            if (this.Control.ContainsFocus)
            {
                bbuff.FillRect(Control.SelectionForeColor, xPos + 0, 0, wdh + 2,
                               Control.View.RowHeight);
                bbuff.FillRect(Control.SelectionBackColor, xPos + 1, 1, wdh,
                               Control.View.RowHeight - 2);
            }
            else
            {
                bbuff.FillRect(Control.InactiveSelectionForeColor, xPos + 0, 0, wdh + 2,
                               Control.View.RowHeight);
                bbuff.FillRect(Control.InactiveSelectionBackColor, xPos + 1, 1, wdh,
                               Control.View.RowHeight - 2);
            }


            wdh = bbuff.DrawTabbedString(str, xPos + 1, 0, taborig,
                                         Control.PixelTabSize).Width;


            //this can crash if document not fully parsed , on error resume next

            if (r.Expansion_StartSegment.EndRow != null)
            {
                if (r.Expansion_StartSegment.EndRow.RowState ==
                    RowState.SegmentParsed)
                    this.Control.Document.Parser.ParseLine
                        (r.Expansion_StartSegment.EndRow.Index, true);

                Word last = r.Expansion_StartSegment.EndWord;
                xPos += Control.View.FirstVisibleColumn * Control.View.CharWidth;
                r.Expansion_StartSegment.EndRow.Expansion_PixelStart = xPos + wdh -
                    Control.View.TextMargin + 2;
                r.Expansion_PixelEnd = xPos - 1;
                RenderSelectedText(Control.Document.IndexOf
                    (r.Expansion_StartSegment.EndRow),
                                   r.Expansion_StartSegment.EndRow.Expansion_PixelStart, last);
            }
        }

        private void RenderCollapsedText(int RowIndex, int xPos)
        {
            GDISurface bbuff = GFX.BackBuffer;
            bbuff.Font = GFX.FontBold;
            bbuff.FontTransparent = true;

            bbuff.TextForeColor = Control.OutlineColor;
            //bbuff.TextForeColor =Color.DarkBlue;
            Row r = Control.Document[RowIndex];
            string str = "";
            str = r.CollapsedText;


            xPos++;
            int taborig = -Control.View.FirstVisibleColumn * Control.View.CharWidth
                + Control.View.TextMargin;
            GFX.StringBuffer.Font = GFX.FontBold;
            int wdh = GFX.StringBuffer.DrawTabbedString(str, xPos + 1, 0, taborig,
                                                        Control.PixelTabSize).Width;
            bbuff.FillRect(GFX.OutlineBrush, xPos + 0, 0, wdh + 2,
                           Control.View.RowHeight);
            bbuff.FillRect(GFX.BackgroundBrush, xPos + 1, 1, wdh,
                           Control.View.RowHeight - 2);
            wdh = bbuff.DrawTabbedString(str, xPos + 1, 0, taborig,
                                         Control.PixelTabSize).Width;


            //this can crash if document not fully parsed , on error resume next

            if (r.Expansion_StartSegment.EndRow != null)
            {
                if (r.Expansion_StartSegment.EndRow.RowState ==
                    RowState.SegmentParsed)
                    this.Control.Document.Parser.ParseLine
                        (r.Expansion_StartSegment.EndRow.Index, true);

                Word last = r.Expansion_StartSegment.EndWord;
                xPos += Control.View.FirstVisibleColumn * Control.View.CharWidth;
                r.Expansion_StartSegment.EndRow.Expansion_PixelStart = xPos + wdh -
                    Control.View.TextMargin + 2;
                r.Expansion_PixelEnd = xPos - 1;
                RenderText(Control.Document.IndexOf(r.Expansion_StartSegment.EndRow),
                           r.Expansion_StartSegment.EndRow.Expansion_PixelStart, last)
                    ;
            }
        }

        private void RenderText(int RowIndex)
        {
            RenderText(RowIndex, 0, null);

        }

        private void RenderText(int RowIndex, int XOffset, Word StartWord)
        {
            GDISurface bbuff = GFX.BackBuffer;
            bbuff.Font = GFX.FontNormal;
            bbuff.FontTransparent = true;
            bool DrawBreakpoint = false;
            if (RowIndex <= Control.Document.Count - 1)
            {
                bbuff.TextForeColor = Color.Black;
                Row xtr = Control.Document[RowIndex];

                //if (xtr.StartSegment != null)
                //	bbuff.DrawTabbedString (xtr.StartSegment.GetHashCode ().ToString (System.Globalization.CultureInfo.InvariantCulture),100,0,0,0);

                //bbuff.TextForeColor = Color.Black;
                //bbuff.DrawTabbedString (xtr.Text,(int)(Control.View.TextMargin -Control.View.ClientAreaStart),1,-Control.View.FirstVisibleColumn*Control.View.CharWidth+Control.View.TextMargin,Control.PixelTabSize);					

                int xpos = Control.View.TextMargin - Control.View.ClientAreaStart +
                    XOffset;
                int wdh = 0;
                int taborig = -Control.View.FirstVisibleColumn *
                    Control.View.CharWidth + Control.View.TextMargin;


                bool ws = Control.ShowWhitespace;
                bool StartDraw = false;
                if (StartWord == null)
                    StartDraw = true;
                xtr.Expansion_StartChar = 0;
                xtr.Expansion_EndChar = 0;
                bool HasExpansion = false;

                WordCollection wordCollection = xtr.FormattedWords;

                Word w = null;

                for (int i = 0; i < wordCollection.Count;i++)
                {
                    w = wordCollection[i];

                    if (StartDraw)
                    {
                        if (w.Segment == xtr.Expansion_StartSegment &&
                            xtr.Expansion_StartSegment != null)
                            if (xtr.Expansion_StartSegment.Expanded == false)
                            {
                                RenderCollapsedText(RowIndex, xpos);
                                HasExpansion = true;
                                break;
                            }

                        if ((w.Type == WordType.xtSpace || w.Type == WordType.xtTab) &&
                            !DrawBreakpoint && Control.ShowTabGuides)
                        {
                            int xtab = xpos - (Control.View.TextMargin -
                                Control.View.ClientAreaStart + XOffset);
                            if (((double)xtab / (double)Control.PixelTabSize) == (xtab /
                                Control.PixelTabSize))
                                bbuff.FillRect(Control.TabGuideColor, xpos, 0, 1,
                                               this.Control.View.RowHeight);
                        }

                        if (w.Type == WordType.xtWord || ws == false)
                        {
                            if (w.Style != null)
                            {
                                SetFont(w.Style.Bold, w.Style.Italic, w.Style.Underline, bbuff);
                                bbuff.TextBackColor = w.Style.BackColor;
                                bbuff.TextForeColor = w.Style.ForeColor;
                                bbuff.FontTransparent = w.Style.Transparent;

                            }
                            else
                            {
                                bbuff.Font = GFX.FontNormal;
                                bbuff.TextForeColor = Color.Black;
                                bbuff.FontTransparent = true;
                            }


                            if (w.Type == WordType.xtWord)
                                DrawBreakpoint = true;

                            if (xtr.Breakpoint && DrawBreakpoint)
                            {
                                bbuff.TextForeColor = Control.BreakPointForeColor;
                                bbuff.TextBackColor = Control.BreakPointBackColor;
                                bbuff.FontTransparent = false;
                            }


                            if (Control.BracketMatching && (w == this.BracketEnd || w ==
                                this.BracketStart))
                            {
                                bbuff.TextForeColor = Control.BracketForeColor;

                                if (Control.BracketBackColor != Color.Transparent)
                                {
                                    bbuff.TextBackColor = Control.BracketBackColor;
                                    bbuff.FontTransparent = false;
                                }

                                wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig,
                                                             Control.PixelTabSize).Width;
                                if (Control.BracketBorderColor != Color.Transparent)
                                {
                                    bbuff.DrawRect(Control.BracketBorderColor, xpos, 0, wdh,
                                                   Control.View.RowHeight - 1);
                                }
                            }
                            else
                            {
                                wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig,
                                                             Control.PixelTabSize).Width;
                            }


                            //render errors
                            if (w.HasError)
                            {
                                //bbuff.FillRect (Color.Red,xpos,Control.View.RowHeight-2,wdh,2);
                                int ey = Control.View.RowHeight - 1;
                                Color c = w.ErrorColor;
                                for (int x = 0; x < wdh + 3; x += 4)
                                {
                                    bbuff.DrawLine(c, new Point(xpos + x, ey), new Point(xpos + x
                                        + 2, ey - 2));
                                    bbuff.DrawLine(c, new Point(xpos + x + 2, ey - 2), new Point
                                        (xpos + x + 4, ey));
                                }
                            }
                        }
                        else if (w.Type == WordType.xtSpace && ws)
                        {
                            bbuff.Font = GFX.FontNormal;
                            bbuff.TextForeColor = this.Control.WhitespaceColor;
                            bbuff.FontTransparent = true;

                            if (xtr.Breakpoint && DrawBreakpoint)
                            {
                                bbuff.TextForeColor = Control.BreakPointForeColor;
                                bbuff.TextBackColor = Control.BreakPointBackColor;
                                bbuff.FontTransparent = false;
                            }

                            bbuff.DrawTabbedString("

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -