1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-16 22:54:38 +02:00

Pass GMenu2X instance by reference instead of pointer

This makes it explicit that null is not accepted.
This commit is contained in:
Maarten ter Huurne 2015-04-21 20:32:33 +02:00
parent 05a58e869c
commit 11ca8308b1
55 changed files with 406 additions and 404 deletions

View File

@ -11,7 +11,7 @@ using std::string;
using std::unique_ptr; using std::unique_ptr;
BrowseDialog::BrowseDialog( BrowseDialog::BrowseDialog(
GMenu2X *gmenu2x, Touchscreen &ts_, GMenu2X& gmenu2x, Touchscreen &ts_,
const string &title, const string &subtitle) const string &title, const string &subtitle)
: Dialog(gmenu2x) : Dialog(gmenu2x)
, ts(ts_) , ts(ts_)
@ -23,27 +23,27 @@ BrowseDialog::BrowseDialog(
gmenu2x, ts, "skin:imgs/buttons/left.png"))); gmenu2x, ts, "skin:imgs/buttons/left.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x, ts, "skin:imgs/buttons/cancel.png",
gmenu2x->tr["Up one folder"], gmenu2x.tr["Up one folder"],
bind(&BrowseDialog::directoryUp, this)))); bind(&BrowseDialog::directoryUp, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Select"], gmenu2x.tr["Select"],
bind(&BrowseDialog::directoryEnter, this)))); bind(&BrowseDialog::directoryEnter, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/start.png", gmenu2x, ts, "skin:imgs/buttons/start.png",
gmenu2x->tr["Confirm"], gmenu2x.tr["Confirm"],
bind(&BrowseDialog::confirm, this)))); bind(&BrowseDialog::confirm, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/select.png", gmenu2x, ts, "skin:imgs/buttons/select.png",
gmenu2x->tr["Exit"], gmenu2x.tr["Exit"],
bind(&BrowseDialog::quit, this)))); bind(&BrowseDialog::quit, this))));
iconGoUp = gmenu2x->sc.skinRes("imgs/go-up.png"); iconGoUp = gmenu2x.sc.skinRes("imgs/go-up.png");
iconFolder = gmenu2x->sc.skinRes("imgs/folder.png"); iconFolder = gmenu2x.sc.skinRes("imgs/folder.png");
iconFile = gmenu2x->sc.skinRes("imgs/file.png"); iconFile = gmenu2x.sc.skinRes("imgs/file.png");
} }
BrowseDialog::~BrowseDialog() BrowseDialog::~BrowseDialog()
@ -57,20 +57,20 @@ bool BrowseDialog::exec()
|| path.compare(0, strlen(CARD_ROOT), CARD_ROOT) != 0) || path.compare(0, strlen(CARD_ROOT), CARD_ROOT) != 0)
setPath(CARD_ROOT); setPath(CARD_ROOT);
const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; const int topBarHeight = gmenu2x.skinConfInt["topBarHeight"];
rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1 rowHeight = gmenu2x.font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
rowHeight = constrain(rowHeight, 20, 40); rowHeight = constrain(rowHeight, 20, 40);
numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; numRows = (gmenu2x.resY - topBarHeight - 20) / rowHeight;
clipRect = (SDL_Rect) { clipRect = (SDL_Rect) {
0, 0,
static_cast<Sint16>(topBarHeight + 1), static_cast<Sint16>(topBarHeight + 1),
static_cast<Uint16>(gmenu2x->resX - 9), static_cast<Uint16>(gmenu2x.resX - 9),
static_cast<Uint16>(gmenu2x->resY - topBarHeight - 25) static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
}; };
touchRect = (SDL_Rect) { touchRect = (SDL_Rect) {
2, 2,
static_cast<Sint16>(topBarHeight + 4), static_cast<Sint16>(topBarHeight + 4),
static_cast<Uint16>(gmenu2x->resX - 12), static_cast<Uint16>(gmenu2x.resX - 12),
clipRect.h clipRect.h
}; };
@ -114,7 +114,7 @@ BrowseDialog::Action BrowseDialog::getAction(InputManager::Button button)
void BrowseDialog::handleInput() void BrowseDialog::handleInput()
{ {
InputManager::Button button = gmenu2x->input.waitForPressedButton(); InputManager::Button button = gmenu2x.input.waitForPressedButton();
BrowseDialog::Action action; BrowseDialog::Action action;
if (ts_pressed && !ts.pressed()) { if (ts_pressed && !ts.pressed()) {
@ -221,17 +221,17 @@ void BrowseDialog::quit()
void BrowseDialog::paint() void BrowseDialog::paint()
{ {
OutputSurface& s = *gmenu2x->s; OutputSurface& 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;
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface 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, gmenu2x->resY - 1); buttonBox.paint(bg, 5, gmenu2x.resY - 1);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
bg.blit(s, 0, 0); bg.blit(s, 0, 0);
@ -246,10 +246,10 @@ 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;
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;
if (lastElement > fl.size()) if (lastElement > fl.size())
@ -271,7 +271,7 @@ void BrowseDialog::paint()
icon = iconFile; icon = iconFile;
} }
icon->blit(s, 5, offsetY); icon->blit(s, 5, offsetY);
gmenu2x->font->write(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()
@ -284,6 +284,6 @@ void BrowseDialog::paint()
} }
s.clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(numRows,fl.size(), firstElement); gmenu2x.drawScrollBar(numRows,fl.size(), firstElement);
s.flip(); s.flip();
} }

View File

@ -35,7 +35,7 @@ class Touchscreen;
class BrowseDialog : protected Dialog { class BrowseDialog : protected Dialog {
protected: protected:
BrowseDialog( BrowseDialog(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &title, const std::string &subtitle); const std::string &title, const std::string &subtitle);
virtual ~BrowseDialog(); virtual ~BrowseDialog();

View File

@ -4,7 +4,7 @@
#include "gmenu2x.h" #include "gmenu2x.h"
#include "font.h" #include "font.h"
Dialog::Dialog(GMenu2X *gmenu2x) : gmenu2x(gmenu2x) Dialog::Dialog(GMenu2X& gmenu2x) : gmenu2x(gmenu2x)
{ {
} }
@ -13,27 +13,27 @@ void Dialog::drawTitleIcon(Surface& s, const std::string &icon, bool skinRes)
Surface *i = NULL; Surface *i = NULL;
if (!icon.empty()) { if (!icon.empty()) {
if (skinRes) if (skinRes)
i = gmenu2x->sc.skinRes(icon); i = gmenu2x.sc.skinRes(icon);
else else
i = gmenu2x->sc[icon]; i = gmenu2x.sc[icon];
} }
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.font->write(s, wrapped, 40,
gmenu2x->skinConfInt["topBarHeight"] gmenu2x.skinConfInt["topBarHeight"]
- gmenu2x->font->getTextHeight(wrapped), - gmenu2x.font->getTextHeight(wrapped),
Font::HAlignLeft, Font::VAlignTop); Font::HAlignLeft, Font::VAlignTop);
} }

View File

@ -9,14 +9,14 @@ class Surface;
class Dialog class Dialog
{ {
public: 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;
}; };
#endif #endif

View File

@ -25,7 +25,7 @@
using namespace std; using namespace std;
DirDialog::DirDialog( DirDialog::DirDialog(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &text, const string &dir) const string &text, const string &dir)
: BrowseDialog(gmenu2x, ts, "Directory Browser", text) : BrowseDialog(gmenu2x, ts, "Directory Browser", text)
{ {

View File

@ -26,7 +26,7 @@
class DirDialog : public BrowseDialog { class DirDialog : public BrowseDialog {
public: public:
DirDialog( DirDialog(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &text, const std::string &dir = ""); const std::string &text, const std::string &dir = "");
}; };

View File

@ -21,12 +21,11 @@
#include "filedialog.h" #include "filedialog.h"
#include "filelister.h" #include "filelister.h"
#include "gmenu2x.h"
using namespace std; using namespace std;
FileDialog::FileDialog( FileDialog::FileDialog(
GMenu2X *gmenu2x, Touchscreen &ts, const string &text, GMenu2X& gmenu2x, Touchscreen &ts, const string &text,
const string &filter, const string &file, const string &title) const string &filter, const string &file, const string &title)
: BrowseDialog(gmenu2x, ts, title, text) : BrowseDialog(gmenu2x, ts, title, text)
{ {

View File

@ -26,7 +26,7 @@
class FileDialog : public BrowseDialog { class FileDialog : public BrowseDialog {
public: public:
FileDialog( FileDialog(
GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text, GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text,
const std::string &filter="*", const std::string &file="", const std::string &filter="*", const std::string &file="",
const std::string &title = "File Dialog"); const std::string &title = "File Dialog");
bool exec(); bool exec();

View File

@ -214,7 +214,7 @@ void GMenu2X::initCPULimits() {
#endif #endif
GMenu2X::GMenu2X() GMenu2X::GMenu2X()
: input(powerSaver) : input(*this, powerSaver)
{ {
usbnet = samba = inet = web = false; usbnet = samba = inet = web = false;
useSelectionPng = false; useSelectionPng = false;
@ -279,7 +279,7 @@ GMenu2X::GMenu2X()
monitor = new MediaMonitor(CARD_ROOT); monitor = new MediaMonitor(CARD_ROOT);
#endif #endif
if (!input.init(this, menu.get())) { if (!input.init(menu.get())) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -376,7 +376,7 @@ void GMenu2X::initFont() {
void GMenu2X::initMenu() { void GMenu2X::initMenu() {
//Menu structure handler //Menu structure handler
menu.reset(new Menu(this, ts)); menu.reset(new Menu(*this, ts));
for (uint i=0; i<menu->getSections().size(); i++) { for (uint i=0; i<menu->getSections().size(); i++) {
//Add virtual links in the applications section //Add virtual links in the applications section
if (menu->getSections()[i]=="applications") { if (menu->getSections()[i]=="applications") {
@ -425,19 +425,19 @@ void GMenu2X::initMenu() {
void GMenu2X::about() { void GMenu2X::about() {
string text(readFileAsString(GMENU2X_SYSTEM_DIR "/about.txt")); string text(readFileAsString(GMENU2X_SYSTEM_DIR "/about.txt"));
string build_date("Build date: " __DATE__); string build_date("Build date: " __DATE__);
TextDialog td(this, "GMenu2X", build_date, "icons/about.png", text); TextDialog td(*this, "GMenu2X", build_date, "icons/about.png", text);
td.exec(); td.exec();
} }
void GMenu2X::viewLog() { void GMenu2X::viewLog() {
string text(readFileAsString(LOG_FILE)); string text(readFileAsString(LOG_FILE));
TextDialog td(this, tr["Log Viewer"], TextDialog td(*this, tr["Log Viewer"],
tr["Displays last launched program's output"], tr["Displays last launched program's output"],
"icons/ebook.png", text); "icons/ebook.png", text);
td.exec(); td.exec();
MessageBox mb(this, tr["Do you want to delete the log file?"], MessageBox mb(*this, tr["Do you want to delete the log file?"],
"icons/ebook.png"); "icons/ebook.png");
mb.setButton(InputManager::ACCEPT, tr["Yes"]); mb.setButton(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(InputManager::CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
@ -659,7 +659,7 @@ void GMenu2X::mainLoop() {
} }
void GMenu2X::explorer() { void GMenu2X::explorer() {
FileDialog fd(this, ts, tr["Select an application"], "sh,bin,py,elf,"); FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,");
if (fd.exec()) { if (fd.exec()) {
if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex())) if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex()))
writeConfig(); writeConfig();
@ -704,35 +704,35 @@ void GMenu2X::showSettings() {
encodings.push_back("NTSC"); encodings.push_back("NTSC");
encodings.push_back("PAL"); encodings.push_back("PAL");
SettingsDialog sd(this, input, ts, tr["Settings"]); SettingsDialog sd(*this, input, ts, tr["Settings"]);
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
this, ts, tr["Language"], *this, ts, tr["Language"],
tr["Set the language used by GMenu2X"], tr["Set the language used by GMenu2X"],
&lang, &translations))); &lang, &translations)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Save last selection"], *this, ts, tr["Save last selection"],
tr["Save the last selected link and section on exit"], tr["Save the last selected link and section on exit"],
&confInt["saveSelection"]))); &confInt["saveSelection"])));
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Clock for GMenu2X"], *this, ts, tr["Clock for GMenu2X"],
tr["Set the cpu working frequency when running GMenu2X"], tr["Set the cpu working frequency when running GMenu2X"],
&confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple))); &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Maximum overclock"], *this, ts, tr["Maximum overclock"],
tr["Set the maximum overclock for launching links"], tr["Set the maximum overclock for launching links"],
&confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple))); &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple)));
#endif #endif
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Output logs"], *this, ts, tr["Output logs"],
tr["Logs the output of the links. Use the Log Viewer to read them."], tr["Logs the output of the links. Use the Log Viewer to read them."],
&confInt["outputLogs"]))); &confInt["outputLogs"])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Screen Timeout"], *this, ts, tr["Screen Timeout"],
tr["Set screen's backlight timeout in seconds"], tr["Set screen's backlight timeout in seconds"],
&confInt["backlightTimeout"], 0, 120))); &confInt["backlightTimeout"], 0, 120)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Button repeat rate"], *this, ts, tr["Button repeat rate"],
tr["Set button repetitions per second"], tr["Set button repetitions per second"],
&confInt["buttonRepeatRate"], 0, 20))); &confInt["buttonRepeatRate"], 0, 20)));
@ -764,33 +764,33 @@ void GMenu2X::skinMenu() {
string curSkin = confStr["skin"]; string curSkin = confStr["skin"];
SettingsDialog sd(this, input, ts, tr["Skin"]); SettingsDialog sd(*this, input, ts, tr["Skin"]);
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
this, ts, tr["Skin"], *this, ts, tr["Skin"],
tr["Set the skin used by GMenu2X"], tr["Set the skin used by GMenu2X"],
&confStr["skin"], &fl_sk.getDirectories()))); &confStr["skin"], &fl_sk.getDirectories())));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Top Bar"], *this, ts, tr["Top Bar"],
tr["Color of the top bar"], tr["Color of the top bar"],
&skinConfColors[COLOR_TOP_BAR_BG]))); &skinConfColors[COLOR_TOP_BAR_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Bottom Bar"], *this, ts, tr["Bottom Bar"],
tr["Color of the bottom bar"], tr["Color of the bottom bar"],
&skinConfColors[COLOR_BOTTOM_BAR_BG]))); &skinConfColors[COLOR_BOTTOM_BAR_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Selection"], *this, ts, tr["Selection"],
tr["Color of the selection and other interface details"], tr["Color of the selection and other interface details"],
&skinConfColors[COLOR_SELECTION_BG]))); &skinConfColors[COLOR_SELECTION_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box"], *this, ts, tr["Message Box"],
tr["Background color of the message box"], tr["Background color of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_BG]))); &skinConfColors[COLOR_MESSAGE_BOX_BG])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box Border"], *this, ts, tr["Message Box Border"],
tr["Border color of the message box"], tr["Border color of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_BORDER]))); &skinConfColors[COLOR_MESSAGE_BOX_BORDER])));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
this, ts, tr["Message Box Selection"], *this, ts, tr["Message Box Selection"],
tr["Color of the selection of the message box"], tr["Color of the selection of the message box"],
&skinConfColors[COLOR_MESSAGE_BOX_SELECTION]))); &skinConfColors[COLOR_MESSAGE_BOX_SELECTION])));
@ -891,7 +891,7 @@ void GMenu2X::showContextMenu() {
} }
void GMenu2X::changeWallpaper() { void GMenu2X::changeWallpaper() {
WallpaperDialog wp(this, ts); WallpaperDialog wp(*this, ts);
if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) { if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) {
confStr["wallpaper"] = wp.wallpaper; confStr["wallpaper"] = wp.wallpaper;
initBG(); initBG();
@ -900,7 +900,7 @@ void GMenu2X::changeWallpaper() {
} }
void GMenu2X::addLink() { void GMenu2X::addLink() {
FileDialog fd(this, ts, tr["Select an application"], "sh,bin,py,elf,"); FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,");
if (fd.exec()) if (fd.exec())
menu->addLink(fd.getPath(), fd.getFile()); menu->addLink(fd.getPath(), fd.getFile());
} }
@ -928,52 +928,52 @@ void GMenu2X::editLink() {
string diagTitle = tr.translate("Edit $1",linkTitle.c_str(),NULL); string diagTitle = tr.translate("Edit $1",linkTitle.c_str(),NULL);
string diagIcon = linkApp->getIconPath(); string diagIcon = linkApp->getIconPath();
SettingsDialog sd(this, input, ts, diagTitle, diagIcon); SettingsDialog sd(*this, input, ts, diagTitle, diagIcon);
if (!linkApp->isOpk()) { if (!linkApp->isOpk()) {
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
this, ts, tr["Title"], *this, ts, tr["Title"],
tr["Link title"], tr["Link title"],
&linkTitle, diagTitle, diagIcon))); &linkTitle, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
this, ts, tr["Description"], *this, ts, tr["Description"],
tr["Link description"], tr["Link description"],
&linkDescription, diagTitle, diagIcon))); &linkDescription, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
this, ts, tr["Section"], *this, ts, tr["Section"],
tr["The section this link belongs to"], tr["The section this link belongs to"],
&newSection, &menu->getSections()))); &newSection, &menu->getSections())));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingImage( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingImage(
this, ts, tr["Icon"], *this, ts, tr["Icon"],
tr.translate("Select an icon for this link", linkTitle.c_str(), NULL), tr.translate("Select an icon for this link", linkTitle.c_str(), NULL),
&linkIcon, "png"))); &linkIcon, "png")));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingFile( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingFile(
this, ts, tr["Manual"], *this, ts, tr["Manual"],
tr["Select a manual or README file"], tr["Select a manual or README file"],
&linkManual, "man.png,txt"))); &linkManual, "man.png,txt")));
} }
if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) { if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) {
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingDir( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingDir(
this, ts, tr["Selector Directory"], *this, ts, tr["Selector Directory"],
tr["Directory to scan for the selector"], tr["Directory to scan for the selector"],
&linkSelDir))); &linkSelDir)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Selector Browser"], *this, ts, tr["Selector Browser"],
tr["Allow the selector to change directory"], tr["Allow the selector to change directory"],
&linkSelBrowser))); &linkSelBrowser)));
} }
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
this, ts, tr["Clock frequency"], *this, ts, tr["Clock frequency"],
tr["CPU clock frequency for this link"], tr["CPU clock frequency for this link"],
&linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple))); &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple)));
#endif #endif
if (!linkApp->isOpk()) { if (!linkApp->isOpk()) {
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
this, ts, tr["Selector Filter"], *this, ts, tr["Selector Filter"],
tr["Selector filter (Separate values with a comma)"], tr["Selector filter (Separate values with a comma)"],
&linkSelFilter, diagTitle, diagIcon))); &linkSelFilter, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
this, ts, tr["Display Console"], *this, ts, tr["Display Console"],
tr["Must be enabled for console-based applications"], tr["Must be enabled for console-based applications"],
&linkApp->consoleApp))); &linkApp->consoleApp)));
} }
@ -1015,7 +1015,7 @@ void GMenu2X::editLink() {
void GMenu2X::deleteLink() { void GMenu2X::deleteLink() {
if (menu->selLinkApp()!=NULL) { if (menu->selLinkApp()!=NULL) {
MessageBox mb(this, tr.translate("Deleting $1",menu->selLink()->getTitle().c_str(),NULL)+"\n"+tr["Are you sure?"], menu->selLink()->getIconPath()); MessageBox mb(*this, tr.translate("Deleting $1",menu->selLink()->getTitle().c_str(),NULL)+"\n"+tr["Are you sure?"], menu->selLink()->getIconPath());
mb.setButton(InputManager::ACCEPT, tr["Yes"]); mb.setButton(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(InputManager::CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == InputManager::ACCEPT) if (mb.exec() == InputManager::ACCEPT)
@ -1024,7 +1024,7 @@ void GMenu2X::deleteLink() {
} }
void GMenu2X::addSection() { void GMenu2X::addSection() {
InputDialog id(this, input, ts, tr["Insert a name for the new section"]); InputDialog id(*this, input, ts, tr["Insert a name for the new section"]);
if (id.exec()) { if (id.exec()) {
//only if a section with the same name does not exist //only if a section with the same name does not exist
if (find(menu->getSections().begin(), menu->getSections().end(), id.getInput()) if (find(menu->getSections().begin(), menu->getSections().end(), id.getInput())
@ -1037,7 +1037,7 @@ void GMenu2X::addSection() {
} }
void GMenu2X::renameSection() { void GMenu2X::renameSection() {
InputDialog id(this, input, ts, tr["Insert a new name for this section"],menu->selSection()); InputDialog id(*this, input, ts, tr["Insert a new name for this section"],menu->selSection());
if (id.exec()) { if (id.exec()) {
//only if a section with the same name does not exist & !samename //only if a section with the same name does not exist & !samename
if (menu->selSection() != id.getInput() if (menu->selSection() != id.getInput()
@ -1069,7 +1069,7 @@ void GMenu2X::renameSection() {
} }
void GMenu2X::deleteSection() { void GMenu2X::deleteSection() {
MessageBox mb(this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]); MessageBox mb(*this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]);
mb.setButton(InputManager::ACCEPT, tr["Yes"]); mb.setButton(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(InputManager::CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == InputManager::ACCEPT) { if (mb.exec() == InputManager::ACCEPT) {

View File

@ -8,7 +8,7 @@ using namespace std;
IconButton::IconButton( IconButton::IconButton(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &icon, const string &label, Action action) const string &icon, const string &label, Action action)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
, ts(ts) , ts(ts)
@ -17,7 +17,7 @@ IconButton::IconButton(
, action(action) , action(action)
, rect({ 0, 0, 0, 0 }) , rect({ 0, 0, 0, 0 })
{ {
iconSurface = gmenu2x->sc[icon]; iconSurface = gmenu2x.sc[icon];
recalcRects(); recalcRects();
} }
@ -42,8 +42,8 @@ void IconButton::recalcRects() {
labelRect = { labelRect = {
static_cast<Sint16>(iconRect.x + iconRect.w + margin), static_cast<Sint16>(iconRect.x + iconRect.w + margin),
static_cast<Sint16>(rect.y + h / 2), static_cast<Sint16>(rect.y + h / 2),
static_cast<Uint16>(gmenu2x->font->getTextWidth(label)), static_cast<Uint16>(gmenu2x.font->getTextWidth(label)),
static_cast<Uint16>(gmenu2x->font->getLineSpacing()) static_cast<Uint16>(gmenu2x.font->getLineSpacing())
}; };
w += margin + labelRect.w; w += margin + labelRect.w;
} }
@ -66,7 +66,7 @@ void IconButton::paint(Surface& s) {
iconSurface->blit(s, iconRect); iconSurface->blit(s, iconRect);
} }
if (!label.empty()) { if (!label.empty()) {
gmenu2x->font->write(s, label, labelRect.x, labelRect.y, gmenu2x.font->write(s, label, labelRect.x, labelRect.y,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} }
} }

View File

@ -17,7 +17,7 @@ class IconButton {
public: public:
typedef std::function<void(void)> Action; typedef std::function<void(void)> Action;
IconButton(GMenu2X *gmenu2x, Touchscreen &ts, IconButton(GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &icon, const std::string &label = "", const std::string &icon, const std::string &label = "",
Action action = nullptr); Action action = nullptr);
@ -31,7 +31,7 @@ public:
private: private:
void recalcRects(); void recalcRects();
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
Touchscreen &ts; Touchscreen &ts;
std::string icon, label; std::string icon, label;
Action action; Action action;

View File

@ -34,7 +34,7 @@
using namespace std; using namespace std;
ImageDialog::ImageDialog( ImageDialog::ImageDialog(
GMenu2X *gmenu2x, Touchscreen &ts, const string &text, GMenu2X& gmenu2x, Touchscreen &ts, const string &text,
const string &filter, const string &file) const string &filter, const string &file)
: FileDialog(gmenu2x, ts, text, filter, file, "Image Browser") : FileDialog(gmenu2x, ts, text, filter, file, "Image Browser")
{ {
@ -42,7 +42,7 @@ ImageDialog::ImageDialog(
string path; string path;
if (!file.empty()) { if (!file.empty()) {
path = strreplace(file, "skin:", gmenu2x->sc.getSkinPath(gmenu2x->confStr["skin"])); path = strreplace(file, "skin:", gmenu2x.sc.getSkinPath(gmenu2x.confStr["skin"]));
string::size_type pos = path.rfind("/"); string::size_type pos = path.rfind("/");
if (pos != string::npos) if (pos != string::npos)
setPath(path.substr(0, pos)); setPath(path.substr(0, pos));
@ -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

@ -31,7 +31,7 @@ protected:
SurfaceCollection previews; SurfaceCollection previews;
public: public:
ImageDialog( ImageDialog(
GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text, GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text,
const std::string &filter = "", const std::string &file = ""); const std::string &filter = "", const std::string &file = "");
virtual ~ImageDialog(); virtual ~ImageDialog();

View File

@ -37,7 +37,7 @@ static bool utf8Code(unsigned char c)
return (c>=194 && c<=198) || c==208 || c==209; return (c>=194 && c<=198) || c==208 || c==209;
} }
InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_, InputDialog::InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr_,
Touchscreen &ts_, const string &text, Touchscreen &ts_, const string &text,
const string &startvalue, const string &title, const string &icon) const string &startvalue, const string &title, const string &icon)
: Dialog(gmenu2x) : Dialog(gmenu2x)
@ -52,7 +52,7 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
this->text = text; this->text = text;
} }
this->icon = ""; this->icon = "";
if (!icon.empty() && gmenu2x->sc[icon] != NULL) { if (!icon.empty() && gmenu2x.sc[icon] != NULL) {
this->icon = icon; this->icon = icon;
} }
@ -98,22 +98,22 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
buttonbox.add(unique_ptr<IconButton>(new IconButton( buttonbox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/l.png", gmenu2x, ts, "skin:imgs/buttons/l.png",
gmenu2x->tr["Backspace"], gmenu2x.tr["Backspace"],
bind(&InputDialog::backspace, this)))); bind(&InputDialog::backspace, this))));
buttonbox.add(unique_ptr<IconButton>(new IconButton( buttonbox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/r.png", gmenu2x, ts, "skin:imgs/buttons/r.png",
gmenu2x->tr["Space"], gmenu2x.tr["Space"],
bind(&InputDialog::space, this)))); bind(&InputDialog::space, this))));
buttonbox.add(unique_ptr<IconButton>(new IconButton( buttonbox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Confirm"], gmenu2x.tr["Confirm"],
bind(&InputDialog::confirm, this)))); bind(&InputDialog::confirm, this))));
buttonbox.add(unique_ptr<IconButton>(new IconButton( buttonbox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x, ts, "skin:imgs/buttons/cancel.png",
gmenu2x->tr["Change keys"], gmenu2x.tr["Change keys"],
bind(&InputDialog::changeKeys, this)))); bind(&InputDialog::changeKeys, this))));
} }
@ -141,34 +141,34 @@ void InputDialog::setKeyboard(int kb) {
bool InputDialog::exec() { bool InputDialog::exec() {
SDL_Rect box = { SDL_Rect box = {
0, 60, 0, static_cast<Uint16>(gmenu2x->font->getLineSpacing() + 4) 0, 60, 0, static_cast<Uint16>(gmenu2x.font->getLineSpacing() + 4)
}; };
Uint32 caretTick = 0, curTick; Uint32 caretTick = 0, curTick;
bool caretOn = true; bool caretOn = true;
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface 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, gmenu2x->resY - 1); buttonbox.paint(bg, 5, gmenu2x.resY - 1);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
close = false; close = false;
ok = true; ok = true;
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
bg.blit(s, 0, 0); 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;
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]);
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(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();
@ -179,7 +179,7 @@ bool InputDialog::exec() {
if (caretOn) { if (caretOn) {
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();
@ -264,10 +264,10 @@ void InputDialog::changeKeys() {
} }
void InputDialog::drawVirtualKeyboard() { void InputDialog::drawVirtualKeyboard() {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
//keyboard border //keyboard border
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;
@ -278,13 +278,13 @@ void InputDialog::drawVirtualKeyboard() {
if (selRow<(int)kb->size()) if (selRow<(int)kb->size())
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;
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]);
} }
//keys //keys
@ -313,8 +313,8 @@ void InputDialog::drawVirtualKeyboard() {
} }
s.rectangle(re, s.rectangle(re,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->font->write(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);
@ -329,23 +329,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
}; };
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(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;
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(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

@ -33,7 +33,7 @@ class Touchscreen;
class InputDialog : protected Dialog { class InputDialog : protected Dialog {
public: public:
InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr, Touchscreen &ts, InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts,
const std::string &text, const std::string &startvalue="", const std::string &text, const std::string &startvalue="",
const std::string &title="", const std::string &icon=""); const std::string &title="", const std::string &icon="");

View File

@ -30,8 +30,8 @@
using namespace std; using namespace std;
bool InputManager::init(GMenu2X *gmenu2x, Menu *menu) { bool InputManager::init(Menu *menu)
this->gmenu2x = gmenu2x; {
this->menu = menu; this->menu = menu;
repeatRateChanged(); repeatRateChanged();
@ -43,7 +43,7 @@ bool InputManager::init(GMenu2X *gmenu2x, Menu *menu) {
/* If a user-specified input.conf file exists, we load it; /* If a user-specified input.conf file exists, we load it;
* otherwise, we load the default one. */ * otherwise, we load the default one. */
string input_file = gmenu2x->getHome() + "/input.conf"; string input_file = gmenu2x.getHome() + "/input.conf";
DEBUG("Loading user-specific input.conf file: %s.\n", input_file.c_str()); DEBUG("Loading user-specific input.conf file: %s.\n", input_file.c_str());
if (!readConfFile(input_file)) { if (!readConfFile(input_file)) {
input_file = GMENU2X_SYSTEM_DIR "/input.conf"; input_file = GMENU2X_SYSTEM_DIR "/input.conf";
@ -57,8 +57,9 @@ bool InputManager::init(GMenu2X *gmenu2x, Menu *menu) {
return true; return true;
} }
InputManager::InputManager(PowerSaver& powerSaver) InputManager::InputManager(GMenu2X& gmenu2x, PowerSaver& powerSaver)
: powerSaver(powerSaver) : gmenu2x(gmenu2x)
, powerSaver(powerSaver)
{ {
#ifndef SDL_JOYSTICK_DISABLED #ifndef SDL_JOYSTICK_DISABLED
int i; int i;
@ -152,7 +153,7 @@ static int repeatRateMs(int repeatRate)
} }
void InputManager::repeatRateChanged() { void InputManager::repeatRateChanged() {
int ms = repeatRateMs(gmenu2x->confInt["buttonRepeatRate"]); int ms = repeatRateMs(gmenu2x.confInt["buttonRepeatRate"]);
if (ms == 0) { if (ms == 0) {
SDL_EnableKeyRepeat(0, 0); SDL_EnableKeyRepeat(0, 0);
} else { } else {
@ -347,7 +348,7 @@ Uint32 InputManager::joystickRepeatCallback(Uint32 timeout __attribute__((unused
}; };
SDL_PushEvent((SDL_Event *) &e); SDL_PushEvent((SDL_Event *) &e);
return repeatRateMs(gmenu2x->confInt["buttonRepeatRate"]); return repeatRateMs(gmenu2x.confInt["buttonRepeatRate"]);
} }
void InputManager::stopTimer(Joystick *joystick) void InputManager::stopTimer(Joystick *joystick)

View File

@ -62,10 +62,10 @@ public:
}; };
#define BUTTON_TYPE_SIZE 10 #define BUTTON_TYPE_SIZE 10
InputManager(PowerSaver& powerSaver); InputManager(GMenu2X& gmenu2x, PowerSaver& powerSaver);
~InputManager(); ~InputManager();
bool init(GMenu2X *gmenu2x, Menu *menu); bool init(Menu *menu);
Button waitForPressedButton(); Button waitForPressedButton();
void repeatRateChanged(); void repeatRateChanged();
Uint32 joystickRepeatCallback(Uint32 timeout, struct Joystick *joystick); Uint32 joystickRepeatCallback(Uint32 timeout, struct Joystick *joystick);
@ -80,7 +80,7 @@ private:
unsigned int kb_code, js_code; unsigned int kb_code, js_code;
}; };
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
Menu *menu; Menu *menu;
PowerSaver& powerSaver; PowerSaver& powerSaver;

View File

@ -32,17 +32,17 @@
using namespace std; using namespace std;
Link::Link(GMenu2X *gmenu2x, Action action) Link::Link(GMenu2X& gmenu2x, Action action)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
, ts(gmenu2x->getTouchscreen()) , ts(gmenu2x.getTouchscreen())
, action(action) , action(action)
, lastTick(0) , lastTick(0)
{ {
// ts = gmenu2x->getTouchscreen(); // ts = gmenu2x.getTouchscreen();
rect.w = gmenu2x->skinConfInt["linkWidth"]; rect.w = gmenu2x.skinConfInt["linkWidth"];
rect.h = gmenu2x->skinConfInt["linkHeight"]; rect.h = gmenu2x.skinConfInt["linkHeight"];
edited = false; edited = false;
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
iconX = 0; iconX = 0;
padding = 0; padding = 0;
@ -67,26 +67,26 @@ bool Link::handleTS() {
} }
void Link::paint() { void Link::paint() {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
if (iconSurface) { if (iconSurface) {
iconSurface->blit(s, iconX, rect.y+padding, 32,32); iconSurface->blit(s, iconX, rect.y+padding, 32,32);
} }
gmenu2x->font->write(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; Surface& s = *gmenu2x.s;
if (gmenu2x->useSelectionPng) if (gmenu2x.useSelectionPng)
gmenu2x->sc["imgs/selection.png"]->blit(s, rect, Font::HAlignCenter, Font::VAlignMiddle); gmenu2x.sc["imgs/selection.png"]->blit(s, rect, Font::HAlignCenter, Font::VAlignMiddle);
else else
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()
{ {
iconSurface = gmenu2x->sc[getIconPath()]; iconSurface = gmenu2x.sc[getIconPath()];
} }
const string &Link::getTitle() { const string &Link::getTitle() {
@ -117,7 +117,7 @@ const string &Link::getIcon() {
void Link::loadIcon() { void Link::loadIcon() {
if (icon.compare(0, 5, "skin:") == 0) { if (icon.compare(0, 5, "skin:") == 0) {
setIconPath(gmenu2x->sc.getSkinFilePath(icon.substr(5, string::npos))); setIconPath(gmenu2x.sc.getSkinFilePath(icon.substr(5, string::npos)));
} }
} }
@ -125,7 +125,7 @@ void Link::setIcon(const string &icon) {
this->icon = icon; this->icon = icon;
if (icon.compare(0, 5, "skin:") == 0) if (icon.compare(0, 5, "skin:") == 0)
this->iconPath = gmenu2x->sc.getSkinFilePath( this->iconPath = gmenu2x.sc.getSkinFilePath(
icon.substr(5, string::npos)); icon.substr(5, string::npos));
else else
this->iconPath = icon; this->iconPath = icon;
@ -135,7 +135,7 @@ void Link::setIcon(const string &icon) {
} }
const string &Link::searchIcon() { const string &Link::searchIcon() {
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
return iconPath; return iconPath;
} }
@ -148,7 +148,7 @@ void Link::setIconPath(const string &icon) {
if (fileExists(icon)) if (fileExists(icon))
iconPath = icon; iconPath = icon;
else else
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
updateSurfaces(); updateSurfaces();
} }
@ -166,7 +166,7 @@ void Link::setPosition(int x, int y) {
void Link::recalcCoordinates() { void Link::recalcCoordinates() {
iconX = rect.x+(rect.w-32)/2; iconX = rect.x+(rect.w-32)/2;
padding = (gmenu2x->skinConfInt["linkHeight"] - 32 - gmenu2x->font->getLineSpacing()) / 3; padding = (gmenu2x.skinConfInt["linkHeight"] - 32 - gmenu2x.font->getLineSpacing()) / 3;
} }
void Link::run() { void Link::run() {

View File

@ -40,7 +40,7 @@ class Link {
public: public:
typedef std::function<void(void)> Action; typedef std::function<void(void)> Action;
Link(GMenu2X *gmenu2x, Action action); Link(GMenu2X& gmenu2x, Action action);
virtual ~Link() {}; virtual ~Link() {};
bool isPressed(); bool isPressed();
@ -66,7 +66,7 @@ public:
void run(); void run();
protected: protected:
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
bool edited; bool edited;
std::string title, description, launchMsg, icon, iconPath; std::string title, description, launchMsg, icon, iconPath;

View File

@ -82,18 +82,18 @@ private:
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable, LinkApp::LinkApp(GMenu2X& gmenu2x, string const& linkfile, bool deletable,
struct OPK *opk, const char *metadata_) struct OPK *opk, const char *metadata_)
#else #else
LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable) LinkApp::LinkApp(GMenu2X& gmenu2x, string const& linkfile, bool deletable)
#endif #endif
: Link(gmenu2x_, bind(&LinkApp::start, this)) : Link(gmenu2x, bind(&LinkApp::start, this))
, deletable(deletable) , deletable(deletable)
{ {
manual = ""; manual = "";
file = linkfile; file = linkfile;
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
setClock(gmenu2x->getDefaultAppClock()); setClock(gmenu2x.getDefaultAppClock());
#else #else
setClock(0); setClock(0);
#endif #endif
@ -141,13 +141,13 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable)
category = category.substr(0, pos); category = category.substr(0, pos);
} else if ((!strncmp(key, "Name", lkey) && title.empty()) } else if ((!strncmp(key, "Name", lkey) && title.empty())
|| !strncmp(key, ("Name[" + gmenu2x->tr["Lng"] + || !strncmp(key, ("Name[" + gmenu2x.tr["Lng"] +
"]").c_str(), lkey)) { "]").c_str(), lkey)) {
title = buf; title = buf;
} else if ((!strncmp(key, "Comment", lkey) && description.empty()) } else if ((!strncmp(key, "Comment", lkey) && description.empty())
|| !strncmp(key, ("Comment[" + || !strncmp(key, ("Comment[" +
gmenu2x->tr["Lng"] + "]").c_str(), lkey)) { gmenu2x.tr["Lng"] + "]").c_str(), lkey)) {
description = buf; description = buf;
} else if (!strncmp(key, "Terminal", lkey)) { } else if (!strncmp(key, "Terminal", lkey)) {
@ -159,7 +159,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable)
} else if (!strncmp(key, "Icon", lkey)) { } else if (!strncmp(key, "Icon", lkey)) {
/* Read the icon from the OPK only /* Read the icon from the OPK only
* if it doesn't exist on the skin */ * if it doesn't exist on the skin */
this->icon = gmenu2x->sc.getSkinFilePath("icons/" + (string) buf + ".png"); this->icon = gmenu2x.sc.getSkinFilePath("icons/" + (string) buf + ".png");
if (this->icon.empty()) { if (this->icon.empty()) {
this->icon = linkfile + '#' + buf + ".png"; this->icon = linkfile + '#' + buf + ".png";
} }
@ -211,7 +211,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable)
#endif /* HAVE_LIBXDGMIME */ #endif /* HAVE_LIBXDGMIME */
} }
file = gmenu2x->getHome() + "/sections/" + category + '/' + opkMount; file = gmenu2x.getHome() + "/sections/" + category + '/' + opkMount;
opkMount = (string) "/mnt/" + opkMount + '/'; opkMount = (string) "/mnt/" + opkMount + '/';
edited = true; edited = true;
} else } else
@ -274,7 +274,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, string const& linkfile, bool deletable)
void LinkApp::loadIcon() { void LinkApp::loadIcon() {
if (icon.compare(0, 5, "skin:") == 0) { if (icon.compare(0, 5, "skin:") == 0) {
string linkIcon = gmenu2x->sc.getSkinFilePath( string linkIcon = gmenu2x.sc.getSkinFilePath(
icon.substr(5, string::npos)); icon.substr(5, string::npos));
if (!fileExists(linkIcon)) if (!fileExists(linkIcon))
searchIcon(); searchIcon();
@ -299,12 +299,12 @@ const string &LinkApp::searchIcon() {
if (pos != string::npos) if (pos != string::npos)
string exectitle = execicon.substr(pos+1,execicon.length()); string exectitle = execicon.substr(pos+1,execicon.length());
if (!gmenu2x->sc.getSkinFilePath("icons/"+exectitle).empty()) if (!gmenu2x.sc.getSkinFilePath("icons/"+exectitle).empty())
iconPath = gmenu2x->sc.getSkinFilePath("icons/"+exectitle); iconPath = gmenu2x.sc.getSkinFilePath("icons/"+exectitle);
else if (fileExists(execicon)) else if (fileExists(execicon))
iconPath = execicon; iconPath = execicon;
else else
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
return iconPath; return iconPath;
} }
@ -378,35 +378,35 @@ bool LinkApp::save() {
void LinkApp::drawLaunch(Surface& s) { void LinkApp::drawLaunch(Surface& s) {
//Darkened background //Darkened background
s.box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,150); s.box(0, 0, gmenu2x.resX, gmenu2x.resY, 0,0,0,150);
string text = getLaunchMsg().empty() string text = getLaunchMsg().empty()
? gmenu2x->tr.translate("Launching $1", getTitle().c_str(), nullptr) ? gmenu2x.tr.translate("Launching $1", getTitle().c_str(), nullptr)
: gmenu2x->tr.translate(getLaunchMsg().c_str(), nullptr); : gmenu2x.tr.translate(getLaunchMsg().c_str(), nullptr);
int textW = gmenu2x->font->getTextWidth(text); int textW = gmenu2x.font->getTextWidth(text);
int boxW = 62+textW; int boxW = 62+textW;
int halfBoxW = boxW/2; int halfBoxW = boxW/2;
//outer box //outer box
s.box(gmenu2x->halfX-2-halfBoxW, gmenu2x->halfY-23, halfBoxW*2+5, 47, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BG]); s.box(gmenu2x.halfX-2-halfBoxW, gmenu2x.halfY-23, halfBoxW*2+5, 47, gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BG]);
//inner rectangle //inner rectangle
s.rectangle(gmenu2x->halfX-halfBoxW, gmenu2x->halfY-21, boxW, 42, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]); s.rectangle(gmenu2x.halfX-halfBoxW, gmenu2x.halfY-21, boxW, 42, gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
int x = gmenu2x->halfX+10-halfBoxW; int x = gmenu2x.halfX + 10 - halfBoxW;
/*if (!getIcon().empty()) /*if (!getIcon().empty())
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);*/
if (iconSurface) { if (iconSurface) {
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() {
if (selectordir.empty()) { if (selectordir.empty()) {
gmenu2x->queueLaunch(prepareLaunch(""), make_shared<LaunchLayer>(*this)); gmenu2x.queueLaunch(prepareLaunch(""), make_shared<LaunchLayer>(*this));
} else { } else {
selector(); selector();
} }
@ -459,16 +459,16 @@ void LinkApp::showManual() {
if (manual.substr(manual.size()-8,8)==".man.png") { if (manual.substr(manual.size()-8,8)==".man.png") {
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
//Raise the clock to speed-up the loading of the manual //Raise the clock to speed-up the loading of the manual
gmenu2x->setSafeMaxClock(); gmenu2x.setSafeMaxClock();
#endif #endif
auto pngman = OffscreenSurface::loadImage(manual); auto pngman = OffscreenSurface::loadImage(manual);
if (!pngman) { if (!pngman) {
return; return;
} }
auto bg = OffscreenSurface::loadImage(gmenu2x->confStr["wallpaper"]); auto bg = OffscreenSurface::loadImage(gmenu2x.confStr["wallpaper"]);
if (!bg) { if (!bg) {
bg = OffscreenSurface::emptySurface(gmenu2x->s->width(), gmenu2x->s->height()); bg = OffscreenSurface::emptySurface(gmenu2x.s->width(), gmenu2x.s->height());
} }
bg->convertToDisplayFormat(); bg->convertToDisplayFormat();
@ -484,34 +484,34 @@ void LinkApp::showManual() {
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
//Lower the clock //Lower the clock
gmenu2x->setMenuClock(); gmenu2x.setMenuClock();
#endif #endif
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
if (repaint) { if (repaint) {
bg->blit(s, 0, 0); bg->blit(s, 0, 0);
pngman->blit(s, -page*320, 0); pngman->blit(s, -page*320, 0);
gmenu2x->drawBottomBar(s); gmenu2x.drawBottomBar(s);
int x = 5; int x = 5;
x = gmenu2x->drawButton(s, "left", "", x); x = gmenu2x.drawButton(s, "left", "", x);
x = gmenu2x->drawButton(s, "right", gmenu2x->tr["Change page"], x); x = gmenu2x.drawButton(s, "right", gmenu2x.tr["Change page"], x);
x = gmenu2x->drawButton(s, "cancel", "", x); x = gmenu2x.drawButton(s, "cancel", "", x);
x = gmenu2x->drawButton(s, "start", gmenu2x->tr["Exit"], x); x = gmenu2x.drawButton(s, "start", gmenu2x.tr["Exit"], x);
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(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); gmenu2x.font->write(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle);
s.flip(); s.flip();
repaint = false; repaint = false;
} }
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x.input.waitForPressedButton()) {
case InputManager::SETTINGS: case InputManager::SETTINGS:
case InputManager::CANCEL: case InputManager::CANCEL:
close = true; close = true;
@ -566,8 +566,8 @@ void LinkApp::selector(int startSelection, const string &selectorDir) {
if (!selectedDir.empty()) { if (!selectedDir.empty()) {
selectordir = selectedDir; selectordir = selectedDir;
} }
gmenu2x->writeTmp(selection, selectedDir); gmenu2x.writeTmp(selection, selectedDir);
gmenu2x->queueLaunch( gmenu2x.queueLaunch(
prepareLaunch(selectedDir + sel.getFile()), prepareLaunch(selectedDir + sel.getFile()),
make_shared<LaunchLayer>(*this)); make_shared<LaunchLayer>(*this));
} }
@ -607,7 +607,7 @@ unique_ptr<Launcher> LinkApp::prepareLaunch(const string &selectedFile) {
} }
} }
if (gmenu2x->confInt["outputLogs"] && !consoleApp) { if (gmenu2x.confInt["outputLogs"] && !consoleApp) {
int fd = open(LOG_FILE, O_WRONLY | O_TRUNC | O_CREAT, 0644); int fd = open(LOG_FILE, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if (fd < 0) { if (fd < 0) {
ERROR("Unable to open log file for write: %s\n", LOG_FILE); ERROR("Unable to open log file for write: %s\n", LOG_FILE);
@ -619,14 +619,14 @@ unique_ptr<Launcher> LinkApp::prepareLaunch(const string &selectedFile) {
} }
} }
gmenu2x->saveSelection(); gmenu2x.saveSelection();
if (selectedFile.empty()) { if (selectedFile.empty()) {
gmenu2x->writeTmp(); gmenu2x.writeTmp();
} }
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
if (clock() != gmenu2x->confInt["menuClock"]) { if (clock() != gmenu2x.confInt["menuClock"]) {
gmenu2x->setClock(clock()); gmenu2x.setClock(clock());
} }
#endif #endif

View File

@ -61,10 +61,10 @@ public:
bool isOpk() { return isOPK; } bool isOpk() { return isOPK; }
const std::string &getOpkFile() { return opkFile; } const std::string &getOpkFile() { return opkFile; }
LinkApp(GMenu2X *gmenu2x, std::string const& linkfile, bool deletable, LinkApp(GMenu2X& gmenu2x, std::string const& linkfile, bool deletable,
struct OPK *opk = NULL, const char *metadata = NULL); struct OPK *opk = NULL, const char *metadata = NULL);
#else #else
LinkApp(GMenu2X *gmenu2x, std::string const& linkfile, bool deletable); LinkApp(GMenu2X& gmenu2x, std::string const& linkfile, bool deletable);
bool isOpk() { return false; } bool isOpk() { return false; }
#endif #endif

View File

@ -67,11 +67,11 @@ void Menu::Animation::step()
} }
} }
Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts) Menu::Menu(GMenu2X& gmenu2x, Touchscreen &ts)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
, ts(ts) , ts(ts)
, btnContextMenu(gmenu2x, ts, "skin:imgs/menu.png", "", , btnContextMenu(gmenu2x, ts, "skin:imgs/menu.png", "",
std::bind(&GMenu2X::showContextMenu, gmenu2x)) std::bind(&GMenu2X::showContextMenu, &gmenu2x))
{ {
readSections(GMENU2X_SYSTEM_DIR "/sections"); readSections(GMENU2X_SYSTEM_DIR "/sections");
readSections(GMenu2X::getHome() + "/sections"); readSections(GMenu2X::getHome() + "/sections");
@ -100,7 +100,7 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
} }
#endif #endif
btnContextMenu.setPosition(gmenu2x->resX - 38, gmenu2x->bottomBarIconY); btnContextMenu.setPosition(gmenu2x.resX - 38, gmenu2x.bottomBarIconY);
} }
Menu::~Menu() { Menu::~Menu() {
@ -130,16 +130,16 @@ void Menu::readSections(std::string parentDir)
} }
void Menu::skinUpdated() { void Menu::skinUpdated() {
ConfIntHash &skinConfInt = gmenu2x->skinConfInt; ConfIntHash &skinConfInt = gmenu2x.skinConfInt;
//recalculate some coordinates based on the new element sizes //recalculate some coordinates based on the new element sizes
linkColumns = (gmenu2x->resX - 10) / skinConfInt["linkWidth"]; linkColumns = (gmenu2x.resX - 10) / skinConfInt["linkWidth"];
linkRows = (gmenu2x->resY - 35 - skinConfInt["topBarHeight"]) / skinConfInt["linkHeight"]; linkRows = (gmenu2x.resY - 35 - skinConfInt["topBarHeight"]) / skinConfInt["linkHeight"];
//reload section icons //reload section icons
vector<string>::size_type i = 0; vector<string>::size_type i = 0;
for (string sectionName : sections) { for (string sectionName : sections) {
gmenu2x->sc["skin:sections/" + sectionName + ".png"]; gmenu2x.sc["skin:sections/" + sectionName + ".png"];
for (Link *&link : links[i]) { for (Link *&link : links[i]) {
link->loadIcon(); link->loadIcon();
@ -150,9 +150,9 @@ void Menu::skinUpdated() {
} }
void Menu::calcSectionRange(int &leftSection, int &rightSection) { void Menu::calcSectionRange(int &leftSection, int &rightSection) {
ConfIntHash &skinConfInt = gmenu2x->skinConfInt; ConfIntHash &skinConfInt = gmenu2x.skinConfInt;
const int linkWidth = skinConfInt["linkWidth"]; const int linkWidth = skinConfInt["linkWidth"];
const int screenWidth = gmenu2x->resX; const int screenWidth = gmenu2x.resX;
const int numSections = sections.size(); const int numSections = sections.size();
rightSection = min( rightSection = min(
max(1, (screenWidth - 20 - linkWidth) / (2 * linkWidth)), max(1, (screenWidth - 20 - linkWidth) / (2 * linkWidth)),
@ -171,15 +171,15 @@ bool Menu::runAnimations() {
void Menu::paint(Surface &s) { void Menu::paint(Surface &s) {
const uint width = s.width(), height = s.height(); const uint width = s.width(), height = s.height();
Font &font = *gmenu2x->font; Font &font = *gmenu2x.font;
SurfaceCollection &sc = gmenu2x->sc; SurfaceCollection &sc = gmenu2x.sc;
ConfIntHash &skinConfInt = gmenu2x->skinConfInt; ConfIntHash &skinConfInt = gmenu2x.skinConfInt;
const int topBarHeight = skinConfInt["topBarHeight"]; const int topBarHeight = skinConfInt["topBarHeight"];
const int bottomBarHeight = skinConfInt["bottomBarHeight"]; const int bottomBarHeight = skinConfInt["bottomBarHeight"];
const int linkWidth = skinConfInt["linkWidth"]; const int linkWidth = skinConfInt["linkWidth"];
const int linkHeight = skinConfInt["linkHeight"]; const int linkHeight = skinConfInt["linkHeight"];
RGBAColor &selectionBgColor = gmenu2x->skinConfColors[COLOR_SELECTION_BG]; RGBAColor &selectionBgColor = gmenu2x.skinConfColors[COLOR_SELECTION_BG];
// Apply section header animation. // Apply section header animation.
int leftSection, rightSection; int leftSection, rightSection;
@ -221,7 +221,7 @@ void Menu::paint(Surface &s) {
vector<Link*> &sectionLinks = links[iSection]; vector<Link*> &sectionLinks = links[iSection];
const uint numLinks = sectionLinks.size(); const uint numLinks = sectionLinks.size();
gmenu2x->drawScrollBar( gmenu2x.drawScrollBar(
linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow); linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow);
//Links //Links
@ -253,14 +253,14 @@ void Menu::paint(Surface &s) {
LinkApp *linkApp = selLinkApp(); LinkApp *linkApp = selLinkApp();
if (linkApp) { if (linkApp) {
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
font.write(s, linkApp->clockStr(gmenu2x->confInt["maxClock"]), font.write(s, linkApp->clockStr(gmenu2x.confInt["maxClock"]),
gmenu2x->cpuX, gmenu2x->bottomBarTextY, gmenu2x.cpuX, gmenu2x.bottomBarTextY,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
#endif #endif
//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()) {
@ -292,7 +292,7 @@ bool Menu::handleButtonPress(InputManager::Button button) {
incSectionIndex(); incSectionIndex();
return true; return true;
case InputManager::MENU: case InputManager::MENU:
gmenu2x->showContextMenu(); gmenu2x.showContextMenu();
return true; return true;
default: default:
return false; return false;
@ -302,9 +302,9 @@ bool Menu::handleButtonPress(InputManager::Button button) {
bool Menu::handleTouchscreen(Touchscreen &ts) { bool Menu::handleTouchscreen(Touchscreen &ts) {
btnContextMenu.handleTS(); btnContextMenu.handleTS();
ConfIntHash &skinConfInt = gmenu2x->skinConfInt; ConfIntHash &skinConfInt = gmenu2x.skinConfInt;
const int topBarHeight = skinConfInt["topBarHeight"]; const int topBarHeight = skinConfInt["topBarHeight"];
const int screenWidth = gmenu2x->resX; const int screenWidth = gmenu2x.resX;
if (ts.pressed() && ts.getY() < topBarHeight) { if (ts.pressed() && ts.getY() < topBarHeight) {
int leftSection, rightSection; int leftSection, rightSection;
@ -391,12 +391,12 @@ void Menu::addActionLink(uint section, const string &title, Action action, const
assert(section < sections.size()); assert(section < sections.size());
Link *link = new Link(gmenu2x, action); Link *link = new Link(gmenu2x, action);
link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); link->setSize(gmenu2x.skinConfInt["linkWidth"], gmenu2x.skinConfInt["linkHeight"]);
link->setTitle(title); link->setTitle(title);
link->setDescription(description); link->setDescription(description);
if (gmenu2x->sc.exists(icon) if (gmenu2x.sc.exists(icon)
|| (icon.substr(0,5)=="skin:" || (icon.substr(0,5)=="skin:"
&& !gmenu2x->sc.getSkinFilePath(icon.substr(5,icon.length())).empty()) && !gmenu2x.sc.getSkinFilePath(icon.substr(5,icon.length())).empty())
|| fileExists(icon)) { || fileExists(icon)) {
link->setIcon(icon); link->setIcon(icon);
} }
@ -475,8 +475,8 @@ bool Menu::addLink(string path, string file, string section) {
if (fileExists(exename+".png")) icon = exename+".png"; if (fileExists(exename+".png")) icon = exename+".png";
//Reduce title lenght to fit the link width //Reduce title lenght to fit the link width
if (gmenu2x->font->getTextWidth(shorttitle)>gmenu2x->skinConfInt["linkWidth"]) { if (gmenu2x.font->getTextWidth(shorttitle)>gmenu2x.skinConfInt["linkWidth"]) {
while (gmenu2x->font->getTextWidth(shorttitle+"..")>gmenu2x->skinConfInt["linkWidth"]) while (gmenu2x.font->getTextWidth(shorttitle+"..")>gmenu2x.skinConfInt["linkWidth"])
shorttitle = shorttitle.substr(0,shorttitle.length()-1); shorttitle = shorttitle.substr(0,shorttitle.length()-1);
shorttitle += ".."; shorttitle += "..";
} }
@ -496,7 +496,7 @@ bool Menu::addLink(string path, string file, string section) {
INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection); INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection);
LinkApp* link = new LinkApp(gmenu2x, linkpath, true); LinkApp* link = new LinkApp(gmenu2x, linkpath, true);
link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]); link->setSize(gmenu2x.skinConfInt["linkWidth"], gmenu2x.skinConfInt["linkHeight"]);
links[isection].push_back( link ); links[isection].push_back( link );
} }
} else { } else {
@ -543,13 +543,13 @@ void Menu::deleteSelectedLink()
icon_used = iconpath == (*link)->getIconPath(); icon_used = iconpath == (*link)->getIconPath();
if (!icon_used) if (!icon_used)
gmenu2x->sc.del(iconpath); gmenu2x.sc.del(iconpath);
} }
void Menu::deleteSelectedSection() { void Menu::deleteSelectedSection() {
INFO("Deleting section '%s'\n", selSection().c_str()); INFO("Deleting section '%s'\n", selSection().c_str());
gmenu2x->sc.del("sections/"+selSection()+".png"); gmenu2x.sc.del("sections/"+selSection()+".png");
links.erase( links.begin()+selSectionIndex() ); links.erase( links.begin()+selSectionIndex() );
sections.erase( sections.begin()+selSectionIndex() ); sections.erase( sections.begin()+selSectionIndex() );
setSectionIndex(0); //reload sections setSectionIndex(0); //reload sections
@ -700,7 +700,7 @@ void Menu::openPackage(std::string path, bool order)
// but that is not something we want to do in the menu, // but that is not something we want to do in the menu,
// so consider this link undeletable. // so consider this link undeletable.
link = new LinkApp(gmenu2x, path, false, opk, name); link = new LinkApp(gmenu2x, path, false, opk, name);
link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); link->setSize(gmenu2x.skinConfInt["linkWidth"], gmenu2x.skinConfInt["linkHeight"]);
addSection(link->getCategory()); addSection(link->getCategory());
for (i = 0; i < sections.size(); i++) { for (i = 0; i < sections.size(); i++) {
@ -840,8 +840,8 @@ void Menu::readLinksOfSection(
LinkApp *link = new LinkApp(gmenu2x, linkfile, deletable); LinkApp *link = new LinkApp(gmenu2x, linkfile, deletable);
if (link->targetExists()) { if (link->targetExists()) {
link->setSize( link->setSize(
gmenu2x->skinConfInt["linkWidth"], gmenu2x.skinConfInt["linkWidth"],
gmenu2x->skinConfInt["linkHeight"]); gmenu2x.skinConfInt["linkHeight"]);
links.push_back(link); links.push_back(link);
} else { } else {
delete link; delete link;

View File

@ -54,7 +54,7 @@ private:
int curr; int curr;
}; };
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
Touchscreen &ts; Touchscreen &ts;
IconButton btnContextMenu; IconButton btnContextMenu;
int iSection, iLink; int iSection, iLink;
@ -102,7 +102,7 @@ private:
public: public:
typedef std::function<void(void)> Action; typedef std::function<void(void)> Action;
Menu(GMenu2X *gmenu2x, Touchscreen &ts); Menu(GMenu2X& gmenu2x, Touchscreen &ts);
virtual ~Menu(); virtual ~Menu();
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK

View File

@ -26,7 +26,7 @@
using std::string; using std::string;
MenuSetting::MenuSetting(GMenu2X *gmenu2x, const string &name, MenuSetting::MenuSetting(GMenu2X& gmenu2x, const string &name,
const string &description) const string &description)
: gmenu2x(gmenu2x) : gmenu2x(gmenu2x)
, name(name) , name(name)
@ -40,8 +40,8 @@ MenuSetting::~MenuSetting()
void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) void MenuSetting::draw(int /*valueX*/, int y, int /*h*/)
{ {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
gmenu2x->font->write(s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); 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,11 +51,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; Surface& s = *gmenu2x.s;
// The selection rectangle // The selection rectangle
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(s, 5, gmenu2x->resY - 1); buttonBox.paint(s, 5, gmenu2x.resY - 1);
} }

View File

@ -32,7 +32,7 @@ Base class for different kind of option
*/ */
class MenuSetting { class MenuSetting {
protected: protected:
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
ButtonBox buttonBox; ButtonBox buttonBox;
@ -40,7 +40,7 @@ protected:
public: public:
MenuSetting( MenuSetting(
GMenu2X *gmenu2x, const std::string &name, GMenu2X& gmenu2x, const std::string &name,
const std::string &description); const std::string &description);
virtual ~MenuSetting(); virtual ~MenuSetting();

View File

@ -32,7 +32,7 @@ using std::string;
using std::unique_ptr; using std::unique_ptr;
MenuSettingBool::MenuSettingBool( MenuSettingBool::MenuSettingBool(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &name, const string &description, int *value) const string &name, const string &description, int *value)
: MenuSetting(gmenu2x, name, description) : MenuSetting(gmenu2x, name, description)
, ts(ts) , ts(ts)
@ -45,7 +45,7 @@ MenuSettingBool::MenuSettingBool(
} }
MenuSettingBool::MenuSettingBool( MenuSettingBool::MenuSettingBool(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &name, const string &description, bool *value) const string &name, const string &description, bool *value)
: MenuSetting(gmenu2x, name, description) : MenuSetting(gmenu2x, name, description)
, ts(ts) , ts(ts)
@ -61,15 +61,15 @@ void MenuSettingBool::initButton()
{ {
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Switch"], gmenu2x.tr["Switch"],
bind(&MenuSettingBool::toggle, this)))); bind(&MenuSettingBool::toggle, this))));
} }
void MenuSettingBool::draw(int valueX, int y, int h) void MenuSettingBool::draw(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
gmenu2x->font->write(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

@ -39,11 +39,11 @@ private:
public: public:
MenuSettingBool( MenuSettingBool(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
bool *value); bool *value);
MenuSettingBool( MenuSettingBool(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
int *value); int *value);
virtual ~MenuSettingBool() {} virtual ~MenuSettingBool() {}

View File

@ -29,19 +29,19 @@ using std::string;
using std::unique_ptr; using std::unique_ptr;
MenuSettingDir::MenuSettingDir( MenuSettingDir::MenuSettingDir(
GMenu2X *gmenu2x, Touchscreen &ts_, GMenu2X& gmenu2x, Touchscreen &ts_,
const string &name, const string &description, string *value) const string &name, const string &description, string *value)
: MenuSettingStringBase(gmenu2x, name, description, value) : MenuSettingStringBase(gmenu2x, name, description, value)
, ts(ts_) , ts(ts_)
{ {
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x, ts, "skin:imgs/buttons/cancel.png",
gmenu2x->tr["Clear"], gmenu2x.tr["Clear"],
bind(&MenuSettingDir::clear, this)))); bind(&MenuSettingDir::clear, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Select"], gmenu2x.tr["Select"],
bind(&MenuSettingDir::edit, this)))); bind(&MenuSettingDir::edit, this))));
} }

View File

@ -33,7 +33,7 @@ protected:
public: public:
MenuSettingDir( MenuSettingDir(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
std::string *value); std::string *value);
virtual ~MenuSettingDir() {} virtual ~MenuSettingDir() {}

View File

@ -29,7 +29,7 @@ using std::string;
using std::unique_ptr; using std::unique_ptr;
MenuSettingFile::MenuSettingFile( MenuSettingFile::MenuSettingFile(
GMenu2X *gmenu2x, Touchscreen &ts_, GMenu2X& gmenu2x, Touchscreen &ts_,
const string &name, const string &description, const string &name, const string &description,
string *value, const string &filter_) string *value, const string &filter_)
: MenuSettingStringBase(gmenu2x, name, description, value) : MenuSettingStringBase(gmenu2x, name, description, value)
@ -38,12 +38,12 @@ MenuSettingFile::MenuSettingFile(
{ {
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x, ts, "skin:imgs/buttons/cancel.png",
gmenu2x->tr["Clear"], gmenu2x.tr["Clear"],
bind(&MenuSettingFile::clear, this)))); bind(&MenuSettingFile::clear, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Select"], gmenu2x.tr["Select"],
bind(&MenuSettingFile::edit, this)))); bind(&MenuSettingFile::edit, this))));
} }

View File

@ -33,7 +33,7 @@ protected:
public: public:
MenuSettingFile( MenuSettingFile(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
std::string *value, const std::string &filter = ""); std::string *value, const std::string &filter = "");
virtual ~MenuSettingFile() {} virtual ~MenuSettingFile() {}

View File

@ -27,7 +27,7 @@
using std::string; using std::string;
MenuSettingImage::MenuSettingImage( MenuSettingImage::MenuSettingImage(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &name, const string &description, const string &name, const string &description,
string *value, const string &filter) string *value, const string &filter)
: MenuSettingFile(gmenu2x, ts, name, description, value, filter) : MenuSettingFile(gmenu2x, ts, name, description, value, filter)
@ -40,10 +40,10 @@ void MenuSettingImage::edit() {
} }
void MenuSettingImage::setValue(const string &value) { void MenuSettingImage::setValue(const string &value) {
string skinpath(gmenu2x->sc.getSkinPath(gmenu2x->confStr["skin"])); string skinpath(gmenu2x.sc.getSkinPath(gmenu2x.confStr["skin"]));
bool inSkinDir = value.substr(0, skinpath.length()) == skinpath; bool inSkinDir = value.substr(0, skinpath.length()) == skinpath;
if (!inSkinDir && gmenu2x->confStr["skin"] != "Default") { if (!inSkinDir && gmenu2x.confStr["skin"] != "Default") {
skinpath = gmenu2x->sc.getSkinPath("Default"); skinpath = gmenu2x.sc.getSkinPath("Default");
inSkinDir = value.substr(0, skinpath.length()) == skinpath; inSkinDir = value.substr(0, skinpath.length()) == skinpath;
} }
if (inSkinDir) { if (inSkinDir) {

View File

@ -27,7 +27,7 @@ protected:
virtual void edit(); virtual void edit();
public: public:
MenuSettingImage(GMenu2X *gmenu2x, Touchscreen &ts, MenuSettingImage(GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
std::string *value, const std::string &filter = ""); std::string *value, const std::string &filter = "");
virtual ~MenuSettingImage() {} virtual ~MenuSettingImage() {}

View File

@ -33,10 +33,10 @@ using std::stringstream;
using std::unique_ptr; using std::unique_ptr;
MenuSettingInt::MenuSettingInt( MenuSettingInt::MenuSettingInt(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &name, const string &description, const string &name, const string &description,
int *value, int min, int max, int increment) int *value, int min, int max, int increment)
: MenuSetting(gmenu2x,name,description) : MenuSetting(gmenu2x, name, description)
{ {
_value = value; _value = value;
originalValue = *value; originalValue = *value;
@ -54,21 +54,21 @@ MenuSettingInt::MenuSettingInt(
"", actionDec))); "", actionDec)));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x, ts, "skin:imgs/buttons/left.png",
gmenu2x->tr["Decrease"], actionDec))); gmenu2x.tr["Decrease"], actionDec)));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/r.png", gmenu2x, ts, "skin:imgs/buttons/r.png",
"", actionInc))); "", actionInc)));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x, ts, "skin:imgs/buttons/right.png",
gmenu2x->tr["Increase"], actionInc))); gmenu2x.tr["Increase"], actionInc)));
} }
void MenuSettingInt::draw(int valueX, int y, int h) void MenuSettingInt::draw(int valueX, int y, int h)
{ {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
gmenu2x->font->write(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

@ -38,7 +38,7 @@ private:
public: public:
MenuSettingInt( MenuSettingInt(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
int *value, int min, int max, int increment = 1); int *value, int min, int max, int increment = 1);
virtual ~MenuSettingInt() {} virtual ~MenuSettingInt() {}

View File

@ -31,7 +31,7 @@ using std::vector;
using std::unique_ptr; using std::unique_ptr;
MenuSettingMultiString::MenuSettingMultiString( MenuSettingMultiString::MenuSettingMultiString(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const string &name, const string &description, const string &name, const string &description,
string *value, const vector<string> *choices_) string *value, const vector<string> *choices_)
: MenuSettingStringBase(gmenu2x, name, description, value) : MenuSettingStringBase(gmenu2x, name, description, value)
@ -44,7 +44,7 @@ MenuSettingMultiString::MenuSettingMultiString(
bind(&MenuSettingMultiString::decSel, this)))); bind(&MenuSettingMultiString::decSel, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x, ts, "skin:imgs/buttons/right.png",
gmenu2x->tr["Change value"], gmenu2x.tr["Change value"],
bind(&MenuSettingMultiString::incSel, this)))); bind(&MenuSettingMultiString::incSel, this))));
} }

View File

@ -42,7 +42,7 @@ private:
public: public:
MenuSettingMultiString( MenuSettingMultiString(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
std::string *value, const std::vector<std::string> *choices); std::string *value, const std::vector<std::string> *choices);
virtual ~MenuSettingMultiString() {}; virtual ~MenuSettingMultiString() {};

View File

@ -34,7 +34,7 @@ using std::unique_ptr;
constexpr unsigned int COMPONENT_WIDTH = 28; constexpr unsigned int COMPONENT_WIDTH = 28;
MenuSettingRGBA::MenuSettingRGBA( MenuSettingRGBA::MenuSettingRGBA(
GMenu2X *gmenu2x, Touchscreen &ts_, GMenu2X& gmenu2x, Touchscreen &ts_,
const string &name, const string &description, RGBAColor *value) const string &name, const string &description, RGBAColor *value)
: MenuSetting(gmenu2x, name, description) : MenuSetting(gmenu2x, name, description)
, ts(ts_) , ts(ts_)
@ -53,16 +53,17 @@ MenuSettingRGBA::MenuSettingRGBA(
} }
void MenuSettingRGBA::draw(int valueX, int y, int h) { void MenuSettingRGBA::draw(int valueX, int y, int h) {
Surface& s = *gmenu2x->s; Surface& s = *gmenu2x.s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
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);
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);
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(s, strR, valueX + h + COMPONENT_WIDTH - 2, y, Font::HAlignRight, Font::VAlignTop); auto& font = gmenu2x.font;
gmenu2x->font->write(s, strG, valueX + h + COMPONENT_WIDTH * 2 - 2, y, Font::HAlignRight, Font::VAlignTop); font->write(s, strR, valueX + h + COMPONENT_WIDTH - 2, y, Font::HAlignRight, Font::VAlignTop);
gmenu2x->font->write(s, strB, valueX + h + COMPONENT_WIDTH * 3 - 2, y, Font::HAlignRight, Font::VAlignTop); font->write(s, strG, valueX + h + COMPONENT_WIDTH * 2 - 2, y, Font::HAlignRight, Font::VAlignTop);
gmenu2x->font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop); font->write(s, strB, valueX + h + COMPONENT_WIDTH * 3 - 2, y, Font::HAlignRight, Font::VAlignTop);
font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop);
} }
void MenuSettingRGBA::handleTS(int valueX, int y, int h) { void MenuSettingRGBA::handleTS(int valueX, int y, int h) {
@ -215,7 +216,7 @@ void MenuSettingRGBA::drawSelected(int valueX, int y, int h)
case 2: color = RGBAColor( 0, 0, 255, 255); break; case 2: color = RGBAColor( 0, 0, 255, 255); break;
case 3: color = RGBAColor(128, 128, 128, 255); break; case 3: color = RGBAColor(128, 128, 128, 255); break;
} }
gmenu2x->s->box( x + h, y, COMPONENT_WIDTH, h, color ); gmenu2x.s->box( x + h, y, COMPONENT_WIDTH, h, color );
MenuSetting::drawSelected(valueX, y, h); MenuSetting::drawSelected(valueX, y, h);
} }
@ -230,13 +231,13 @@ void MenuSettingRGBA::updateButtonBox()
buttonBox.clear(); buttonBox.clear();
if (edit) { if (edit) {
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png"))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x->tr["Decrease"]))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png"))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Increase"]))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"]))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"])));
} else { } else {
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png"))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Change color component"]))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Edit"]))); buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"])));
} }
} }

View File

@ -47,7 +47,7 @@ private:
public: public:
MenuSettingRGBA( MenuSettingRGBA(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X& gmenu2x, Touchscreen &ts,
const std::string &name, const std::string &description, const std::string &name, const std::string &description,
RGBAColor *value); RGBAColor *value);
virtual ~MenuSettingRGBA() {}; virtual ~MenuSettingRGBA() {};

View File

@ -29,7 +29,7 @@ using std::string;
using std::unique_ptr; using std::unique_ptr;
MenuSettingString::MenuSettingString( MenuSettingString::MenuSettingString(
GMenu2X *gmenu2x, Touchscreen &ts_, GMenu2X& gmenu2x, Touchscreen &ts_,
const string &name, const string &description, string *value, const string &name, const string &description, string *value,
const string &diagTitle_, const string &diagIcon_) const string &diagTitle_, const string &diagIcon_)
: MenuSettingStringBase(gmenu2x, name, description, value) : MenuSettingStringBase(gmenu2x, name, description, value)
@ -39,19 +39,19 @@ MenuSettingString::MenuSettingString(
{ {
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x, ts, "skin:imgs/buttons/cancel.png",
gmenu2x->tr["Clear"], gmenu2x.tr["Clear"],
bind(&MenuSettingString::clear, this)))); bind(&MenuSettingString::clear, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton( buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x->tr["Edit"], gmenu2x.tr["Edit"],
bind(&MenuSettingString::edit, this)))); bind(&MenuSettingString::edit, this))));
} }
void MenuSettingString::edit() void MenuSettingString::edit()
{ {
InputDialog id( InputDialog id(
gmenu2x, gmenu2x->input, ts, gmenu2x, gmenu2x.input, ts,
description, value(), diagTitle, diagIcon); description, value(), diagTitle, diagIcon);
if (id.exec()) setValue(id.getInput()); if (id.exec()) setValue(id.getInput());
} }

View File

@ -35,7 +35,7 @@ protected:
public: public:
MenuSettingString( MenuSettingString(
GMenu2X *gmenu2x, Touchscreen &ts, const std::string &name, GMenu2X& gmenu2x, Touchscreen &ts, const std::string &name,
const std::string &description, std::string *value, const std::string &description, std::string *value,
const std::string &diagTitle = "", const std::string &diagTitle = "",
const std::string &diagIcon = ""); const std::string &diagIcon = "");

View File

@ -25,7 +25,7 @@
using std::string; using std::string;
MenuSettingStringBase::MenuSettingStringBase( MenuSettingStringBase::MenuSettingStringBase(
GMenu2X *gmenu2x, const string &name, GMenu2X& gmenu2x, const string &name,
const string &description, string *value) const string &description, string *value)
: MenuSetting(gmenu2x, name, description) : MenuSetting(gmenu2x, name, description)
, originalValue(*value) , originalValue(*value)
@ -39,9 +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; Surface& s = *gmenu2x.s;
MenuSetting::draw(valueX, y, h); MenuSetting::draw(valueX, y, h);
gmenu2x->font->write(s, value(), valueX, y, gmenu2x.font->write(s, value(), valueX, y,
Font::HAlignLeft, Font::VAlignTop); Font::HAlignLeft, Font::VAlignTop);
} }

View File

@ -33,7 +33,7 @@ protected:
public: public:
MenuSettingStringBase( MenuSettingStringBase(
GMenu2X *gmenu2x, const std::string &name, GMenu2X& gmenu2x, const std::string &name,
const std::string &description, std::string *value); const std::string &description, std::string *value);
virtual ~MenuSettingStringBase(); virtual ~MenuSettingStringBase();

View File

@ -30,15 +30,15 @@ constexpr unsigned int ICON_PADDING = 6;
constexpr unsigned int TEXT_PADDING = 8; constexpr unsigned int TEXT_PADDING = 8;
constexpr unsigned int ICON_DIMENSION = 32; constexpr unsigned int ICON_DIMENSION = 32;
MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon) { MessageBox::MessageBox(GMenu2X& gmenu2x, const string &text, const string &icon)
this->gmenu2x = gmenu2x; : gmenu2x(gmenu2x)
this->text = text; , text(text)
this->icon = icon; , icon(icon)
{
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) { for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
buttons[i] = ""; buttons[i] = "";
buttonLabels[i] = ""; buttonLabels[i] = "";
buttonPositions[i].h = gmenu2x->font->getLineSpacing(); buttonPositions[i].h = gmenu2x.font->getLineSpacing();
} }
//Default enabled button //Default enabled button
@ -62,39 +62,39 @@ void MessageBox::setButton(InputManager::Button button, const string &label) {
} }
int MessageBox::exec() { int MessageBox::exec() {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
OffscreenSurface bg(s); OffscreenSurface 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);
SDL_Rect box; SDL_Rect box;
int textHeight = gmenu2x->font->getTextHeight(text); int textHeight = gmenu2x.font->getTextHeight(text);
box.h = textHeight + 2 * TEXT_PADDING; box.h = textHeight + 2 * TEXT_PADDING;
box.w = gmenu2x->font->getTextWidth(text) + 2 * TEXT_PADDING; box.w = gmenu2x.font->getTextWidth(text) + 2 * TEXT_PADDING;
if (gmenu2x->sc[icon]) { if (gmenu2x.sc[icon]) {
box.h = max(box.h, (Uint16) (ICON_DIMENSION + 2 * ICON_PADDING)); box.h = max(box.h, (Uint16) (ICON_DIMENSION + 2 * ICON_PADDING));
box.w += ICON_DIMENSION + ICON_PADDING; box.w += ICON_DIMENSION + ICON_PADDING;
} }
box.x = gmenu2x->halfX - box.w/2; box.x = gmenu2x.halfX - box.w / 2;
box.y = gmenu2x->halfY - box.h/2; box.y = gmenu2x.halfY - box.h / 2;
//outer box //outer box
bg.box(box.x - 2, box.y - 2, box.w + 4, box.h + 4, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BG]); bg.box(box.x - 2, box.y - 2, box.w + 4, box.h + 4, gmenu2x.skinConfColors[COLOR_MESSAGE_BOX_BG]);
//draw inner rectangle //draw inner rectangle
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++) {
if (!buttons[i].empty()) { if (!buttons[i].empty()) {
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;
@ -108,7 +108,7 @@ int MessageBox::exec() {
int result = -1; int result = -1;
while (result < 0) { while (result < 0) {
InputManager::Button button; InputManager::Button button;
if (gmenu2x->input.pollButton(&button) if (gmenu2x.input.pollButton(&button)
&& !buttons[button].empty()) { && !buttons[button].empty()) {
result = button; result = button;
} }

View File

@ -30,13 +30,13 @@ class GMenu2X;
class MessageBox { class MessageBox {
public: public:
MessageBox(GMenu2X *gmenu2x, const std::string &text, MessageBox(GMenu2X& gmenu2x, const std::string &text,
const std::string &icon=""); const std::string &icon="");
void setButton(InputManager::Button button, const std::string &label); void setButton(InputManager::Button button, const std::string &label);
int exec(); int exec();
private: private:
GMenu2X *gmenu2x; GMenu2X& gmenu2x;
std::string text, icon; std::string text, icon;
std::string buttons[BUTTON_TYPE_SIZE]; std::string buttons[BUTTON_TYPE_SIZE];
std::string buttonLabels[BUTTON_TYPE_SIZE]; std::string buttonLabels[BUTTON_TYPE_SIZE];

View File

@ -39,7 +39,7 @@
using namespace std; using namespace std;
Selector::Selector(GMenu2X *gmenu2x, LinkApp& link, const string &selectorDir) Selector::Selector(GMenu2X& gmenu2x, LinkApp& link, const string &selectorDir)
: Dialog(gmenu2x) : Dialog(gmenu2x)
, link(link) , link(link)
{ {
@ -58,30 +58,30 @@ int Selector::exec(int startSelection) {
dir = parentDir(dir); dir = parentDir(dir);
} }
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface 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());
int x = 5; int x = 5;
if (fl.size() != 0) { if (fl.size() != 0) {
x = gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], x); x = gmenu2x.drawButton(bg, "accept", gmenu2x.tr["Select"], x);
} }
if (showDirectories) { if (showDirectories) {
x = gmenu2x->drawButton(bg, "left", "", x); x = gmenu2x.drawButton(bg, "left", "", x);
x = gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], x); x = gmenu2x.drawButton(bg, "cancel", gmenu2x.tr["Up one folder"], x);
} else { } else {
x = gmenu2x->drawButton(bg, "cancel", "", x); x = gmenu2x.drawButton(bg, "cancel", "", x);
} }
x = gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], x); x = gmenu2x.drawButton(bg, "start", gmenu2x.tr["Exit"], x);
unsigned int top, height; unsigned int top, height;
tie(top, height) = gmenu2x->getContentArea(); tie(top, height) = gmenu2x.getContentArea();
auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png"); auto folderIcon = gmenu2x.sc.skinRes("imgs/folder.png");
// Figure out how many items we can fit in the content area. // Figure out how many items we can fit in the content area.
int lineHeight = gmenu2x->font->getLineSpacing(); int lineHeight = gmenu2x.font->getLineSpacing();
if (showDirectories && folderIcon) { if (showDirectories && folderIcon) {
lineHeight = max(lineHeight, folderIcon->height() + 2); lineHeight = max(lineHeight, folderIcon->height() + 2);
} }
@ -97,12 +97,12 @@ int Selector::exec(int startSelection) {
bool close = false, result = true; bool close = false, result = true;
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
bg.blit(s, 0, 0); bg.blit(s, 0, 0);
if (fl.size() == 0) { if (fl.size() == 0) {
gmenu2x->font->write(s, "(" + gmenu2x->tr["no items"] + ")", gmenu2x.font->write(s, "(" + gmenu2x.tr["no items"] + ")",
4, top + lineHeight / 2, 4, top + lineHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} else { } else {
@ -123,7 +123,7 @@ int Selector::exec(int startSelection) {
//Selection //Selection
int iY = top + (selected - firstElement) * lineHeight; int iY = top + (selected - firstElement) * lineHeight;
if (selected<fl.size()) if (selected<fl.size())
s.box(1, iY, 309, lineHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); s.box(1, iY, 309, lineHeight, gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
//Files & Dirs //Files & Dirs
s.setClipRect(0, top, 311, height); s.setClipRect(0, top, 311, height);
@ -137,11 +137,11 @@ int Selector::exec(int startSelection) {
x, iY + (lineHeight - folderIcon->height()) / 2); x, iY + (lineHeight - folderIcon->height()) / 2);
x += folderIcon->width() + 2; x += folderIcon->width() + 2;
} }
gmenu2x->font->write(s, fl[i], gmenu2x.font->write(s, fl[i],
x, iY + lineHeight / 2, x, iY + lineHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} else { } else {
gmenu2x->font->write(s, trimExtension(fl[i]), gmenu2x.font->write(s, trimExtension(fl[i]),
x, iY + lineHeight / 2, x, iY + lineHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} }
@ -149,10 +149,10 @@ int Selector::exec(int startSelection) {
s.clearClipRect(); s.clearClipRect();
} }
gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement); gmenu2x.drawScrollBar(nb_elements, fl.size(), firstElement);
s.flip(); s.flip();
switch (gmenu2x->input.waitForPressedButton()) { switch (gmenu2x.input.waitForPressedButton()) {
case InputManager::SETTINGS: case InputManager::SETTINGS:
close = true; close = true;
result = false; result = false;

View File

@ -44,7 +44,7 @@ private:
int goToParentDir(FileLister& fl); int goToParentDir(FileLister& fl);
public: public:
Selector(GMenu2X *gmenu2x, LinkApp& link, Selector(GMenu2X& gmenu2x, LinkApp& link,
const std::string &selectorDir = ""); const std::string &selectorDir = "");
int exec(int startSelection = 0); int exec(int startSelection = 0);

View File

@ -28,14 +28,14 @@
using namespace std; using namespace std;
SettingsDialog::SettingsDialog( SettingsDialog::SettingsDialog(
GMenu2X *gmenu2x_, InputManager &inputMgr_, Touchscreen &ts_, GMenu2X& gmenu2x, InputManager &inputMgr_, Touchscreen &ts_,
const string &text_, const string &icon) const string &text_, const string &icon)
: Dialog(gmenu2x_) : Dialog(gmenu2x)
, inputMgr(inputMgr_) , inputMgr(inputMgr_)
, ts(ts_) , ts(ts_)
, text(text_) , text(text_)
{ {
if (!icon.empty() && gmenu2x->sc[icon] != NULL) { if (!icon.empty() && gmenu2x.sc[icon] != NULL) {
this->icon = icon; this->icon = icon;
} else { } else {
this->icon = "icons/generic.png"; this->icon = "icons/generic.png";
@ -43,46 +43,46 @@ SettingsDialog::SettingsDialog(
} }
bool SettingsDialog::exec() { bool SettingsDialog::exec() {
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface bg(*gmenu2x.bg);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
bool close = false, ts_pressed = false; bool close = false, ts_pressed = false;
uint i, sel = 0, firstElement = 0; uint i, sel = 0, firstElement = 0;
const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; const int topBarHeight = gmenu2x.skinConfInt["topBarHeight"];
SDL_Rect clipRect = { SDL_Rect clipRect = {
0, 0,
static_cast<Sint16>(topBarHeight + 1), static_cast<Sint16>(topBarHeight + 1),
static_cast<Uint16>(gmenu2x->resX - 9), static_cast<Uint16>(gmenu2x.resX - 9),
static_cast<Uint16>(gmenu2x->resY - topBarHeight - 25) static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
}; };
SDL_Rect touchRect = { SDL_Rect touchRect = {
2, 2,
static_cast<Sint16>(topBarHeight + 4), static_cast<Sint16>(topBarHeight + 4),
static_cast<Uint16>(gmenu2x->resX - 12), static_cast<Uint16>(gmenu2x.resX - 12),
static_cast<Uint16>(clipRect.h) static_cast<Uint16>(clipRect.h)
}; };
uint rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1 uint rowHeight = gmenu2x.font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; uint numRows = (gmenu2x.resY - topBarHeight - 20) / rowHeight;
uint maxNameWidth = 0; uint maxNameWidth = 0;
for (auto it = settings.begin(); it != settings.end(); it++) { for (auto it = settings.begin(); it != settings.end(); it++) {
maxNameWidth = max(maxNameWidth, (uint) gmenu2x->font->getTextWidth((*it)->getName())); maxNameWidth = max(maxNameWidth, (uint) gmenu2x.font->getTextWidth((*it)->getName()));
} }
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
if (ts.available()) ts.poll(); if (ts.available()) ts.poll();
bg.blit(s, 0, 0); bg.blit(s, 0, 0);
gmenu2x->drawTopBar(s); gmenu2x.drawTopBar(s);
//link icon //link icon
drawTitleIcon(s, icon); drawTitleIcon(s, icon);
writeTitle(s, text); writeTitle(s, text);
gmenu2x->drawBottomBar(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;
@ -111,7 +111,7 @@ bool SettingsDialog::exec() {
} }
} }
gmenu2x->drawScrollBar(numRows, settings.size(), firstElement); gmenu2x.drawScrollBar(numRows, settings.size(), firstElement);
//description //description
writeSubTitle(s, settings[sel]->getDescription()); writeSubTitle(s, settings[sel]->getDescription());

View File

@ -40,7 +40,7 @@ private:
std::string text, icon; std::string text, icon;
public: public:
SettingsDialog(GMenu2X *gmenu2x, InputManager &inputMgr, Touchscreen &ts, SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts,
const std::string &text, const std::string &text,
const std::string &icon = "skin:sections/settings.png"); const std::string &icon = "skin:sections/settings.png");

View File

@ -27,10 +27,10 @@
using namespace std; using namespace std;
TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, const string &text) TextDialog::TextDialog(GMenu2X& gmenu2x, const string &title, const string &description, const string &icon, const string &text)
: Dialog(gmenu2x) : Dialog(gmenu2x)
{ {
split(this->text, gmenu2x->font->wordWrap(text, (int) gmenu2x->resX - 15), "\n"); split(this->text, gmenu2x.font->wordWrap(text, (int) gmenu2x.resX - 15), "\n");
this->title = title; this->title = title;
this->description = description; this->description = description;
this->icon = icon; this->icon = icon;
@ -39,28 +39,28 @@ 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; 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++) {
const string &line = text.at(i); const string &line = text.at(i);
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;
s.box(5, rowY, gmenu2x->resX - 16, 1, 255, 255, 255, 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); s.box(5, rowY+1, gmenu2x.resX - 16, 1, 0, 0, 0, 130);
} else { } else {
gmenu2x->font->write(s, line, 5, rowY); gmenu2x.font->write(s, line, 5, rowY);
} }
} }
gmenu2x->drawScrollBar(rowsPerPage, text.size(), firstRow); gmenu2x.drawScrollBar(rowsPerPage, text.size(), firstRow);
} }
void TextDialog::exec() { void TextDialog::exec() {
bool close = false; bool close = false;
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface bg(*gmenu2x.bg);
//link icon //link icon
if (!fileExists(icon)) if (!fileExists(icon))
@ -71,16 +71,16 @@ void TextDialog::exec() {
writeSubTitle(bg, description); writeSubTitle(bg, description);
int x = 5; int x = 5;
x = gmenu2x->drawButton(bg, "up", "", x); x = gmenu2x.drawButton(bg, "up", "", x);
x = gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], x); x = gmenu2x.drawButton(bg, "down", gmenu2x.tr["Scroll"], x);
x = gmenu2x->drawButton(bg, "cancel", "", x); x = gmenu2x.drawButton(bg, "cancel", "", x);
x = gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], x); x = gmenu2x.drawButton(bg, "start", gmenu2x.tr["Exit"], x);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
const int fontHeight = gmenu2x->font->getLineSpacing(); const int fontHeight = gmenu2x.font->getLineSpacing();
unsigned int contentY, contentHeight; unsigned int contentY, contentHeight;
tie(contentY, contentHeight) = gmenu2x->getContentArea(); tie(contentY, contentHeight) = gmenu2x.getContentArea();
const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u); const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u);
const unsigned maxFirstRow = const unsigned maxFirstRow =
text.size() < rowsPerPage ? 0 : text.size() - rowsPerPage; text.size() < rowsPerPage ? 0 : text.size() - rowsPerPage;
@ -88,13 +88,13 @@ void TextDialog::exec() {
unsigned firstRow = 0; unsigned firstRow = 0;
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
bg.blit(s, 0, 0); bg.blit(s, 0, 0);
drawText(text, contentY, firstRow, rowsPerPage); drawText(text, contentY, firstRow, rowsPerPage);
s.flip(); s.flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x.input.waitForPressedButton()) {
case InputManager::UP: case InputManager::UP:
if (firstRow > 0) firstRow--; if (firstRow > 0) firstRow--;
break; break;

View File

@ -35,7 +35,7 @@ protected:
unsigned int firstRow, unsigned int rowsPerPage); unsigned int firstRow, unsigned int rowsPerPage);
public: public:
TextDialog(GMenu2X *gmenu2x, const std::string &title, TextDialog(GMenu2X& gmenu2x, const std::string &title,
const std::string &description, const std::string &icon, const std::string &description, const std::string &icon,
const std::string &text); const std::string &text);
void exec(); void exec();

View File

@ -29,9 +29,9 @@
using namespace std; using namespace std;
TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, const string &text) TextManualDialog::TextManualDialog(GMenu2X& gmenu2x, const string &title, const string &icon, const string &text)
: TextDialog(gmenu2x,title,"",icon,text) { : TextDialog(gmenu2x, title, "", icon, text)
{
//split the text in multiple pages //split the text in multiple pages
for (uint i=0; i<this->text.size(); i++) { for (uint i=0; i<this->text.size(); i++) {
string line = trim(this->text.at(i)); string line = trim(this->text.at(i));
@ -42,7 +42,7 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
} else { } else {
if (pages.size()==0) { if (pages.size()==0) {
ManualPage mp; ManualPage mp;
mp.title = gmenu2x->tr["Untitled"]; mp.title = gmenu2x.tr["Untitled"];
pages.push_back(mp); pages.push_back(mp);
} }
pages[pages.size()-1].text.push_back(this->text.at(i)); pages[pages.size()-1].text.push_back(this->text.at(i));
@ -50,7 +50,7 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
} }
if (pages.size()==0) { if (pages.size()==0) {
ManualPage mp; ManualPage mp;
mp.title = gmenu2x->tr["Untitled"]; mp.title = gmenu2x.tr["Untitled"];
pages.push_back(mp); pages.push_back(mp);
} }
@ -70,7 +70,7 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
} }
void TextManualDialog::exec() { void TextManualDialog::exec() {
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface bg(*gmenu2x.bg);
//link icon //link icon
if (!fileExists(icon)) if (!fileExists(icon))
@ -80,12 +80,12 @@ void TextManualDialog::exec() {
writeTitle(bg, title+(description.empty() ? "" : ": "+description)); writeTitle(bg, title+(description.empty() ? "" : ": "+description));
int x = 5; int x = 5;
x = gmenu2x->drawButton(bg, "up", "", x); x = gmenu2x.drawButton(bg, "up", "", x);
x = gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], x); x = gmenu2x.drawButton(bg, "down", gmenu2x.tr["Scroll"], x);
x = gmenu2x->drawButton(bg, "left", "", x); x = gmenu2x.drawButton(bg, "left", "", x);
x = gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"], x); x = gmenu2x.drawButton(bg, "right", gmenu2x.tr["Change page"], x);
x = gmenu2x->drawButton(bg, "cancel", "", x); x = gmenu2x.drawButton(bg, "cancel", "", x);
x = gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], x); x = gmenu2x.drawButton(bg, "start", gmenu2x.tr["Exit"], x);
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
@ -95,9 +95,9 @@ void TextManualDialog::exec() {
ss >> spagecount; ss >> spagecount;
string pageStatus; string pageStatus;
const int fontHeight = gmenu2x->font->getLineSpacing(); const int fontHeight = gmenu2x.font->getLineSpacing();
unsigned int contentY, contentHeight; unsigned int contentY, contentHeight;
tie(contentY, contentHeight) = gmenu2x->getContentArea(); tie(contentY, contentHeight) = gmenu2x.getContentArea();
const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u); const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u);
contentY += (contentHeight % fontHeight) / 2; contentY += (contentHeight % fontHeight) / 2;
@ -105,7 +105,7 @@ void TextManualDialog::exec() {
bool close = false; bool close = false;
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& s = *gmenu2x.s;
bg.blit(s,0,0); bg.blit(s,0,0);
writeSubTitle(s, pages[page].title); writeSubTitle(s, pages[page].title);
@ -114,15 +114,15 @@ void TextManualDialog::exec() {
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(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle); gmenu2x.font->write(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle);
s.flip(); s.flip();
const unsigned maxFirstRow = pages[page].text.size() < rowsPerPage const unsigned maxFirstRow = pages[page].text.size() < rowsPerPage
? 0 : pages[page].text.size() - rowsPerPage; ? 0 : pages[page].text.size() - rowsPerPage;
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x.input.waitForPressedButton()) {
case InputManager::UP: case InputManager::UP:
if (firstRow > 0) firstRow--; if (firstRow > 0) firstRow--;
break; break;

View File

@ -36,7 +36,7 @@ private:
std::vector<ManualPage> pages; std::vector<ManualPage> pages;
public: public:
TextManualDialog(GMenu2X *gmenu2x, const std::string &title, TextManualDialog(GMenu2X& gmenu2x, const std::string &title,
const std::string &icon, const std::string &text); const std::string &icon, const std::string &text);
void exec(); void exec();
}; };

View File

@ -32,7 +32,7 @@
using namespace std; using namespace std;
WallpaperDialog::WallpaperDialog(GMenu2X *gmenu2x, Touchscreen &ts_) WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts_)
: Dialog(gmenu2x) : Dialog(gmenu2x)
, ts(ts_) , ts(ts_)
{ {
@ -47,11 +47,11 @@ bool WallpaperDialog::exec()
fl.setFilter("png"); fl.setFilter("png");
fl.browse(GMenu2X::getHome() + "/skins/" fl.browse(GMenu2X::getHome() + "/skins/"
+ gmenu2x->confStr["skin"] + "/wallpapers", true); + gmenu2x.confStr["skin"] + "/wallpapers", true);
fl.browse(GMENU2X_SYSTEM_DIR "/skins/" fl.browse(GMENU2X_SYSTEM_DIR "/skins/"
+ gmenu2x->confStr["skin"] + "/wallpapers", false); + gmenu2x.confStr["skin"] + "/wallpapers", false);
if (gmenu2x->confStr["skin"] != "Default") { if (gmenu2x.confStr["skin"] != "Default") {
fl.browse(GMenu2X::getHome() + "/skins/Default/wallpapers", false); fl.browse(GMenu2X::getHome() + "/skins/Default/wallpapers", false);
fl.browse(GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers", false); fl.browse(GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers", false);
} }
@ -63,17 +63,17 @@ bool WallpaperDialog::exec()
uint i, selected = 0, firstElement = 0, iY; uint i, selected = 0, firstElement = 0, iY;
ButtonBox buttonbox; ButtonBox buttonbox;
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"]))); buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"])));
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"]))); buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"])));
unsigned int top, height; unsigned int top, height;
tie(top, height) = gmenu2x->getContentArea(); tie(top, height) = gmenu2x.getContentArea();
int fontheight = gmenu2x->font->getLineSpacing(); int fontheight = gmenu2x.font->getLineSpacing();
unsigned int nb_elements = height / fontheight; unsigned int nb_elements = height / fontheight;
while (!close) { while (!close) {
OutputSurface& s = *gmenu2x->s; OutputSurface& 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;
@ -81,37 +81,37 @@ bool WallpaperDialog::exec()
firstElement = selected; firstElement = selected;
//Wallpaper //Wallpaper
gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(s, 0, 0); gmenu2x.sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(s, 0, 0);
gmenu2x->drawTopBar(s); gmenu2x.drawTopBar(s);
gmenu2x->drawBottomBar(s); gmenu2x.drawBottomBar(s);
drawTitleIcon(s, "icons/wallpaper.png", true); drawTitleIcon(s, "icons/wallpaper.png", true);
writeTitle(s, gmenu2x->tr["Wallpaper selection"]); writeTitle(s, gmenu2x.tr["Wallpaper selection"]);
writeSubTitle(s, gmenu2x->tr["Select a wallpaper from the list"]); writeSubTitle(s, gmenu2x.tr["Select a wallpaper from the list"]);
buttonbox.paint(s, 5, gmenu2x->resY - 1); buttonbox.paint(s, 5, gmenu2x.resY - 1);
//Selection //Selection
iY = selected - firstElement; iY = selected - firstElement;
iY = top + (iY * fontheight); iY = top + (iY * fontheight);
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
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(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);
} }
s.clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement); gmenu2x.drawScrollBar(nb_elements, wallpapers.size(), firstElement);
s.flip(); s.flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x.input.waitForPressedButton()) {
case InputManager::CANCEL: case InputManager::CANCEL:
close = true; close = true;
result = false; result = false;
@ -139,15 +139,16 @@ bool WallpaperDialog::exec()
case InputManager::ACCEPT: case InputManager::ACCEPT:
close = true; close = true;
if (wallpapers.size() > 0) if (wallpapers.size() > 0)
wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]); wallpaper = gmenu2x.sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);
else result = false; else result = false;
default: default:
break; break;
} }
} }
for (uint i=0; i<wallpapers.size(); i++) for (uint i=0; i<wallpapers.size(); i++) {
gmenu2x->sc.del("skin:wallpapers/" + wallpapers[i]); gmenu2x.sc.del("skin:wallpapers/" + wallpapers[i]);
}
return result; return result;
} }

View File

@ -32,7 +32,7 @@ private:
Touchscreen &ts; Touchscreen &ts;
public: public:
WallpaperDialog(GMenu2X *gmenu2x, Touchscreen &ts); WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts);
std::string wallpaper; std::string wallpaper;
bool exec(); bool exec();