diff --git a/src/button.cpp b/src/button.cpp index ff61fae..a02640d 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -4,19 +4,17 @@ using namespace std; using namespace fastdelegate; -Button::Button(GMenu2X * gmenu2x, bool doubleClick) { - this->gmenu2x = gmenu2x; - this->doubleClick = doubleClick; - lastTick = 0; - action = MakeDelegate(this, &Button::voidAction); - rect.x = 0; - rect.y = 0; - rect.w = 0; - rect.h = 0; +Button::Button(Touchscreen &ts_, bool doubleClick_) + : ts(ts_) + , action(MakeDelegate(this, &Button::voidAction)) + , rect((SDL_Rect) { 0, 0, 0, 0 }) + , doubleClick(doubleClick_) + , lastTick(0) +{ } void Button::paint() { - if (gmenu2x->ts.inRect(rect)) + if (ts.inRect(rect)) if (!paintHover()) return; } @@ -25,11 +23,11 @@ bool Button::paintHover() { } bool Button::isPressed() { - return gmenu2x->ts.pressed() && gmenu2x->ts.inRect(rect); + return ts.pressed() && ts.inRect(rect); } bool Button::isReleased() { - return gmenu2x->ts.released() && gmenu2x->ts.inRect(rect); + return ts.released() && ts.inRect(rect); } bool Button::handleTS() { @@ -48,7 +46,7 @@ bool Button::handleTS() { } void Button::exec() { - gmenu2x->ts.setHandled(); + ts.setHandled(); action(); } diff --git a/src/button.h b/src/button.h index fe2b09c..fc8e918 100644 --- a/src/button.h +++ b/src/button.h @@ -29,18 +29,20 @@ using std::string; using fastdelegate::FastDelegate0; typedef FastDelegate0<> ButtonAction; -class GMenu2X; +class Touchscreen; class Button { +private: + Touchscreen &ts; + protected: - GMenu2X *gmenu2x; ButtonAction action; SDL_Rect rect; bool doubleClick; int lastTick; public: - Button(GMenu2X *gmenu2x, bool doubleClick = false); + Button(Touchscreen &ts, bool doubleClick = false); virtual ~Button() {}; SDL_Rect getRect(); diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index 38f350f..80b8581 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -5,7 +5,11 @@ using namespace std; 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; labelPosition = IconButton::DISP_RIGHT; labelMargin = 2; diff --git a/src/iconbutton.h b/src/iconbutton.h index 16355c0..4c094f7 100644 --- a/src/iconbutton.h +++ b/src/iconbutton.h @@ -11,6 +11,7 @@ class Surface; class IconButton : public Button { protected: + GMenu2X *gmenu2x; string icon, label; int labelPosition, labelMargin; unsigned short labelHAlign, labelVAlign; diff --git a/src/link.cpp b/src/link.cpp index 5195da2..468e4b9 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -26,7 +26,10 @@ using namespace std; 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); edited = false; iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); diff --git a/src/link.h b/src/link.h index a73fea5..7bebfcb 100644 --- a/src/link.h +++ b/src/link.h @@ -40,6 +40,7 @@ private: uint iconX, padding; protected: + GMenu2X *gmenu2x; bool edited; string title, description, icon, iconPath; diff --git a/src/linkaction.cpp b/src/linkaction.cpp index e9f8b4e..af8cc3f 100644 --- a/src/linkaction.cpp +++ b/src/linkaction.cpp @@ -25,7 +25,6 @@ using namespace std; LinkAction::LinkAction(GMenu2X *gmenu2x, LinkRunAction act) : Link(gmenu2x) { - this->gmenu2x = gmenu2x; this->action = act; } diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 290c3f0..6067c53 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -30,8 +30,9 @@ using namespace std; -LinkApp::LinkApp(GMenu2X *gmenu2x, const char* linkfile) - : Link(gmenu2x) { +LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile) + : Link(gmenu2x_) +{ manual = ""; file = linkfile; wrapper = false;