public TerminalEmulator(int cols, int lines) { _inv_lock = new object(); _font = new FontGroup(new Font[] { new UnicodeFont(new System.Drawing.Font("Consolas", 16.0F), new PointF()) }, new SizeF(10.0F, 20.0F)); _chars = new TerminalChars(this, cols, lines); SetStyle(ControlStyles.ResizeRedraw, true); DoubleBuffered = true; InitializeComponent(); }
internal TerminalChars(TerminalEmulator parent, int cols, int lines, TerminalChars src) { _parent = parent; _size.col = cols; _size.line = lines; _char = new TerminalChar[_size.line, _size.col]; am = src.am; fg = src.fg; bg = src.bg; for (int i = 0; i < Math.Min(_size.line, src._size.line); i++) { for (int j = 0; j < Math.Min(_size.col, src._size.col); j++) { _char[i, j] = src._char[i, j]; } for (int j = src._size.col; j < _size.col; j++) { _char[i, j] = new TerminalCharSpace(bg); } } for (int i = src._size.line; i < _size.line; i++) { for (int j = 0; j < _size.col; j++) { _char[i, j] = _char[i, j] = new TerminalCharSpace(bg); } } }
protected void DrawChar(TerminalChars chars, Graphics graphics, int i, int j, bool draw_second_part) { if (chars[i, j].DoubleWidth) // a width char { SizeF t = Font.Size; t.Width *= 2; RectangleF rec = new RectangleF(new PointF(j * Font.Size.Width, i * Font.Size.Height), t); chars[i, j].Draw(graphics, Font, rec); } else if (draw_second_part && chars[i, j].Partial) // second part of width char { SizeF t = Font.Size; t.Width *= 2; RectangleF rec = new RectangleF(new PointF((j - 1) * Font.Size.Width, i * Font.Size.Height), t); chars[i, j - 1].Draw(graphics, Font, rec); } else // a normal char { RectangleF rec = new RectangleF(new PointF(j * Font.Size.Width, i * Font.Size.Height), Font.Size); chars[i, j].Draw(graphics, Font, rec); } }
internal void invalidate(TerminalChars.Cursor pos) { invalidate(pos.line, pos.col); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_IME_STARTCOMPOSITION: _ime = new TerminalChars(this, Color.Red, Color.Transparent, cols, lines); return; case WM_IME_ENDCOMPOSITION: _ime = null; Invalidate(); return; case WM_IME_COMPOSITION: if (_ime != null) { IntPtr hIMC = ImmGetContext(Handle); if ((((int)m.LParam) & GCS_COMPSTR) != 0) { int dwSize = ImmGetCompositionString(hIMC, GCS_COMPSTR, null, 0); byte[] bs = new byte[dwSize]; ImmGetCompositionString(hIMC, GCS_COMPSTR, bs, bs.Length); string str = UnicodeEncoding.Unicode.GetString(bs); _ime.clear(); _ime.cursor = _chars._cursor; _ime.bg = Color.Black; _ime.fg = Color.Red; foreach (char c in str) { _ime.put(c, 0); } _ime.bg = Color.Transparent; _ime.fg = Color.Red; } if ((((int)m.LParam) & GCS_CURSORPOS) != 0) { _ime.cursor = _chars._cursor; for (int pos = ImmGetCompositionString(hIMC, GCS_CURSORPOS, null, 0); pos != 0; --pos) { _ime.advanceVisible(); } } CANDIDATEFORM l = new CANDIDATEFORM(); l.dwIndex = 0; l.dwStyle = CFS_CANDIDATEPOS; l.ptCurrentPos.X = (int)(10 + _ime.cursor.col * Font.Size.Width); l.ptCurrentPos.Y = (int)(10 + _ime.cursor.line * Font.Size.Height); ImmSetCandidateWindow(hIMC, ref l); ImmReleaseContext(Handle, hIMC); } base.WndProc(ref m); return; default: base.WndProc(ref m); return; } }
private void SelectRange(out TerminalChars.Cursor begin, out TerminalChars.Cursor end) { if (_begin.GreaterThan(_end)) { begin = _end; end = _begin; } else { begin = _begin; end = _end; } if (_chars[begin].Partial) begin.col -= 1; if (_chars[end].DoubleWidth) end.col += 1; }