2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
/* $Id: rect.h,v 1.23 2008/01/21 20:55:51 rsavoye Exp $ */
24
#include "gnashconfig.h"
27
#include "tu_config.h"
32
#include <cassert> // for inlines
33
#include <iostream> // for output operator
44
/// Rectangle class, basically a wrapper around a
45
/// gnash::geometry::Range2d<float> with a few
46
/// additional methods for reading it from the
49
/// used by render handler (?)
55
geometry::Range2d<float> _range;
60
friend std::ostream& operator<< (std::ostream& os, const rect& rect);
62
/// Construct a NULL rectangle
68
/// Construct a rectangle with given coordinates
69
rect(float xmin, float ymin, float xmax, float ymax)
71
_range(xmin, ymin, xmax, ymax)
75
/// returns true if this is the NULL rectangle
78
return _range.isNull();
81
/// returns true if this is the WORLD rectangle
84
return _range.isWorld();
87
/// set the rectangle to the NULL value
93
/// set the rectangle to the WORLD value
99
/// Read a bit-packed rectangle from an SWF stream
101
/// Format of the bit-packed rectangle is:
103
/// bits | name | description
104
/// ------+-------+-------------------------
105
/// 5 | nbits | number of bits used in subsequent values
106
/// nbits | xmin | minimum X value
107
/// nbits | xmax | maximum X value
108
/// nbits | ymin | minimum Y value
109
/// nbits | ymax | maximum Y value
111
/// If max values are less then min values the SWF is malformed;
112
/// in this case this method will raise an swf_error and set the
113
/// rectangle to the NULL rectangle. See is_null().
116
void read(stream* in);
120
/// Return true if the specified point is inside this rect.
121
bool point_test(float x, float y) const
123
return _range.contains(x, y);
126
/// Expand this rectangle to enclose the given point.
127
void expand_to_point(float x, float y)
129
_range.expandTo(x, y);
132
/// Expand this rectangle to enclose the given circle.
133
void expand_to_circle(float x, float y, float radius)
135
_range.expandToCircle(x, y, radius);
138
/// Set ourself to bound the given point
139
void enclose_point(float x, float y)
144
/// Return width this rectangle
147
return _range.width();
150
/// Return height this rectangle
153
return _range.height();
156
/// Shift this rectangle horizontally
158
/// A positive offset will shift to the right,
159
/// A negative offset will shift to the left.
161
void shift_x(float offset)
163
_range.shiftX(offset);
166
/// Shift this rectangle vertically
168
/// A positive offset will increment y values.
169
/// A negative offset will decrement y values.
171
/// TODO: document what the orientation is supposed
172
/// to be (up/down) ?
174
void shift_y(float offset)
176
_range.shiftY(offset);
179
/// Scale this rectangle horizontally
181
/// A positive factor will make the rectangle bigger.
182
/// A negative factor will make the rectangle smaller.
183
/// A factor of 1 will leave it unchanged.
185
void scale_x(float factor)
187
_range.scaleX(factor);
190
/// Scale this rectangle vertically
192
/// A positive factor will make the rectangle bigger.
193
/// A negative factor will make the rectangle smaller.
194
/// A factor of 1 will leave it unchanged.
196
void scale_y(float factor)
198
_range.scaleY(factor);
201
/// Get min X ordinate.
203
/// Don't call this against a null rectangle
205
float get_x_min() const
207
return _range.getMinX();
210
/// Get max X ordinate.
212
/// Don't call this against a null rectangle
214
float get_x_max() const
216
return _range.getMaxX();
219
/// Get min Y ordinate.
221
/// Don't call this against a null rectangle
223
float get_y_min() const
225
return _range.getMinY();
228
/// Get max Y ordinate.
230
/// Don't call this against a null rectangle
232
float get_y_max() const
234
return _range.getMaxY();
237
/// Get one of the rect verts.
239
/// Don't call on a NULL rect !
241
/// TODO: deprecate this ?
242
point get_corner(int i) const;
245
/// Make sure that the given point falls
246
/// in this rectangle, modifying it's coordinates
249
/// Don't call against a NULL rectangle !
251
void clamp(point& p) const;
253
/// Set ourself to bound a rectangle that has been transformed
254
/// by m. This is an axial bound of an oriented (and/or
255
/// sheared, scaled, etc) box.
256
void enclose_transformed_rect(const matrix& m, const rect& r);
258
/// Same as enclose_transformed_rect but expanding the current rect instead
260
DSOEXPORT void expand_to_transformed_rect(const matrix& m, const rect& r);
262
/// Makes union of the given and the current rect
263
DSOEXPORT void expand_to_rect(const rect& r);
265
void set_lerp(const rect& a, const rect& b, float t);
269
/// Returns a const reference to the underlying
271
const geometry::Range2d<float> & getRange() const
276
/// Return a string representation for this rectangle
277
std::string toString() const;
281
operator<< (std::ostream& os, const rect& rect)
283
return os << rect._range;
288
#endif // GNASH_RECT_H
293
// indent-tabs-mode: t