SerialConnect: some simplifications
* Use integers for x and y coordinates in the draw loop, too * Simplify _GetCell by using the return value of vterm_screen_get_cell to detect out of bounds access, instead of testing for that manually.
This commit is contained in:
@@ -66,8 +66,8 @@ TermView::Draw(BRect updateRect)
|
|||||||
|
|
||||||
for (pos.row = updatedChars.start_row; pos.row <= updatedChars.end_row;
|
for (pos.row = updatedChars.start_row; pos.row <= updatedChars.end_row;
|
||||||
pos.row++) {
|
pos.row++) {
|
||||||
float x = updatedChars.start_col * fFontWidth + kBorderSpacing;
|
int x = updatedChars.start_col * fFontWidth + kBorderSpacing;
|
||||||
float y = pos.row * fFontHeight + height.ascent + kBorderSpacing;
|
int y = pos.row * fFontHeight + (int)ceil(height.ascent) + kBorderSpacing;
|
||||||
MovePenTo(x, y);
|
MovePenTo(x, y);
|
||||||
|
|
||||||
for (pos.col = updatedChars.start_col;
|
for (pos.col = updatedChars.start_col;
|
||||||
@@ -97,14 +97,14 @@ TermView::Draw(BRect updateRect)
|
|||||||
SetHighColor(foreground);
|
SetHighColor(foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
FillRect(BRect(x,
|
FillRect(BRect(x, y - ceil(height.ascent) + 1,
|
||||||
y - ceil(height.ascent) + 1,
|
|
||||||
x + cell.width * fFontWidth - 1,
|
x + cell.width * fFontWidth - 1,
|
||||||
y + ceil(height.descent) + ceil(height.leading)),
|
y + ceil(height.descent) + ceil(height.leading)),
|
||||||
B_SOLID_LOW);
|
B_SOLID_LOW);
|
||||||
|
|
||||||
if (cell.chars[0] == 0) {
|
if (cell.chars[0] == 0) {
|
||||||
x += fFontWidth;
|
x += fFontWidth;
|
||||||
|
MovePenTo(x, y);
|
||||||
pos.col ++;
|
pos.col ++;
|
||||||
} else {
|
} else {
|
||||||
char buffer[VTERM_MAX_CHARS_PER_CELL];
|
char buffer[VTERM_MAX_CHARS_PER_CELL];
|
||||||
@@ -112,7 +112,7 @@ TermView::Draw(BRect updateRect)
|
|||||||
VTERM_MAX_CHARS_PER_CELL);
|
VTERM_MAX_CHARS_PER_CELL);
|
||||||
|
|
||||||
DrawString(buffer);
|
DrawString(buffer);
|
||||||
x += StringWidth(buffer);
|
x += (int)ceil(StringWidth(buffer));
|
||||||
pos.col += cell.width;
|
pos.col += cell.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,35 +279,29 @@ TermView::_GlyphsToPixels(const int width, const int height) const
|
|||||||
void
|
void
|
||||||
TermView::_GetCell(VTermPos pos, VTermScreenCell& cell)
|
TermView::_GetCell(VTermPos pos, VTermScreenCell& cell)
|
||||||
{
|
{
|
||||||
int availableRows, availableCols;
|
// First handle cells from the normal screen
|
||||||
vterm_get_size(fTerm, &availableRows, &availableCols);
|
if (vterm_screen_get_cell(fTermScreen, pos, &cell) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (pos.col < 0 || pos.row < -kScrollBackSize || pos.col >= availableCols
|
// Try the scroll-back buffer
|
||||||
|| pos.row >= availableRows) {
|
if (pos.row < 0 && pos.col >= 0) {
|
||||||
// All cells outside the used terminal area are drawn with the same
|
|
||||||
// background color as the top-left one.
|
|
||||||
// TODO should they use the attributes of the closest neighbor instead?
|
|
||||||
VTermPos firstPos;
|
|
||||||
firstPos.row = 0;
|
|
||||||
firstPos.col = 0;
|
|
||||||
vterm_screen_get_cell(fTermScreen, firstPos, &cell);
|
|
||||||
cell.chars[0] = 0;
|
|
||||||
cell.width = 1;
|
|
||||||
} else if (pos.row < 0) {
|
|
||||||
// This is a cell from the scroll-back buffer
|
|
||||||
int offset = - pos.row - 1;
|
int offset = - pos.row - 1;
|
||||||
ScrollBufferItem* line = (ScrollBufferItem*)fScrollBuffer.ItemAt(offset);
|
ScrollBufferItem* line = (ScrollBufferItem*)fScrollBuffer.ItemAt(offset);
|
||||||
if (line == NULL || pos.col >= line->cols) {
|
if (line != NULL && pos.col < line->cols) {
|
||||||
VTermPos firstPos;
|
|
||||||
firstPos.row = 0;
|
|
||||||
firstPos.col = 0;
|
|
||||||
vterm_screen_get_cell(fTermScreen, firstPos, &cell);
|
|
||||||
cell.chars[0] = 0;
|
|
||||||
cell.width = 1;
|
|
||||||
} else
|
|
||||||
cell = line->cells[pos.col];
|
cell = line->cells[pos.col];
|
||||||
} else
|
return;
|
||||||
vterm_screen_get_cell(fTermScreen, pos, &cell);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All cells outside the used terminal area are drawn with the same
|
||||||
|
// background color as the top-left one.
|
||||||
|
// TODO should they use the attributes of the closest neighbor instead?
|
||||||
|
VTermPos firstPos;
|
||||||
|
firstPos.row = 0;
|
||||||
|
firstPos.col = 0;
|
||||||
|
vterm_screen_get_cell(fTermScreen, firstPos, &cell);
|
||||||
|
cell.chars[0] = 0;
|
||||||
|
cell.width = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user