1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 12:09:41 +02:00

Move methods only used by dialogs from the GMenu2x class to a common base class

for all dialog classes.
This commit is contained in:
Lars-Peter Clausen 2010-05-05 14:35:52 +02:00
parent cb654dd520
commit 6da573f303
18 changed files with 123 additions and 80 deletions

View File

@ -11,7 +11,7 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
utilities.cpp wallpaperdialog.cpp listview.cpp tinyxml/tinystr.cpp \ utilities.cpp wallpaperdialog.cpp listview.cpp tinyxml/tinystr.cpp \
tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp \ tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp \
browsedialog.cpp buttonbox.cpp browsedialog.cpp buttonbox.cpp dialog.cpp
noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \ filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \
@ -22,7 +22,7 @@ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
messagebox.h pxml.h selectordetector.h selector.h settingsdialog.h \ messagebox.h pxml.h selectordetector.h selector.h settingsdialog.h \
sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \ sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \
touchscreen.h translator.h utilities.h wallpaperdialog.h \ touchscreen.h translator.h utilities.h wallpaperdialog.h \
tinyxml/tinystr.h tinyxml/tinyxml.h browsedialog.h buttonbox.h tinyxml/tinystr.h tinyxml/tinyxml.h browsedialog.h buttonbox.h dialog.h
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@ AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@

View File

@ -8,8 +8,8 @@
using namespace fastdelegate; using namespace fastdelegate;
BrowseDialog::BrowseDialog(GMenu2X *gmenu2x, const string &title, BrowseDialog::BrowseDialog(GMenu2X *gmenu2x, const string &title,
const string &subtitle) : const string &subtitle) : Dialog(gmenu2x),
gmenu2x(gmenu2x), title(title), subtitle(subtitle), buttonBox(gmenu2x) title(title), subtitle(subtitle), buttonBox(gmenu2x)
{ {
IconButton *btn; IconButton *btn;
@ -190,9 +190,9 @@ void BrowseDialog::paint()
Surface *icon; Surface *icon;
gmenu2x->bg->blit(gmenu2x->s, 0, 0); gmenu2x->bg->blit(gmenu2x->s, 0, 0);
gmenu2x->drawTitleIcon("icons/explorer.png", true); drawTitleIcon("icons/explorer.png", true);
gmenu2x->writeTitle(title); writeTitle(title);
gmenu2x->writeSubTitle(subtitle); writeSubTitle(subtitle);
buttonBox.paint(5); buttonBox.paint(5);

View File

@ -25,13 +25,14 @@
#include "filelister.h" #include "filelister.h"
#include "gmenu2x.h" #include "gmenu2x.h"
#include "buttonbox.h" #include "buttonbox.h"
#include "dialog.h"
class FileLister; class FileLister;
using std::string; using std::string;
using std::vector; using std::vector;
class BrowseDialog { class BrowseDialog : protected Dialog {
protected: protected:
enum Action { enum Action {
ACT_NONE, ACT_NONE,
@ -57,7 +58,6 @@ protected:
FileLister *fl; FileLister *fl;
unsigned int selected; unsigned int selected;
GMenu2X *gmenu2x;
private: private:
int selRow; int selRow;

44
src/dialog.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <string>
#include "dialog.h"
#include "gmenu2x.h"
#include "asfont.h"
Dialog::Dialog(GMenu2X *gmenu2x) : gmenu2x(gmenu2x)
{
}
void Dialog::drawTitleIcon(const std::string &icon, bool skinRes, Surface *s)
{
if (s==NULL)
s = gmenu2x->s;
Surface *i = NULL;
if (!icon.empty()) {
if (skinRes)
i = gmenu2x->sc.skinRes(icon);
else
i = gmenu2x->sc[icon];
}
if (i==NULL)
i = gmenu2x->sc.skinRes("icons/generic.png");
i->blit(s,4,(gmenu2x->skinConfInt["topBarHeight"]-32)/2);
}
void Dialog::writeTitle(const std::string &title, Surface *s)
{
if (s==NULL)
s = gmenu2x->s;
s->write(gmenu2x->font, title, 40, gmenu2x->skinConfInt["topBarHeight"]/4, SFontHAlignLeft, SFontVAlignMiddle);
}
void Dialog::writeSubTitle(const std::string &subtitle, Surface *s)
{
if (s==NULL)
s = gmenu2x->s;
s->write(gmenu2x->font, subtitle, 40, gmenu2x->skinConfInt["topBarHeight"]/4*3, SFontHAlignLeft, SFontVAlignMiddle);
}

22
src/dialog.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __DIALOG_H__
#define __DIALOG_H__
#include <string>
class GMenu2X;
class Surface;
class Dialog
{
public:
Dialog(GMenu2X *gmenu2x);
protected:
void drawTitleIcon(const std::string &icon, bool skinRes = false, Surface *s = NULL);
void writeTitle(const std::string &title, Surface *s = NULL);
void writeSubTitle(const std::string &subtitle, Surface *s = NULL);
GMenu2X *gmenu2x;
};
#endif

View File

@ -1963,33 +1963,6 @@ void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint to
s->box(resX-6, by, 3, bs, skinConfColors[COLOR_SELECTION_BG]); s->box(resX-6, by, 3, bs, skinConfColors[COLOR_SELECTION_BG]);
} }
void GMenu2X::drawTitleIcon(const string &icon, bool skinRes, Surface *s) {
if (s==NULL) s = this->s;
Surface *i = NULL;
if (!icon.empty()) {
if (skinRes)
i = sc.skinRes(icon);
else
i = sc[icon];
}
if (i==NULL)
i = sc.skinRes("icons/generic.png");
i->blit(s,4,(skinConfInt["topBarHeight"]-32)/2);
}
void GMenu2X::writeTitle(const string &title, Surface *s) {
if (s==NULL) s = this->s;
s->write(font,title,40, skinConfInt["topBarHeight"]/4, SFontHAlignLeft, SFontVAlignMiddle);
}
void GMenu2X::writeSubTitle(const string &subtitle, Surface *s) {
if (s==NULL) s = this->s;
s->write(font,subtitle,40, skinConfInt["topBarHeight"]/4*3, SFontHAlignLeft, SFontVAlignMiddle);
}
void GMenu2X::drawTopBar(Surface *s) { void GMenu2X::drawTopBar(Surface *s) {
if (s==NULL) s = this->s; if (s==NULL) s = this->s;

View File

@ -243,9 +243,6 @@ public:
int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10); int drawButtonRight(Surface *s, const string &btn, const string &text, int x=5, int y=-10);
void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height); void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height);
void drawTitleIcon(const string &icon, bool skinRes=true, Surface *s=NULL);
void writeTitle(const string &title, Surface *s=NULL);
void writeSubTitle(const string &subtitle, Surface *s=NULL);
void drawTopBar(Surface *s=NULL); void drawTopBar(Surface *s=NULL);
void drawBottomBar(Surface *s=NULL); void drawBottomBar(Surface *s=NULL);

View File

@ -26,8 +26,10 @@
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
InputDialog::InputDialog(GMenu2X *gmenu2x, const string &text, const string &startvalue, const string &title, const string &icon) { InputDialog::InputDialog(GMenu2X *gmenu2x, const string &text,
this->gmenu2x = gmenu2x; const string &startvalue, const string &title, const string &icon) :
Dialog(gmenu2x)
{
if (title=="") { if (title=="") {
this->title = text; this->title = text;
this->text = ""; this->text = "";
@ -129,9 +131,9 @@ bool InputDialog::exec() {
ok = true; ok = true;
while (!close) { while (!close) {
gmenu2x->bg->blit(gmenu2x->s,0,0); gmenu2x->bg->blit(gmenu2x->s,0,0);
gmenu2x->writeTitle(title); writeTitle(title);
gmenu2x->writeSubTitle(text); writeSubTitle(text);
gmenu2x->drawTitleIcon(icon); drawTitleIcon(icon);
gmenu2x->drawButton(gmenu2x->s, "y", gmenu2x->tr["Change keys"], gmenu2x->drawButton(gmenu2x->s, "y", gmenu2x->tr["Change keys"],
gmenu2x->drawButton(gmenu2x->s, "b", gmenu2x->tr["Confirm"], gmenu2x->drawButton(gmenu2x->s, "b", gmenu2x->tr["Confirm"],

View File

@ -39,18 +39,18 @@
#include <string> #include <string>
#include "gmenu2x.h" #include "gmenu2x.h"
#include "dialog.h"
using std::string; using std::string;
using std::vector; using std::vector;
typedef vector<string> stringlist; typedef vector<string> stringlist;
class InputDialog { class InputDialog : protected Dialog {
private: private:
int selRow, selCol; int selRow, selCol;
bool close, ok; bool close, ok;
string title, text, icon; string title, text, icon;
GMenu2X *gmenu2x;
short curKeyboard; short curKeyboard;
vector<stringlist> keyboard; vector<stringlist> keyboard;
stringlist *kb; stringlist *kb;

View File

@ -33,8 +33,9 @@
using namespace std; using namespace std;
Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) { Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) :
this->gmenu2x = gmenu2x; Dialog(gmenu2x)
{
this->link = link; this->link = link;
loadAliases(); loadAliases();
selRow = 0; selRow = 0;
@ -54,9 +55,9 @@ int Selector::exec(int startSelection) {
fl.browse(); fl.browse();
Surface bg(gmenu2x->bg); Surface bg(gmenu2x->bg);
gmenu2x->drawTitleIcon(link->getIconPath(),true,&bg); drawTitleIcon(link->getIconPath(), true, &bg);
gmenu2x->writeTitle(link->getTitle(),&bg); writeTitle(link->getTitle(), &bg);
gmenu2x->writeSubTitle(link->getDescription(),&bg); writeSubTitle(link->getDescription(), &bg);
if (link->getSelectorBrowser()) { if (link->getSelectorBrowser()) {
gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(&bg, "start", gmenu2x->tr["Exit"],

View File

@ -24,6 +24,7 @@
#include <string> #include <string>
#include "gmenu2x.h" #include "gmenu2x.h"
#include "utilities.h" #include "utilities.h"
#include "dialog.h"
#define SELECTOR_ELEMENTS 11 #define SELECTOR_ELEMENTS 11
@ -33,10 +34,9 @@ class FileLister;
using std::string; using std::string;
using std::vector; using std::vector;
class Selector { class Selector : protected Dialog {
private: private:
int selRow; int selRow;
GMenu2X *gmenu2x;
LinkApp *link; LinkApp *link;
hash_map<string, string> aliases; hash_map<string, string> aliases;

View File

@ -25,8 +25,9 @@
using namespace std; using namespace std;
SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon) { SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon)
this->gmenu2x = gmenu2x; : Dialog(gmenu2x)
{
this->text = text; this->text = text;
if (icon!="" && gmenu2x->sc[icon] != NULL) if (icon!="" && gmenu2x->sc[icon] != NULL)
@ -61,8 +62,9 @@ bool SettingsDialog::exec() {
gmenu2x->drawTopBar(gmenu2x->s); gmenu2x->drawTopBar(gmenu2x->s);
//link icon //link icon
gmenu2x->drawTitleIcon(icon); drawTitleIcon(icon);
gmenu2x->writeTitle(text); writeTitle(text);
gmenu2x->drawBottomBar(gmenu2x->s); gmenu2x->drawBottomBar(gmenu2x->s);
if (sel>firstElement+numRows-1) firstElement=sel-numRows+1; if (sel>firstElement+numRows-1) firstElement=sel-numRows+1;
@ -95,7 +97,7 @@ bool SettingsDialog::exec() {
gmenu2x->drawScrollBar(numRows,voices.size(),firstElement,clipRect.y+1,clipRect.h); gmenu2x->drawScrollBar(numRows,voices.size(),firstElement,clipRect.y+1,clipRect.h);
//description //description
gmenu2x->writeSubTitle(voices[sel]->description); writeSubTitle(voices[sel]->description);
gmenu2x->s->flip(); gmenu2x->s->flip();
voices[sel]->handleTS(); voices[sel]->handleTS();

View File

@ -29,15 +29,15 @@
#include <string> #include <string>
#include "gmenu2x.h" #include "gmenu2x.h"
#include "menusetting.h" #include "menusetting.h"
#include "dialog.h"
using std::string; using std::string;
using std::vector; using std::vector;
class SettingsDialog { class SettingsDialog : protected Dialog {
private: private:
vector<MenuSetting *> voices; vector<MenuSetting *> voices;
string text, icon; string text, icon;
GMenu2X *gmenu2x;
public: public:
SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon="skin:sections/settings.png"); SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon="skin:sections/settings.png");

View File

@ -22,8 +22,9 @@
using namespace std; using namespace std;
TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, vector<string> *text) { TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, vector<string> *text)
this->gmenu2x = gmenu2x; : Dialog(gmenu2x)
{
this->text = text; this->text = text;
this->title = title; this->title = title;
this->description = description; this->description = description;
@ -99,11 +100,11 @@ void TextDialog::exec() {
//link icon //link icon
if (!fileExists(icon)) if (!fileExists(icon))
gmenu2x->drawTitleIcon("icons/ebook.png",true,&bg); drawTitleIcon("icons/ebook.png",true,&bg);
else else
gmenu2x->drawTitleIcon(icon,false,&bg); drawTitleIcon(icon,false,&bg);
gmenu2x->writeTitle(title,&bg); writeTitle(title,&bg);
gmenu2x->writeSubTitle(description,&bg); writeSubTitle(description,&bg);
gmenu2x->drawButton(&bg, "x", gmenu2x->tr["Exit"], gmenu2x->drawButton(&bg, "x", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"], gmenu2x->drawButton(&bg, "down", gmenu2x->tr["Scroll"],

View File

@ -23,15 +23,15 @@
#include <string> #include <string>
#include "gmenu2x.h" #include "gmenu2x.h"
#include "dialog.h"
using std::string; using std::string;
using std::vector; using std::vector;
class TextDialog { class TextDialog : protected Dialog {
protected: protected:
vector<string> *text; vector<string> *text;
string title, description, icon; string title, description, icon;
GMenu2X *gmenu2x;
void preProcess(); void preProcess();
void drawText(vector<string> *text, uint firstRow, uint rowsPerPage); void drawText(vector<string> *text, uint firstRow, uint rowsPerPage);

View File

@ -25,7 +25,6 @@ using namespace std;
TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, vector<string> *text) TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, vector<string> *text)
: TextDialog(gmenu2x,title,"",icon,text) { : TextDialog(gmenu2x,title,"",icon,text) {
this->gmenu2x = gmenu2x;
//split the text in multiple pages //split the text in multiple pages
for (uint i=0; i<text->size(); i++) { for (uint i=0; i<text->size(); i++) {
@ -70,10 +69,10 @@ void TextManualDialog::exec() {
//link icon //link icon
if (!fileExists(icon)) if (!fileExists(icon))
gmenu2x->drawTitleIcon("icons/ebook.png",true,&bg); drawTitleIcon("icons/ebook.png",true,&bg);
else else
gmenu2x->drawTitleIcon(icon,false,&bg); drawTitleIcon(icon,false,&bg);
gmenu2x->writeTitle(title+(description.empty() ? "" : ": "+description),&bg); writeTitle(title+(description.empty() ? "" : ": "+description),&bg);
gmenu2x->drawButton(&bg, "x", gmenu2x->tr["Exit"], gmenu2x->drawButton(&bg, "x", gmenu2x->tr["Exit"],
gmenu2x->drawButton(&bg, "right", gmenu2x->tr["Change page"], gmenu2x->drawButton(&bg, "right", gmenu2x->tr["Change page"],
@ -89,7 +88,7 @@ void TextManualDialog::exec() {
string pageStatus; string pageStatus;
while (!close) { while (!close) {
bg.blit(gmenu2x->s,0,0); bg.blit(gmenu2x->s,0,0);
gmenu2x->writeSubTitle(pages[page].title); writeSubTitle(pages[page].title);
drawText(&pages[page].text, firstRow, rowsPerPage); drawText(&pages[page].text, firstRow, rowsPerPage);
ss.clear(); ss.clear();

View File

@ -23,12 +23,13 @@
using namespace std; using namespace std;
WallpaperDialog::WallpaperDialog(GMenu2X *gmenu2x) { WallpaperDialog::WallpaperDialog(GMenu2X *gmenu2x) : Dialog(gmenu2x)
this->gmenu2x = gmenu2x; {
selRow = 0; selRow = 0;
} }
bool WallpaperDialog::exec() { bool WallpaperDialog::exec()
{
bool close = false, result = true; bool close = false, result = true;
FileLister fl("skins/"+gmenu2x->confStr["skin"]+"/wallpapers"); FileLister fl("skins/"+gmenu2x->confStr["skin"]+"/wallpapers");
@ -61,9 +62,9 @@ bool WallpaperDialog::exec() {
gmenu2x->drawTopBar(gmenu2x->s); gmenu2x->drawTopBar(gmenu2x->s);
gmenu2x->drawBottomBar(gmenu2x->s); gmenu2x->drawBottomBar(gmenu2x->s);
gmenu2x->drawTitleIcon("icons/wallpaper.png",true); drawTitleIcon("icons/wallpaper.png",true);
gmenu2x->writeTitle("Wallpaper selection"); writeTitle("Wallpaper selection");
gmenu2x->writeSubTitle("Select an image from the list, to use as a wallpaper"); writeSubTitle("Select an image from the list, to use as a wallpaper");
gmenu2x->drawButton(gmenu2x->s, "b", gmenu2x->tr["Select wallpaper"],5); gmenu2x->drawButton(gmenu2x->s, "b", gmenu2x->tr["Select wallpaper"],5);

View File

@ -23,11 +23,12 @@
#include <string> #include <string>
#include "gmenu2x.h" #include "gmenu2x.h"
#include "dialog.h"
using std::string; using std::string;
using std::vector; using std::vector;
class WallpaperDialog { class WallpaperDialog : protected Dialog {
private: private:
int selRow; int selRow;
GMenu2X *gmenu2x; GMenu2X *gmenu2x;