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

📄 painter_gdi.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
📖 第 1 页 / 共 3 页
字号:
            }
        }

        private void SetSpanIndicators()
        {
            SpanFound = false;
            //try
            //{
                Segment s = this.Control.Caret.CurrentSegment();

                if (s == null || s.StartWord == null || s.StartWord.Row == null ||
                    s.EndWord == null || s.EndWord.Row == null)
                    return;

                FirstSpanRow = s.StartWord.Row.Index;
                LastSpanRow = s.EndWord.Row.Index;
                SpanFound = true;
            //}
            //catch
            //{
            //}
        }

        /// <summary>
        /// Implementation of the IPainter RenderCaret method
        /// </summary>
        /// <param name="g"></param>
        private bool RenderCaretRowOnly = false;

        public void RenderCaret(Graphics g)
        {
            RenderCaretRowOnly = true;
            RenderAll(g);
            RenderCaretRowOnly = false;
        }

        /// <summary>
        /// Implementation of the IPainter RenderAll method
        /// </summary>
        /// <param name="g">Target Graphics object</param>
        public void RenderAll(Graphics g)
        {
                Control.InitVars();
                Control.InitScrollbars();
                SetBrackets();
                SetSpanIndicators();
                int j = Control.View.FirstVisibleRow;

                int diff = j - this.LastRow;
                this.LastRow = j;
                if (this.Control.SmoothScroll)
                {
                    if (diff == 1)
                    {
                        for (int i = this.Control.View.RowHeight; i > 0; i -=
                            this.Control.SmoothScrollSpeed)
                        {
                            this.yOffset = i + this.Control.View.YOffset;
                            RenderAll2(g);
                            g.Flush();
                            //BOO Thread.Sleep(0);
                        }
                    }
                    else if (diff == -1)
                    {
                        for (int i = -this.Control.View.RowHeight; i < 0; i +=
                            this.Control.SmoothScrollSpeed)
                        {
                            this.yOffset = i + this.Control.View.YOffset;
                            RenderAll2(g);
                            g.Flush();
                            //BOO Thread.Sleep(0);
                        }
                    }
                }

                this.yOffset = this.Control.View.YOffset;
                RenderAll2(g);
                //g.Flush ();
                //System.Threading.Thread.Sleep (0);
        }

        private void RenderAll2(Graphics g)
        {
                int j = Control.View.FirstVisibleRow;

                Row r = null;


                if (Control.AutoListStartPos != null)
                {

                        if (Control.AutoListVisible)
                        {
                            Point alP = GetTextPointPixelPos(Control.AutoListStartPos);
                            if (alP == new Point(-1, -1))
                            {
                                Control.AutoList.Visible = false;
                            }
                            else
                            {
                                alP.Y += Control.View.RowHeight + 2;
                                alP.X += -20;
                                alP = Control.PointToScreen(alP);

                                Screen screen =
                                    Screen.FromPoint(new Point
                                        (this.Control.Right, alP.Y));

                                if (alP.Y + Control.AutoList.Height > screen.WorkingArea.Height)
                                {
                                    alP.Y -= Control.View.RowHeight + 2 + Control.AutoList.Height;
                                }

                                if (alP.X + Control.AutoList.Width > screen.WorkingArea.Width)
                                {
                                    alP.X -= alP.X + Control.AutoList.Width -
                                        screen.WorkingArea.Width;
                                }


                                Control.AutoList.Location = alP;
                                Control.AutoList.Visible = true;
                                //Control.Controls[0].Focus();
                                Control.Focus();
                            }
                        }
                        else
                        {
                        }
                }

                if (Control.InfoTipStartPos != null)
                {

                        if (Control.InfoTipVisible)
                        {
                            Point itP = GetTextPointPixelPos(Control.InfoTipStartPos);
                            if (itP == new Point(-1, -1))
                            {
                                Control.InfoTip.Visible = false;
                            }
                            else
                            {
                                itP.Y += Control.View.RowHeight + 2;
                                itP.X += -20;

                                itP = Control.PointToScreen(itP);

                                Screen screen =
                                    Screen.FromPoint(new Point
                                        (this.Control.Right, itP.Y));

                                if (itP.Y + Control.InfoTip.Height > screen.WorkingArea.Height)
                                {
                                    itP.Y -= Control.View.RowHeight + 2 + Control.InfoTip.Height;
                                }

                                if (itP.X + Control.InfoTip.Width > screen.WorkingArea.Width)
                                {
                                    itP.X -= itP.X + Control.InfoTip.Width -
                                        screen.WorkingArea.Width;
                                }


                                Control.InfoTip.Location = itP;
                                Control.InfoTip.Visible = true;
                               // System.Diagnostics.Debug.WriteLine("Infotip Made Visible");
                            }
                        }
                        else
                        {
                            Control.InfoTip.Visible = false;
                            //System.Diagnostics.Debug.WriteLine("Infotip Made Invisible");
                        }
                }
                

                for (int i = 0; i < Control.View.VisibleRowCount; i++)
                {
                    if (j >= 0 && j < Control.Document.VisibleRows.Count)
                    {
                        r = Control.Document.VisibleRows[j];
                        if (RenderCaretRowOnly)
                        {
                            if (r == Control.Caret.CurrentRow)
                            {
                                RenderRow(g, Control.Document.IndexOf(r), i);
                            }
                            //Control.Caret.CurrentRow.Expansion_EndSegment.StartRow.Index
                            if (Control.Caret.CurrentRow.Expansion_EndSegment != null &&
                                Control.Caret.CurrentRow.Expansion_EndSegment.StartRow !=
                                    null &&
                                Control.Caret.CurrentRow.Expansion_EndSegment.StartRow == r)
                            {
                                RenderRow(g, Control.Document.IndexOf(r), i);
                            }
                        }
                        else
                        {
                            RenderRow(g, Control.Document.IndexOf(r), i);
                        }
                    }
                    else
                    {
                        if (RenderCaretRowOnly)
                        {
                        }
                        else
                        {
                            RenderRow(g, Control.Document.Count, i);
                        }
                    }
                    j++;
                }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="RowIndex"></param>
        public void RenderRow(int RowIndex)
        {
            RenderRow(RowIndex, 10);
        }

        private void RenderRow(int RowIndex, int RowPos)
        {
            using (Graphics g = Control.CreateGraphics())
            {
                RenderRow(g, RowIndex, RowPos);
            }
        }

        private void RenderRow(Graphics g, int RowIndex, int RowPos)
        {
            //		if (RowIndex ==-1)
            //			System.Diagnostics.Debugger.Break ();

            if (RowIndex >= 0 && RowIndex < this.Control.Document.Count)
            {
                //do keyword parse before we render the line...
                if (this.Control.Document[RowIndex].RowState == RowState.SegmentParsed)
                {
                    this.Control.Document.Parser.ParseLine(RowIndex, true);
                    this.Control.Document[RowIndex].RowState = RowState.AllParsed;
                }

            }



            GDISurface bbuff = GFX.BackBuffer;
            bool found = false;


            GDIBrush bg = GFX.BackgroundBrush;


            if (RowIndex < this.Control.Document.Count && RowIndex >= 0)
            {
                Row r = Control.Document[RowIndex];
                if (SpanFound && RowIndex >= FirstSpanRow && RowIndex <=
                    LastSpanRow && Control._CodeEditor.ScopeBackColor !=
                        Color.Transparent)
                {
                    bg = new GDIBrush(Control._CodeEditor.ScopeBackColor);
                    found = true;
                }
                else if (r.BackColor != Color.Transparent)
                {
                    bg = new GDIBrush(r.BackColor);
                    found = true;
                }
                else
                {
                    if (r.EndSegment != null)
                    {
                        Segment tmp = null;
                        tmp = r.Expansion_EndSegment;
                        while (tmp != null)
                        {
                            if (tmp.BlockType.Transparent == false)
                            {
                                bg = new GDIBrush(tmp.BlockType.BackColor);
                                found = true;
                                break;
                            }
                            tmp = tmp.Parent;
                        }


                        if (!found)
                        {
                            tmp = r.EndSegment;
                            while (tmp != null)
                            {
                                if (tmp.BlockType.Transparent == false)
                                {
                                    bg = new GDIBrush(tmp.BlockType.BackColor);
                                    found = true;
                                    break;
                                }
                                tmp = tmp.Parent;
                            }
                        }
                        if (!found)
                        {
                            tmp = r.Expansion_EndSegment;
                            while (tmp != null)
                            {
                                if (tmp.BlockType.Transparent == false)
                                {
                                    bg = new GDIBrush(tmp.BlockType.BackColor);
                                    found = true;
                                    break;
                                }
                                tmp = tmp.Parent;
                            }
                        }
                    }

                }
            }


            if (RowIndex == Control.Caret.Position.Y && Control.HighLightActiveLine)
                bbuff.Clear(GFX.HighLightLineBrush);
            else if (RowIndex >= 0 && RowIndex < Control.Document.Count)
            {
                if (Control.Document[RowIndex].IsCollapsed)
                {
                    if (Control.Document[RowIndex].Expansion_EndRow.Index ==
                        Control.Caret.Position.Y && Control.HighLightActiveLine)
                        bbuff.Clear(GFX.HighLightLineBrush);
                    else
                        bbuff.Clear(bg);
                }
                else
                    bbuff.Clear(bg);
            }
            else
                bbuff.Clear(bg);


            //only render normal text if any part of the row is visible
            if (RowIndex <= Control.Selection.LogicalBounds.FirstRow || RowIndex >=
                Control.Selection.LogicalBounds.LastRow)
            {
                RenderText(RowIndex);
            }

            //only render selection text if the line is selected
            if (Control.Selection.IsValid)
            {
                if (RowIndex >= Control.Selection.LogicalBounds.FirstRow && RowIndex
                    <= Control.Selection.LogicalBounds.LastRow)
                {

⌨️ 快捷键说明

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