2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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 3 of the License, or
8 // (at your option) any later version.
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.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Original author: Thatcher Ulrich <tu@tulrich.com> 2003
25 #ifndef GNASH_MATRIX_H
26 #define GNASH_MATRIX_H
28 #include "dsodefs.h" // for DSOEXPORT
31 #include <boost/cstdint.hpp>
33 // Forward declarations
38 template<typename T
> class Range2d
;
45 /// The SWF SWFMatrix record.
47 /// Conceptually, it represents a 3*3 linear transformation SWFMatrix like this:
49 /// | scale_x rotateSkew_y translate_x |
50 /// | rotateSkey_x scale_y traslate_y |
53 class DSOEXPORT SWFMatrix
57 /// Construct an identity SWFMatrix
68 /// Construct a SWFMatrix with all values.
69 SWFMatrix(int a
, int b
, int c
, int d
, int x
, int y
)
79 boost::int32_t a() const {
83 boost::int32_t b() const {
87 boost::int32_t c() const {
91 boost::int32_t d() const {
95 boost::int32_t tx() const {
99 boost::int32_t ty() const {
103 /// Set the SWFMatrix to identity.
106 /// Concatenate m's transform onto ours.
108 /// When transforming points, m happens first,
109 /// then our original xform.
110 void concatenate(const SWFMatrix
& m
);
112 /// Concatenate a translation onto the front of our SWFMatrix.
114 /// When transforming points, the translation
115 /// happens first, then our original xform.
116 void concatenate_translation(int _tx
, int _ty
);
118 /// Concatenate scale x and y to the front of our SWFMatrix
120 /// When transforming points, these scales happen first, then
121 /// our original SWFMatrix.
122 void concatenate_scale(double x
, double y
);
124 /// Set this SWFMatrix to a blend of m1 and m2, parameterized by t.
125 void set_lerp(const SWFMatrix
& m1
, const SWFMatrix
& m2
, float t
);
127 /// Set the scale & rotation part of the SWFMatrix. angle in radians.
128 void set_scale_rotation(double x_scale
, double y_scale
, double rotation
);
130 /// Set x and y scales, rotation is unchanged.
131 void set_scale(double x_scale
, double y_scale
);
133 /// Set x scale, rotation any y scale are unchanged.
134 void set_x_scale(double scale
);
136 /// Set y scale, rotation and x scale are unchanged.
137 void set_y_scale(double scale
);
139 /// Set rotation in radians, scales component are unchanged.
140 void set_rotation(double rotation
);
142 /// Set x translation in TWIPS
143 void set_x_translation(int x
) {
147 /// Set y translation in TWIPS.
148 void set_y_translation(int y
) {
152 /// Set x and y translation in TWIPS.
153 void set_translation(int x
, int y
) {
158 /// Transform a given point by our SWFMatrix
159 void transform(geometry::Point2d
& p
) const;
161 /// Transform the given point by our SWFMatrix.
162 void transform(boost::int32_t& x
, boost::int32_t& y
) const;
164 /// Transform point 'p' by our SWFMatrix.
166 /// Put the result in *result.
168 void transform(geometry::Point2d
* result
, const geometry::Point2d
& p
) const;
170 /// Transform Range2d<float> 'r' by our SWFMatrix.
172 /// NULL and WORLD ranges are untouched.
174 void transform(geometry::Range2d
<boost::int32_t>& r
) const;
176 void transform(SWFRect
& r
) const;
178 /// Invert this SWFMatrix and return the result.
181 /// return the magnitude scale of our x coord output
182 double get_x_scale() const;
184 /// return the magnitude scale of our y coord output
185 double get_y_scale() const;
187 /// return rotation component in radians.
188 double get_rotation() const;
190 /// return x translation n TWIPS unit.
191 int get_x_translation() const {
195 /// return y translation in TWIPS unit.
196 int get_y_translation() const {
200 /// Allow direct access to values for equality
201 friend bool operator==(const SWFMatrix
& a
, const SWFMatrix
& b
);
205 /// Return the determinant of this SWFMatrix in 32.32 fixed point format.
206 boost::int64_t determinant() const;
208 /// Xscale, 16.16 fixed point. xx in swfdec. 'a' in AS Matrix.
211 /// Xshear, 16.16 fixed point. yx in swfdec. 'b' in AS Matrix.
214 /// Yshear, 16.16 fixed point. xy in swfdec. 'c' in AS Matrix.
217 /// Yscale, 16.16 fixed point. yy in swfdec. 'd' in AS Matrix.
220 /// Xtranslation, TWIPS. x0 in swfdec. '_tx' in AS Matrix.
223 /// Ytranslation, TWIPS. y0 in swfdec. '_ty' in AS Matrix.
227 }; //end of SWFMatrix
230 operator==(const SWFMatrix
& a
, const SWFMatrix
& b
)
241 std::ostream
& operator<<(std::ostream
& o
, const SWFMatrix
& m
);
250 // indent-tabs-mode: t