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

Give Button a direct reference to the Touchscreen object instead of fetching it from the GMenu2X object.

This commit is contained in:
Maarten ter Huurne 2010-07-27 22:12:28 +02:00
parent 8032d96a17
commit 4468464505
8 changed files with 30 additions and 21 deletions

View File

@ -4,19 +4,17 @@
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
Button::Button(GMenu2X * gmenu2x, bool doubleClick) { Button::Button(Touchscreen &ts_, bool doubleClick_)
this->gmenu2x = gmenu2x; : ts(ts_)
this->doubleClick = doubleClick; , action(MakeDelegate(this, &Button::voidAction))
lastTick = 0; , rect((SDL_Rect) { 0, 0, 0, 0 })
action = MakeDelegate(this, &Button::voidAction); , doubleClick(doubleClick_)
rect.x = 0; , lastTick(0)
rect.y = 0; {
rect.w = 0;
rect.h = 0;
} }
void Button::paint() { void Button::paint() {
if (gmenu2x->ts.inRect(rect)) if (ts.inRect(rect))
if (!paintHover()) return; if (!paintHover()) return;
} }
@ -25,11 +23,11 @@ bool Button::paintHover() {
} }
bool Button::isPressed() { bool Button::isPressed() {
return gmenu2x->ts.pressed() && gmenu2x->ts.inRect(rect); return ts.pressed() && ts.inRect(rect);
} }
bool Button::isReleased() { bool Button::isReleased() {
return gmenu2x->ts.released() && gmenu2x->ts.inRect(rect); return ts.released() && ts.inRect(rect);
} }
bool Button::handleTS() { bool Button::handleTS() {
@ -48,7 +46,7 @@ bool Button::handleTS() {
} }
void Button::exec() { void Button::exec() {
gmenu2x->ts.setHandled(); ts.setHandled();
action(); action();
} }

View File

@ -29,18 +29,20 @@ using std::string;
using fastdelegate::FastDelegate0; using fastdelegate::FastDelegate0;
typedef FastDelegate0<> ButtonAction; typedef FastDelegate0<> ButtonAction;
class GMenu2X; class Touchscreen;
class Button { class Button {
private:
Touchscreen &ts;
protected: protected:
GMenu2X *gmenu2x;
ButtonAction action; ButtonAction action;
SDL_Rect rect; SDL_Rect rect;
bool doubleClick; bool doubleClick;
int lastTick; int lastTick;
public: public:
Button(GMenu2X *gmenu2x, bool doubleClick = false); Button(Touchscreen &ts, bool doubleClick = false);
virtual ~Button() {}; virtual ~Button() {};
SDL_Rect getRect(); SDL_Rect getRect();

View File

@ -5,7 +5,11 @@
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
IconButton::IconButton(GMenu2X *gmenu2x, const string &icon, const string &label) : Button(gmenu2x) { IconButton::IconButton(GMenu2X *gmenu2x_, const string &icon,
const string &label)
: Button(gmenu2x_->ts)
, gmenu2x(gmenu2x_)
{
this->icon = icon; this->icon = icon;
labelPosition = IconButton::DISP_RIGHT; labelPosition = IconButton::DISP_RIGHT;
labelMargin = 2; labelMargin = 2;

View File

@ -11,6 +11,7 @@ class Surface;
class IconButton : public Button { class IconButton : public Button {
protected: protected:
GMenu2X *gmenu2x;
string icon, label; string icon, label;
int labelPosition, labelMargin; int labelPosition, labelMargin;
unsigned short labelHAlign, labelVAlign; unsigned short labelHAlign, labelVAlign;

View File

@ -26,7 +26,10 @@
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
Link::Link(GMenu2X *gmenu2x) : Button(gmenu2x, true) { Link::Link(GMenu2X *gmenu2x_)
: Button(gmenu2x_->ts, true)
, gmenu2x(gmenu2x_)
{
action = MakeDelegate(this, &Link::run); action = MakeDelegate(this, &Link::run);
edited = false; edited = false;
iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png");

View File

@ -40,6 +40,7 @@ private:
uint iconX, padding; uint iconX, padding;
protected: protected:
GMenu2X *gmenu2x;
bool edited; bool edited;
string title, description, icon, iconPath; string title, description, icon, iconPath;

View File

@ -25,7 +25,6 @@ using namespace std;
LinkAction::LinkAction(GMenu2X *gmenu2x, LinkRunAction act) LinkAction::LinkAction(GMenu2X *gmenu2x, LinkRunAction act)
: Link(gmenu2x) { : Link(gmenu2x) {
this->gmenu2x = gmenu2x;
this->action = act; this->action = act;
} }

View File

@ -30,8 +30,9 @@
using namespace std; using namespace std;
LinkApp::LinkApp(GMenu2X *gmenu2x, const char* linkfile) LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile)
: Link(gmenu2x) { : Link(gmenu2x_)
{
manual = ""; manual = "";
file = linkfile; file = linkfile;
wrapper = false; wrapper = false;