From 902145b698d838d63c0bf7db3fee22b41e0d23bf Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 31 Jul 2014 23:10:16 +0200 Subject: [PATCH] Removed Surface::write method All it did was redirect to Font::write, so it's better to call that method directly. --- src/background.cpp | 2 +- src/browsedialog.cpp | 2 +- src/contextmenu.cpp | 12 ++++++------ src/dialog.cpp | 6 ++---- src/gmenu2x.cpp | 6 +++--- src/helppopup.cpp | 14 +++++++------- src/iconbutton.cpp | 2 +- src/inputdialog.cpp | 8 ++++---- src/link.cpp | 2 +- src/linkapp.cpp | 4 ++-- src/menu.cpp | 4 ++-- src/menusetting.cpp | 2 +- src/menusettingbool.cpp | 2 +- src/menusettingint.cpp | 2 +- src/menusettingrgba.cpp | 8 ++++---- src/menusettingstringbase.cpp | 2 +- src/messagebox.cpp | 2 +- src/selector.cpp | 4 ++-- src/surface.h | 6 ------ src/textmanualdialog.cpp | 2 +- src/wallpaperdialog.cpp | 2 +- 21 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/background.cpp b/src/background.cpp index 05e41af..e19a6ca 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -18,7 +18,7 @@ void Background::paint(Surface &s) { sc["bgmain"]->blit(&s, 0, 0); - s.write(&font, clock.getTime(), + font.write(&s, clock.getTime(), s.width() / 2, gmenu2x.bottomBarTextY, Font::HAlignCenter, Font::VAlignMiddle); diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index bd3207e..875b9d4 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -272,7 +272,7 @@ void BrowseDialog::paint() icon = iconFile; } icon->blit(gmenu2x->s, 5, offsetY); - gmenu2x->s->write(gmenu2x->font, (*fl)[i], 24, offsetY + rowHeight / 2, + gmenu2x->font->write(gmenu2x->s, (*fl)[i], 24, offsetY + rowHeight / 2, Font::HAlignLeft, Font::VAlignMiddle); if (ts.available() && ts.pressed() diff --git a/src/contextmenu.cpp b/src/contextmenu.cpp index fc69f8b..b4c248f 100644 --- a/src/contextmenu.cpp +++ b/src/contextmenu.cpp @@ -25,7 +25,7 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu) , selected(0) { Translator &tr = gmenu2x.tr; - Font *font = gmenu2x.font; + Font& font = *gmenu2x.font; LinkApp* app = menu.selLinkApp(); // Init menu options: @@ -78,10 +78,10 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu) // Compute bounding box. int w = 0; for (auto option : options) { - w = std::max(w, font->getTextWidth(option->text)); + w = std::max(w, font.getTextWidth(option->text)); } w += 23; - const int h = (font->getLineSpacing() + 2) * options.size() + 8; + const int h = (font.getLineSpacing() + 2) * options.size() + 8; box = { static_cast((gmenu2x.resX - w) / 2), static_cast((gmenu2x.resY - h) / 2), @@ -105,7 +105,7 @@ bool ContextMenu::runAnimations() void ContextMenu::paint(Surface &s) { - Font *font = gmenu2x.font; + Font& font = *gmenu2x.font; // Darken background. s.box(0, 0, gmenu2x.resX, gmenu2x.resY, 0, 0, 0, fadeAlpha); @@ -116,7 +116,7 @@ void ContextMenu::paint(Surface &s) gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BORDER]); // Draw selection background. - const int h = font->getLineSpacing(); + const int h = font.getLineSpacing(); SDL_Rect selbox = { static_cast(box.x + 4), static_cast(box.y + 4 + (h + 2) * selected), @@ -127,7 +127,7 @@ void ContextMenu::paint(Surface &s) // List options. for (uint i = 0; i < options.size(); i++) { - s.write(font, options[i]->text, box.x + 12, box.y + 5 + (h + 2) * i, + font.write(&s, options[i]->text, box.x + 12, box.y + 5 + (h + 2) * i, Font::HAlignLeft, Font::VAlignTop); } } diff --git a/src/dialog.cpp b/src/dialog.cpp index dc85de1..5c01c01 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -31,7 +31,7 @@ void Dialog::writeTitle(const std::string &title, Surface *s) { if (s==NULL) s = gmenu2x->s; - s->write(gmenu2x->font, title, 40, 0, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(s, title, 40, 0, Font::HAlignLeft, Font::VAlignTop); } void Dialog::writeSubTitle(const std::string &subtitle, Surface *s) @@ -39,7 +39,5 @@ void Dialog::writeSubTitle(const std::string &subtitle, Surface *s) if (s==NULL) s = gmenu2x->s; std::string wrapped = gmenu2x->font->wordWrap(subtitle, gmenu2x->resX - 48); - s->write(gmenu2x->font, wrapped, 40, gmenu2x->skinConfInt["topBarHeight"] - gmenu2x->font->getTextHeight(wrapped), Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(s, wrapped, 40, gmenu2x->skinConfInt["topBarHeight"] - gmenu2x->font->getTextHeight(wrapped), Font::HAlignLeft, Font::VAlignTop); } - - diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 232b136..5412978 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -313,7 +313,7 @@ void GMenu2X::initBG() { if (sd) sd->blit(bgmain, 3, bottomBarIconY); string df = getDiskFree(getHome().c_str()); - bgmain->write(font, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle); + font->write(bgmain, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle); delete sd; cpuX = font->getTextWidth(df)+32; @@ -1058,7 +1058,7 @@ int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); re.w = sc["imgs/buttons/"+btn+".png"]->width() + 3; - s->write(font, text, x+re.w, y, Font::HAlignLeft, Font::VAlignMiddle); + font->write(s, text, x+re.w, y, Font::HAlignLeft, Font::VAlignMiddle); re.w += font->getTextWidth(text); } return x+re.w+6; @@ -1070,7 +1070,7 @@ int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text, x -= 16; sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); x -= 3; - s->write(font, text, x, y, Font::HAlignRight, Font::VAlignMiddle); + font->write(s, text, x, y, Font::HAlignRight, Font::VAlignMiddle); return x-6-font->getTextWidth(text); } return x-6; diff --git a/src/helppopup.cpp b/src/helppopup.cpp index 1501b24..1e246ab 100644 --- a/src/helppopup.cpp +++ b/src/helppopup.cpp @@ -12,7 +12,7 @@ HelpPopup::HelpPopup(GMenu2X &gmenu2x) } void HelpPopup::paint(Surface &s) { - Font *font = gmenu2x.font; + Font& font = *gmenu2x.font; Translator &tr = gmenu2x.tr; int helpBoxHeight = 154; @@ -20,13 +20,13 @@ void HelpPopup::paint(Surface &s) { gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BG]); s.rectangle(12, 52, 296, helpBoxHeight, gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BORDER]); - s.write(font, tr["CONTROLS"], 20, 60); + font.write(&s, tr["CONTROLS"], 20, 60); #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) - s.write(font, tr["A: Launch link / Confirm action"], 20, 80); - s.write(font, tr["B: Show this help menu"], 20, 95); - s.write(font, tr["L, R: Change section"], 20, 110); - s.write(font, tr["SELECT: Show contextual menu"], 20, 155); - s.write(font, tr["START: Show options menu"], 20, 170); + font.write(&s, tr["A: Launch link / Confirm action"], 20, 80); + font.write(&s, tr["B: Show this help menu"], 20, 95); + font.write(&s, tr["L, R: Change section"], 20, 110); + font.write(&s, tr["SELECT: Show contextual menu"], 20, 155); + font.write(&s, tr["START: Show options menu"], 20, 170); #endif } diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index 8254fef..c11ad93 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -70,7 +70,7 @@ void IconButton::paint(Surface *s) { iconSurface->blit(s, iconRect); } if (!label.empty()) { - s->write(gmenu2x->font, label, labelRect.x, labelRect.y, + gmenu2x->font->write(s, label, labelRect.x, labelRect.y, Font::HAlignLeft, Font::VAlignMiddle); } } diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index 8e6df7d..e770f81 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -168,7 +168,7 @@ bool InputDialog::exec() { gmenu2x->s->rectangle(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - gmenu2x->s->write(gmenu2x->font, input, box.x + 5, box.y + box.h - 2, + gmenu2x->font->write(gmenu2x->s, input, box.x + 5, box.y + box.h - 2, Font::HAlignLeft, Font::VAlignBottom); curTick = SDL_GetTicks(); @@ -312,7 +312,7 @@ void InputDialog::drawVirtualKeyboard() { gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - gmenu2x->s->write(gmenu2x->font, charX, + gmenu2x->font->write(gmenu2x->s, charX, kbLeft + xc * KEY_WIDTH + KEY_WIDTH / 2 - 1, KB_TOP + l * KEY_HEIGHT + KEY_HEIGHT / 2, Font::HAlignCenter, Font::VAlignMiddle); @@ -332,7 +332,7 @@ void InputDialog::drawVirtualKeyboard() { selCol = 0; selRow = kb->size(); } - gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["Cancel"], + gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["Cancel"], (int)(160 - kbLength * KEY_WIDTH / 4), KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, Font::HAlignCenter, Font::VAlignMiddle); @@ -343,7 +343,7 @@ void InputDialog::drawVirtualKeyboard() { selCol = 1; selRow = kb->size(); } - gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"], + gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["OK"], (int)(160 + kbLength * KEY_WIDTH / 4), KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, Font::HAlignCenter, Font::VAlignMiddle); diff --git a/src/link.cpp b/src/link.cpp index 9a3c6b0..423548a 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -70,7 +70,7 @@ void Link::paint() { if (iconSurface) { iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32); } - gmenu2x->s->write(gmenu2x->font, getTitle(), iconX+16, rect.y + gmenu2x->skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom); + gmenu2x->font->write(gmenu2x->s, getTitle(), iconX+16, rect.y + gmenu2x->skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom); } void Link::paintHover() { diff --git a/src/linkapp.cpp b/src/linkapp.cpp index a8baa6a..43e5ba3 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -357,7 +357,7 @@ void LinkApp::drawRun() { else gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/ iconSurface->blit(gmenu2x->s,x,gmenu2x->halfY-16); - gmenu2x->s->write( gmenu2x->font, text, x+42, gmenu2x->halfY+1, Font::HAlignLeft, Font::VAlignMiddle ); + gmenu2x->font->write(gmenu2x->s, text, x+42, gmenu2x->halfY+1, Font::HAlignLeft, Font::VAlignMiddle ); gmenu2x->s->flip(); } @@ -458,7 +458,7 @@ void LinkApp::showManual() { ss << page+1; ss >> pageStatus; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; - gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); + gmenu2x->font->write(gmenu2x->s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); gmenu2x->s->flip(); repaint = false; diff --git a/src/menu.cpp b/src/menu.cpp index df5d368..8b8b063 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -222,7 +222,7 @@ void Menu::paint(Surface &s) { x += (((t * t) / linkWidth) * t) / linkWidth; } icon->blit(&s, x - 16, sectionLinkPadding, 32, 32); - s.write(&font, sections[j], x, topBarHeight - sectionLinkPadding, + font.write(&s, sections[j], x, topBarHeight - sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom); } sc.skinRes("imgs/section-l.png")->blit(&s, 0, 0); @@ -254,7 +254,7 @@ void Menu::paint(Surface &s) { } if (selLink()) { - s.write(&font, selLink()->getDescription(), + font.write(&s, selLink()->getDescription(), width / 2, height - bottomBarHeight + 2, Font::HAlignCenter, Font::VAlignBottom); } diff --git a/src/menusetting.cpp b/src/menusetting.cpp index 26d5c3a..8c88911 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -41,7 +41,7 @@ MenuSetting::~MenuSetting() void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) { - gmenu2x->s->write( gmenu2x->font, name, 5, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->font->write(gmenu2x->s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); } void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index 3909824..855b822 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -68,7 +68,7 @@ void MenuSettingBool::initButton() void MenuSettingBool::draw(int valueX, int y, int h) { MenuSetting::draw(valueX, y, h); - gmenu2x->s->write( gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->font->write(gmenu2x->s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); } bool MenuSettingBool::handleButtonPress(InputManager::Button button) diff --git a/src/menusettingint.cpp b/src/menusettingint.cpp index c6356df..8e16519 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -70,7 +70,7 @@ MenuSettingInt::MenuSettingInt( void MenuSettingInt::draw(int valueX, int y, int h) { MenuSetting::draw(valueX, y, h); - gmenu2x->s->write(gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(gmenu2x->s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); } bool MenuSettingInt::handleButtonPress(InputManager::Button button) diff --git a/src/menusettingrgba.cpp b/src/menusettingrgba.cpp index f7da467..b2ebc7a 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -56,10 +56,10 @@ void MenuSettingRGBA::draw(int valueX, int y, int h) { gmenu2x->s->rectangle( valueX, y + 1, h - 2, h - 2, 0,0,0,255 ); gmenu2x->s->rectangle( valueX + 1, y + 2, h - 4, h - 4, 255,255,255,255 ); gmenu2x->s->box( valueX + 2, y + 3, h - 6, h - 6, value() ); - gmenu2x->s->write( gmenu2x->font, "R: "+strR, valueX + h + 3, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "G: "+strG, valueX + h + 3 + COMPONENT_WIDTH, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "B: "+strB, valueX + h + 3 + COMPONENT_WIDTH * 2, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "A: "+strA, valueX + h + 3 + COMPONENT_WIDTH * 3, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->font->write(gmenu2x->s, "R: "+strR, valueX + h + 3, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(gmenu2x->s, "G: "+strG, valueX + h + 3 + COMPONENT_WIDTH, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(gmenu2x->s, "B: "+strB, valueX + h + 3 + COMPONENT_WIDTH * 2, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(gmenu2x->s, "A: "+strA, valueX + h + 3 + COMPONENT_WIDTH * 3, y, Font::HAlignLeft, Font::VAlignTop); } void MenuSettingRGBA::handleTS(int valueX, int y, int h) { diff --git a/src/menusettingstringbase.cpp b/src/menusettingstringbase.cpp index a5e19a7..449060b 100644 --- a/src/menusettingstringbase.cpp +++ b/src/menusettingstringbase.cpp @@ -40,7 +40,7 @@ MenuSettingStringBase::~MenuSettingStringBase() void MenuSettingStringBase::draw(int valueX, int y, int h) { MenuSetting::draw(valueX, y, h); - gmenu2x->s->write(gmenu2x->font, value(), valueX, y, + gmenu2x->font->write(gmenu2x->s, value(), valueX, y, Font::HAlignLeft, Font::VAlignTop); } diff --git a/src/messagebox.cpp b/src/messagebox.cpp index d5994ce..192015b 100644 --- a/src/messagebox.cpp +++ b/src/messagebox.cpp @@ -85,7 +85,7 @@ int MessageBox::exec() { if (gmenu2x->sc[icon]) { gmenu2x->sc[icon]->blitCenter( &bg, box.x + ICON_PADDING + ICON_DIMENSION / 2, box.y + ICON_PADDING + ICON_DIMENSION / 2 ); } - bg.write( gmenu2x->font, text, box.x + TEXT_PADDING + (gmenu2x->sc[icon] ? ICON_PADDING + ICON_DIMENSION : 0), box.y + (box.h - textHeight) / 2, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->font->write(&bg, text, box.x + TEXT_PADDING + (gmenu2x->sc[icon] ? ICON_PADDING + ICON_DIMENSION : 0), box.y + (box.h - textHeight) / 2, Font::HAlignLeft, Font::VAlignTop); int btnX = gmenu2x->halfX+box.w/2-6; for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) { diff --git a/src/selector.cpp b/src/selector.cpp index 3efd8f5..ba64bfe 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -124,11 +124,11 @@ int Selector::exec(int startSelection) { iY = i-firstElement; if (fl.isDirectory(i)) { gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, top + (iY * fontheight)); - gmenu2x->s->write(gmenu2x->font, fl[i], 21, + gmenu2x->font->write(gmenu2x->s, fl[i], 21, top + (iY * fontheight) + (fontheight / 2), Font::HAlignLeft, Font::VAlignMiddle); } else - gmenu2x->s->write(gmenu2x->font, titles[i - fl.dirCount()], 4, + gmenu2x->font->write(gmenu2x->s, titles[i - fl.dirCount()], 4, top + (iY * fontheight) + (fontheight / 2), Font::HAlignLeft, Font::VAlignMiddle); } diff --git a/src/surface.h b/src/surface.h index 5b7931c..d5ff751 100644 --- a/src/surface.h +++ b/src/surface.h @@ -75,12 +75,6 @@ public: void blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; void blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; - void write(Font *font, const std::string &text, int x, int y, - Font::HAlign halign = Font::HAlignLeft, - Font::VAlign valign = Font::VAlignTop) { - font->write(this, text, x, y, halign, valign); - } - void box(SDL_Rect re, RGBAColor c); void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) { box((SDL_Rect){ x, y, w, h }, c); diff --git a/src/textmanualdialog.cpp b/src/textmanualdialog.cpp index 25736cd..c0e3114 100644 --- a/src/textmanualdialog.cpp +++ b/src/textmanualdialog.cpp @@ -105,7 +105,7 @@ void TextManualDialog::exec() { ss << page+1; ss >> pageStatus; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; - gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); + gmenu2x->font->write(gmenu2x->s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); gmenu2x->s->flip(); diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 155daf1..7704e03 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -115,7 +115,7 @@ bool WallpaperDialog::exec() for (i = firstElement; i < wallpapers.size() && i < firstElement + nb_elements; i++) { iY = i-firstElement; - gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, + gmenu2x->font->write(gmenu2x->s, wallpapers[i], 5, top + (iY * fontheight), Font::HAlignLeft, Font::VAlignTop); }