mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-26 19:29:49 +00:00
sdl/rect: Add contains(rect) overload to check for contained subrect
This commit is contained in:
parent
65515848ef
commit
635bdd8c3e
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user