MiniEngine/SDLWrapper/Rect.cpp

75 lines
1.1 KiB
C++
Raw Normal View History

2017-06-18 17:00:08 +08:00
#include "Rect.h"
2017-07-31 00:18:10 +08:00
namespace MiniEngine
{
2017-06-18 17:00:08 +08:00
Rect::Rect(int X, int Y, int W, int H)
{
x = X;
y = Y;
w = W;
h = H;
}
2017-06-18 20:37:45 +08:00
// explicit
2017-06-18 17:00:08 +08:00
Rect::Rect(const SDL_Rect& r):Rect(r.x,r.y,r.w,r.h)
{
}
Rect::Rect()
{
x = y = w = h = 0;
}
SDL_Rect Rect::toSDLRect() const
{
SDL_Rect r;
r.x = x;
r.y = y;
r.w = w;
r.h = h;
return r;
}
2017-06-18 20:37:45 +08:00
bool Rect::isEmpty() const
2017-06-18 17:00:08 +08:00
{
SDL_Rect r=toSDLRect();
return SDL_RectEmpty(&r)==SDL_TRUE;
}
bool Rect::operator == (const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_RectEquals(&a,&b)==SDL_TRUE;
}
bool Rect::hasIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
}
Rect Rect::getIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
if(SDL_IntersectRect(&a,&b,&c)==SDL_TRUE)
{
return Rect(c);
}
else
{
return Rect();
}
}
Rect Rect::getUnion(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
SDL_UnionRect(&a,&b,&c);//void
return Rect(c);
}
2017-07-31 00:18:10 +08:00
} /// End of namespace MiniEngine