1 #ifndef __SDL_CXX_LAYER_RECT_H__ 2 #define __SDL_CXX_LAYER_RECT_H__ 3 4 /* sdlx - c++ wrapper for libSDL 5 * Copyright (C) 2005-2007 Vladimir Menshakov 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #include "sdlx.h" 23 24 namespace sdlx { 25 class SDLXAPI Rect : public SDL_Rect { 26 public: reset()27 inline void reset() { 28 x = y = w = h = 0; 29 } 30 Rect()31 inline Rect() { x = y = w = h = 0; } 32 Rect(int _x,int _y,int _w,int _h)33 inline Rect(int _x, int _y, int _w, int _h) { 34 x = _x; y = _y; w = _w; h = _h; 35 } 36 in(const int _x,const int _y)37 inline const bool in(const int _x, const int _y) const { 38 return (_x>=x && _y>=y && _x < x+w && _y < y+h); 39 } 40 intersects(const Rect & other)41 inline const bool intersects(const Rect & other) const { 42 return !( x >= (other.x + other.w) || (x + w) <= other.x || 43 y >= (other.y + other.h) || (y + h) <= other.y ); 44 } 45 inside(const Rect & other)46 inline const bool inside(const Rect &other) const { 47 return x >= other.x && x + w <= other.x + other.w && 48 y >= other.y && y + h <= other.y + other.h; 49 } 50 }; 51 } 52 53 #endif 54