summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/rect.h
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/rect.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/rect.h122
1 files changed, 61 insertions, 61 deletions
diff --git a/noncore/games/sfcave-sdl/rect.h b/noncore/games/sfcave-sdl/rect.h
index dc9c9d5..30f082c 100644
--- a/noncore/games/sfcave-sdl/rect.h
+++ b/noncore/games/sfcave-sdl/rect.h
@@ -1,61 +1,61 @@
1#ifndef __RECT_H 1#ifndef __RECT_H
2#define __RECT_H 2#define __RECT_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6class Rect 6class Rect
7{ 7{
8public: 8public:
9 Rect() { r.x = r.y = r.w = r.h = 0; } 9 Rect() { r.x = r.y = r.w = r.h = 0; }
10 Rect( int x, int y, int w, int h ) { setRect( x, y, w, h ); } 10 Rect( int x, int y, int w, int h ) { setRect( x, y, w, h ); }
11 ~Rect() {} 11 ~Rect() {}
12 12
13 void setRect( int x, int y, int w, int h ) { r.x = x; r.y = y; r.w = w; r.h = h; } 13 void setRect( int x, int y, int w, int h ) { r.x = x; r.y = y; r.w = w; r.h = h; }
14 SDL_Rect getRect() { return r; } 14 SDL_Rect getRect() { return r; }
15 int x() { return r.x; } 15 int x() { return r.x; }
16 int y() { return r.y; } 16 int y() { return r.y; }
17 int w() { return r.w; } 17 int w() { return r.w; }
18 int h() { return r.h; } 18 int h() { return r.h; }
19 19
20 void x( int x) { r.x = x; } 20 void x( int x) { r.x = x; }
21 void y( int y) { r.y = y; } 21 void y( int y) { r.y = y; }
22 void w( int w) { r.w = w; } 22 void w( int w) { r.w = w; }
23 void h( int h) { r.h = h; } 23 void h( int h) { r.h = h; }
24 24
25 void moveBy( int x, int y ) 25 void moveBy( int x, int y )
26 { 26 {
27 r.x += x; 27 r.x += x;
28 r.y += y; 28 r.y += y;
29 } 29 }
30 30
31 bool intersects( Rect r2 ) 31 bool intersects( Rect r2 )
32 { 32 {
33 int tw = r.w; 33 int tw = r.w;
34 int th = r.h; 34 int th = r.h;
35 int rw = r2.w(); 35 int rw = r2.w();
36 int rh = r2.h(); 36 int rh = r2.h();
37 if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { 37 if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
38 return false; 38 return false;
39 } 39 }
40 int tx = r.x; 40 int tx = r.x;
41 int ty = r.y; 41 int ty = r.y;
42 int rx = r2.x(); 42 int rx = r2.x();
43 int ry = r2.y(); 43 int ry = r2.y();
44 rw += rx; 44 rw += rx;
45 rh += ry; 45 rh += ry;
46 tw += tx; 46 tw += tx;
47 th += ty; 47 th += ty;
48 48
49 // overflow || intersect 49 // overflow || intersect
50 return ((rw < rx || rw > tx) && 50 return ((rw < rx || rw > tx) &&
51 (rh < ry || rh > ty) && 51 (rh < ry || rh > ty) &&
52 (tw < tx || tw > rx) && 52 (tw < tx || tw > rx) &&
53 (th < ty || th > ry)); 53 (th < ty || th > ry));
54 } 54 }
55 55
56private: 56private:
57 SDL_Rect r; 57 SDL_Rect r;
58}; 58};
59 59
60#endif 60#endif
61 61