mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:09:41 +02:00
Removed "delegate.h"
The abstraction it provided was so thin that I think it is simpler to just have the code use std::bind directly.
This commit is contained in:
parent
7e308879c1
commit
fe0db484ec
@ -6,6 +6,7 @@
|
||||
#include "surface.h"
|
||||
#include "utilities.h"
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -23,22 +24,22 @@ BrowseDialog::BrowseDialog(
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/cancel.png",
|
||||
gmenu2x->tr["Up one folder"],
|
||||
BIND(&BrowseDialog::directoryUp))));
|
||||
bind(&BrowseDialog::directoryUp, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Select"],
|
||||
BIND(&BrowseDialog::directoryEnter))));
|
||||
bind(&BrowseDialog::directoryEnter, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/start.png",
|
||||
gmenu2x->tr["Confirm"],
|
||||
BIND(&BrowseDialog::confirm))));
|
||||
bind(&BrowseDialog::confirm, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/select.png",
|
||||
gmenu2x->tr["Exit"],
|
||||
BIND(&BrowseDialog::quit))));
|
||||
bind(&BrowseDialog::quit, this))));
|
||||
|
||||
iconGoUp = gmenu2x->sc.skinRes("imgs/go-up.png");
|
||||
iconFolder = gmenu2x->sc.skinRes("imgs/folder.png");
|
||||
|
@ -3,20 +3,21 @@
|
||||
|
||||
#include "contextmenu.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "linkapp.h"
|
||||
#include "menu.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
|
||||
struct ContextMenu::MenuOption {
|
||||
MenuOption(std::string text, function_t action)
|
||||
typedef std::function<void(void)> Action;
|
||||
MenuOption(std::string text, Action action)
|
||||
: text(text), action(action) {}
|
||||
std::string text;
|
||||
function_t action;
|
||||
Action action;
|
||||
};
|
||||
|
||||
ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu)
|
||||
|
@ -1,10 +0,0 @@
|
||||
#ifndef __DELEGATE_H__
|
||||
#define __DELEGATE_H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
typedef std::function<void(void)> function_t;
|
||||
|
||||
#define BIND(function) std::bind(function, this)
|
||||
|
||||
#endif /* __DELEGATE_H__ */
|
@ -381,17 +381,36 @@ void GMenu2X::initMenu() {
|
||||
for (uint i=0; i<menu->getSections().size(); i++) {
|
||||
//Add virtual links in the applications section
|
||||
if (menu->getSections()[i]=="applications") {
|
||||
menu->addActionLink(i,"Explorer", BIND(&GMenu2X::explorer),tr["Launch an application"],"skin:icons/explorer.png");
|
||||
menu->addActionLink(i, "Explorer",
|
||||
bind(&GMenu2X::explorer, this),
|
||||
tr["Launch an application"],
|
||||
"skin:icons/explorer.png");
|
||||
}
|
||||
|
||||
//Add virtual links in the setting section
|
||||
else if (menu->getSections()[i]=="settings") {
|
||||
menu->addActionLink(i,"GMenu2X",BIND(&GMenu2X::showSettings),tr["Configure GMenu2X's options"],"skin:icons/configure.png");
|
||||
menu->addActionLink(i,tr["Skin"],BIND(&GMenu2X::skinMenu),tr["Configure skin"],"skin:icons/skin.png");
|
||||
menu->addActionLink(i,tr["Wallpaper"],BIND(&GMenu2X::changeWallpaper),tr["Change GMenu2X wallpaper"],"skin:icons/wallpaper.png");
|
||||
if (fileExists(LOG_FILE))
|
||||
menu->addActionLink(i,tr["Log Viewer"],BIND(&GMenu2X::viewLog),tr["Displays last launched program's output"],"skin:icons/ebook.png");
|
||||
menu->addActionLink(i,tr["About"],BIND(&GMenu2X::about),tr["Info about GMenu2X"],"skin:icons/about.png");
|
||||
menu->addActionLink(i, "GMenu2X",
|
||||
bind(&GMenu2X::showSettings, this),
|
||||
tr["Configure GMenu2X's options"],
|
||||
"skin:icons/configure.png");
|
||||
menu->addActionLink(i, tr["Skin"],
|
||||
bind(&GMenu2X::skinMenu, this),
|
||||
tr["Configure skin"],
|
||||
"skin:icons/skin.png");
|
||||
menu->addActionLink(i, tr["Wallpaper"],
|
||||
bind(&GMenu2X::changeWallpaper, this),
|
||||
tr["Change GMenu2X wallpaper"],
|
||||
"skin:icons/wallpaper.png");
|
||||
if (fileExists(LOG_FILE)) {
|
||||
menu->addActionLink(i, tr["Log Viewer"],
|
||||
bind(&GMenu2X::viewLog, this),
|
||||
tr["Displays last launched program's output"],
|
||||
"skin:icons/ebook.png");
|
||||
}
|
||||
menu->addActionLink(i, tr["About"],
|
||||
bind(&GMenu2X::about, this),
|
||||
tr["Info about GMenu2X"],
|
||||
"skin:icons/about.png");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ using namespace std;
|
||||
|
||||
IconButton::IconButton(
|
||||
GMenu2X *gmenu2x, Touchscreen &ts,
|
||||
const string &icon, const string &label, function_t action)
|
||||
const string &icon, const string &label, Action action)
|
||||
: gmenu2x(gmenu2x)
|
||||
, ts(ts)
|
||||
, icon(icon)
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef ICONBUTTON_H
|
||||
#define ICONBUTTON_H
|
||||
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
class OffscreenSurface;
|
||||
@ -14,9 +15,11 @@ class Touchscreen;
|
||||
|
||||
class IconButton {
|
||||
public:
|
||||
typedef std::function<void(void)> Action;
|
||||
|
||||
IconButton(GMenu2X *gmenu2x, Touchscreen &ts,
|
||||
const std::string &icon, const std::string &label = "",
|
||||
function_t action = nullptr);
|
||||
Action action = nullptr);
|
||||
|
||||
SDL_Rect getRect() { return rect; }
|
||||
void setPosition(int x, int y);
|
||||
@ -31,7 +34,7 @@ private:
|
||||
GMenu2X *gmenu2x;
|
||||
Touchscreen &ts;
|
||||
std::string icon, label;
|
||||
function_t action;
|
||||
Action action;
|
||||
|
||||
SDL_Rect rect, iconRect, labelRect;
|
||||
OffscreenSurface *iconSurface;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "inputdialog.h"
|
||||
|
||||
#include "buttonbox.h"
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
#include "surface.h"
|
||||
@ -100,22 +99,22 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
|
||||
buttonbox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/l.png",
|
||||
gmenu2x->tr["Backspace"],
|
||||
BIND(&InputDialog::backspace))));
|
||||
bind(&InputDialog::backspace, this))));
|
||||
|
||||
buttonbox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/r.png",
|
||||
gmenu2x->tr["Space"],
|
||||
BIND(&InputDialog::space))));
|
||||
bind(&InputDialog::space, this))));
|
||||
|
||||
buttonbox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Confirm"],
|
||||
BIND(&InputDialog::confirm))));
|
||||
bind(&InputDialog::confirm, this))));
|
||||
|
||||
buttonbox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/cancel.png",
|
||||
gmenu2x->tr["Change keys"],
|
||||
BIND(&InputDialog::changeKeys))));
|
||||
bind(&InputDialog::changeKeys, this))));
|
||||
}
|
||||
|
||||
void InputDialog::setKeyboard(int kb) {
|
||||
|
@ -32,7 +32,7 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
Link::Link(GMenu2X *gmenu2x, function_t action)
|
||||
Link::Link(GMenu2X *gmenu2x, Action action)
|
||||
: gmenu2x(gmenu2x)
|
||||
, ts(gmenu2x->getTouchscreen())
|
||||
, action(action)
|
||||
|
10
src/link.h
10
src/link.h
@ -21,9 +21,9 @@
|
||||
#ifndef LINK_H
|
||||
#define LINK_H
|
||||
|
||||
#include "delegate.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
class GMenu2X;
|
||||
@ -38,7 +38,9 @@ Base class that represents a link on screen.
|
||||
*/
|
||||
class Link {
|
||||
public:
|
||||
Link(GMenu2X *gmenu2x, function_t action);
|
||||
typedef std::function<void(void)> Action;
|
||||
|
||||
Link(GMenu2X *gmenu2x, Action action);
|
||||
virtual ~Link() {};
|
||||
|
||||
bool isPressed();
|
||||
@ -78,7 +80,7 @@ private:
|
||||
void recalcCoordinates();
|
||||
|
||||
Touchscreen &ts;
|
||||
function_t action;
|
||||
Action action;
|
||||
|
||||
SDL_Rect rect;
|
||||
uint iconX, padding;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "linkapp.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "launcher.h"
|
||||
#include "layer.h"
|
||||
@ -87,7 +86,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile,
|
||||
#else
|
||||
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile)
|
||||
#endif
|
||||
: Link(gmenu2x_, BIND(&LinkApp::start))
|
||||
: Link(gmenu2x_, bind(&LinkApp::start, this))
|
||||
{
|
||||
manual = "";
|
||||
file = linkfile;
|
||||
|
@ -387,7 +387,7 @@ void Menu::setSectionIndex(int i) {
|
||||
/*====================================
|
||||
LINKS MANAGEMENT
|
||||
====================================*/
|
||||
void Menu::addActionLink(uint section, const string &title, function_t action, const string &description, const string &icon) {
|
||||
void Menu::addActionLink(uint section, const string &title, Action action, const string &description, const string &icon) {
|
||||
assert(section < sections.size());
|
||||
|
||||
Link *link = new Link(gmenu2x, action);
|
||||
|
@ -21,11 +21,11 @@
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
#include "delegate.h"
|
||||
#include "iconbutton.h"
|
||||
#include "layer.h"
|
||||
#include "link.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -99,6 +99,8 @@ private:
|
||||
void linkDown();
|
||||
|
||||
public:
|
||||
typedef std::function<void(void)> Action;
|
||||
|
||||
Menu(GMenu2X *gmenu2x, Touchscreen &ts);
|
||||
virtual ~Menu();
|
||||
|
||||
@ -115,7 +117,7 @@ public:
|
||||
void setSectionIndex(int i);
|
||||
|
||||
void addActionLink(uint section, const std::string &title,
|
||||
function_t action, const std::string &description="",
|
||||
Action action, const std::string &description="",
|
||||
const std::string &icon="");
|
||||
bool addLink(std::string path, std::string file, std::string section="");
|
||||
bool addSection(const std::string §ionName);
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "menusettingbool.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
#include "surface.h"
|
||||
@ -28,6 +27,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -62,7 +62,7 @@ void MenuSettingBool::initButton()
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Switch"],
|
||||
BIND(&MenuSettingBool::toggle))));
|
||||
bind(&MenuSettingBool::toggle, this))));
|
||||
}
|
||||
|
||||
void MenuSettingBool::draw(int valueX, int y, int h)
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include "menusettingdir.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "dirdialog.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -37,12 +37,12 @@ MenuSettingDir::MenuSettingDir(
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/cancel.png",
|
||||
gmenu2x->tr["Clear"],
|
||||
BIND(&MenuSettingDir::clear))));
|
||||
bind(&MenuSettingDir::clear, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Select"],
|
||||
BIND(&MenuSettingDir::edit))));
|
||||
bind(&MenuSettingDir::edit, this))));
|
||||
}
|
||||
|
||||
void MenuSettingDir::edit()
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include "menusettingfile.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "filedialog.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -39,12 +39,12 @@ MenuSettingFile::MenuSettingFile(
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/cancel.png",
|
||||
gmenu2x->tr["Clear"],
|
||||
BIND(&MenuSettingFile::clear))));
|
||||
bind(&MenuSettingFile::clear, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Select"],
|
||||
BIND(&MenuSettingFile::edit))));
|
||||
bind(&MenuSettingFile::edit, this))));
|
||||
}
|
||||
|
||||
void MenuSettingFile::edit()
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "menusettingint.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
#include "surface.h"
|
||||
@ -28,6 +27,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
using std::unique_ptr;
|
||||
@ -46,8 +46,8 @@ MenuSettingInt::MenuSettingInt(
|
||||
setValue(this->value());
|
||||
|
||||
//Delegates
|
||||
function_t actionInc = BIND(&MenuSettingInt::inc);
|
||||
function_t actionDec = BIND(&MenuSettingInt::dec);
|
||||
IconButton::Action actionInc = bind(&MenuSettingInt::inc, this);
|
||||
IconButton::Action actionDec = bind(&MenuSettingInt::dec, this);
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/l.png",
|
||||
|
@ -18,13 +18,13 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "delegate.h"
|
||||
#include "menusettingmultistring.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::bind;
|
||||
using std::find;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@ -41,11 +41,11 @@ MenuSettingMultiString::MenuSettingMultiString(
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/left.png", "",
|
||||
BIND(&MenuSettingMultiString::decSel))));
|
||||
bind(&MenuSettingMultiString::decSel, this))));
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/right.png",
|
||||
gmenu2x->tr["Change value"],
|
||||
BIND(&MenuSettingMultiString::incSel))));
|
||||
bind(&MenuSettingMultiString::incSel, this))));
|
||||
}
|
||||
|
||||
bool MenuSettingMultiString::handleButtonPress(InputManager::Button button)
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include "menusettingstring.h"
|
||||
|
||||
#include "delegate.h"
|
||||
#include "gmenu2x.h"
|
||||
#include "iconbutton.h"
|
||||
#include "inputdialog.h"
|
||||
|
||||
using std::bind;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -40,12 +40,12 @@ MenuSettingString::MenuSettingString(
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/cancel.png",
|
||||
gmenu2x->tr["Clear"],
|
||||
BIND(&MenuSettingString::clear))));
|
||||
bind(&MenuSettingString::clear, this))));
|
||||
|
||||
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
||||
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
||||
gmenu2x->tr["Edit"],
|
||||
BIND(&MenuSettingString::edit))));
|
||||
bind(&MenuSettingString::edit, this))));
|
||||
}
|
||||
|
||||
void MenuSettingString::edit()
|
||||
|
Loading…
Reference in New Issue
Block a user