mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add more functions to class Rect
This commit is contained in:
parent
bb563d069d
commit
d8d77a5bd2
|
@ -126,12 +126,17 @@ namespace MiniEngine
|
||||||
h = H;
|
h = H;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect::Rect(const SDL_Rect& r):Rect(r.x,r.y,r.w,r.h)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Rect::Rect()
|
Rect::Rect()
|
||||||
{
|
{
|
||||||
x = y = w = h = 0;
|
x = y = w = h = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect Rect::toSDLRect()
|
SDL_Rect Rect::toSDLRect() const
|
||||||
{
|
{
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
r.x = x;
|
r.x = x;
|
||||||
|
@ -141,6 +146,44 @@ namespace MiniEngine
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Rect::isEmpty()
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
|
||||||
|
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect Rect::getIntersection(const Rect& r)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
|
||||||
|
SDL_UnionRect(&a,&b,&c);//void
|
||||||
|
return Rect(c);
|
||||||
|
}
|
||||||
|
|
||||||
Point::Point(int X, int Y)
|
Point::Point(int X, int Y)
|
||||||
{
|
{
|
||||||
x = X;
|
x = X;
|
||||||
|
|
|
@ -33,8 +33,14 @@ namespace MiniEngine
|
||||||
public:
|
public:
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
Rect(int X, int Y, int W, int H);
|
Rect(int X, int Y, int W, int H);
|
||||||
|
Rect(const SDL_Rect&);
|
||||||
Rect();
|
Rect();
|
||||||
SDL_Rect toSDLRect();
|
SDL_Rect toSDLRect() const;
|
||||||
|
bool isEmpty();
|
||||||
|
bool operator == (const Rect&) const;
|
||||||
|
bool hasIntersection(const Rect&);
|
||||||
|
Rect getIntersection(const Rect&);
|
||||||
|
Rect getUnion(const Rect&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Point
|
class Point
|
||||||
|
|
Loading…
Reference in New Issue
Block a user