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