Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgmatrix.h

00001 /****************************************************************************
00002 ** $Id: fgmatrix.h,v 1.5 2004/08/25 21:16:10 majo Exp $
00003 **
00004 ** Definition of FGMatrix class
00005 **
00006 ** Created : 941020
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef FGMATRIX_H
00039 #define FGMATRIX_H
00040 
00041 #ifdef FG_NAMESPACE
00042 namespace fgl {
00043 #endif
00044 
00045 
00046 #ifdef __BORLANDC__
00047 #pragma option push -b
00048 #pragma option push -a4
00049 #endif
00050 
00051 class FGMatrix                  // 2D transform matrix
00052 {
00053   public:
00054     FGMatrix();
00055     FGMatrix(const FGMatrix& old) { memcpy(this, &old, sizeof(*this)); }
00056     FGMatrix( double m11, double m12, double m21, double m22,
00057           double dx, double dy );
00058 
00059     void    setMatrix( double m11, double m12, double m21, double m22,
00060                double dx,  double dy );
00061 
00062     double  m11() const { return _m11; }
00063     double  m12() const { return _m12; }
00064     double  m21() const { return _m21; }
00065     double  m22() const { return _m22; }
00066     double  dx()  const { return _dx; }
00067     double  dy()  const { return _dy; }
00068 
00069     void    map( int x, int y, int *tx, int *ty )         const;
00070     void    map( double x, double y, double *tx, double *ty ) const;
00071     FGRect  mapRect( const FGRect & )   const;
00072 
00073     FGPoint map( const FGPoint &p ) const { return operator *( p ); }
00074     FGCircle map( const FGCircle &c )   const { return operator *( c ); }
00075     FGSize  map( const FGSize &sz ) const { return operator *( sz ); }
00076     FGRect  map( const FGRect &r )  const { return mapRect ( r ); }
00077     FGPointArray map( const FGPointArray &a ) const { return operator * ( a ); }
00078     void    map(FGPointArray& src, FGPointArray& dst);
00079     void    reset();
00080     bool    isIdentity() const;
00081 
00082     FGMatrix   &translate( double dx, double dy );
00083     FGMatrix   &scale( double sx, double sy );
00084     FGMatrix   &shear( double sh, double sv );
00085     FGMatrix   &rotate( double a );
00086 
00087     void    shift_x(double x) { _dx += x; }
00088     void    shift_y(double y) { _dy += y; }
00089     void    SetDxDy(double dx, double dy) { _dx = dx; _dy = dy; }
00090     void    zoom(double val) { _m11 *= val; _m22 *= val; }
00091 
00092     FGMatrix &FGMatrix::scale_with_center( double sx, double sy, double center_x, double center_y)
00093     {
00094         scale(sx, sy);
00095         _dx = center_x + ((_dx - center_x) * sx);
00096         _dy = center_y + ((_dy - center_y) * sy);
00097 
00098         return *this;
00099 
00100     }
00101 
00102     bool isInvertible() const { return (_m11*_m22 - _m12*_m21) != 0; }
00103     double det() const { return _m11*_m22 - _m12*_m21; }
00104 
00105     FGMatrix    invert( bool * = 0 ) const;
00106 
00107     bool    operator==( const FGMatrix & ) const;
00108     bool    operator!=( const FGMatrix & ) const;
00109     FGMatrix   &operator*=( const FGMatrix & );
00110 
00111     /* we use matrix multiplication semantics here */
00112     FGCircle operator * (const FGCircle & ) const;
00113     FGPoint operator * (const FGPoint & ) const;
00114     FGSize operator * (const FGSize & ) const;
00115     FGPointArray operator *  ( const FGPointArray &a ) const;
00116 
00117     enum TransformationMode {   Points, Areas  };
00118 
00119     static void setTransformationMode( FGMatrix::TransformationMode m );
00120     static TransformationMode transformationMode();
00121 
00122   private:
00123     double  _m11, _m12;
00124     double  _m21, _m22;
00125     double  _dx,  _dy;
00126 
00127     struct FGDoublePoint
00128     {
00129         double x,y;
00130     };
00131 };
00132 
00133 #ifdef __BORLANDC__
00134 #pragma option pop /* pop -a switch */
00135 #pragma option pop /* pop -b */
00136 #endif
00137 
00138 #ifdef FG_NAMESPACE
00139 }
00140 #endif
00141 
00142 #endif // FGMATRIX_H

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0