SerialConnect: use ints for font metrics

As pointed by Ingo, using a float here is useless because we want each
line to be the same integer number of pixels. Now thigs are drawn
properly and the view has the exact same size as Terminal's one (tested
with font sizes 10 and 18, so different leading values don't seem to be
a problem).

Thanks for reviewing!
This commit is contained in:
Adrien Destugues 2014-08-13 08:16:03 +02:00
parent 6288f7b453
commit c38dd82ded
2 changed files with 6 additions and 7 deletions

View File

@ -141,9 +141,9 @@ void
TermView::GetPreferredSize(float* width, float* height) TermView::GetPreferredSize(float* width, float* height)
{ {
if (width != NULL) if (width != NULL)
*width = kDefaultWidth * fFontWidth + 2 * kBorderSpacing; *width = kDefaultWidth * fFontWidth + 2 * kBorderSpacing - 1;
if (height != NULL) if (height != NULL)
*height = kDefaultHeight * fFontHeight + 2 * kBorderSpacing; *height = kDefaultHeight * fFontHeight + 2 * kBorderSpacing - 1;
} }
@ -194,7 +194,8 @@ TermView::_Init()
font_height height; font_height height;
GetFontHeight(&height); GetFontHeight(&height);
fFontHeight = height.ascent + height.descent + height.leading + 1; fFontHeight = ceilf(height.ascent) + ceilf(height.descent)
+ ceilf(height.leading);
fFontWidth = be_fixed_font->StringWidth("X"); fFontWidth = be_fixed_font->StringWidth("X");
fTerm = vterm_new(kDefaultHeight, kDefaultWidth); fTerm = vterm_new(kDefaultHeight, kDefaultWidth);
@ -338,8 +339,6 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells)
BScrollBar* scrollBar = ScrollBar(B_VERTICAL); BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
if (scrollBar != NULL) { if (scrollBar != NULL) {
// FIXME this is not exactly right, it's off by a few pixels so one step
// isn't exactly equal to one line.
float range = (fScrollBuffer.CountItems() + availableRows) * fFontHeight; float range = (fScrollBuffer.CountItems() + availableRows) * fFontHeight;
scrollBar->SetRange(availableRows * fFontHeight - range, 0.0f); scrollBar->SetRange(availableRows * fFontHeight - range, 0.0f);
// TODO we need to adjust this in FrameResized, as availableRows can // TODO we need to adjust this in FrameResized, as availableRows can

View File

@ -49,8 +49,8 @@ class TermView: public BView
VTerm* fTerm; VTerm* fTerm;
VTermScreen* fTermScreen; VTermScreen* fTermScreen;
BList fScrollBuffer; BList fScrollBuffer;
float fFontWidth; int fFontWidth;
float fFontHeight; int fFontHeight;
static const VTermScreenCallbacks sScreenCallbacks; static const VTermScreenCallbacks sScreenCallbacks;