SerialConnect: draw the cursor.

* Drawn as "inverse video" for now.
* Should use VTerm state to get the cursor shape (rect, underline or
left line)
* Should also handle blinking if enabled, and visibility.
This commit is contained in:
Adrien Destugues 2014-08-13 10:02:32 +02:00
parent ea7fbc874f
commit 30636d2eb6
2 changed files with 41 additions and 5 deletions

View File

@ -74,6 +74,9 @@ TermView::Draw(BRect updateRect)
font_height height;
GetFontHeight(&height);
VTermPos cursorPos;
vterm_state_get_cursorpos(vterm_obtain_state(fTerm), &cursorPos);
for (pos.row = updatedChars.start_row; pos.row <= updatedChars.end_row;
pos.row++) {
float x = updatedChars.start_col * fFontWidth + kBorderSpacing;
@ -96,7 +99,8 @@ TermView::Draw(BRect updateRect)
background.blue = cell.bg.blue;
background.alpha = 255;
if (cell.attrs.reverse) {
if ((cell.attrs.reverse != 0) ^ (pos.col == cursorPos.col
&& pos.row == cursorPos.row)) {
SetLowColor(foreground);
SetViewColor(foreground);
SetHighColor(background);
@ -107,9 +111,10 @@ TermView::Draw(BRect updateRect)
}
BPoint penLocation = PenLocation();
FillRect(BRect(penLocation.x, penLocation.y - height.ascent,
FillRect(BRect(penLocation.x,
penLocation.y - ceil(height.ascent) + 1,
penLocation.x + cell.width * fFontWidth - 1,
penLocation.y + height.descent + height.leading),
penLocation.y + ceil(height.descent) + ceil(height.leading)),
B_SOLID_LOW);
if (cell.chars[0] == 0) {
@ -308,11 +313,28 @@ TermView::_GetCell(VTermPos pos, VTermScreenCell& cell)
void
TermView::_Damage(VTermRect rect)
{
// Invalidate();
Invalidate(_GlyphsToPixels(rect));
}
void
TermView::_MoveCursor(VTermPos pos, VTermPos oldPos, int visible)
{
VTermRect r;
r.start_row = pos.row;
r.start_col = pos.col;
r.end_col = pos.col + 1;
r.end_row = pos.row + 1;
Invalidate(_GlyphsToPixels(r));
r.start_row = oldPos.row;
r.start_col = oldPos.col;
r.end_col = oldPos.col + 1;
r.end_row = oldPos.row + 1;
Invalidate(_GlyphsToPixels(r));
}
void
TermView::_PushLine(int cols, const VTermScreenCell* cells)
{
@ -359,6 +381,16 @@ TermView::_Damage(VTermRect rect, void* user)
}
/* static */ int
TermView::_MoveCursor(VTermPos pos, VTermPos oldPos, int visible, void* user)
{
TermView* view = (TermView*)user;
view->_MoveCursor(pos, oldPos, visible);
return 0;
}
/* static */ int
TermView::_PushLine(int cols, const VTermScreenCell* cells, void* user)
{
@ -373,7 +405,7 @@ const
VTermScreenCallbacks TermView::sScreenCallbacks = {
&TermView::_Damage,
/*.moverect =*/ NULL,
/*.movecursor =*/ NULL,
&TermView::_MoveCursor,
/*.settermprop =*/ NULL,
/*.setmousefunc =*/ NULL,
/*.bell =*/ NULL,

View File

@ -37,9 +37,13 @@ class TermView: public BView
void _GetCell(VTermPos pos, VTermScreenCell& cell);
void _Damage(VTermRect rect);
void _MoveCursor(VTermPos pos, VTermPos oldPos,
int visible);
void _PushLine(int cols, const VTermScreenCell* cells);
static int _Damage(VTermRect rect, void* user);
static int _MoveCursor(VTermPos pos, VTermPos oldPos,
int visible, void* user);
static int _PushLine(int cols, const VTermScreenCell* cells,
void* user);
static int _PopLine(int cols, const VTermScreenCell* cells,