00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "sdlmm_config.h"
00024
00025 #include <SDL.h>
00026 #include "sdlmm_srect.h"
00027 #include "sdlmm_misc.h"
00028
00029 namespace SDLmm {
00030 SRect::SRect() {
00031 x = y = w = h = 0;
00032 }
00033
00034 SRect::SRect(const SRect& rect) {
00035 x = rect.x; y = rect.y;
00036 w = rect.w; h = rect.h;
00037 }
00038
00039 SRect::SRect(const SDL_Rect& rect) {
00040 x = rect.x; y = rect.y;
00041 w = rect.w; h = rect.h;
00042 }
00043
00044 SRect::SRect(Sint16 nx, Sint16 ny, Uint16 nw, Uint16 nh) {
00045 x = nx; y = ny; w = nw; h = nh;
00046 }
00047
00048 SRect::SRect(Uint16 nw, Uint16 nh) {
00049 x = y = 0;
00050 w = nw; h = nh;
00051 }
00052
00053 SRect::SRect(const SPoint &point) {
00054 x = point.x; y = point.y;
00055 w = 0; h = 0;
00056 }
00057 SRect::SRect(const SPoint &point, Uint16 nw, Uint16 nh) {
00058 x = point.x; y = point.y;
00059 w = nw; h = nh;
00060 }
00061
00062 SRect::SRect(const SPoint &upper_left_point,
00063 const SPoint &bottom_right_point) {
00064 ASSERT(upper_left_point <= bottom_right_point);
00065 x = upper_left_point.x; y = upper_left_point.y;
00066 w = bottom_right_point.x - upper_left_point.x;
00067 h = bottom_right_point.y - upper_left_point.y;
00068 }
00069
00070 SRect Intersect(const SRect& r1, const SRect& r2) {
00071 SRect r;
00072 r.x = Max(r1.x, r2.x);
00073 r.y = Max(r1.y, r2.y);
00074 r.w = Min(r1.x + r1.w, r2.x + r2.w) - r.x;
00075 r.h = Min(r1.y + r1.h, r2.y + r2.h) - r.y;
00076 if (r.w < 0) r.w = 0;
00077 if (r.h < 0) r.h = 0;
00078 return r;
00079 }
00080
00081 SRect Union(const SRect& r1, const SRect& r2) {
00082 SRect r;
00083 r.x = Min(r1.x, r2.x);
00084 r.y = Min(r1.y, r2.y);
00085 r.w = Max(r1.x + r1.w, r2.x + r2.w) - r.x;
00086 r.h = Max(r1.y + r1.h, r2.y + r2.h) - r.y;
00087 ASSERT(r.w >= 0);
00088 ASSERT(r.h >= 0);
00089 return r;
00090 }
00091 }
00092
00093