SerialConnect: fix font metrics for good.

* Set the background color in AttachedToWindow to avoid white lines in
initial drawing,
* Fix computation of font size again so lines don't overlap.

Note: lines are apparently spaced 1px less than in Terminal. But they
don't seem to touch or overlap each other in SerialConnect.
This commit is contained in:
Adrien Destugues
2014-08-11 23:14:41 +02:00
parent c9a4d52483
commit b54c6f2e65
+21 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2012, Adrien Destugues, [email protected] * Copyright 2012-2014, Adrien Destugues, [email protected]
* Distributed under the terms of the MIT licence. * Distributed under the terms of the MIT licence.
*/ */
@@ -23,7 +23,7 @@ TermView::TermView()
font_height height; font_height height;
GetFontHeight(&height); GetFontHeight(&height);
fFontHeight = height.ascent + height.descent + height.leading; fFontHeight = height.ascent + height.descent + height.leading + 1;
fFontWidth = be_fixed_font->StringWidth("X"); fFontWidth = be_fixed_font->StringWidth("X");
fTerm = vterm_new(kDefaultHeight, kDefaultWidth); fTerm = vterm_new(kDefaultHeight, kDefaultWidth);
@@ -44,6 +44,20 @@ TermView::~TermView()
void TermView::AttachedToWindow() void TermView::AttachedToWindow()
{ {
MakeFocus(); MakeFocus();
VTermScreenCell cell;
VTermPos firstPos;
firstPos.row = 0;
firstPos.col = 0;
vterm_screen_get_cell(fTermScreen, firstPos, &cell);
rgb_color background;
background.red = cell.bg.red;
background.green = cell.bg.green;
background.blue = cell.bg.blue;
background.alpha = 255;
SetViewColor(background);
} }
@@ -61,7 +75,7 @@ void 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; float x = updatedChars.start_col * fFontWidth + kBorderSpacing;
float y = pos.row * fFontHeight + height.ascent + kBorderSpacing + 1; float y = pos.row * fFontHeight + height.ascent + kBorderSpacing;
MovePenTo(x, y); MovePenTo(x, y);
for (pos.col = updatedChars.start_col; for (pos.col = updatedChars.start_col;
@@ -104,7 +118,8 @@ void TermView::Draw(BRect updateRect)
BPoint penLocation = PenLocation(); BPoint penLocation = PenLocation();
FillRect(BRect(penLocation.x, penLocation.y - height.ascent, FillRect(BRect(penLocation.x, penLocation.y - height.ascent,
penLocation.x + cell.width * fFontWidth, penLocation.y + 1), penLocation.x + cell.width * fFontWidth - 1,
penLocation.y + height.descent + height.leading - 1),
B_SOLID_LOW); B_SOLID_LOW);
if (cell.chars[0] == 0) { if (cell.chars[0] == 0) {
@@ -211,7 +226,7 @@ BRect TermView::GlyphsToPixels(const VTermRect& glyphs) const
rect.right = glyphs.end_col * fFontWidth; rect.right = glyphs.end_col * fFontWidth;
rect.OffsetBy(kBorderSpacing, kBorderSpacing); rect.OffsetBy(kBorderSpacing, kBorderSpacing);
/* #if 0
printf( printf(
"TOP %d ch > %f px (%f)\n" "TOP %d ch > %f px (%f)\n"
"BTM %d ch > %f px\n" "BTM %d ch > %f px\n"
@@ -222,7 +237,7 @@ BRect TermView::GlyphsToPixels(const VTermRect& glyphs) const
glyphs.start_col, rect.left, fFontWidth, glyphs.start_col, rect.left, fFontWidth,
glyphs.end_col, rect.right glyphs.end_col, rect.right
); );
*/ #endif
return rect; return rect;
} }