internal void Draw(Graphics g, Rectangle textArea, TextCursor cursor) { int startX = textArea.Left * BaseFormat.FontWidth; int endX = textArea.Right * BaseFormat.FontWidth; int x = startX + BaseFormat.LeftMargin; int y = textArea.Y * BaseFormat.FontHeight; int emptyLines = 0; foreach (TextLine line in DrawLines.Skip(textArea.Top).Take(textArea.Height)) { if (line != null) { if (emptyLines > 0) { DrawEmptyLines(g, new Rectangle(startX, y, endX, BaseFormat.FontHeight * emptyLines)); y += BaseFormat.FontHeight * emptyLines; emptyLines = 0; } line.Draw(g, cursor, textArea.Left, textArea.Width, x, ref y); y += BaseFormat.FontHeight; } else { emptyLines++; } } if (emptyLines > 0) { DrawEmptyLines(g, new Rectangle(startX, y, endX, BaseFormat.FontHeight * emptyLines)); } }
private void drawChars(Graphics g, TextCursor cursor, int start, int count, int x, int y) { int charIndex = start; foreach (FormattedChar ch in Chars.Skip(start).Take(count)) { ch.Draw(g, x, y); charIndex++; x += BaseFormat.FontWidth; } // draw selection if (cursor.GetLineSelection(LineIndex, out int st, out int ct)) { if (st < start) { ct -= start - st; st = start; } if (st + ct > start + count) { ct = start + count - st; } x = (st - start + 1) * BaseFormat.FontWidth; int w = ct * BaseFormat.FontWidth; g.FillRectangle(BaseFormat.SelectionBrush, x, y, w, BaseFormat.FontHeight); } }
public TextAction(TextCursor cursor, ActionType type) { Cursor = cursor; Type = type; Text = new StringBuilder(); AfterText = new StringBuilder(); Selection = Cursor.Selection; Location = Cursor.Location; }
public TextAction PeekIf(TextCursor cursor, TextAction.ActionType type, Func <TextAction, bool> condition) { if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type) && condition(UndoActions.Peek())) { return(UndoActions.Peek()); } else { return(Add(cursor, type)); } }
public TextAction PeekOrAdd(TextCursor cursor, TextAction.ActionType type) { if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type)) { return(UndoActions.Peek()); } else { return(Add(cursor, type)); } }
public TextAction Add(TextCursor cursor, TextAction.ActionType type) { TextAction action = new TextAction(cursor, type); UndoActions.Push(action); if (RedoActions.Any()) { RedoActions.Clear(); } return(action); }
public bool Redo(out TextCursor cursor) { cursor = null; if (!RedoActions.Any()) { return(false); } var action = RedoActions.Pop(); cursor = action.Cursor; cursor.Redo(action); UndoActions.Push(action); return(RedoActions.Any()); }
public void Draw(Graphics g, TextCursor cursor, int start, int count, int x, ref int y) { drawChars(g, cursor, start, count, x, y); }
public TextView(TextFormatter formatter) { Text = new Text(this, formatter); Cursor = new TextCursor(Text, new ActionsManager()); }
public bool Match(TextCursor cursor, ActionType type) { return(cursor == Cursor && type == Type && AfterSelection == cursor.Selection && AfterLocation == cursor.Location); }