00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021 #ifndef header_rect
00022 #define header_rect
00023
00024 class CL_Rect
00025 {
00026 public:
00027 int x1, y1;
00028 int x2, y2;
00029
00030 public:
00031 CL_Rect() : x1(0), y1(0), x2(0), y2(0) { }
00032 CL_Rect(int nx1, int ny1, int nx2, int ny2) : x1(nx1), y1(ny1), x2(nx2), y2(ny2) { }
00033
00034 CL_Rect(const CL_Rect &rect)
00035 {
00036 this->x1 = rect.x1;
00037 this->x2 = rect.x2;
00038 this->y1 = rect.y1;
00039 this->y2 = rect.y2;
00040 };
00041
00042 static CL_Rect center(int center_x, int center_y, int width, int height)
00043 {
00044 return CL_Rect(
00045 center_x - width/2,
00046 center_y - height/2,
00047 center_x + width/2,
00048 center_y + height/2);
00049 }
00050
00051 static CL_Rect left(int x, int y, int width, int height, bool center_vert = true)
00052 {
00053 return CL_Rect(
00054 x - width,
00055 center_vert ? (y - height/2) : y,
00056 x,
00057 center_vert ? (y + height/2) : y);
00058 }
00059
00060 static CL_Rect right(int x, int y, int width, int height, bool center_vert = true)
00061 {
00062 return CL_Rect(
00063 x,
00064 center_vert ? (y - height/2) : y,
00065 x + width,
00066 center_vert ? (y + height/2) : y);
00067 }
00068
00069 bool operator == (const CL_Rect &rect) const;
00070
00071 void move(int delta_x, int delta_y)
00072 {
00073 x1 += delta_x;
00074 x2 += delta_x;
00075 y1 += delta_y;
00076 y2 += delta_y;
00077 };
00078
00079 bool inside(int x, int y) const
00080 {
00081 return x >= x1 && y >= y1 && x < x2 && y < y2;
00082 }
00083
00084 int get_width() const { return x2 - x1; };
00085 int get_height() const { return y2 - y1; };
00086 };
00087
00088 #endif