ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
rect.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) by Fred Klaus *
3  * development@fkweb.de *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef SDLTK_RECT_H
21 #define SDLTK_RECT_H
22 
23 #include "point.h"
24 #include "size.h"
25 #include "SDL.h"
26 
27 namespace sdltk
28 {
29 
32  class Rect : public SDL_Rect
33  {
34 
35  public:
38  Rect(const Point & origin, const Size & size)
39  { SDL_Rect::x = origin.x();
40  SDL_Rect::y = origin.y();
41  SDL_Rect::w = size.width();
42  SDL_Rect::h = size.height();
43  }
44  //Rect(const Point & origin, Sint16 width, Sint16 height)
45  // {mOrigin=origin; mSize.set(width, height);}
46  //Rect(Sint16 x, Sint16 y, const Size & size)
47  // {mOrigin.set(x, y); mSize=size;}
48  Rect(Sint16 x, Sint16 y, Uint16 w, Uint16 h)
49  { SDL_Rect::x = x; SDL_Rect::y = y;
50  SDL_Rect::w = w; SDL_Rect::h = h;}
51 
52  Rect(Sint16 x, Sint16 y, const Size & size)
53  { SDL_Rect::x = x; SDL_Rect::y = y;
54  SDL_Rect::w = size.width(); SDL_Rect::h = size.height();}
55 
56  Rect(SDL_Rect* rect)
57  { SDL_Rect::x = rect->x; SDL_Rect::y = rect->y;
58  SDL_Rect::w = rect->w; SDL_Rect::h = rect->h;}
59 
62  Rect(const Rect & rect)
63  { SDL_Rect::x = rect.x(); SDL_Rect::y = rect.y();
64  SDL_Rect::w = rect.width(); SDL_Rect::h = rect.height();}
65 
68 
69  void set(Sint16 x, Sint16 y, Uint16 w, Uint16 h)
70  {SDL_Rect::x = x; SDL_Rect::y = y; SDL_Rect::w = w; SDL_Rect::h = h;}
71  //void set(const Rect & rect)
72  // {mOrigin = rect.origin(); mSize=rect.size();}
73  void set(const Point & pos)
74  {SDL_Rect::x = pos.x(); SDL_Rect::y = pos.y();}
75  void set(const Size & size)
76  {SDL_Rect::w = size.width(); SDL_Rect::h = size.height();}
77  void set(const Point & pos, const Size & size)
78  {SDL_Rect::x = pos.x(); SDL_Rect::y = pos.y();
79  SDL_Rect::w = size.width(); SDL_Rect::h = size.height();}
80 
81  void setOrigin(Sint16 x, Sint16 y) {SDL_Rect::x = x; SDL_Rect::y = y;}
82  void setOrigin(const Point & origin)
83  {SDL_Rect::x = origin.x(); SDL_Rect::y = origin.y();}
84 
85  void setPos(Sint16 x, Sint16 y) {SDL_Rect::x = x; SDL_Rect::y = y;}
86  void setPos(const Point & pos)
87  {SDL_Rect::x = pos.x(), SDL_Rect::y = pos.y();}
88 
89  void setSize(Uint16 w, Uint16 h) {SDL_Rect::w = w; SDL_Rect::h = h;}
90  void setSize(const Size & size)
91  {SDL_Rect::w = size.width(); SDL_Rect::h = size.height();}
92 
93  void setX(Sint16 x) {SDL_Rect::x = x;}
94  void setY(Sint16 y) {SDL_Rect::y = y;}
95  void setWidth (Uint16 w) {SDL_Rect::w = w;}
96  void setHeight(Uint16 h) {SDL_Rect::h = h;}
97 
99  Point pos() const {return Point(SDL_Rect::x, SDL_Rect::y);}
100  Size size() const {return Size(SDL_Rect::w, SDL_Rect::h);}
101 
102  Sint16 x() const {return SDL_Rect::x;}
103  Sint16 y() const {return SDL_Rect::y;}
104  Uint16 width() const {return SDL_Rect::w;}
105  Uint16 height() const {return SDL_Rect::h;}
106  Sint16 x2() const {return SDL_Rect::x + SDL_Rect::w;}
107  Sint16 y2() const {return SDL_Rect::y + SDL_Rect::h;}
108 
109  inline bool inside(const Point & p) const;
110  inline bool inside(Uint16 x, Uint16 y) const;
111 
112 
113  // Overloaded operator =. A deep copy will done, so it's save to
114  // assign Rect to itself.
115  //Rect & operator=(const Rect & r)
116  // {if (this == &r) return *this; mOrigin=r.origin(); mSize=r.size();
117  // return *this;}
118  // Overloaded operator ==. Comparsion between Rects are save.
119  //bool operator==(const Rect & r) const
120  // {return (mSize == r.size() && mOrigin == r.pos() ) ? true : false;}
121  // Overloaded operator !=. Comparsion between Rects are save.
122  //bool operator!=(const Rect & r) const
123  // {return (mSize != r.size() && mOrigin != r.pos() ) ? true : false;}
124  };
125 
126  inline bool Rect::inside(const Point & p) const
127  {
128  if ((p.x() >= SDL_Rect::x)
129  && (p.y() <= SDL_Rect::y)
130  && (p.x() <= SDL_Rect::x + SDL_Rect::w)
131  && (p.y() >= SDL_Rect::y + SDL_Rect::h)) return true;
132  else return false;
133  }
134 
135  inline bool Rect::inside(Uint16 x, Uint16 y) const
136  {
137  if ((x >= SDL_Rect::x)
138  && (y >= SDL_Rect::y)
139  && (x <= SDL_Rect::x + SDL_Rect::w)
140  && (y <= SDL_Rect::y + SDL_Rect::h)) return true;
141  else return false;
142  }
143 
144 } // sdltk
145 
146 #endif // SDLTK_RECT_H
Rect(const Rect &rect)
Definition: rect.h:62
void setPos(Sint16 x, Sint16 y)
Definition: rect.h:85
Sint16 x() const
Definition: rect.h:102
Rect(Sint16 x, Sint16 y, Uint16 w, Uint16 h)
Definition: rect.h:48
Sint16 Uint16 w
Definition: rect.h:69
void setSize(Uint16 w, Uint16 h)
Definition: rect.h:89
Sint16 Uint16 Uint16 h
Definition: rect.h:70
Rect() ROLAND_DEFAULT Rect(const Point &origin
Standard Constructor.
bool inside(const Point &p) const
Definition: rect.h:126
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLfloat x
Definition: glfunclist.h:25
Sint16 y2() const
Definition: rect.h:107
Sint16 x2() const
Definition: rect.h:106
Point pos() const
Definition: rect.h:99
void setSize(const Size &size)
Definition: rect.h:90
Sint16 y() const
Definition: rect.h:103
void setHeight(Uint16 h)
Definition: rect.h:96
Point origin() const
Definition: rect.h:98
Size size() const
Definition: rect.h:100
void setOrigin(const Point &origin)
Definition: rect.h:82
Rect(SDL_Rect *rect)
Definition: rect.h:56
Sint16 y
Definition: rect.h:69
void setPos(const Point &pos)
Definition: rect.h:86
#define ROLAND_DEFAULT
Definition: compspec.h:46
~Rect() ROLAND_DEFAULT void set(Sint16 x
Standard Destructor. Does nothing.
Defines a 2D point (x, y)
Definition: point.h:28
Uint16 height() const
Definition: rect.h:105
void setX(Sint16 x)
Definition: rect.h:93
defines a planar size (width, height)
Definition: size.h:30
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLfloat GLfloat y GLubyte GLubyte GLubyte GLubyte a GLfloat GLbitfield mask void GLfloat size GLint GLint y
Definition: glfunclist.h:37
void setY(Sint16 y)
Definition: rect.h:94
void setWidth(Uint16 w)
Definition: rect.h:95
Uint16 height() const
Definition: size.h:59
Uint16 width() const
Definition: size.h:57
Definition: rect.h:32
Sint16 y
Definition: point.h:35
void setOrigin(Sint16 x, Sint16 y)
Definition: rect.h:81
Uint16 width() const
Definition: rect.h:104
the SDL based Stuff
Definition: audio.cpp:22
Rect(Sint16 x, Sint16 y, const Size &size)
Definition: rect.h:52