diff --git a/src/sdl/rect.cpp b/src/sdl/rect.cpp index c38fa88827d..338c5ba111f 100644 --- a/src/sdl/rect.cpp +++ b/src/sdl/rect.cpp @@ -62,10 +62,18 @@ bool rect::contains(const point& point) const return SDL_PointInRect(&point, this) != SDL_FALSE; } +bool rect::contains(const SDL_Rect& r) const +{ + if(this->x > r.x) return false; + if(this->y > r.y) return false; + if(this->x + this->w < r.x + r.w) return false; + if(this->y + this->h < r.y + r.h) return false; + return true; +} + bool rect::overlaps(const SDL_Rect& r) const { - return (r.x < x + w && x < r.x + r.w && - r.y < y + h && y < r.y + r.h); + return SDL_HasIntersection(this, &r); } rect rect::minimal_cover(const SDL_Rect& other) const diff --git a/src/sdl/rect.hpp b/src/sdl/rect.hpp index ba2b72708cc..de936905f89 100644 --- a/src/sdl/rect.hpp +++ b/src/sdl/rect.hpp @@ -77,6 +77,9 @@ public: bool contains(int x, int y) const; bool contains(const point& p) const; + /** Whether the given rectangle is completely contained by this one. */ + bool contains(const SDL_Rect& r) const; + /** Whether the given rectangle and this rectangle overlap. */ bool overlaps(const SDL_Rect& r) const;