From aff5f53f7d0e5388d1cbce84ab284aa4ffe9bbe6 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sun, 10 Aug 2014 04:26:59 +0200 Subject: [PATCH] Don't pass around naked Surface pointers when drawing Use references instead. --- src/background.cpp | 12 +++++----- src/background.h | 8 +++---- src/browsedialog.cpp | 24 ++++++++++--------- src/buttonbox.cpp | 8 ++++--- src/buttonbox.h | 2 +- src/contextmenu.cpp | 2 +- src/dialog.cpp | 13 ++++++---- src/dialog.h | 6 ++--- src/font.cpp | 14 +++++------ src/font.h | 4 ++-- src/gmenu2x.cpp | 28 +++++++++++----------- src/gmenu2x.h | 10 ++++---- src/helppopup.cpp | 18 +++++++------- src/helppopup.h | 8 +++---- src/iconbutton.cpp | 2 +- src/iconbutton.h | 3 +-- src/imagedialog.cpp | 2 +- src/inputdialog.cpp | 42 +++++++++++++++++--------------- src/link.cpp | 12 ++++++---- src/linkapp.cpp | 26 ++++++++++---------- src/menu.cpp | 14 +++++------ src/menusetting.cpp | 9 ++++--- src/menusettingbool.cpp | 3 ++- src/menusettingint.cpp | 3 ++- src/menusettingrgba.cpp | 16 +++++++------ src/menusettingstringbase.cpp | 3 ++- src/messagebox.cpp | 13 +++++----- src/selector.cpp | 45 ++++++++++++++++++----------------- src/settingsdialog.cpp | 16 +++++++------ src/surface.cpp | 18 +++++++------- src/surface.h | 8 +++---- src/textdialog.cpp | 29 ++++++++++++---------- src/textmanualdialog.cpp | 28 ++++++++++++---------- src/wallpaperdialog.cpp | 26 ++++++++++---------- 34 files changed, 255 insertions(+), 220 deletions(-) diff --git a/src/background.cpp b/src/background.cpp index e19a6ca..7b4d169 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -6,23 +6,23 @@ #include "gmenu2x.h" -Background::Background(GMenu2X &gmenu2x) +Background::Background(GMenu2X& gmenu2x) : gmenu2x(gmenu2x) , battery(gmenu2x.sc) { } -void Background::paint(Surface &s) { +void Background::paint(Surface& s) { Font &font = *gmenu2x.font; SurfaceCollection &sc = gmenu2x.sc; - sc["bgmain"]->blit(&s, 0, 0); + sc["bgmain"]->blit(s, 0, 0); - font.write(&s, clock.getTime(), + font.write(s, clock.getTime(), s.width() / 2, gmenu2x.bottomBarTextY, Font::HAlignCenter, Font::VAlignMiddle); - battery.getIcon().blit(&s, s.width() - 19, gmenu2x.bottomBarIconY); + battery.getIcon().blit(s, s.width() - 19, gmenu2x.bottomBarIconY); } bool Background::handleButtonPress(InputManager::Button button) { @@ -38,6 +38,6 @@ bool Background::handleButtonPress(InputManager::Button button) { } } -bool Background::handleTouchscreen(Touchscreen &/*ts*/) { +bool Background::handleTouchscreen(Touchscreen&) { return false; } diff --git a/src/background.h b/src/background.h index ced3470..98e3431 100644 --- a/src/background.h +++ b/src/background.h @@ -16,15 +16,15 @@ class GMenu2X; */ class Background : public Layer { public: - Background(GMenu2X &gmenu2x); + Background(GMenu2X& gmenu2x); // Layer implementation: - virtual void paint(Surface &s); + virtual void paint(Surface& s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen &ts); + virtual bool handleTouchscreen(Touchscreen& ts); private: - GMenu2X &gmenu2x; + GMenu2X& gmenu2x; Battery battery; Clock clock; }; diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index b679e02..5f5e039 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -224,18 +224,20 @@ void BrowseDialog::quit() void BrowseDialog::paint() { + Surface& s = *gmenu2x->s; + unsigned int i, iY; unsigned int firstElement, lastElement; unsigned int offsetY; Surface bg(gmenu2x->bg); - drawTitleIcon(&bg, "icons/explorer.png", true); - writeTitle(&bg, title); - writeSubTitle(&bg, subtitle); - buttonBox.paint(&bg, 5); + drawTitleIcon(bg, "icons/explorer.png", true); + writeTitle(bg, title); + writeSubTitle(bg, subtitle); + buttonBox.paint(bg, 5); bg.convertToDisplayFormat(); - bg.blit(gmenu2x->s,0,0); + bg.blit(s, 0, 0); // TODO(MtH): I have no idea what the right value of firstElement would be, // but originally it was undefined and that is never a good idea. @@ -249,7 +251,7 @@ void BrowseDialog::paint() //Selection const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; iY = topBarHeight + 1 + (selected - firstElement) * rowHeight; - gmenu2x->s->box(2, iY, gmenu2x->resX - 12, rowHeight - 1, + s.box(2, iY, gmenu2x->resX - 12, rowHeight - 1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); lastElement = firstElement + numRows; @@ -259,7 +261,7 @@ void BrowseDialog::paint() offsetY = topBarHeight + 1; //Files & Directories - gmenu2x->s->setClipRect(clipRect); + s.setClipRect(clipRect); for (i = firstElement; i < lastElement; i++) { Surface *icon; if (fl->isDirectory(i)) { @@ -271,8 +273,8 @@ void BrowseDialog::paint() } else { icon = iconFile; } - icon->blit(gmenu2x->s, 5, offsetY); - gmenu2x->font->write(gmenu2x->s, (*fl)[i], 24, offsetY + rowHeight / 2, + icon->blit(s, 5, offsetY); + gmenu2x->font->write(s, (*fl)[i], 24, offsetY + rowHeight / 2, Font::HAlignLeft, Font::VAlignMiddle); if (ts.available() && ts.pressed() @@ -283,8 +285,8 @@ void BrowseDialog::paint() offsetY += rowHeight; } - gmenu2x->s->clearClipRect(); + s.clearClipRect(); gmenu2x->drawScrollBar(numRows,fl->size(), firstElement); - gmenu2x->s->flip(); + s.flip(); } diff --git a/src/buttonbox.cpp b/src/buttonbox.cpp index c04d057..4a1265e 100644 --- a/src/buttonbox.cpp +++ b/src/buttonbox.cpp @@ -22,14 +22,16 @@ void ButtonBox::clear() buttons.clear(); } -void ButtonBox::paint(Surface *s, unsigned int posX) +void ButtonBox::paint(Surface& s, unsigned int posX) { - for (auto button : buttons) + for (auto button : buttons) { posX = gmenu2x->drawButton(s, button, posX); + } } void ButtonBox::handleTS() { - for (auto button : buttons) + for (auto button : buttons) { button->handleTS(); + } } diff --git a/src/buttonbox.h b/src/buttonbox.h index b4442cf..caa918f 100644 --- a/src/buttonbox.h +++ b/src/buttonbox.h @@ -16,7 +16,7 @@ public: void add(IconButton *button); void clear(); - void paint(Surface *s, unsigned int posX); + void paint(Surface& s, unsigned int posX); void handleTS(); private: diff --git a/src/contextmenu.cpp b/src/contextmenu.cpp index b4c248f..27bec1a 100644 --- a/src/contextmenu.cpp +++ b/src/contextmenu.cpp @@ -127,7 +127,7 @@ void ContextMenu::paint(Surface &s) // List options. for (uint i = 0; i < options.size(); i++) { - font.write(&s, 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 af9ec9a..2baad6b 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -8,7 +8,7 @@ Dialog::Dialog(GMenu2X *gmenu2x) : gmenu2x(gmenu2x) { } -void Dialog::drawTitleIcon(Surface *s, const std::string &icon, bool skinRes) +void Dialog::drawTitleIcon(Surface& s, const std::string &icon, bool skinRes) { Surface *i = NULL; if (!icon.empty()) { @@ -21,16 +21,19 @@ void Dialog::drawTitleIcon(Surface *s, const std::string &icon, bool skinRes) if (i==NULL) i = gmenu2x->sc.skinRes("icons/generic.png"); - i->blit(s,4,(gmenu2x->skinConfInt["topBarHeight"]-32)/2); + i->blit(s, 4, (gmenu2x->skinConfInt["topBarHeight"] - 32) / 2); } -void Dialog::writeTitle(Surface *s, const std::string &title) +void Dialog::writeTitle(Surface& s, const std::string &title) { gmenu2x->font->write(s, title, 40, 0, Font::HAlignLeft, Font::VAlignTop); } -void Dialog::writeSubTitle(Surface *s, const std::string &subtitle) +void Dialog::writeSubTitle(Surface& s, const std::string &subtitle) { std::string wrapped = gmenu2x->font->wordWrap(subtitle, gmenu2x->resX - 48); - gmenu2x->font->write(s, 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/dialog.h b/src/dialog.h index c95658e..d319d06 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -12,9 +12,9 @@ public: Dialog(GMenu2X *gmenu2x); protected: - void drawTitleIcon(Surface *s, const std::string &icon, bool skinRes = false); - void writeTitle(Surface *s, const std::string &title); - void writeSubTitle(Surface *s, const std::string &subtitle); + void drawTitleIcon(Surface& s, const std::string &icon, bool skinRes = false); + void writeTitle(Surface& s, const std::string &title); + void writeSubTitle(Surface& s, const std::string &subtitle); GMenu2X *gmenu2x; }; diff --git a/src/font.cpp b/src/font.cpp index 02d7c23..e8fa7de 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -197,7 +197,7 @@ int Font::getTextHeight(const string &text) return nLines * getLineSpacing(); } -void Font::write(Surface *surface, const string &text, +void Font::write(Surface& surface, const string &text, int x, int y, HAlign halign, VAlign valign) { if (!font) { @@ -220,7 +220,7 @@ void Font::write(Surface *surface, const string &text, } } -void Font::writeLine(Surface *surface, std::string const& text, +void Font::writeLine(Surface& surface, std::string const& text, int x, int y, HAlign halign, VAlign valign) { if (!font) { @@ -261,21 +261,21 @@ void Font::writeLine(Surface *surface, std::string const& text, } SDL_Rect rect = { (Sint16) x, (Sint16) (y - 1), 0, 0 }; - SDL_BlitSurface(s, NULL, surface->raw, &rect); + SDL_BlitSurface(s, NULL, surface.raw, &rect); /* Note: rect.x / rect.y are reset everytime because SDL_BlitSurface * will modify them if negative */ rect.x = x; rect.y = y + 1; - SDL_BlitSurface(s, NULL, surface->raw, &rect); + SDL_BlitSurface(s, NULL, surface.raw, &rect); rect.x = x - 1; rect.y = y; - SDL_BlitSurface(s, NULL, surface->raw, &rect); + SDL_BlitSurface(s, NULL, surface.raw, &rect); rect.x = x + 1; rect.y = y; - SDL_BlitSurface(s, NULL, surface->raw, &rect); + SDL_BlitSurface(s, NULL, surface.raw, &rect); SDL_FreeSurface(s); rect.x = x; @@ -289,6 +289,6 @@ void Font::writeLine(Surface *surface, std::string const& text, ERROR("Font rendering failed for text \"%s\"\n", text.c_str()); return; } - SDL_BlitSurface(s, NULL, surface->raw, &rect); + SDL_BlitSurface(s, NULL, surface.raw, &rect); SDL_FreeSurface(s); } diff --git a/src/font.h b/src/font.h index be09539..1c2552e 100644 --- a/src/font.h +++ b/src/font.h @@ -38,7 +38,7 @@ public: return lineSpacing; } - void write(Surface *surface, + void write(Surface& surface, const std::string &text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop); @@ -48,7 +48,7 @@ private: std::string wordWrapSingleLine(const std::string &text, size_t start, size_t end, int width); - void writeLine(Surface *surface, std::string const& text, + void writeLine(Surface& surface, std::string const& text, int x, int y, HAlign halign, VAlign valign); TTF_Font *font; diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 8c8bd05..7737ac4 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -322,17 +322,17 @@ void GMenu2X::initBG() { bg = Surface::emptySurface(resX, resY); } - drawTopBar(bg); - drawBottomBar(bg); + drawTopBar(*bg); + drawBottomBar(*bg); Surface *bgmain = new Surface(bg); sc.add(bgmain,"bgmain"); Surface *sd = Surface::loadImage("imgs/sd.png", confStr["skin"]); - if (sd) sd->blit(bgmain, 3, bottomBarIconY); + if (sd) sd->blit(*bgmain, 3, bottomBarIconY); string df = getDiskFree(getHome().c_str()); - font->write(bgmain, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle); + font->write(*bgmain, df, 22, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle); delete sd; cpuX = font->getTextWidth(df)+32; @@ -351,20 +351,20 @@ void GMenu2X::initBG() { if (web) { Surface *webserver = Surface::loadImage( "imgs/webserver.png", confStr["skin"]); - if (webserver) webserver->blit(bgmain, serviceX, bottomBarIconY); + if (webserver) webserver->blit(*bgmain, serviceX, bottomBarIconY); serviceX -= 19; delete webserver; } if (samba) { Surface *sambaS = Surface::loadImage( "imgs/samba.png", confStr["skin"]); - if (sambaS) sambaS->blit(bgmain, serviceX, bottomBarIconY); + if (sambaS) sambaS->blit(*bgmain, serviceX, bottomBarIconY); serviceX -= 19; delete sambaS; } if (inet) { Surface *inetS = Surface::loadImage("imgs/inet.png", confStr["skin"]); - if (inetS) inetS->blit(bgmain, serviceX, bottomBarIconY); + if (inetS) inetS->blit(*bgmain, serviceX, bottomBarIconY); serviceX -= 19; delete inetS; } @@ -1044,14 +1044,14 @@ string GMenu2X::getDiskFree(const char *path) { return df; } -int GMenu2X::drawButton(Surface *s, IconButton *btn, int x, int y) { +int GMenu2X::drawButton(Surface& s, IconButton *btn, int x, int y) { if (y<0) y = resY+y; btn->setPosition(x, y-7); btn->paint(s); return x+btn->getRect().w+6; } -int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x, int y) { +int GMenu2X::drawButton(Surface& s, const string &btn, const string &text, int x, int y) { if (y<0) y = resY+y; SDL_Rect re = { static_cast(x), static_cast(y - 7), 0, 16 }; if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { @@ -1063,7 +1063,7 @@ int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x return x+re.w+6; } -int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text, int x, int y) { +int GMenu2X::drawButtonRight(Surface& s, const string &btn, const string &text, int x, int y) { if (y<0) y = resY+y; if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { x -= 16; @@ -1097,22 +1097,22 @@ void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) { skinConfColors[COLOR_SELECTION_BG]); } -void GMenu2X::drawTopBar(Surface *s) { +void GMenu2X::drawTopBar(Surface& s) { Surface *bar = sc.skinRes("imgs/topbar.png", false); if (bar) { bar->blit(s, 0, 0); } else { const int h = skinConfInt["topBarHeight"]; - s->box(0, 0, resX, h, skinConfColors[COLOR_TOP_BAR_BG]); + s.box(0, 0, resX, h, skinConfColors[COLOR_TOP_BAR_BG]); } } -void GMenu2X::drawBottomBar(Surface *s) { +void GMenu2X::drawBottomBar(Surface& s) { Surface *bar = sc.skinRes("imgs/bottombar.png", false); if (bar) { bar->blit(s, 0, resY-bar->height()); } else { const int h = skinConfInt["bottomBarHeight"]; - s->box(0, resY - h, resX, h, skinConfColors[COLOR_BOTTOM_BAR_BG]); + s.box(0, resY - h, resX, h, skinConfColors[COLOR_BOTTOM_BAR_BG]); } } diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 41fc87d..3b6cbc3 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -199,13 +199,13 @@ public: void renameSection(); void deleteSection(); - int drawButton(Surface *s, IconButton *btn, int x=5, int y=-10); - int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10); - int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10); + int drawButton(Surface& s, IconButton *btn, int x=5, int y=-10); + int drawButton(Surface& s, const std::string &btn, const std::string &text, int x=5, int y=-10); + int drawButtonRight(Surface& s, const std::string &btn, const std::string &text, int x=5, int y=-10); void drawScrollBar(uint pageSize, uint totalSize, uint pagePos); - void drawTopBar(Surface *s); - void drawBottomBar(Surface *s); + void drawTopBar(Surface& s); + void drawBottomBar(Surface& s); Touchscreen &getTouchscreen() { return ts; } }; diff --git a/src/helppopup.cpp b/src/helppopup.cpp index 1e246ab..792f5cb 100644 --- a/src/helppopup.cpp +++ b/src/helppopup.cpp @@ -6,12 +6,12 @@ #include "gmenu2x.h" -HelpPopup::HelpPopup(GMenu2X &gmenu2x) +HelpPopup::HelpPopup(GMenu2X& gmenu2x) : gmenu2x(gmenu2x) { } -void HelpPopup::paint(Surface &s) { +void HelpPopup::paint(Surface& s) { 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]); - font.write(&s, tr["CONTROLS"], 20, 60); + font.write(s, tr["CONTROLS"], 20, 60); #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) - 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); + 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 } @@ -37,7 +37,7 @@ bool HelpPopup::handleButtonPress(InputManager::Button button) { return true; } -bool HelpPopup::handleTouchscreen(Touchscreen &ts) { +bool HelpPopup::handleTouchscreen(Touchscreen& ts) { if (ts.pressed()) { dismiss(); ts.setHandled(); diff --git a/src/helppopup.h b/src/helppopup.h index c2e64ae..6a49b38 100644 --- a/src/helppopup.h +++ b/src/helppopup.h @@ -14,15 +14,15 @@ class GMenu2X; */ class HelpPopup : public Layer { public: - HelpPopup(GMenu2X &gmenu2x); + HelpPopup(GMenu2X& gmenu2x); // Layer implementation: - virtual void paint(Surface &s); + virtual void paint(Surface& s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen &ts); + virtual bool handleTouchscreen(Touchscreen& ts); private: - GMenu2X &gmenu2x; + GMenu2X& gmenu2x; }; #endif // HELPPOPUP_H diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index c11ad93..92cd3dc 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -65,7 +65,7 @@ bool IconButton::handleTS() { return false; } -void IconButton::paint(Surface *s) { +void IconButton::paint(Surface& s) { if (iconSurface) { iconSurface->blit(s, iconRect); } diff --git a/src/iconbutton.h b/src/iconbutton.h index aeb4957..34ae21b 100644 --- a/src/iconbutton.h +++ b/src/iconbutton.h @@ -23,8 +23,7 @@ public: bool handleTS(); - void paint(Surface *s); - void paint() { paint(gmenu2x->s); } + void paint(Surface& s); private: void recalcRects(); diff --git a/src/imagedialog.cpp b/src/imagedialog.cpp index 02a28d0..dbb6767 100644 --- a/src/imagedialog.cpp +++ b/src/imagedialog.cpp @@ -55,7 +55,7 @@ ImageDialog::~ImageDialog() { void ImageDialog::beforeFileList() { if (fl->isFile(selected) && fileExists(getPath()+"/"+(*fl)[selected])) - previews[getPath()+"/"+(*fl)[selected]]->blitRight(gmenu2x->s, 310, 43); + previews[getPath()+"/"+(*fl)[selected]]->blitRight(*gmenu2x->s, 310, 43); } void ImageDialog::onChangeDir() { diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index 3aafb3b..21f16ce 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -150,25 +150,27 @@ bool InputDialog::exec() { bool caretOn = true; Surface bg(gmenu2x->bg); - drawTitleIcon(&bg, icon, false); - writeTitle(&bg, title); - writeSubTitle(&bg, text); - buttonbox->paint(&bg, 5); + drawTitleIcon(bg, icon, false); + writeTitle(bg, title); + writeSubTitle(bg, text); + buttonbox->paint(bg, 5); bg.convertToDisplayFormat(); close = false; ok = true; while (!close) { - bg.blit(gmenu2x->s,0,0); + Surface& s = *gmenu2x->s; + + bg.blit(s, 0, 0); box.w = gmenu2x->font->getTextWidth(input) + 18; box.x = 160 - box.w / 2; - gmenu2x->s->box(box.x, box.y, box.w, box.h, + s.box(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - gmenu2x->s->rectangle(box.x, box.y, box.w, box.h, + s.rectangle(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - gmenu2x->font->write(gmenu2x->s, input, box.x + 5, box.y + box.h - 2, + gmenu2x->font->write(s, input, box.x + 5, box.y + box.h - 2, Font::HAlignLeft, Font::VAlignBottom); curTick = SDL_GetTicks(); @@ -178,13 +180,13 @@ bool InputDialog::exec() { } if (caretOn) { - gmenu2x->s->box(box.x + box.w - 12, box.y + 3, 8, box.h - 6, + s.box(box.x + box.w - 12, box.y + 3, 8, box.h - 6, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); } if (ts.available()) ts.poll(); drawVirtualKeyboard(); - gmenu2x->s->flip(); + s.flip(); switch (inputMgr.waitForPressedButton()) { case InputManager::SETTINGS: @@ -264,8 +266,10 @@ void InputDialog::changeKeys() { } void InputDialog::drawVirtualKeyboard() { + Surface& s = *gmenu2x->s; + //keyboard border - gmenu2x->s->rectangle(kbRect, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.rectangle(kbRect, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); if (selCol<0) selCol = selRow==(int)kb->size() ? 1 : kbLength-1; if (selCol>=(int)kbLength) selCol = 0; @@ -274,13 +278,13 @@ void InputDialog::drawVirtualKeyboard() { //selection if (selRow<(int)kb->size()) - gmenu2x->s->box(kbLeft + selCol * KEY_WIDTH - 1, + s.box(kbLeft + selCol * KEY_WIDTH - 1, KB_TOP + selRow * KEY_HEIGHT, KEY_WIDTH - 1, KEY_HEIGHT - 2, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); else { if (selCol > 1) selCol = 0; if (selCol < 0) selCol = 1; - gmenu2x->s->box(kbLeft + selCol * kbLength * KEY_WIDTH / 2 - 1, + s.box(kbLeft + selCol * kbLength * KEY_WIDTH / 2 - 1, KB_TOP + kb->size() * KEY_HEIGHT, kbLength * KEY_WIDTH / 2 - 1, KEY_HEIGHT - 1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); } @@ -310,9 +314,9 @@ void InputDialog::drawVirtualKeyboard() { selRow = l; } - gmenu2x->s->rectangle(re, + s.rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - gmenu2x->font->write(gmenu2x->s, charX, + gmenu2x->font->write(s, charX, kbLeft + xc * KEY_WIDTH + KEY_WIDTH / 2 - 1, KB_TOP + l * KEY_HEIGHT + KEY_HEIGHT / 2, Font::HAlignCenter, Font::VAlignMiddle); @@ -327,23 +331,23 @@ void InputDialog::drawVirtualKeyboard() { static_cast(kbLength * KEY_WIDTH / 2 - 1), KEY_HEIGHT - 1 }; - gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); if (ts.available() && ts.pressed() && ts.inRect(re)) { selCol = 0; selRow = kb->size(); } - gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["Cancel"], + gmenu2x->font->write(s, gmenu2x->tr["Cancel"], (int)(160 - kbLength * KEY_WIDTH / 4), KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, Font::HAlignCenter, Font::VAlignMiddle); re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1; - gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); if (ts.available() && ts.pressed() && ts.inRect(re)) { selCol = 1; selRow = kb->size(); } - gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["OK"], + gmenu2x->font->write(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 423548a..4feeff3 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -67,17 +67,21 @@ bool Link::handleTS() { } void Link::paint() { + Surface& s = *gmenu2x->s; + if (iconSurface) { - iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32); + iconSurface->blit(s, iconX, rect.y+padding, 32,32); } - gmenu2x->font->write(gmenu2x->s, getTitle(), iconX+16, rect.y + gmenu2x->skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom); + gmenu2x->font->write(s, getTitle(), iconX+16, rect.y + gmenu2x->skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom); } void Link::paintHover() { + Surface& s = *gmenu2x->s; + if (gmenu2x->useSelectionPng) - gmenu2x->sc["imgs/selection.png"]->blit(gmenu2x->s, rect, Font::HAlignCenter, Font::VAlignMiddle); + gmenu2x->sc["imgs/selection.png"]->blit(s, rect, Font::HAlignCenter, Font::VAlignMiddle); else - gmenu2x->s->box(rect.x, rect.y, rect.w, rect.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.box(rect.x, rect.y, rect.w, rect.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); } void Link::updateSurfaces() diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 57426d8..bd7fb01 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -371,8 +371,8 @@ void LinkApp::drawLaunch(Surface& s) { gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104); else gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/ - iconSurface->blit(&s, x, gmenu2x->halfY - 16); - gmenu2x->font->write(&s, text, x + 42, gmenu2x->halfY + 1, Font::HAlignLeft, Font::VAlignMiddle); + iconSurface->blit(s, x, gmenu2x->halfY - 16); + gmenu2x->font->write(s, text, x + 42, gmenu2x->halfY + 1, Font::HAlignLeft, Font::VAlignMiddle); } void LinkApp::start() { @@ -459,23 +459,25 @@ void LinkApp::showManual() { #endif while (!close) { - if (repaint) { - bg->blit(gmenu2x->s, 0, 0); - pngman->blit(gmenu2x->s, -page*320, 0); + Surface& s = *gmenu2x->s; - gmenu2x->drawBottomBar(gmenu2x->s); - gmenu2x->drawButton(gmenu2x->s, "start", gmenu2x->tr["Exit"], - gmenu2x->drawButton(gmenu2x->s, "cancel", "", - gmenu2x->drawButton(gmenu2x->s, "right", gmenu2x->tr["Change page"], - gmenu2x->drawButton(gmenu2x->s, "left", "", 5)-10))-10); + if (repaint) { + bg->blit(s, 0, 0); + pngman->blit(s, -page*320, 0); + + gmenu2x->drawBottomBar(s); + gmenu2x->drawButton(s, "start", gmenu2x->tr["Exit"], + gmenu2x->drawButton(s, "cancel", "", + gmenu2x->drawButton(s, "right", gmenu2x->tr["Change page"], + gmenu2x->drawButton(s, "left", "", 5)-10))-10); ss.clear(); ss << page+1; ss >> pageStatus; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; - gmenu2x->font->write(gmenu2x->s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); + gmenu2x->font->write(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); - gmenu2x->s->flip(); + s.flip(); repaint = false; } diff --git a/src/menu.cpp b/src/menu.cpp index 8b8b063..544067e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -221,12 +221,12 @@ void Menu::paint(Surface &s) { int t = sectionDelta < 0 ? sectionDelta + linkWidth : sectionDelta; x += (((t * t) / linkWidth) * t) / linkWidth; } - icon->blit(&s, x - 16, sectionLinkPadding, 32, 32); - font.write(&s, sections[j], x, topBarHeight - sectionLinkPadding, + icon->blit(s, x - 16, sectionLinkPadding, 32, 32); + font.write(s, sections[j], x, topBarHeight - sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom); } - sc.skinRes("imgs/section-l.png")->blit(&s, 0, 0); - sc.skinRes("imgs/section-r.png")->blit(&s, width - 10, 0); + sc.skinRes("imgs/section-l.png")->blit(s, 0, 0); + sc.skinRes("imgs/section-r.png")->blit(s, width - 10, 0); vector §ionLinks = links[iSection]; const uint numLinks = sectionLinks.size(); @@ -254,7 +254,7 @@ void Menu::paint(Surface &s) { } if (selLink()) { - font.write(&s, selLink()->getDescription(), + font.write(s, selLink()->getDescription(), width / 2, height - bottomBarHeight + 2, Font::HAlignCenter, Font::VAlignBottom); } @@ -269,11 +269,11 @@ void Menu::paint(Surface &s) { //Manual indicator if (!linkApp->getManual().empty()) sc.skinRes("imgs/manual.png")->blit( - &s, gmenu2x->manualX, gmenu2x->bottomBarIconY); + s, gmenu2x->manualX, gmenu2x->bottomBarIconY); } if (ts.available()) { - btnContextMenu->paint(); + btnContextMenu->paint(s); } } diff --git a/src/menusetting.cpp b/src/menusetting.cpp index 8c88911..46c8c42 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -41,7 +41,8 @@ MenuSetting::~MenuSetting() void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) { - gmenu2x->font->write(gmenu2x->s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); + Surface& s = *gmenu2x->s; + gmenu2x->font->write(s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); } void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) @@ -51,9 +52,11 @@ void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) void MenuSetting::drawSelected(int valueX, int y, int h) { + Surface& s = *gmenu2x->s; + // The selection rectangle - gmenu2x->s->box(0, y, valueX - 5, h, + s.box(0, y, valueX - 5, h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - buttonBox.paint(gmenu2x->s, 5); + buttonBox.paint(s, 5); } diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index 855b822..fad8690 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -67,8 +67,9 @@ void MenuSettingBool::initButton() void MenuSettingBool::draw(int valueX, int y, int h) { + Surface& s = *gmenu2x->s; MenuSetting::draw(valueX, y, h); - gmenu2x->font->write(gmenu2x->s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(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 8e16519..41f8a26 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -69,8 +69,9 @@ MenuSettingInt::MenuSettingInt( void MenuSettingInt::draw(int valueX, int y, int h) { + Surface& s = *gmenu2x->s; MenuSetting::draw(valueX, y, h); - gmenu2x->font->write(gmenu2x->s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(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 b2ebc7a..5abdb07 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -52,14 +52,16 @@ MenuSettingRGBA::MenuSettingRGBA( } void MenuSettingRGBA::draw(int valueX, int y, int h) { + Surface& s = *gmenu2x->s; + MenuSetting::draw(valueX, y, 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->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); + s.rectangle(valueX, y + 1, h - 2, h - 2, 0,0,0,255); + s.rectangle(valueX + 1, y + 2, h - 4, h - 4, 255,255,255,255); + s.box(valueX + 2, y + 3, h - 6, h - 6, value()); + gmenu2x->font->write(s, "R: "+strR, valueX + h + 3, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(s, "G: "+strG, valueX + h + 3 + COMPONENT_WIDTH, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(s, "B: "+strB, valueX + h + 3 + COMPONENT_WIDTH * 2, y, Font::HAlignLeft, Font::VAlignTop); + gmenu2x->font->write(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 449060b..849bb1d 100644 --- a/src/menusettingstringbase.cpp +++ b/src/menusettingstringbase.cpp @@ -39,8 +39,9 @@ MenuSettingStringBase::~MenuSettingStringBase() void MenuSettingStringBase::draw(int valueX, int y, int h) { + Surface& s = *gmenu2x->s; MenuSetting::draw(valueX, y, h); - gmenu2x->font->write(gmenu2x->s, value(), valueX, y, + gmenu2x->font->write(s, value(), valueX, y, Font::HAlignLeft, Font::VAlignTop); } diff --git a/src/messagebox.cpp b/src/messagebox.cpp index 192015b..889a0d0 100644 --- a/src/messagebox.cpp +++ b/src/messagebox.cpp @@ -62,7 +62,8 @@ void MessageBox::setButton(InputManager::Button button, const string &label) { } int MessageBox::exec() { - Surface bg(gmenu2x->s); + Surface& s = *gmenu2x->s; + Surface bg(s); //Darken background bg.box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,200); @@ -83,9 +84,9 @@ int MessageBox::exec() { bg.rectangle(box, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]); //icon+text if (gmenu2x->sc[icon]) { - gmenu2x->sc[icon]->blitCenter( &bg, box.x + ICON_PADDING + ICON_DIMENSION / 2, box.y + ICON_PADDING + ICON_DIMENSION / 2 ); + gmenu2x->sc[icon]->blitCenter(bg, box.x + ICON_PADDING + ICON_DIMENSION / 2, box.y + ICON_PADDING + ICON_DIMENSION / 2); } - 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); + 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++) { @@ -93,7 +94,7 @@ int MessageBox::exec() { buttonPositions[i].y = box.y+box.h+8; buttonPositions[i].w = btnX; - btnX = gmenu2x->drawButtonRight(&bg, buttonLabels[i], buttons[i], btnX, buttonPositions[i].y); + btnX = gmenu2x->drawButtonRight(bg, buttonLabels[i], buttons[i], btnX, buttonPositions[i].y); buttonPositions[i].x = btnX; buttonPositions[i].w = buttonPositions[i].x-btnX-6; @@ -101,8 +102,8 @@ int MessageBox::exec() { } bg.convertToDisplayFormat(); - bg.blit(gmenu2x->s,0,0); - gmenu2x->s->flip(); + bg.blit(s, 0, 0); + s.flip(); int result = -1; while (result < 0) { diff --git a/src/selector.cpp b/src/selector.cpp index 5d2fabe..e5b901b 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -60,19 +60,19 @@ int Selector::exec(int startSelection) { fl.browse(); Surface bg(gmenu2x->bg); - drawTitleIcon(&bg, link->getIconPath(), true); - writeTitle(&bg, link->getTitle()); - writeSubTitle(&bg, link->getDescription()); + drawTitleIcon(bg, link->getIconPath(), true); + writeTitle(bg, link->getTitle()); + writeSubTitle(bg, link->getDescription()); if (link->getSelectorBrowser()) { - gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], - gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select"], - gmenu2x->drawButton(&bg, "cancel", gmenu2x->tr["Up one folder"], - gmenu2x->drawButton(&bg, "left", "", 5)-10))); + gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], + gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], + gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], + gmenu2x->drawButton(bg, "left", "", 5)-10))); } else { - gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], - gmenu2x->drawButton(&bg, "cancel", "", - gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select"], 5)) - 10); + gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], + gmenu2x->drawButton(bg, "cancel", "", + gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], 5)) - 10); } unsigned int top, height; @@ -95,7 +95,9 @@ int Selector::exec(int startSelection) { gmenu2x->sc.addSkinRes("imgs/folder.png"); gmenu2x->sc.defaultAlpha = false; while (!close) { - bg.blit(gmenu2x->s,0,0); + Surface& s = *gmenu2x->s; + + bg.blit(s, 0, 0); if (selected >= firstElement + nb_elements) firstElement = selected - nb_elements + 1; @@ -106,36 +108,35 @@ int Selector::exec(int startSelection) { if (selected-fl.dirCount()sc[screens[selected-fl.dirCount()]]; - if (screenshot) - screenshot->blitRight( - gmenu2x->s, 320, 0, 320, 240, - 128u); + if (screenshot) { + screenshot->blitRight(s, 320, 0, 320, 240, 128u); + } } //Selection iY = top + (selected - firstElement) * fontheight; if (selecteds->box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); //Files & Dirs - gmenu2x->s->setClipRect(0, top, 311, height); + s.setClipRect(0, top, 311, height); for (i = firstElement; i < fl.size() && i < firstElement + nb_elements; i++) { iY = i-firstElement; if (fl.isDirectory(i)) { - gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, top + (iY * fontheight)); - gmenu2x->font->write(gmenu2x->s, fl[i], 21, + gmenu2x->sc["imgs/folder.png"]->blit(s, 4, top + (iY * fontheight)); + gmenu2x->font->write(s, fl[i], 21, top + (iY * fontheight) + (fontheight / 2), Font::HAlignLeft, Font::VAlignMiddle); } else - gmenu2x->font->write(gmenu2x->s, titles[i - fl.dirCount()], 4, + gmenu2x->font->write(s, titles[i - fl.dirCount()], 4, top + (iY * fontheight) + (fontheight / 2), Font::HAlignLeft, Font::VAlignMiddle); } - gmenu2x->s->clearClipRect(); + s.clearClipRect(); gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement); - gmenu2x->s->flip(); + s.flip(); switch (gmenu2x->input.waitForPressedButton()) { case InputManager::SETTINGS: diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index f2e1169..8bb860c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -78,16 +78,18 @@ bool SettingsDialog::exec() { } while (!close) { + Surface& s = *gmenu2x->s; + if (ts.available()) ts.poll(); - bg.blit(gmenu2x->s,0,0); + bg.blit(s, 0, 0); - gmenu2x->drawTopBar(gmenu2x->s); + gmenu2x->drawTopBar(s); //link icon - drawTitleIcon(gmenu2x->s, icon); - writeTitle(gmenu2x->s, text); + drawTitleIcon(s, icon); + writeTitle(s, text); - gmenu2x->drawBottomBar(gmenu2x->s); + gmenu2x->drawBottomBar(s); if (sel>firstElement+numRows-1) firstElement=sel-numRows+1; if (seldrawScrollBar(numRows, voices.size(), firstElement); //description - writeSubTitle(gmenu2x->s, voices[sel]->getDescription()); + writeSubTitle(s, voices[sel]->getDescription()); - gmenu2x->s->flip(); + s.flip(); voices[sel]->handleTS(maxNameWidth + 15, iY, rowHeight); InputManager::Button button = inputMgr.waitForPressedButton(); diff --git a/src/surface.cpp b/src/surface.cpp index bc7ccca..cd79b6a 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -159,8 +159,8 @@ void Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) SDL_SetAlpha(raw, SDL_SRCALPHA|SDL_RLEACCEL, a); SDL_BlitSurface(raw, (w==0 || h==0) ? NULL : &src, destination, &dest); } -void Surface::blit(Surface *destination, int x, int y, int w, int h, int a) const { - blit(destination->raw,x,y,w,h,a); +void Surface::blit(Surface& destination, int x, int y, int w, int h, int a) const { + blit(destination.raw, x, y, w, h, a); } void Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, int a) const { @@ -168,17 +168,17 @@ void Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, i int oh = raw->h / 2; if (h != 0) oh = min(oh, h / 2); blit(destination, x - ow, y - oh, w, h, a); } -void Surface::blitCenter(Surface *destination, int x, int y, int w, int h, int a) const { - blitCenter(destination->raw,x,y,w,h,a); +void Surface::blitCenter(Surface& destination, int x, int y, int w, int h, int a) const { + blitCenter(destination.raw, x, y, w, h, a); } void Surface::blitRight(SDL_Surface *destination, int x, int y, int w, int h, int a) const { if (!w) w = raw->w; - blit(destination,x-min(raw->w,w),y,w,h,a); + blit(destination, x - min(raw->w, w), y, w, h, a); } -void Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a) const { +void Surface::blitRight(Surface& destination, int x, int y, int w, int h, int a) const { if (!w) w = raw->w; - blitRight(destination->raw,x,y,w,h,a); + blitRight(destination.raw, x, y, w, h, a); } void Surface::box(SDL_Rect re, RGBAColor c) { @@ -252,7 +252,7 @@ void Surface::applyClipRect(SDL_Rect& rect) { } } -void Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign, Font::VAlign valign) const { +void Surface::blit(Surface& destination, SDL_Rect container, Font::HAlign halign, Font::VAlign valign) const { switch (halign) { case Font::HAlignLeft: break; @@ -275,7 +275,7 @@ void Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign break; } - blit(destination,container.x,container.y); + blit(destination, container.x, container.y); } static inline uint32_t mult8x4(uint32_t c, uint8_t a) { diff --git a/src/surface.h b/src/surface.h index aa643d7..b643934 100644 --- a/src/surface.h +++ b/src/surface.h @@ -76,10 +76,10 @@ public: void setClipRect(int x, int y, int w, int h); void setClipRect(SDL_Rect rect); - void blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; - void blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const; - 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 blit(Surface& destination, int x, int y, int w=0, int h=0, int a=-1) const; + void blit(Surface& destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const; + 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 box(SDL_Rect re, RGBAColor c); void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) { diff --git a/src/textdialog.cpp b/src/textdialog.cpp index d1a705c..ae26730 100644 --- a/src/textdialog.cpp +++ b/src/textdialog.cpp @@ -37,6 +37,7 @@ TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &desc void TextDialog::drawText(const vector &text, unsigned int y, unsigned int firstRow, unsigned int rowsPerPage) { + Surface& s = *gmenu2x->s; const int fontHeight = gmenu2x->font->getLineSpacing(); for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text.size(); i++) { @@ -44,10 +45,10 @@ void TextDialog::drawText(const vector &text, unsigned int y, int rowY = y + (i - firstRow) * fontHeight; if (line == "----") { // horizontal ruler rowY += fontHeight / 2; - gmenu2x->s->box(5, rowY, gmenu2x->resX - 16, 1, 255, 255, 255, 130); - gmenu2x->s->box(5, rowY+1, gmenu2x->resX - 16, 1, 0, 0, 0, 130); + s.box(5, rowY, gmenu2x->resX - 16, 1, 255, 255, 255, 130); + s.box(5, rowY+1, gmenu2x->resX - 16, 1, 0, 0, 0, 130); } else { - gmenu2x->font->write(gmenu2x->s, line, 5, rowY); + gmenu2x->font->write(s, line, 5, rowY); } } @@ -61,16 +62,16 @@ void TextDialog::exec() { //link icon if (!fileExists(icon)) - drawTitleIcon(&bg, "icons/ebook.png", true); + drawTitleIcon(bg, "icons/ebook.png", true); else - drawTitleIcon(&bg, icon, false); - writeTitle(&bg, title); - writeSubTitle(&bg, description); + drawTitleIcon(bg, icon, false); + writeTitle(bg, title); + writeSubTitle(bg, description); - gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], - gmenu2x->drawButton(&bg, "cancel", "", - gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"], - gmenu2x->drawButton(&bg, "up", "", 5)-10))-10); + gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], + gmenu2x->drawButton(bg, "cancel", "", + gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], + gmenu2x->drawButton(bg, "up", "", 5)-10))-10); bg.convertToDisplayFormat(); @@ -82,9 +83,11 @@ void TextDialog::exec() { unsigned firstRow = 0; while (!close) { - bg.blit(gmenu2x->s, 0, 0); + Surface& s = *gmenu2x->s; + + bg.blit(s, 0, 0); drawText(text, contentY, firstRow, rowsPerPage); - gmenu2x->s->flip(); + s.flip(); switch(gmenu2x->input.waitForPressedButton()) { case InputManager::UP: diff --git a/src/textmanualdialog.cpp b/src/textmanualdialog.cpp index 3e3198f..a198018 100644 --- a/src/textmanualdialog.cpp +++ b/src/textmanualdialog.cpp @@ -75,17 +75,17 @@ void TextManualDialog::exec() { //link icon if (!fileExists(icon)) - drawTitleIcon(&bg, "icons/ebook.png", true); + drawTitleIcon(bg, "icons/ebook.png", true); else - drawTitleIcon(&bg, icon, false); - writeTitle(&bg, title+(description.empty() ? "" : ": "+description)); + drawTitleIcon(bg, icon, false); + writeTitle(bg, title+(description.empty() ? "" : ": "+description)); - gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], - gmenu2x->drawButton(&bg, "cancel", "", - gmenu2x->drawButton(&bg, "right", gmenu2x->tr["Change page"], - gmenu2x->drawButton(&bg, "left", "", - gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"], - gmenu2x->drawButton(&bg, "up", "", 5)-10))-10))-10); + gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], + gmenu2x->drawButton(bg, "cancel", "", + gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"], + gmenu2x->drawButton(bg, "left", "", + gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], + gmenu2x->drawButton(bg, "up", "", 5)-10))-10))-10); bg.convertToDisplayFormat(); @@ -97,17 +97,19 @@ void TextManualDialog::exec() { string pageStatus; while (!close) { - bg.blit(gmenu2x->s,0,0); - writeSubTitle(gmenu2x->s, pages[page].title); + Surface& s = *gmenu2x->s; + + bg.blit(s,0,0); + writeSubTitle(s, pages[page].title); drawText(pages[page].text, 42 /* TODO */, firstRow, rowsPerPage); ss.clear(); ss << page+1; ss >> pageStatus; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; - gmenu2x->font->write(gmenu2x->s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); + gmenu2x->font->write(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); - gmenu2x->s->flip(); + s.flip(); switch(gmenu2x->input.waitForPressedButton()) { case InputManager::UP: diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 98c6ecc..d7ed451 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -88,41 +88,43 @@ bool WallpaperDialog::exec() unsigned int nb_elements = height / fontheight; while (!close) { + Surface& s = *gmenu2x->s; + if (selected > firstElement + nb_elements - 1) firstElement = selected - nb_elements + 1; if (selected < firstElement) firstElement = selected; //Wallpaper - gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0); + gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(s, 0, 0); - gmenu2x->drawTopBar(gmenu2x->s); - gmenu2x->drawBottomBar(gmenu2x->s); + gmenu2x->drawTopBar(s); + gmenu2x->drawBottomBar(s); - drawTitleIcon(gmenu2x->s, "icons/wallpaper.png", true); - writeTitle(gmenu2x->s, gmenu2x->tr["Wallpaper selection"]); - writeSubTitle(gmenu2x->s, gmenu2x->tr["Select a wallpaper from the list"]); + drawTitleIcon(s, "icons/wallpaper.png", true); + writeTitle(s, gmenu2x->tr["Wallpaper selection"]); + writeSubTitle(s, gmenu2x->tr["Select a wallpaper from the list"]); - buttonbox.paint(gmenu2x->s, 5); + buttonbox.paint(s, 5); //Selection iY = selected - firstElement; iY = top + (iY * fontheight); - gmenu2x->s->box(2, iY, 308, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + s.box(2, iY, 308, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); //Files & Directories - gmenu2x->s->setClipRect(0, top, 311, height); + s.setClipRect(0, top, 311, height); for (i = firstElement; i < wallpapers.size() && i < firstElement + nb_elements; i++) { iY = i-firstElement; - gmenu2x->font->write(gmenu2x->s, wallpapers[i], 5, + gmenu2x->font->write(s, wallpapers[i], 5, top + (iY * fontheight), Font::HAlignLeft, Font::VAlignTop); } - gmenu2x->s->clearClipRect(); + s.clearClipRect(); gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement); - gmenu2x->s->flip(); + s.flip(); switch(gmenu2x->input.waitForPressedButton()) { case InputManager::CANCEL: