1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 03:06:15 +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 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();
}

View File

@ -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();

View File

@ -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;

View File

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

View File

@ -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");

View File

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

View File

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

View File

@ -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;