Gnash  0.8.10
SWFMatrix.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 // 
00020 //
00021 // Original author: Thatcher Ulrich <tu@tulrich.com> 2003
00022 //
00023 //
00024 
00025 #ifndef GNASH_MATRIX_H
00026 #define GNASH_MATRIX_H
00027 
00028 #include "dsodefs.h" // for DSOEXPORT
00029 
00030 #include <iosfwd> 
00031 #include <boost/cstdint.hpp>
00032 
00033 // Forward declarations
00034 namespace gnash {
00035     class SWFRect;
00036     namespace geometry {
00037         class Point2d;
00038         template<typename T> class Range2d;
00039     }
00040 }
00041 
00042 
00043 namespace gnash {
00044 
00053 class DSOEXPORT SWFMatrix
00054 {
00055 public:
00056 
00058     SWFMatrix()
00059         :
00060         _a(65536),
00061         _b(0),
00062         _c(0),
00063         _d(65536),
00064         _tx(0),
00065         _ty(0)
00066     {}
00067 
00069     SWFMatrix(int a, int b, int c, int d, int x, int y)
00070         :
00071         _a(a),
00072         _b(b),
00073         _c(c),
00074         _d(d),
00075         _tx(x),
00076         _ty(y)
00077     {}
00078 
00079     boost::int32_t a() const {
00080         return _a;
00081     }
00082 
00083     boost::int32_t b() const {
00084         return _b;
00085     }
00086 
00087     boost::int32_t c() const {
00088         return _c;
00089     }
00090 
00091     boost::int32_t d() const {
00092         return _d;
00093     }
00094 
00095     boost::int32_t tx() const {
00096         return _tx;
00097     }
00098 
00099     boost::int32_t ty() const {
00100         return _ty;
00101     }
00102 
00104     void set_identity();
00105 
00107     //
00110     void concatenate(const SWFMatrix& m);
00111 
00113     //
00116     void concatenate_translation(int _tx, int _ty);
00117 
00119     //
00122     void concatenate_scale(double x, double y);
00123 
00125     void set_lerp(const SWFMatrix& m1, const SWFMatrix& m2, float t);
00126 
00128     void set_scale_rotation(double x_scale, double y_scale, double rotation);
00129 
00131     void set_scale(double x_scale, double y_scale);
00132 
00134     void set_x_scale(double scale);
00135 
00137     void set_y_scale(double scale);
00138 
00140     void set_rotation(double rotation);
00141 
00143     void set_x_translation(int x) {
00144         _tx = x;
00145     }
00146 
00148     void set_y_translation(int y) {
00149         _ty = y;
00150     }
00151 
00153     void set_translation(int x, int y) {
00154         _tx = x;
00155         _ty = y;
00156     }
00157 
00159     void transform(geometry::Point2d& p) const;
00160 
00162     void transform(boost::int32_t& x, boost::int32_t& y) const;
00163     
00165     //
00168     void transform(geometry::Point2d* result, const geometry::Point2d& p) const;
00169 
00171     //
00174     void transform(geometry::Range2d<boost::int32_t>& r) const;
00175 
00176     void transform(SWFRect& r) const;
00177     
00179     SWFMatrix& invert();
00180     
00182     double get_x_scale() const;
00183 
00185     double get_y_scale() const;
00186 
00188     double get_rotation() const;
00189 
00191     int get_x_translation() const {
00192         return _tx;
00193     }
00194 
00196     int get_y_translation() const {
00197         return _ty;
00198     }
00199 
00201     friend bool operator==(const SWFMatrix& a, const SWFMatrix& b);
00202 
00203 private: 
00204 
00206     boost::int64_t  determinant() const;
00207 
00209     boost::int32_t _a; 
00210 
00212     boost::int32_t _b;
00213 
00215     boost::int32_t _c;
00216 
00218     boost::int32_t _d; 
00219 
00221     boost::int32_t _tx; 
00222 
00224     boost::int32_t _ty; 
00225              
00226 
00227 }; //end of SWFMatrix
00228 
00229 inline bool
00230 operator==(const SWFMatrix& a, const SWFMatrix& b)
00231 {
00232     return  
00233         a.a()  == b._a  &&
00234         a._b == b._b &&
00235         a._tx  == b._tx  &&
00236         a._d  == b._d  &&
00237         a._c == b._c &&
00238         a._ty  == b._ty;
00239 }
00240 
00241 std::ostream& operator<<(std::ostream& o, const SWFMatrix& m);
00242 
00243 } // namespace gnash
00244 
00245 #endif 
00246 
00247 
00248 // Local Variables:
00249 // mode: C++
00250 // indent-tabs-mode: t
00251 // End:
00252 //