1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 22:59:42 +02:00

Touchscreen: Avoid constructing an SDL_Rect for is-inside tests.

Made the SDL_Rect versions of the methods call the plain-int versions
instead of vice versa.
This commit is contained in:
Maarten ter Huurne 2012-04-10 22:44:56 +02:00
parent b248aaf808
commit 58d6077e5c
2 changed files with 13 additions and 15 deletions

View File

@ -104,23 +104,21 @@ bool Touchscreen::released() {
return !pressed() && wasPressed; return !pressed() && wasPressed;
} }
bool Touchscreen::inRect(SDL_Rect r) { bool Touchscreen::inRect(int ix, int iy, int iw, int ih) {
return !_handled && return !_handled &&
(y >= r.y) && (y <= r.y + r.h) && (x >= r.x) && (x <= r.x + r.w); (y >= iy) && (y <= iy + ih) && (x >= ix) && (x <= ix + iw);
} }
bool Touchscreen::inRect(int x, int y, int w, int h) { bool Touchscreen::inRect(SDL_Rect r) {
SDL_Rect rect = { x, y, w, h }; return inRect(r.x, r.y, r.w, r.h);
return inRect(rect); }
bool Touchscreen::startedInRect(int ix, int iy, int iw, int ih) {
return !_handled &&
(startY >= iy) && (startY <= iy + ih) &&
(startX >= ix) && (startX <= ix + iw);
} }
bool Touchscreen::startedInRect(SDL_Rect r) { bool Touchscreen::startedInRect(SDL_Rect r) {
return !_handled && return startedInRect(r.x, r.y, r.w, r.h);
(startY >= r.y) && (startY <= r.y + r.h) &&
(startX >= r.x) && (startX <= r.x + r.w);
}
bool Touchscreen::startedInRect(int x, int y, int w, int h) {
SDL_Rect rect = { x, y, w, h };
return startedInRect(rect);
} }

View File

@ -52,10 +52,10 @@ public:
bool handled(); bool handled();
void setHandled(); void setHandled();
bool inRect(SDL_Rect r);
bool inRect(int x, int y, int w, int h); bool inRect(int x, int y, int w, int h);
bool startedInRect(SDL_Rect r); bool inRect(SDL_Rect r);
bool startedInRect(int x, int y, int w, int h); bool startedInRect(int x, int y, int w, int h);
bool startedInRect(SDL_Rect r);
int getX() { return x; } int getX() { return x; }
int getY() { return y; } int getY() { return y; }