public void Render(Graphics g) { g.Clear(Color.White); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; if (lineNumbering) { g.FillRectangle(Brushes.AliceBlue, lineNumberArea); g.DrawLine(Pens.DodgerBlue, lineNumberArea.Right, lineNumberArea.Top, lineNumberArea.Right, lineNumberArea.Bottom); } int line = viewPosn.Line; int numLines = NumVisibleLines; List <SubLine> subLines; int extraSubLines = viewPosn.SubLine;; int i = 0; Line l = null; while (i < numLines && line < doc.NumLines) { l = doc[line]; if (line >= doc.NumLines) { return; } int subLineIndex = 0; if (lineNumbering && extraSubLines == 0) { TextRenderer.DrawText(g, (line + 1).ToString(), FontInfo.Default.Font, lineNumberRects[i], Color.DodgerBlue, tffr); } subLines = l.VisibleSubLines; while (i < numLines && subLineIndex < subLines.Count) { if (extraSubLines-- > 0) { subLineIndex++; } else { SubLine sl = subLines[subLineIndex++]; sl.Render(g, rects[i++], viewPosn.Column, getSelectionArea(line, sl)); } } extraSubLines = 0; line++; } }
private Point getSelectionArea(int LineNum, SubLine SubLine) { if (Selection == null || Selection.IsEmpty) { return(Point.Empty); } if (Selection.End.LineNumber < LineNum) { return(Point.Empty); } if (Selection.Start.LineNumber > LineNum) { return(Point.Empty); } if (Selection.Start.LineNumber < LineNum && Selection.End.LineNumber > LineNum) { return(new Point(0, int.MaxValue / 2)); } if (Selection.Start.LineNumber < LineNum) { return(new Point(0, Selection.End.ColumnNumber - SubLine.Start)); } if (Selection.End.LineNumber > LineNum) { return(new Point(Math.Max(0, Selection.Start.ColumnNumber - SubLine.Start), int.MaxValue / 2)); } if (selection.End.ColumnNumber <= SubLine.Start) { return(Point.Empty); } return(new Point(Math.Max(0, Selection.Start.ColumnNumber - SubLine.Start), Selection.End.ColumnNumber - Math.Max(SubLine.Start, Selection.Start.ColumnNumber))); }
public QTextBox(Font Font, StringComparer Comparer) { InitializeComponent(); // NOP this.SuspendLayout(); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Name = "QTextBox"; this.DoubleBuffered = true; this.BackColor = Color.White; FontInfo.SetFont(Font); ki = new KeywordInfo(comparer = Comparer); SubLine.SetKeywordInfo(ki); Line.SetKeywordInfo(ki); currentView = new View(new Document(4), this); curDoc = currentView.Document; EventManager.ViewChanged += () => { vsb.SetValue(currentView.FirstVisibleLine); this.Invalidate(); }; EventManager.DocumentChanged += () => { if (DocumentChanged != null) { DocumentChanged.Invoke(this, EventArgs.Empty); } }; EventManager.CaretLocationChanged += () => { if (CaretLocationChanged != null) { CaretLocationChanged.Invoke(currentView.CaretDocLoc); } }; EventManager.SelectionChanged += () => { if (SelectionChanged != null) { SelectionChanged.Invoke(this, EventArgs.Empty); } }; EventManager.NumLinesChanged += updateMaxLinesChanged; EventManager.LongestLineChanged += updateForLongestLine; vsb = new QVScrollBar(SCROLL_BAR_WIDTH); this.Controls.Add(vsb); vsb.ValChanged += (e) => { switch (e.Delta) { case -1: if (!currentView.ScrollView(-1)) { e.Accept = false; } break; case 1: if (!currentView.ScrollView(1)) { e.Accept = false; } break; default: currentView.FirstVisibleLine = vsb.Value; break; } }; hsb = new QHScrollBar(SCROLL_BAR_WIDTH); this.Controls.Add(hsb); hsb.ValueChanged += (s, e) => { currentView.FirstVisibleColumn = hsb.Value; this.Invalidate(); }; hsb.Visible = false; this.ResumeLayout(false); ViewEnvironment.NumColumnsPerLineChanged += setMetrics; FontInfo.FontMetricsChanged += setMetrics; EventManager.DocumentChangedChanged += () => { if (this.DocumentChangedChanged != null) { DocumentChangedChanged.Invoke(this, EventArgs.Empty); } }; this.Size = new System.Drawing.Size(492, 313); }