Exemple #1
0
        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));
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 public TextAction(TextCursor cursor, ActionType type)
 {
     Cursor    = cursor;
     Type      = type;
     Text      = new StringBuilder();
     AfterText = new StringBuilder();
     Selection = Cursor.Selection;
     Location  = Cursor.Location;
 }
Exemple #4
0
 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));
     }
 }
Exemple #5
0
 public TextAction PeekOrAdd(TextCursor cursor, TextAction.ActionType type)
 {
     if (UndoActions.Any() && UndoActions.Peek().Match(cursor, type))
     {
         return(UndoActions.Peek());
     }
     else
     {
         return(Add(cursor, type));
     }
 }
Exemple #6
0
        public TextAction Add(TextCursor cursor, TextAction.ActionType type)
        {
            TextAction action = new TextAction(cursor, type);

            UndoActions.Push(action);
            if (RedoActions.Any())
            {
                RedoActions.Clear();
            }
            return(action);
        }
Exemple #7
0
        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());
        }
Exemple #8
0
 public void Draw(Graphics g, TextCursor cursor, int start, int count, int x, ref int y)
 {
     drawChars(g, cursor, start, count, x, y);
 }
Exemple #9
0
 public TextView(TextFormatter formatter)
 {
     Text   = new Text(this, formatter);
     Cursor = new TextCursor(Text, new ActionsManager());
 }
Exemple #10
0
 public bool Match(TextCursor cursor, ActionType type)
 {
     return(cursor == Cursor && type == Type && AfterSelection == cursor.Selection && AfterLocation == cursor.Location);
 }