43 lines
698 B
C
43 lines
698 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 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);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
#endif // RECT_H
|