1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 17:51:34 +02:00

Don't pass around naked Surface pointers when drawing

Use references instead.
This commit is contained in:
Maarten ter Huurne 2014-08-10 04:26:59 +02:00
parent 20c5ec4eb6
commit aff5f53f7d
34 changed files with 255 additions and 220 deletions

View File

@ -6,23 +6,23 @@
#include "gmenu2x.h" #include "gmenu2x.h"
Background::Background(GMenu2X &gmenu2x) Background::Background(GMenu2X& gmenu2x)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
, battery(gmenu2x.sc) , battery(gmenu2x.sc)
{ {
} }
void Background::paint(Surface &s) { void Background::paint(Surface& s) {
Font &font = *gmenu2x.font; Font &font = *gmenu2x.font;
SurfaceCollection &sc = gmenu2x.sc; 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, s.width() / 2, gmenu2x.bottomBarTextY,
Font::HAlignCenter, Font::VAlignMiddle); 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) { 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; return false;
} }

View File

@ -16,15 +16,15 @@ class GMenu2X;
*/ */
class Background : public Layer { class Background : public Layer {
public: public:
Background(GMenu2X &gmenu2x); Background(GMenu2X& gmenu2x);
// Layer implementation: // Layer implementation:
virtual void paint(Surface &s); virtual void paint(Surface& s);
virtual bool handleButtonPress(InputManager::Button button); virtual bool handleButtonPress(InputManager::Button button);
virtual bool handleTouchscreen(Touchscreen &ts); virtual bool handleTouchscreen(Touchscreen& ts);
private: private:
GMenu2X &gmenu2x; GMenu2X& gmenu2x;
Battery battery; Battery battery;
Clock clock; Clock clock;
}; };

View File

@ -224,18 +224,20 @@ void BrowseDialog::quit()
void BrowseDialog::paint() void BrowseDialog::paint()
{ {
Surface& s = *gmenu2x->s;
unsigned int i, iY; unsigned int i, iY;
unsigned int firstElement, lastElement; unsigned int firstElement, lastElement;
unsigned int offsetY; unsigned int offsetY;
Surface bg(gmenu2x->bg); Surface bg(gmenu2x->bg);
drawTitleIcon(&bg, "icons/explorer.png", true); drawTitleIcon(bg, "icons/explorer.png", true);
writeTitle(&bg, title); writeTitle(bg, title);
writeSubTitle(&bg, subtitle); writeSubTitle(bg, subtitle);
buttonBox.paint(&bg, 5); buttonBox.paint(bg, 5);
bg.convertToDisplayFormat(); 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, // 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. // but originally it was undefined and that is never a good idea.
@ -249,7 +251,7 @@ void BrowseDialog::paint()
//Selection //Selection
const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"];
iY = topBarHeight + 1 + (selected - firstElement) * rowHeight; 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]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
lastElement = firstElement + numRows; lastElement = firstElement + numRows;
@ -259,7 +261,7 @@ void BrowseDialog::paint()
offsetY = topBarHeight + 1; offsetY = topBarHeight + 1;
//Files & Directories //Files & Directories
gmenu2x->s->setClipRect(clipRect); s.setClipRect(clipRect);
for (i = firstElement; i < lastElement; i++) { for (i = firstElement; i < lastElement; i++) {
Surface *icon; Surface *icon;
if (fl->isDirectory(i)) { if (fl->isDirectory(i)) {
@ -271,8 +273,8 @@ void BrowseDialog::paint()
} else { } else {
icon = iconFile; icon = iconFile;
} }
icon->blit(gmenu2x->s, 5, offsetY); icon->blit(s, 5, offsetY);
gmenu2x->font->write(gmenu2x->s, (*fl)[i], 24, offsetY + rowHeight / 2, gmenu2x->font->write(s, (*fl)[i], 24, offsetY + rowHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
if (ts.available() && ts.pressed() if (ts.available() && ts.pressed()
@ -283,8 +285,8 @@ void BrowseDialog::paint()
offsetY += rowHeight; offsetY += rowHeight;
} }
gmenu2x->s->clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(numRows,fl->size(), firstElement); gmenu2x->drawScrollBar(numRows,fl->size(), firstElement);
gmenu2x->s->flip(); s.flip();
} }

View File

@ -22,14 +22,16 @@ void ButtonBox::clear()
buttons.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); posX = gmenu2x->drawButton(s, button, posX);
}
} }
void ButtonBox::handleTS() void ButtonBox::handleTS()
{ {
for (auto button : buttons) for (auto button : buttons) {
button->handleTS(); button->handleTS();
}
} }

View File

@ -16,7 +16,7 @@ public:
void add(IconButton *button); void add(IconButton *button);
void clear(); void clear();
void paint(Surface *s, unsigned int posX); void paint(Surface& s, unsigned int posX);
void handleTS(); void handleTS();
private: private:

View File

@ -127,7 +127,7 @@ void ContextMenu::paint(Surface &s)
// List options. // List options.
for (uint i = 0; i < options.size(); i++) { 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); Font::HAlignLeft, Font::VAlignTop);
} }
} }

View File

@ -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; Surface *i = NULL;
if (!icon.empty()) { if (!icon.empty()) {
@ -21,16 +21,19 @@ void Dialog::drawTitleIcon(Surface *s, const std::string &icon, bool skinRes)
if (i==NULL) if (i==NULL)
i = gmenu2x->sc.skinRes("icons/generic.png"); 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); 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); 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);
} }

View File

@ -12,9 +12,9 @@ public:
Dialog(GMenu2X *gmenu2x); Dialog(GMenu2X *gmenu2x);
protected: protected:
void drawTitleIcon(Surface *s, const std::string &icon, bool skinRes = false); void drawTitleIcon(Surface& s, const std::string &icon, bool skinRes = false);
void writeTitle(Surface *s, const std::string &title); void writeTitle(Surface& s, const std::string &title);
void writeSubTitle(Surface *s, const std::string &subtitle); void writeSubTitle(Surface& s, const std::string &subtitle);
GMenu2X *gmenu2x; GMenu2X *gmenu2x;
}; };

View File

@ -197,7 +197,7 @@ int Font::getTextHeight(const string &text)
return nLines * getLineSpacing(); 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) int x, int y, HAlign halign, VAlign valign)
{ {
if (!font) { 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) int x, int y, HAlign halign, VAlign valign)
{ {
if (!font) { 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_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 /* Note: rect.x / rect.y are reset everytime because SDL_BlitSurface
* will modify them if negative */ * will modify them if negative */
rect.x = x; rect.x = x;
rect.y = y + 1; rect.y = y + 1;
SDL_BlitSurface(s, NULL, surface->raw, &rect); SDL_BlitSurface(s, NULL, surface.raw, &rect);
rect.x = x - 1; rect.x = x - 1;
rect.y = y; rect.y = y;
SDL_BlitSurface(s, NULL, surface->raw, &rect); SDL_BlitSurface(s, NULL, surface.raw, &rect);
rect.x = x + 1; rect.x = x + 1;
rect.y = y; rect.y = y;
SDL_BlitSurface(s, NULL, surface->raw, &rect); SDL_BlitSurface(s, NULL, surface.raw, &rect);
SDL_FreeSurface(s); SDL_FreeSurface(s);
rect.x = x; 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()); ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
return; return;
} }
SDL_BlitSurface(s, NULL, surface->raw, &rect); SDL_BlitSurface(s, NULL, surface.raw, &rect);
SDL_FreeSurface(s); SDL_FreeSurface(s);
} }

View File

@ -38,7 +38,7 @@ public:
return lineSpacing; return lineSpacing;
} }
void write(Surface *surface, void write(Surface& surface,
const std::string &text, int x, int y, const std::string &text, int x, int y,
HAlign halign = HAlignLeft, VAlign valign = VAlignTop); HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
@ -48,7 +48,7 @@ private:
std::string wordWrapSingleLine(const std::string &text, std::string wordWrapSingleLine(const std::string &text,
size_t start, size_t end, int width); 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); int x, int y, HAlign halign, VAlign valign);
TTF_Font *font; TTF_Font *font;

View File

@ -322,17 +322,17 @@ void GMenu2X::initBG() {
bg = Surface::emptySurface(resX, resY); bg = Surface::emptySurface(resX, resY);
} }
drawTopBar(bg); drawTopBar(*bg);
drawBottomBar(bg); drawBottomBar(*bg);
Surface *bgmain = new Surface(bg); Surface *bgmain = new Surface(bg);
sc.add(bgmain,"bgmain"); sc.add(bgmain,"bgmain");
Surface *sd = Surface::loadImage("imgs/sd.png", confStr["skin"]); 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()); 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; delete sd;
cpuX = font->getTextWidth(df)+32; cpuX = font->getTextWidth(df)+32;
@ -351,20 +351,20 @@ void GMenu2X::initBG() {
if (web) { if (web) {
Surface *webserver = Surface::loadImage( Surface *webserver = Surface::loadImage(
"imgs/webserver.png", confStr["skin"]); "imgs/webserver.png", confStr["skin"]);
if (webserver) webserver->blit(bgmain, serviceX, bottomBarIconY); if (webserver) webserver->blit(*bgmain, serviceX, bottomBarIconY);
serviceX -= 19; serviceX -= 19;
delete webserver; delete webserver;
} }
if (samba) { if (samba) {
Surface *sambaS = Surface::loadImage( Surface *sambaS = Surface::loadImage(
"imgs/samba.png", confStr["skin"]); "imgs/samba.png", confStr["skin"]);
if (sambaS) sambaS->blit(bgmain, serviceX, bottomBarIconY); if (sambaS) sambaS->blit(*bgmain, serviceX, bottomBarIconY);
serviceX -= 19; serviceX -= 19;
delete sambaS; delete sambaS;
} }
if (inet) { if (inet) {
Surface *inetS = Surface::loadImage("imgs/inet.png", confStr["skin"]); 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; serviceX -= 19;
delete inetS; delete inetS;
} }
@ -1044,14 +1044,14 @@ string GMenu2X::getDiskFree(const char *path) {
return df; 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; if (y<0) y = resY+y;
btn->setPosition(x, y-7); btn->setPosition(x, y-7);
btn->paint(s); btn->paint(s);
return x+btn->getRect().w+6; 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; if (y<0) y = resY+y;
SDL_Rect re = { static_cast<Sint16>(x), static_cast<Sint16>(y - 7), 0, 16 }; SDL_Rect re = { static_cast<Sint16>(x), static_cast<Sint16>(y - 7), 0, 16 };
if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { 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; 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 (y<0) y = resY+y;
if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) {
x -= 16; x -= 16;
@ -1097,22 +1097,22 @@ void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) {
skinConfColors[COLOR_SELECTION_BG]); skinConfColors[COLOR_SELECTION_BG]);
} }
void GMenu2X::drawTopBar(Surface *s) { void GMenu2X::drawTopBar(Surface& s) {
Surface *bar = sc.skinRes("imgs/topbar.png", false); Surface *bar = sc.skinRes("imgs/topbar.png", false);
if (bar) { if (bar) {
bar->blit(s, 0, 0); bar->blit(s, 0, 0);
} else { } else {
const int h = skinConfInt["topBarHeight"]; 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); Surface *bar = sc.skinRes("imgs/bottombar.png", false);
if (bar) { if (bar) {
bar->blit(s, 0, resY-bar->height()); bar->blit(s, 0, resY-bar->height());
} else { } else {
const int h = skinConfInt["bottomBarHeight"]; 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]);
} }
} }

View File

@ -199,13 +199,13 @@ public:
void renameSection(); void renameSection();
void deleteSection(); void deleteSection();
int drawButton(Surface *s, IconButton *btn, 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 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 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 drawScrollBar(uint pageSize, uint totalSize, uint pagePos);
void drawTopBar(Surface *s); void drawTopBar(Surface& s);
void drawBottomBar(Surface *s); void drawBottomBar(Surface& s);
Touchscreen &getTouchscreen() { return ts; } Touchscreen &getTouchscreen() { return ts; }
}; };

View File

@ -6,12 +6,12 @@
#include "gmenu2x.h" #include "gmenu2x.h"
HelpPopup::HelpPopup(GMenu2X &gmenu2x) HelpPopup::HelpPopup(GMenu2X& gmenu2x)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
{ {
} }
void HelpPopup::paint(Surface &s) { void HelpPopup::paint(Surface& s) {
Font& font = *gmenu2x.font; Font& font = *gmenu2x.font;
Translator &tr = gmenu2x.tr; Translator &tr = gmenu2x.tr;
int helpBoxHeight = 154; int helpBoxHeight = 154;
@ -20,13 +20,13 @@ void HelpPopup::paint(Surface &s) {
gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BG]); gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BG]);
s.rectangle(12, 52, 296, helpBoxHeight, s.rectangle(12, 52, 296, helpBoxHeight,
gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BORDER]); 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) #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
font.write(&s, tr["A: Launch link / Confirm action"], 20, 80); 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["B: Show this help menu"], 20, 95);
font.write(&s, tr["L, R: Change section"], 20, 110); font.write(s, tr["L, R: Change section"], 20, 110);
font.write(&s, tr["SELECT: Show contextual menu"], 20, 155); font.write(s, tr["SELECT: Show contextual menu"], 20, 155);
font.write(&s, tr["START: Show options menu"], 20, 170); font.write(s, tr["START: Show options menu"], 20, 170);
#endif #endif
} }
@ -37,7 +37,7 @@ bool HelpPopup::handleButtonPress(InputManager::Button button) {
return true; return true;
} }
bool HelpPopup::handleTouchscreen(Touchscreen &ts) { bool HelpPopup::handleTouchscreen(Touchscreen& ts) {
if (ts.pressed()) { if (ts.pressed()) {
dismiss(); dismiss();
ts.setHandled(); ts.setHandled();

View File

@ -14,15 +14,15 @@ class GMenu2X;
*/ */
class HelpPopup : public Layer { class HelpPopup : public Layer {
public: public:
HelpPopup(GMenu2X &gmenu2x); HelpPopup(GMenu2X& gmenu2x);
// Layer implementation: // Layer implementation:
virtual void paint(Surface &s); virtual void paint(Surface& s);
virtual bool handleButtonPress(InputManager::Button button); virtual bool handleButtonPress(InputManager::Button button);
virtual bool handleTouchscreen(Touchscreen &ts); virtual bool handleTouchscreen(Touchscreen& ts);
private: private:
GMenu2X &gmenu2x; GMenu2X& gmenu2x;
}; };
#endif // HELPPOPUP_H #endif // HELPPOPUP_H

View File

@ -65,7 +65,7 @@ bool IconButton::handleTS() {
return false; return false;
} }
void IconButton::paint(Surface *s) { void IconButton::paint(Surface& s) {
if (iconSurface) { if (iconSurface) {
iconSurface->blit(s, iconRect); iconSurface->blit(s, iconRect);
} }

View File

@ -23,8 +23,7 @@ public:
bool handleTS(); bool handleTS();
void paint(Surface *s); void paint(Surface& s);
void paint() { paint(gmenu2x->s); }
private: private:
void recalcRects(); void recalcRects();

View File

@ -55,7 +55,7 @@ ImageDialog::~ImageDialog() {
void ImageDialog::beforeFileList() { void ImageDialog::beforeFileList() {
if (fl->isFile(selected) && fileExists(getPath()+"/"+(*fl)[selected])) 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() { void ImageDialog::onChangeDir() {

View File

@ -150,25 +150,27 @@ bool InputDialog::exec() {
bool caretOn = true; bool caretOn = true;
Surface bg(gmenu2x->bg); Surface bg(gmenu2x->bg);
drawTitleIcon(&bg, icon, false); drawTitleIcon(bg, icon, false);
writeTitle(&bg, title); writeTitle(bg, title);
writeSubTitle(&bg, text); writeSubTitle(bg, text);
buttonbox->paint(&bg, 5); buttonbox->paint(bg, 5);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
close = false; close = false;
ok = true; ok = true;
while (!close) { 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.w = gmenu2x->font->getTextWidth(input) + 18;
box.x = 160 - box.w / 2; 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->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->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); Font::HAlignLeft, Font::VAlignBottom);
curTick = SDL_GetTicks(); curTick = SDL_GetTicks();
@ -178,13 +180,13 @@ bool InputDialog::exec() {
} }
if (caretOn) { 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]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
} }
if (ts.available()) ts.poll(); if (ts.available()) ts.poll();
drawVirtualKeyboard(); drawVirtualKeyboard();
gmenu2x->s->flip(); s.flip();
switch (inputMgr.waitForPressedButton()) { switch (inputMgr.waitForPressedButton()) {
case InputManager::SETTINGS: case InputManager::SETTINGS:
@ -264,8 +266,10 @@ void InputDialog::changeKeys() {
} }
void InputDialog::drawVirtualKeyboard() { void InputDialog::drawVirtualKeyboard() {
Surface& s = *gmenu2x->s;
//keyboard border //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<0) selCol = selRow==(int)kb->size() ? 1 : kbLength-1;
if (selCol>=(int)kbLength) selCol = 0; if (selCol>=(int)kbLength) selCol = 0;
@ -274,13 +278,13 @@ void InputDialog::drawVirtualKeyboard() {
//selection //selection
if (selRow<(int)kb->size()) 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, KB_TOP + selRow * KEY_HEIGHT, KEY_WIDTH - 1, KEY_HEIGHT - 2,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
else { else {
if (selCol > 1) selCol = 0; if (selCol > 1) selCol = 0;
if (selCol < 0) selCol = 1; 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, KB_TOP + kb->size() * KEY_HEIGHT, kbLength * KEY_WIDTH / 2 - 1,
KEY_HEIGHT - 1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); KEY_HEIGHT - 1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
} }
@ -310,9 +314,9 @@ void InputDialog::drawVirtualKeyboard() {
selRow = l; selRow = l;
} }
gmenu2x->s->rectangle(re, s.rectangle(re,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->font->write(gmenu2x->s, charX, gmenu2x->font->write(s, charX,
kbLeft + xc * KEY_WIDTH + KEY_WIDTH / 2 - 1, kbLeft + xc * KEY_WIDTH + KEY_WIDTH / 2 - 1,
KB_TOP + l * KEY_HEIGHT + KEY_HEIGHT / 2, KB_TOP + l * KEY_HEIGHT + KEY_HEIGHT / 2,
Font::HAlignCenter, Font::VAlignMiddle); Font::HAlignCenter, Font::VAlignMiddle);
@ -327,23 +331,23 @@ void InputDialog::drawVirtualKeyboard() {
static_cast<Uint16>(kbLength * KEY_WIDTH / 2 - 1), static_cast<Uint16>(kbLength * KEY_WIDTH / 2 - 1),
KEY_HEIGHT - 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)) { if (ts.available() && ts.pressed() && ts.inRect(re)) {
selCol = 0; selCol = 0;
selRow = kb->size(); selRow = kb->size();
} }
gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["Cancel"], gmenu2x->font->write(s, gmenu2x->tr["Cancel"],
(int)(160 - kbLength * KEY_WIDTH / 4), (int)(160 - kbLength * KEY_WIDTH / 4),
KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
Font::HAlignCenter, Font::VAlignMiddle); Font::HAlignCenter, Font::VAlignMiddle);
re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1; 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)) { if (ts.available() && ts.pressed() && ts.inRect(re)) {
selCol = 1; selCol = 1;
selRow = kb->size(); selRow = kb->size();
} }
gmenu2x->font->write(gmenu2x->s, gmenu2x->tr["OK"], gmenu2x->font->write(s, gmenu2x->tr["OK"],
(int)(160 + kbLength * KEY_WIDTH / 4), (int)(160 + kbLength * KEY_WIDTH / 4),
KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
Font::HAlignCenter, Font::VAlignMiddle); Font::HAlignCenter, Font::VAlignMiddle);

View File

@ -67,17 +67,21 @@ bool Link::handleTS() {
} }
void Link::paint() { void Link::paint() {
Surface& s = *gmenu2x->s;
if (iconSurface) { 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() { void Link::paintHover() {
Surface& s = *gmenu2x->s;
if (gmenu2x->useSelectionPng) 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 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() void Link::updateSurfaces()

View File

@ -371,8 +371,8 @@ void LinkApp::drawLaunch(Surface& s) {
gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104); gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104);
else else
gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/ gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/
iconSurface->blit(&s, x, gmenu2x->halfY - 16); iconSurface->blit(s, x, gmenu2x->halfY - 16);
gmenu2x->font->write(&s, text, x + 42, gmenu2x->halfY + 1, Font::HAlignLeft, Font::VAlignMiddle); gmenu2x->font->write(s, text, x + 42, gmenu2x->halfY + 1, Font::HAlignLeft, Font::VAlignMiddle);
} }
void LinkApp::start() { void LinkApp::start() {
@ -459,23 +459,25 @@ void LinkApp::showManual() {
#endif #endif
while (!close) { while (!close) {
if (repaint) { Surface& s = *gmenu2x->s;
bg->blit(gmenu2x->s, 0, 0);
pngman->blit(gmenu2x->s, -page*320, 0);
gmenu2x->drawBottomBar(gmenu2x->s); if (repaint) {
gmenu2x->drawButton(gmenu2x->s, "start", gmenu2x->tr["Exit"], bg->blit(s, 0, 0);
gmenu2x->drawButton(gmenu2x->s, "cancel", "", pngman->blit(s, -page*320, 0);
gmenu2x->drawButton(gmenu2x->s, "right", gmenu2x->tr["Change page"],
gmenu2x->drawButton(gmenu2x->s, "left", "", 5)-10))-10); 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.clear();
ss << page+1; ss << page+1;
ss >> pageStatus; ss >> pageStatus;
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; 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; repaint = false;
} }

View File

@ -221,12 +221,12 @@ void Menu::paint(Surface &s) {
int t = sectionDelta < 0 ? sectionDelta + linkWidth : sectionDelta; int t = sectionDelta < 0 ? sectionDelta + linkWidth : sectionDelta;
x += (((t * t) / linkWidth) * t) / linkWidth; x += (((t * t) / linkWidth) * t) / linkWidth;
} }
icon->blit(&s, x - 16, sectionLinkPadding, 32, 32); icon->blit(s, x - 16, sectionLinkPadding, 32, 32);
font.write(&s, sections[j], x, topBarHeight - sectionLinkPadding, font.write(s, sections[j], x, topBarHeight - sectionLinkPadding,
Font::HAlignCenter, Font::VAlignBottom); Font::HAlignCenter, Font::VAlignBottom);
} }
sc.skinRes("imgs/section-l.png")->blit(&s, 0, 0); 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-r.png")->blit(s, width - 10, 0);
vector<Link*> &sectionLinks = links[iSection]; vector<Link*> &sectionLinks = links[iSection];
const uint numLinks = sectionLinks.size(); const uint numLinks = sectionLinks.size();
@ -254,7 +254,7 @@ void Menu::paint(Surface &s) {
} }
if (selLink()) { if (selLink()) {
font.write(&s, selLink()->getDescription(), font.write(s, selLink()->getDescription(),
width / 2, height - bottomBarHeight + 2, width / 2, height - bottomBarHeight + 2,
Font::HAlignCenter, Font::VAlignBottom); Font::HAlignCenter, Font::VAlignBottom);
} }
@ -269,11 +269,11 @@ void Menu::paint(Surface &s) {
//Manual indicator //Manual indicator
if (!linkApp->getManual().empty()) if (!linkApp->getManual().empty())
sc.skinRes("imgs/manual.png")->blit( sc.skinRes("imgs/manual.png")->blit(
&s, gmenu2x->manualX, gmenu2x->bottomBarIconY); s, gmenu2x->manualX, gmenu2x->bottomBarIconY);
} }
if (ts.available()) { if (ts.available()) {
btnContextMenu->paint(); btnContextMenu->paint(s);
} }
} }

View File

@ -41,7 +41,8 @@ MenuSetting::~MenuSetting()
void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) 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*/) 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) void MenuSetting::drawSelected(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s;
// The selection rectangle // The selection rectangle
gmenu2x->s->box(0, y, valueX - 5, h, s.box(0, y, valueX - 5, h,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
buttonBox.paint(gmenu2x->s, 5); buttonBox.paint(s, 5);
} }

View File

@ -67,8 +67,9 @@ void MenuSettingBool::initButton()
void MenuSettingBool::draw(int valueX, int y, int h) void MenuSettingBool::draw(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s;
MenuSetting::draw(valueX, y, h); 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) bool MenuSettingBool::handleButtonPress(InputManager::Button button)

View File

@ -69,8 +69,9 @@ MenuSettingInt::MenuSettingInt(
void MenuSettingInt::draw(int valueX, int y, int h) void MenuSettingInt::draw(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s;
MenuSetting::draw(valueX, y, h); 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) bool MenuSettingInt::handleButtonPress(InputManager::Button button)

View File

@ -52,14 +52,16 @@ MenuSettingRGBA::MenuSettingRGBA(
} }
void MenuSettingRGBA::draw(int valueX, int y, int h) { void MenuSettingRGBA::draw(int valueX, int y, int h) {
Surface& s = *gmenu2x->s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
gmenu2x->s->rectangle( valueX, y + 1, h - 2, h - 2, 0,0,0,255 ); 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 ); 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() ); 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(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(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(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); 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) { void MenuSettingRGBA::handleTS(int valueX, int y, int h) {

View File

@ -39,8 +39,9 @@ MenuSettingStringBase::~MenuSettingStringBase()
void MenuSettingStringBase::draw(int valueX, int y, int h) void MenuSettingStringBase::draw(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
gmenu2x->font->write(gmenu2x->s, value(), valueX, y, gmenu2x->font->write(s, value(), valueX, y,
Font::HAlignLeft, Font::VAlignTop); Font::HAlignLeft, Font::VAlignTop);
} }

View File

@ -62,7 +62,8 @@ void MessageBox::setButton(InputManager::Button button, const string &label) {
} }
int MessageBox::exec() { int MessageBox::exec() {
Surface bg(gmenu2x->s); Surface& s = *gmenu2x->s;
Surface bg(s);
//Darken background //Darken background
bg.box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,200); 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]); bg.rectangle(box, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
//icon+text //icon+text
if (gmenu2x->sc[icon]) { 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; int btnX = gmenu2x->halfX+box.w/2-6;
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) { 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].y = box.y+box.h+8;
buttonPositions[i].w = btnX; 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].x = btnX;
buttonPositions[i].w = buttonPositions[i].x-btnX-6; buttonPositions[i].w = buttonPositions[i].x-btnX-6;
@ -101,8 +102,8 @@ int MessageBox::exec() {
} }
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
bg.blit(gmenu2x->s,0,0); bg.blit(s, 0, 0);
gmenu2x->s->flip(); s.flip();
int result = -1; int result = -1;
while (result < 0) { while (result < 0) {

View File

@ -60,19 +60,19 @@ int Selector::exec(int startSelection) {
fl.browse(); fl.browse();
Surface bg(gmenu2x->bg); Surface bg(gmenu2x->bg);
drawTitleIcon(&bg, link->getIconPath(), true); drawTitleIcon(bg, link->getIconPath(), true);
writeTitle(&bg, link->getTitle()); writeTitle(bg, link->getTitle());
writeSubTitle(&bg, link->getDescription()); writeSubTitle(bg, link->getDescription());
if (link->getSelectorBrowser()) { if (link->getSelectorBrowser()) {
gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select"], gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"],
gmenu2x->drawButton(&bg, "cancel", gmenu2x->tr["Up one folder"], gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"],
gmenu2x->drawButton(&bg, "left", "", 5)-10))); gmenu2x->drawButton(bg, "left", "", 5)-10)));
} else { } else {
gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "cancel", "", gmenu2x->drawButton(bg, "cancel", "",
gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select"], 5)) - 10); gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], 5)) - 10);
} }
unsigned int top, height; unsigned int top, height;
@ -95,7 +95,9 @@ int Selector::exec(int startSelection) {
gmenu2x->sc.addSkinRes("imgs/folder.png"); gmenu2x->sc.addSkinRes("imgs/folder.png");
gmenu2x->sc.defaultAlpha = false; gmenu2x->sc.defaultAlpha = false;
while (!close) { while (!close) {
bg.blit(gmenu2x->s,0,0); Surface& s = *gmenu2x->s;
bg.blit(s, 0, 0);
if (selected >= firstElement + nb_elements) if (selected >= firstElement + nb_elements)
firstElement = selected - nb_elements + 1; firstElement = selected - nb_elements + 1;
@ -106,36 +108,35 @@ int Selector::exec(int startSelection) {
if (selected-fl.dirCount()<screens.size() if (selected-fl.dirCount()<screens.size()
&& !screens[selected-fl.dirCount()].empty()) { && !screens[selected-fl.dirCount()].empty()) {
Surface *screenshot = gmenu2x->sc[screens[selected-fl.dirCount()]]; Surface *screenshot = gmenu2x->sc[screens[selected-fl.dirCount()]];
if (screenshot) if (screenshot) {
screenshot->blitRight( screenshot->blitRight(s, 320, 0, 320, 240, 128u);
gmenu2x->s, 320, 0, 320, 240, }
128u);
} }
//Selection //Selection
iY = top + (selected - firstElement) * fontheight; iY = top + (selected - firstElement) * fontheight;
if (selected<fl.size()) if (selected<fl.size())
gmenu2x->s->box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); s.box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
//Files & Dirs //Files & Dirs
gmenu2x->s->setClipRect(0, top, 311, height); s.setClipRect(0, top, 311, height);
for (i = firstElement; i < fl.size() for (i = firstElement; i < fl.size()
&& i < firstElement + nb_elements; i++) { && i < firstElement + nb_elements; i++) {
iY = i-firstElement; iY = i-firstElement;
if (fl.isDirectory(i)) { if (fl.isDirectory(i)) {
gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, top + (iY * fontheight)); gmenu2x->sc["imgs/folder.png"]->blit(s, 4, top + (iY * fontheight));
gmenu2x->font->write(gmenu2x->s, fl[i], 21, gmenu2x->font->write(s, fl[i], 21,
top + (iY * fontheight) + (fontheight / 2), top + (iY * fontheight) + (fontheight / 2),
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} else } 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), top + (iY * fontheight) + (fontheight / 2),
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} }
gmenu2x->s->clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement); gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement);
gmenu2x->s->flip(); s.flip();
switch (gmenu2x->input.waitForPressedButton()) { switch (gmenu2x->input.waitForPressedButton()) {
case InputManager::SETTINGS: case InputManager::SETTINGS:

View File

@ -78,16 +78,18 @@ bool SettingsDialog::exec() {
} }
while (!close) { while (!close) {
Surface& s = *gmenu2x->s;
if (ts.available()) ts.poll(); 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 //link icon
drawTitleIcon(gmenu2x->s, icon); drawTitleIcon(s, icon);
writeTitle(gmenu2x->s, text); writeTitle(s, text);
gmenu2x->drawBottomBar(gmenu2x->s); gmenu2x->drawBottomBar(s);
if (sel>firstElement+numRows-1) firstElement=sel-numRows+1; if (sel>firstElement+numRows-1) firstElement=sel-numRows+1;
if (sel<firstElement) firstElement=sel; if (sel<firstElement) firstElement=sel;
@ -119,9 +121,9 @@ bool SettingsDialog::exec() {
gmenu2x->drawScrollBar(numRows, voices.size(), firstElement); gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
//description //description
writeSubTitle(gmenu2x->s, voices[sel]->getDescription()); writeSubTitle(s, voices[sel]->getDescription());
gmenu2x->s->flip(); s.flip();
voices[sel]->handleTS(maxNameWidth + 15, iY, rowHeight); voices[sel]->handleTS(maxNameWidth + 15, iY, rowHeight);
InputManager::Button button = inputMgr.waitForPressedButton(); InputManager::Button button = inputMgr.waitForPressedButton();

View File

@ -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_SetAlpha(raw, SDL_SRCALPHA|SDL_RLEACCEL, a);
SDL_BlitSurface(raw, (w==0 || h==0) ? NULL : &src, destination, &dest); 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 { void Surface::blit(Surface& destination, int x, int y, int w, int h, int a) const {
blit(destination->raw,x,y,w,h,a); 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 { 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); int oh = raw->h / 2; if (h != 0) oh = min(oh, h / 2);
blit(destination, x - ow, y - oh, w, h, a); 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 { void Surface::blitCenter(Surface& destination, int x, int y, int w, int h, int a) const {
blitCenter(destination->raw,x,y,w,h,a); 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 { void Surface::blitRight(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
if (!w) w = raw->w; 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; 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) { 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) { switch (halign) {
case Font::HAlignLeft: case Font::HAlignLeft:
break; break;
@ -275,7 +275,7 @@ void Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign
break; break;
} }
blit(destination,container.x,container.y); blit(destination, container.x, container.y);
} }
static inline uint32_t mult8x4(uint32_t c, uint8_t a) { static inline uint32_t mult8x4(uint32_t c, uint8_t a) {

View File

@ -76,10 +76,10 @@ public:
void setClipRect(int x, int y, int w, int h); void setClipRect(int x, int y, int w, int h);
void setClipRect(SDL_Rect rect); 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, 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 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 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 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(SDL_Rect re, RGBAColor c);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) { void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {

View File

@ -37,6 +37,7 @@ TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &desc
void TextDialog::drawText(const vector<string> &text, unsigned int y, void TextDialog::drawText(const vector<string> &text, unsigned int y,
unsigned int firstRow, unsigned int rowsPerPage) unsigned int firstRow, unsigned int rowsPerPage)
{ {
Surface& s = *gmenu2x->s;
const int fontHeight = gmenu2x->font->getLineSpacing(); const int fontHeight = gmenu2x->font->getLineSpacing();
for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text.size(); i++) { for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text.size(); i++) {
@ -44,10 +45,10 @@ void TextDialog::drawText(const vector<string> &text, unsigned int y,
int rowY = y + (i - firstRow) * fontHeight; int rowY = y + (i - firstRow) * fontHeight;
if (line == "----") { // horizontal ruler if (line == "----") { // horizontal ruler
rowY += fontHeight / 2; rowY += fontHeight / 2;
gmenu2x->s->box(5, rowY, gmenu2x->resX - 16, 1, 255, 255, 255, 130); 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+1, gmenu2x->resX - 16, 1, 0, 0, 0, 130);
} else { } 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 //link icon
if (!fileExists(icon)) if (!fileExists(icon))
drawTitleIcon(&bg, "icons/ebook.png", true); drawTitleIcon(bg, "icons/ebook.png", true);
else else
drawTitleIcon(&bg, icon, false); drawTitleIcon(bg, icon, false);
writeTitle(&bg, title); writeTitle(bg, title);
writeSubTitle(&bg, description); writeSubTitle(bg, description);
gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "cancel", "", gmenu2x->drawButton(bg, "cancel", "",
gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"], gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"],
gmenu2x->drawButton(&bg, "up", "", 5)-10))-10); gmenu2x->drawButton(bg, "up", "", 5)-10))-10);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
@ -82,9 +83,11 @@ void TextDialog::exec() {
unsigned firstRow = 0; unsigned firstRow = 0;
while (!close) { while (!close) {
bg.blit(gmenu2x->s, 0, 0); Surface& s = *gmenu2x->s;
bg.blit(s, 0, 0);
drawText(text, contentY, firstRow, rowsPerPage); drawText(text, contentY, firstRow, rowsPerPage);
gmenu2x->s->flip(); s.flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
case InputManager::UP: case InputManager::UP:

View File

@ -75,17 +75,17 @@ void TextManualDialog::exec() {
//link icon //link icon
if (!fileExists(icon)) if (!fileExists(icon))
drawTitleIcon(&bg, "icons/ebook.png", true); drawTitleIcon(bg, "icons/ebook.png", true);
else else
drawTitleIcon(&bg, icon, false); drawTitleIcon(bg, icon, false);
writeTitle(&bg, title+(description.empty() ? "" : ": "+description)); writeTitle(bg, title+(description.empty() ? "" : ": "+description));
gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "cancel", "", gmenu2x->drawButton(bg, "cancel", "",
gmenu2x->drawButton(&bg, "right", gmenu2x->tr["Change page"], gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"],
gmenu2x->drawButton(&bg, "left", "", gmenu2x->drawButton(bg, "left", "",
gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"], gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"],
gmenu2x->drawButton(&bg, "up", "", 5)-10))-10))-10); gmenu2x->drawButton(bg, "up", "", 5)-10))-10))-10);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
@ -97,17 +97,19 @@ void TextManualDialog::exec() {
string pageStatus; string pageStatus;
while (!close) { while (!close) {
bg.blit(gmenu2x->s,0,0); Surface& s = *gmenu2x->s;
writeSubTitle(gmenu2x->s, pages[page].title);
bg.blit(s,0,0);
writeSubTitle(s, pages[page].title);
drawText(pages[page].text, 42 /* TODO */, firstRow, rowsPerPage); drawText(pages[page].text, 42 /* TODO */, firstRow, rowsPerPage);
ss.clear(); ss.clear();
ss << page+1; ss << page+1;
ss >> pageStatus; ss >> pageStatus;
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; 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()) { switch(gmenu2x->input.waitForPressedButton()) {
case InputManager::UP: case InputManager::UP:

View File

@ -88,41 +88,43 @@ bool WallpaperDialog::exec()
unsigned int nb_elements = height / fontheight; unsigned int nb_elements = height / fontheight;
while (!close) { while (!close) {
Surface& s = *gmenu2x->s;
if (selected > firstElement + nb_elements - 1) if (selected > firstElement + nb_elements - 1)
firstElement = selected - nb_elements + 1; firstElement = selected - nb_elements + 1;
if (selected < firstElement) if (selected < firstElement)
firstElement = selected; firstElement = selected;
//Wallpaper //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->drawTopBar(s);
gmenu2x->drawBottomBar(gmenu2x->s); gmenu2x->drawBottomBar(s);
drawTitleIcon(gmenu2x->s, "icons/wallpaper.png", true); drawTitleIcon(s, "icons/wallpaper.png", true);
writeTitle(gmenu2x->s, gmenu2x->tr["Wallpaper selection"]); writeTitle(s, gmenu2x->tr["Wallpaper selection"]);
writeSubTitle(gmenu2x->s, gmenu2x->tr["Select a wallpaper from the list"]); writeSubTitle(s, gmenu2x->tr["Select a wallpaper from the list"]);
buttonbox.paint(gmenu2x->s, 5); buttonbox.paint(s, 5);
//Selection //Selection
iY = selected - firstElement; iY = selected - firstElement;
iY = top + (iY * fontheight); 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 //Files & Directories
gmenu2x->s->setClipRect(0, top, 311, height); s.setClipRect(0, top, 311, height);
for (i = firstElement; i < wallpapers.size() for (i = firstElement; i < wallpapers.size()
&& i < firstElement + nb_elements; i++) { && i < firstElement + nb_elements; i++) {
iY = i-firstElement; iY = i-firstElement;
gmenu2x->font->write(gmenu2x->s, wallpapers[i], 5, gmenu2x->font->write(s, wallpapers[i], 5,
top + (iY * fontheight), top + (iY * fontheight),
Font::HAlignLeft, Font::VAlignTop); Font::HAlignLeft, Font::VAlignTop);
} }
gmenu2x->s->clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement); gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement);
gmenu2x->s->flip(); s.flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
case InputManager::CANCEL: case InputManager::CANCEL: