63 lines
974 B
C
63 lines
974 B
C
#ifndef RECT_H
|
|
#define RECT_H
|
|
|
|
struct Rect
|
|
{
|
|
int left;
|
|
int top;
|
|
int width;
|
|
int height;
|
|
|
|
static const Rect None;
|
|
|
|
Rect() { }
|
|
Rect(int _left, int _top, int _width, int _height) : left(_left), top(_top), width(_width), height(_height) { }
|
|
|
|
bool operator ==(const Rect &other) const
|
|
{
|
|
return left == other.left && top == other.top && width == other.width && height == other.height;
|
|
}
|
|
|
|
bool operator !=(const Rect &other) const
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
bool operator !() const
|
|
{
|
|
return *this == None;
|
|
}
|
|
|
|
operator bool() const
|
|
{
|
|
return *this != None;
|
|
}
|
|
|
|
bool HitX(int x) const
|
|
{
|
|
return x >= left && x < left + width;
|
|
}
|
|
|
|
bool HitY(int y) const
|
|
{
|
|
return y >= top && y < top + height;
|
|
}
|
|
|
|
bool Hit(int x, int y) const
|
|
{
|
|
return HitX(x) && HitY(y);
|
|
}
|
|
|
|
void SetIfHitX(int x, Rect &other)
|
|
{
|
|
if (!other && HitX(x)) other = *this;
|
|
}
|
|
|
|
void SetIfHitY(int y, Rect &other)
|
|
{
|
|
if (!other && HitY(y)) other = *this;
|
|
}
|
|
};
|
|
|
|
#endif // RECT_H
|