Adonthell  0.4
drawing_area.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 The Adonthell Project
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell 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  Adonthell 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 Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 
21 /**
22  * @file drawing_area.h
23  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
24  *
25  * @brief Declares the drawing_area class.
26  *
27  *
28  */
29 
30 #ifndef DRAWING_AREA_H_
31 #define DRAWING_AREA_H_
32 
33 #include "types.h"
34 
35 
36 /**
37  * Implements "drawing zones" for drawing operations.
38  * An object which is drawn into a drawing_area will only appear in
39  * the rectangular zone it covers.
40  * During some drawing operations, you may want to limit the blits to a limited
41  * area of the %screen. For example, if you want to draw an image into a
42  * window, and that image is larger than this window, you don't want the
43  * entire image to appear, only the part that fits into the window. This is
44  * exactly what drawing areas are for. A drawing area is a square that can be
45  * any size and located anywhere on the %screen. If you assign a drawing area
46  * to a drawable object (for example, an image), and then draw the image on
47  * the %screen, the part of the image that doesn't fit the drawing area limits
48  * isn't displayed. A drawing area can be assigned to any drawable, but also
49  * to another drawing area, in which case the result of blitting operations
50  * from objects that are assigned to the second drawing area will be limited
51  * to the intersection of the two drawing areas. Recursively, you can use as many
52  * drawing_areas as you wish for drawing operations.
53  */
55 {
56 public:
57  /** Default constructor.
58  * The drawing_area is then located at (0, 0) and is (0, 0) sized.
59  */
60  drawing_area ();
61 
62 #ifndef SWIG
63  /** Builds a drawing_area from the parameters.
64  * @param px X position.
65  * @param py Y position.
66  * @param pw Length.
67  * @param ph Height.
68  *
69  * @note Not available from Python.
70  */
71  drawing_area (s_int16 px, s_int16 py, u_int16 pw, u_int16 ph);
72 #endif
73 
74  /** Returns the horizontal position of the drawing_area.
75  * @return horizontal position of the drawing_area.
76  */
77  s_int16 x () const
78  {
79  return rect.x;
80  }
81 
82  /** Returns the vertical position of the drawing_area.
83  * @return vertical position of the drawing_area.
84  */
85  s_int16 y () const
86  {
87  return rect.y;
88  }
89 
90  /** Returns the length of the drawing_area.
91  * @return length of the drawing_area.
92  */
93  u_int16 length () const
94  {
95  return rect.w;
96  }
97 
98  /** Returns the height of the drawing_area.
99  * @return height of the drawing_area.
100  */
101  u_int16 height () const
102  {
103  return rect.h;
104  }
105 
106  /** Move the drawing_area.
107  * @param nx new horizontal position.
108  * @param ny new vertical position.
109  */
110  void move (s_int16 nx, s_int16 ny)
111  {
112  rect.x = nx;
113  rect.y = ny;
114  }
115 
116  /** Resize the drawing_area.
117  * @param nl new length.
118  * @param nl new height.
119  */
120  void resize (u_int16 nl, u_int16 nh)
121  {
122  rect.w = nl;
123  rect.h = nh;
124  }
125 
126  /** Assign a drawing_area to this drawing_area.
127  * If a drawing area is assigned to another one, the zone covered
128  * by the drawing_area is the intersection of the two.
129  * @param da the drawing_area to assign.
130  */
132  {
133  draw_to = (drawing_area *) da;
134  }
135 
136  /**
137  * Returns a pointer to the drawing_area assigned to this one.
138  *
139  *
140  * @return pointer to the assigned drawing_area, NULL if none.
141  */
143  {
144  return draw_to;
145  }
146 
147  /** Detach (if needed) the drawing_area which was attached to this
148  * one.
149  */
151  {
152  draw_to = NULL;
153  }
154 
155 #ifndef SWIG
156  /**
157  * Convert an SDL_Rect into a drawing_area.
158  *
159  * @param r SDL_rect to convert.
160  *
161  * @return drawing_area which has the same dimensions and location as r.
162  */
163  drawing_area& operator = (SDL_Rect& r);
164 #endif
165 
166  /**
167  * Gets the real parameters of this drawing_area.
168  *
169  *
170  * @return SDL_Rect which is the intersection of this drawing area and
171  * all the drawing areas assigned to it.
172  */
173  SDL_Rect setup_rects () const;
174 
175 private:
176  /// drawing_area location and size.
177  SDL_Rect rect;
178 
179  /// Attached drawing_area.
180  drawing_area *draw_to;
181 
182 };
183 
184 
185 #endif
Declares some basic types.
s_int16 y() const
Returns the vertical position of the drawing_area.
Definition: drawing_area.h:85
drawing_area()
Default constructor.
Definition: drawing_area.cc:31
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
void detach_drawing_area()
Detach (if needed) the drawing_area which was attached to this one.
Definition: drawing_area.h:150
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:93
void resize(u_int16 nl, u_int16 nh)
Resize the drawing_area.
Definition: drawing_area.h:120
void assign_drawing_area(const drawing_area *da)
Assign a drawing_area to this drawing_area.
Definition: drawing_area.h:131
s_int16 x() const
Returns the horizontal position of the drawing_area.
Definition: drawing_area.h:77
drawing_area & operator=(SDL_Rect &r)
Convert an SDL_Rect into a drawing_area.
Definition: drawing_area.cc:45
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:54
#define s_int16
16 bits long signed integer
Definition: types.h:47
drawing_area * assigned_drawing_area() const
Returns a pointer to the drawing_area assigned to this one.
Definition: drawing_area.h:142
SDL_Rect setup_rects() const
Gets the real parameters of this drawing_area.
Definition: drawing_area.cc:52
void move(s_int16 nx, s_int16 ny)
Move the drawing_area.
Definition: drawing_area.h:110
u_int16 height() const
Returns the height of the drawing_area.
Definition: drawing_area.h:101