mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-17 20:37:30 +02:00
Use the font's suggested line height instead of its ascent and descent.
In well-described fonts, this enables multi-line text (e.g. in manuals) to be more readable. The term "height" is also replaced with "line spacing" in Font's code.
This commit is contained in:
parent
349e758b3b
commit
099bd24556
@ -59,7 +59,7 @@ bool BrowseDialog::exec()
|
||||
fl->browse();
|
||||
|
||||
const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"];
|
||||
rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1
|
||||
rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
|
||||
rowHeight = constrain(rowHeight, 20, 40);
|
||||
numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
|
||||
clipRect = (SDL_Rect) {
|
||||
|
@ -81,7 +81,7 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu)
|
||||
w = std::max(w, font->getTextWidth(option->text));
|
||||
}
|
||||
w += 23;
|
||||
const int h = (font->getHeight() + 2) * options.size() + 8;
|
||||
const int h = (font->getLineSpacing() + 2) * options.size() + 8;
|
||||
box = {
|
||||
static_cast<Sint16>((gmenu2x.resX - w) / 2),
|
||||
static_cast<Sint16>((gmenu2x.resY - h) / 2),
|
||||
@ -116,7 +116,7 @@ void ContextMenu::paint(Surface &s)
|
||||
gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
|
||||
|
||||
// Draw selection background.
|
||||
const int h = font->getHeight();
|
||||
const int h = font->getLineSpacing();
|
||||
SDL_Rect selbox = {
|
||||
static_cast<Sint16>(box.x + 4),
|
||||
static_cast<Sint16>(box.y + 4 + (h + 2) * selected),
|
||||
@ -158,7 +158,7 @@ bool ContextMenu::handleButtonPress(InputManager::Button button) {
|
||||
bool ContextMenu::handleTouchscreen(Touchscreen &ts) {
|
||||
if (ts.inRect(box)) {
|
||||
int i = std::max(0, std::min(static_cast<int>(options.size()) - 1,
|
||||
(ts.getY() - (box.y + 4)) / (gmenu2x.font->getHeight() + 2)));
|
||||
(ts.getY() - (box.y + 4)) / (gmenu2x.font->getLineSpacing() + 2)));
|
||||
if (ts.released()) {
|
||||
options[i]->action();
|
||||
dismiss();
|
||||
|
10
src/font.cpp
10
src/font.cpp
@ -22,7 +22,7 @@ Font *Font::defaultFont()
|
||||
Font::Font(const std::string &path, unsigned int size)
|
||||
{
|
||||
font = nullptr;
|
||||
fontheight = 1;
|
||||
lineSpacing = 1;
|
||||
|
||||
/* Note: TTF_Init and TTF_Quit perform reference counting, so call them
|
||||
* both unconditionally for each font. */
|
||||
@ -38,7 +38,7 @@ Font::Font(const std::string &path, unsigned int size)
|
||||
return;
|
||||
}
|
||||
|
||||
fontheight = TTF_FontHeight(font);
|
||||
lineSpacing = TTF_FontLineSkip(font);
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
@ -76,7 +76,7 @@ void Font::write(Surface *surface, const string &text,
|
||||
|
||||
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
|
||||
writeLine(surface, it->c_str(), x, y, halign, valign);
|
||||
y += fontheight;
|
||||
y += lineSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,10 +102,10 @@ void Font::writeLine(Surface *surface, const char *text,
|
||||
case VAlignTop:
|
||||
break;
|
||||
case VAlignMiddle:
|
||||
y -= fontheight / 2;
|
||||
y -= lineSpacing / 2;
|
||||
break;
|
||||
case VAlignBottom:
|
||||
y -= fontheight;
|
||||
y -= lineSpacing;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,9 @@ public:
|
||||
return getTextWidth(text.c_str());
|
||||
}
|
||||
|
||||
int getHeight()
|
||||
int getLineSpacing()
|
||||
{
|
||||
return fontheight;
|
||||
return lineSpacing;
|
||||
}
|
||||
|
||||
void write(Surface *surface,
|
||||
@ -45,7 +45,7 @@ private:
|
||||
int x, int y, HAlign halign, VAlign valign);
|
||||
|
||||
TTF_Font *font;
|
||||
unsigned int fontheight;
|
||||
int lineSpacing;
|
||||
};
|
||||
|
||||
#endif /* FONT_H */
|
||||
|
@ -47,7 +47,7 @@ void IconButton::recalcRects() {
|
||||
static_cast<Sint16>(iconRect.x + iconRect.w + margin),
|
||||
static_cast<Sint16>(rect.y + h / 2),
|
||||
static_cast<Uint16>(gmenu2x->font->getTextWidth(label)),
|
||||
static_cast<Uint16>(gmenu2x->font->getHeight())
|
||||
static_cast<Uint16>(gmenu2x->font->getLineSpacing())
|
||||
};
|
||||
w += margin + labelRect.w;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ void InputDialog::setKeyboard(int kb) {
|
||||
|
||||
bool InputDialog::exec() {
|
||||
SDL_Rect box = {
|
||||
0, 60, 0, static_cast<Uint16>(gmenu2x->font->getHeight() + 4)
|
||||
0, 60, 0, static_cast<Uint16>(gmenu2x->font->getLineSpacing() + 4)
|
||||
};
|
||||
|
||||
Uint32 caretTick = 0, curTick;
|
||||
|
@ -158,7 +158,7 @@ void Link::setPosition(int x, int y) {
|
||||
|
||||
void Link::recalcCoordinates() {
|
||||
iconX = rect.x+(rect.w-32)/2;
|
||||
padding = (gmenu2x->skinConfInt["linkHeight"] - 32 - gmenu2x->font->getHeight()) / 3;
|
||||
padding = (gmenu2x->skinConfInt["linkHeight"] - 32 - gmenu2x->font->getLineSpacing()) / 3;
|
||||
}
|
||||
|
||||
void Link::run() {
|
||||
|
@ -205,7 +205,7 @@ void Menu::paint(Surface &s) {
|
||||
|
||||
// Paint section headers.
|
||||
s.box(width / 2 - linkWidth / 2, 0, linkWidth, topBarHeight, selectionBgColor);
|
||||
const uint sectionLinkPadding = (topBarHeight - 32 - font.getHeight()) / 3;
|
||||
const uint sectionLinkPadding = (topBarHeight - 32 - font.getLineSpacing()) / 3;
|
||||
const uint numSections = sections.size();
|
||||
for (int i = leftSection; i <= rightSection; i++) {
|
||||
uint j = (centerSection + numSections + i) % numSections;
|
||||
|
@ -36,7 +36,7 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon)
|
||||
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
|
||||
buttons[i] = "";
|
||||
buttonLabels[i] = "";
|
||||
buttonPositions[i].h = gmenu2x->font->getHeight();
|
||||
buttonPositions[i].h = gmenu2x->font->getLineSpacing();
|
||||
}
|
||||
|
||||
//Default enabled button
|
||||
@ -65,7 +65,7 @@ int MessageBox::exec() {
|
||||
bg.box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,200);
|
||||
|
||||
SDL_Rect box;
|
||||
box.h = gmenu2x->font->getHeight()*3 +4;
|
||||
box.h = gmenu2x->font->getLineSpacing()*3 +4;
|
||||
box.w = gmenu2x->font->getTextWidth(text) + 24 + (gmenu2x->sc[icon] != NULL ? 37 : 0);
|
||||
box.x = gmenu2x->halfX - box.w/2 -2;
|
||||
box.y = gmenu2x->halfY - box.h/2 -2;
|
||||
@ -73,12 +73,12 @@ int MessageBox::exec() {
|
||||
//outer box
|
||||
bg.box(box, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BG]);
|
||||
//draw inner rectangle
|
||||
bg.rectangle(box.x+2, box.y+2, box.w-4, box.h-gmenu2x->font->getHeight(),
|
||||
bg.rectangle(box.x+2, box.y+2, box.w-4, box.h-gmenu2x->font->getLineSpacing(),
|
||||
gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
|
||||
//icon+text
|
||||
if (gmenu2x->sc[icon] != NULL)
|
||||
gmenu2x->sc[icon]->blitCenter( &bg, box.x+25, box.y+gmenu2x->font->getHeight()+3 );
|
||||
bg.write( gmenu2x->font, text, box.x+(gmenu2x->sc[icon] != NULL ? 47 : 10), box.y+gmenu2x->font->getHeight()+3, Font::HAlignLeft, Font::VAlignMiddle );
|
||||
gmenu2x->sc[icon]->blitCenter( &bg, box.x+25, box.y+gmenu2x->font->getLineSpacing()+3 );
|
||||
bg.write( gmenu2x->font, text, box.x+(gmenu2x->sc[icon] != NULL ? 47 : 10), box.y+gmenu2x->font->getLineSpacing()+3, Font::HAlignLeft, Font::VAlignMiddle );
|
||||
|
||||
int btnX = gmenu2x->halfX+box.w/2-6;
|
||||
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
|
||||
|
@ -79,7 +79,7 @@ int Selector::exec(int startSelection) {
|
||||
unsigned int top, height;
|
||||
tie(top, height) = gmenu2x->getContentArea();
|
||||
|
||||
int fontheight = gmenu2x->font->getHeight();
|
||||
int fontheight = gmenu2x->font->getLineSpacing();
|
||||
if (link->getSelectorBrowser())
|
||||
fontheight = constrain(fontheight, 20, 40);
|
||||
unsigned int nb_elements = height / fontheight;
|
||||
|
@ -70,7 +70,7 @@ bool SettingsDialog::exec() {
|
||||
static_cast<Uint16>(gmenu2x->resX - 12),
|
||||
static_cast<Uint16>(clipRect.h)
|
||||
};
|
||||
uint rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1
|
||||
uint rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
|
||||
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
|
||||
|
||||
while (!close) {
|
||||
|
@ -80,7 +80,7 @@ void TextDialog::preProcess() {
|
||||
void TextDialog::drawText(vector<string> *text, unsigned int y,
|
||||
unsigned int firstRow, unsigned int rowsPerPage)
|
||||
{
|
||||
const int fontHeight = gmenu2x->font->getHeight();
|
||||
const int fontHeight = gmenu2x->font->getLineSpacing();
|
||||
|
||||
for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text->size(); i++) {
|
||||
const string &line = text->at(i);
|
||||
@ -117,7 +117,7 @@ void TextDialog::exec() {
|
||||
|
||||
bg.convertToDisplayFormat();
|
||||
|
||||
const int fontHeight = gmenu2x->font->getHeight();
|
||||
const int fontHeight = gmenu2x->font->getLineSpacing();
|
||||
unsigned int contentY, contentHeight;
|
||||
tie(contentY, contentHeight) = gmenu2x->getContentArea();
|
||||
const unsigned rowsPerPage = contentHeight / fontHeight;
|
||||
|
@ -89,7 +89,7 @@ void TextManualDialog::exec() {
|
||||
|
||||
bg.convertToDisplayFormat();
|
||||
|
||||
uint firstRow = 0, rowsPerPage = 180/gmenu2x->font->getHeight();
|
||||
uint firstRow = 0, rowsPerPage = 180/gmenu2x->font->getLineSpacing();
|
||||
stringstream ss;
|
||||
ss << pages.size();
|
||||
string spagecount;
|
||||
|
@ -84,7 +84,7 @@ bool WallpaperDialog::exec()
|
||||
unsigned int top, height;
|
||||
tie(top, height) = gmenu2x->getContentArea();
|
||||
|
||||
int fontheight = gmenu2x->font->getHeight();
|
||||
int fontheight = gmenu2x->font->getLineSpacing();
|
||||
unsigned int nb_elements = height / fontheight;
|
||||
|
||||
while (!close) {
|
||||
|
Loading…
Reference in New Issue
Block a user