00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __MX_TYPE_X_H_
00017 #define __MX_TYPE_X_H_
00018
00019 #include "SDL.h"
00020
00021 namespace mx {
00022
00023
00027 struct Point {
00029 int x;
00031 int y;
00033 Point(int x=0, int y=0)
00034 {
00035 this->x = x, this->y = y;
00036 }
00037 };
00041 struct Size {
00042
00044 int width;
00046 int height;
00048 Size() { width = height = 0; }
00053 Size(int width, int height)
00054 {
00055 this->width = width;
00056 this->height = height;
00057 }
00058 };
00059
00063 struct Rect {
00065 Point point;
00067 Size rsize;
00069 Rect() { }
00073 Rect(SDL_Rect &rc) : point(rc.x, rc.y) , rsize(rc.w, rc.h) {}
00077 Rect(SDL_Rect *rc)
00078 {
00079 if(rc == 0) return;
00080 point = mx::Point(rc->x, rc->y);
00081 rsize = mx::Size(rc->w, rc->h);
00082 }
00083
00090 Rect(int x, int y, int width, int height) : point(x,y), rsize(width, height) {}
00094 Rect( const Rect &r ) : point(r.point), rsize(r.rsize) {}
00099 Rect( const Point &p, const Size &s ) : point(p), rsize(s) {}
00100
00104 const int width() const { return rsize.width; }
00108 const int height() const { return rsize.height; }
00112 const int x() const { return point.x; }
00116 const int y() const { return point.y; }
00117
00122 const bool pointInRect(Point p) const
00123 {
00124 if(p.x >= point.x && p.x <= point.x+rsize.width && p.y >= point.y && p.y <= point.y+rsize.height) return true;
00125 return false;
00126 }
00130 operator SDL_Rect() {
00131 SDL_Rect rc = { point.x, point.y, rsize.width, rsize.height };
00132 return rc;
00133 }
00134 };
00135
00136
00140 struct Line {
00142 Point p1;
00144 Point p2;
00146 Line () { }
00151 Line(Point p_1 , Point p_2) : p1(p_1), p2(p_2) { }
00158 Line(int start_x, int start_y, int stop_x, int stop_y)
00159 {
00160 p1 = Point(start_x, start_y);
00161 p2 = Point(stop_x, stop_y);
00162 }
00164 const int x1() const { return p1.x; }
00166 const int y1() const { return p1.y; }
00168 const int x2() const { return p2.x; }
00170 const int y2() const { return p2.y; }
00171 };
00172 }
00173 #endif