1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 03:57:30 +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 \
utilities.cpp wallpaperdialog.cpp listview.cpp tinyxml/tinystr.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 \
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 \
sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.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@

View File

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

View File

@ -25,13 +25,14 @@
#include "filelister.h"
#include "gmenu2x.h"
#include "buttonbox.h"
#include "dialog.h"
class FileLister;
using std::string;
using std::vector;
class BrowseDialog {
class BrowseDialog : protected Dialog {
protected:
enum Action {
ACT_NONE,
@ -57,7 +58,6 @@ protected:
FileLister *fl;
unsigned int selected;
GMenu2X *gmenu2x;
private:
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]);
}
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) {
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);
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 drawBottomBar(Surface *s=NULL);

View File

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

View File

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

View File

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

View File

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

View File

@ -25,8 +25,9 @@
using namespace std;
SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon) {
this->gmenu2x = gmenu2x;
SettingsDialog::SettingsDialog(GMenu2X *gmenu2x, const string &text, const string &icon)
: Dialog(gmenu2x)
{
this->text = text;
if (icon!="" && gmenu2x->sc[icon] != NULL)
@ -61,8 +62,9 @@ bool SettingsDialog::exec() {
gmenu2x->drawTopBar(gmenu2x->s);
//link icon
gmenu2x->drawTitleIcon(icon);
gmenu2x->writeTitle(text);
drawTitleIcon(icon);
writeTitle(text);
gmenu2x->drawBottomBar(gmenu2x->s);
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);
//description
gmenu2x->writeSubTitle(voices[sel]->description);
writeSubTitle(voices[sel]->description);
gmenu2x->s->flip();
voices[sel]->handleTS();

View File

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

View File

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

View File

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

View File

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

View File

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