public bool KeyPress(char c, CharacterArea area, CharacterView view) { switch ((int)c) { case 8: area.TypeBackspace(view); return(true); case 9: break; case 10: return(false); case 13: area.TypeEnter(view); return(true); case 27: area.Selections.Clear(); return(false); } if (!area.TypeCharacter(c, view, false)) { return(false); } area.MoveLeft(view, false); return(true); }
public void Indent(CharacterArea area, CharacterView view) { for (var t = 0; t < 3; t++) { area.TypeCharacter(' ', view, true); area.MoveLeft(view, t == 2); } }
public void KeyDown(Keys keyCode, CharacterArea area, CharacterView view) { switch (keyCode) { case Keys.Delete: area.TypeDelete(view); break; case Keys.Down: area.MoveDown(view, false); break; case Keys.Up: area.MoveUp(view); break; case Keys.Left: area.MoveRight(view, false); break; case Keys.Right: area.MoveLeft(view, false); break; case Keys.Home: area.MoveToHome(view); break; case Keys.End: area.MoveToEnd(view); break; case Keys.PageUp: area.PageUp(view); break; case Keys.PageDown: area.PageDown(view); break; } }
public void Outdent(CharacterArea area, CharacterView view) { if (area.CurrentRowLength <= 0) { return; } for (var t = 0; t < 3; t++) { if (area.CurrentRow[0] != ' ') { continue; } area.DeleteAt(0, area.CursorY); if (area.CursorX > 0) { area.CursorX--; } } var offsetX = _options.ScrollAhead && area.CursorX > 0 ? -1 : 0; view.EnsurePositionIsVisible(area.CursorX + offsetX, area.CursorY); }
public void Draw(CharacterArea area, Graphics g, Font secondaryFont, int viewportX, int viewportY, int viewportWidth, int viewportHeight) { var xpos = (double)viewportX; var ypos = (double)viewportY; var charWidth = viewportWidth / (double)ZoomLevels.GetCurrentZoom().Columns; var charHeight = viewportHeight / (double)ZoomLevels.GetCurrentZoom().Rows; var physicalWidth = (float)charWidth; var physicalHeight = (float)charHeight; using (var background = new SolidBrush(_options.BackgroundColor)) { using (var foreground = new SolidBrush(_options.CursorColor)) { using (var selection = new SolidBrush(_options.SelectionColor)) { g.Clear(Color.Black); var z = g.MeasureString("l", Font); var charOffsetX = (float)(charWidth / 2 - z.Width / 2); var charOffsetY = (float)(charHeight / 2 - z.Height / 2); for (var y = 0; y < ZoomLevels.GetCurrentZoom().Rows; y++) { var rowSelection = area.GetRowSelection(y + OffsetY); var physicalY = (float)ypos; for (var x = 0; x < ZoomLevels.GetCurrentZoom().Columns; x++) { var physicalX = (float)xpos; var s = area.GetCharacterAt(x + OffsetX, y + OffsetY); if (rowSelection.CharacterIsSelected(x + OffsetX)) { g.FillRectangle(selection, physicalX, physicalY, physicalWidth, physicalHeight); } var charX = physicalX + charOffsetX; var charY = physicalY + charOffsetY; if (x + OffsetX == area.CursorX && y + OffsetY == area.CursorY) { g.FillRectangle(foreground, physicalX, physicalY, physicalWidth, physicalHeight); if (!string.IsNullOrWhiteSpace(s)) { g.DrawString(s, Font, background, charX, charY); } } else { g.DrawString(s, Font, foreground, charX, charY); } #if DEBUG var whitespace = area.GetCharacterOrWhitespaceAt(x + OffsetX, y + OffsetY); if (whitespace != null) { if (whitespace == " ") { g.FillRectangle(Brushes.Yellow, (physicalX + (int)(charWidth / 2)) - 1, (physicalY + (int)(charHeight / 2)) - 1, 2, 2); } else if (whitespace[0] == 9) { g.FillRectangle(Brushes.Pink, (physicalX + (int)(charWidth / 2)) - 1, (physicalY + (int)(charHeight / 2)) - 1, 2, 2); } } #endif xpos += charWidth; } xpos = viewportX; ypos += charHeight; } } } } if (!_options.ShowCurrentLineNumber && !_options.ShowTotalLines && !_options.ShowColumnNumber) { return; } string row; if (_options.ShowColumnNumber && (_options.ShowCurrentLineNumber || _options.ShowTotalLines)) { row = $"{area.CursorX + 1}, "; } else if (_options.ShowColumnNumber) { row = $"{area.CursorX + 1}"; } else { row = ""; } row += _options.ShowCurrentLineNumber && _options.ShowTotalLines ? $"{area.CursorY + 1}/{area.RowCount}" : _options.ShowCurrentLineNumber ? $"{area.CursorY + 1}" : $"{area.RowCount}"; var m = g.MeasureString(row, secondaryFont); const int margin = 3; using (var b = new SolidBrush(Color.FromArgb(50, 255, 255, 255))) g.DrawString(row, secondaryFont, b, viewportX + viewportWidth - m.Width - margin, viewportY + margin); }