svgtopt/gfx2d/inc/GfxAffineTransform.h
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Graphics Extension Library header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef GFXAFFINETRANSFORM_H
       
    20 #define GFXAFFINETRANSFORM_H
       
    21 
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include "GfxFloatFixPt.h"
       
    27 
       
    28 
       
    29 // These constants are used because enumeration cannot
       
    30 // accept bit operation
       
    31 const TInt32 KTransformIdentity = 0;
       
    32 const TInt32 KTransformTranslate = 1;
       
    33 const TInt32 KTransformScale = 2;
       
    34 const TInt32 KTransformShear = 4;
       
    35 
       
    36 typedef TFloatFixPt TMatrixElType;
       
    37 typedef TUint32     TGfxTransformType;
       
    38 
       
    39 class TGfxAffineTransform;
       
    40 class CGfxShape;
       
    41 class TGfxPoint2D;
       
    42 
       
    43 
       
    44 /**
       
    45  * This class implements operations of a 2D transform matrix.
       
    46  *
       
    47  *  @lib Gfx2D.lib
       
    48  *  @since 1.0
       
    49  */
       
    50 class TGfxAffineTransform
       
    51     {
       
    52     public:
       
    53 
       
    54         /**
       
    55          * Construct an identity matrix.
       
    56          *
       
    57          * @since 1.0
       
    58          * @param
       
    59          * @return
       
    60          */
       
    61                                     TGfxAffineTransform();
       
    62 
       
    63         /**
       
    64          * Constructor.
       
    65          *
       
    66          * @since 1.0
       
    67          * @param aM00 : row 0, column 0 value of matrix.
       
    68          * @param aM10 : row 1, column 0 value of matrix.
       
    69          * @param aM01 : row 0, column 1 value of matrix.
       
    70          * @param aM11 : row 1, column 1 value of matrix.
       
    71          * @param aM02 : row 0, column 2 value of matrix.
       
    72          * @param aM12 : row 1, column 2 value of matrix.
       
    73          * @return
       
    74          */
       
    75                                     TGfxAffineTransform( TReal32 aM00,
       
    76                                                                  TReal32 aM10,
       
    77                                                                  TReal32 aM01,
       
    78                                                                  TReal32 aM11,
       
    79                                                                  TReal32 aM02,
       
    80                                                                  TReal32 aM12 );
       
    81 
       
    82 
       
    83         /**
       
    84          * Return a TGfxAffineTransform object with the rotation info
       
    85          * of the given angle applied.
       
    86          *
       
    87          * @since 1.0
       
    88          * @param aTheta : angle to create a rotation affine transform.
       
    89          * @return
       
    90          */
       
    91          static TGfxAffineTransform GetRotateInstance( TReal32 aTheta );
       
    92 
       
    93         /**
       
    94          * Return a TGfxAffineTransform object with the rotation info
       
    95          * of the given angle, rotated at the given point.
       
    96          *
       
    97          * @since 1.0
       
    98          * @param aTheta : angle to create a rotation affine transform.
       
    99          * @param aX : x value of rotation center.
       
   100          * @param aY : x value of rotation center.
       
   101          * @return
       
   102          */
       
   103          static TGfxAffineTransform GetRotateInstance( TReal32 aTheta,
       
   104                                                                const TFloatFixPt& aX,
       
   105                                                                const TFloatFixPt& aY );
       
   106 
       
   107 /**
       
   108          * Return a TGfxAffineTransform object with the zoom info
       
   109          * of the given scalefactor, scaled at the given point.
       
   110          *
       
   111          * @since 1.0
       
   112          * @param aScaleFactor : scaling factor
       
   113          * @param aX : x value of scaling center.
       
   114          * @param aY : x value of scaling center.
       
   115          * @return
       
   116          */
       
   117          static TGfxAffineTransform GetZoomInstance( TReal32 aScaleFactor,
       
   118                                                                const TFloatFixPt& aX,
       
   119                                                                const TFloatFixPt& aY );
       
   120        
       
   121         /**
       
   122          * Return a TGfxAffineTransform object with the scaling info
       
   123          * applied.
       
   124          *
       
   125          * @since 1.0
       
   126          * @param aSx : scaling factor in the x axis.
       
   127          * @param aSy : scaling factor in the y axis.
       
   128          * @return
       
   129          */
       
   130          static TGfxAffineTransform GetScaleInstance( TReal32 aSx,
       
   131                                                               TReal32 aSy );
       
   132 
       
   133         /**
       
   134          * Return a TGfxAffineTransform object with the shearing info
       
   135          * applied.
       
   136          *
       
   137          * @since 1.0
       
   138          * @param aShx : shearing factor in the x axis.
       
   139          * @param aShy : shearing factor in the y axis.
       
   140          * @return
       
   141          */
       
   142          static TGfxAffineTransform GetShearInstance( TReal32 aShx,
       
   143                                                               TReal32 aShy );
       
   144 
       
   145         /**
       
   146          * Return a TGfxAffineTransform object with the translation info
       
   147          * applied.
       
   148          *
       
   149          * @since 1.0
       
   150          * @param aTx : translation value in the x axis.
       
   151          * @param aTy : translation value in the y axis.
       
   152          * @return
       
   153          */
       
   154          static TGfxAffineTransform GetTranslateInstance( const TFloatFixPt& aTx,
       
   155                                                                   const TFloatFixPt& aTy );
       
   156 
       
   157         /**
       
   158          * Return the determinate value of this matrix.
       
   159          *
       
   160          * @since 1.0
       
   161          * @return the determinate value
       
   162          */
       
   163          TReal32                    Determinant() const;
       
   164 
       
   165         /**
       
   166          * Return wether this matrix is an indentity matrix.
       
   167          *
       
   168          * @since 1.0
       
   169          * @return true if this matrix is an identity matrix.
       
   170          */
       
   171          TBool                      IsIdentity() const;
       
   172 
       
   173         /**
       
   174          * Return the scaling factor in the x axis.
       
   175          *
       
   176          * @since 1.0
       
   177          * @return scaling factor in the x axis.
       
   178          */
       
   179          TReal32                    ScaleX() const;
       
   180 
       
   181         /**
       
   182          * Return the scaling factor in the y axis.
       
   183          *
       
   184          * @since 1.0
       
   185          * @return scaling factor in the y axis.
       
   186          */
       
   187          TReal32                    ScaleY() const;
       
   188 
       
   189         /**
       
   190          * Return the shearing factor in the x axis.
       
   191          *
       
   192          * @since 1.0
       
   193          * @return shearing factor in the x axis.
       
   194          */
       
   195          TReal32                    ShearX() const;
       
   196 
       
   197         /**
       
   198          * Return the shearing factor in the y axis.
       
   199          *
       
   200          * @since 1.0
       
   201          * @return shearing factor in the y axis.
       
   202          */
       
   203          TReal32                    ShearY() const;
       
   204 
       
   205         /**
       
   206          * Return the translation value in the x axis.
       
   207          *
       
   208          * @since 1.0
       
   209          * @return translation value in the x axis.
       
   210          */
       
   211          TReal32                    TranslateX() const;
       
   212 
       
   213         /**
       
   214          * Return the translation value in the y axis.
       
   215          *
       
   216          * @since 1.0
       
   217          * @return translation value in the y axis.
       
   218          */
       
   219          TReal32                    TranslateY() const;
       
   220 
       
   221         /**
       
   222          * Create the inverse tranformation matrix of this matrix.
       
   223          *
       
   224          * @since 1.0
       
   225          * @return inverse matrix.
       
   226          */
       
   227          TGfxAffineTransform        CreateInverse();
       
   228 
       
   229 
       
   230         /**
       
   231          * Muliply this given matrix with this matrix.
       
   232          *
       
   233          * @since 1.0
       
   234          * @return
       
   235          */
       
   236          void                       Concatenate( const TGfxAffineTransform& aTransform );
       
   237 
       
   238 
       
   239         /**
       
   240          * Appends this transform with the existing transform
       
   241          * Multiply in reverse order
       
   242          * For Ex:  In cases of zoom, rotate and pan of already transformed content.
       
   243          * If T is the existing transform and zoom operation has to be applied to it
       
   244          * the resultant transform would be Z*T.
       
   245          * @since 1.0
       
   246          * @return
       
   247          */
       
   248          void                       AppendTransform( const TGfxAffineTransform& aTransform );
       
   249         
       
   250         /**
       
   251          * Apply the given rotation angle to this matrix.
       
   252          *
       
   253          * @since 1.0
       
   254          * @param aTheta : angle of rotation
       
   255          * @return
       
   256          */
       
   257          void                       Rotate( TReal32 aTheta );
       
   258 
       
   259         /**
       
   260          * Apply the given rotation angle about this given point to this matrix.
       
   261          *
       
   262          * @since 1.0
       
   263          * @param aTheta : angle of rotation
       
   264          * @param aX : x coordinate for center of rotation.
       
   265          * @param aY : y coordinate for center of rotation.
       
   266          * @return
       
   267          */
       
   268          void                       Rotate( TReal32 aTheta,
       
   269                                                     const TFloatFixPt& aX,
       
   270                                                     const TFloatFixPt& aY );
       
   271 
       
   272         /**
       
   273          * Apply the given rotation angle about this given point to this matrix.
       
   274          *
       
   275          * @since 1.0
       
   276          * @param aTheta : angle of rotation
       
   277          * @param aX : x coordinate for center of rotation.
       
   278          * @param aY : y coordinate for center of rotation.
       
   279          * @return
       
   280          */
       
   281 
       
   282          void                       UserRotate( TReal32 aTheta,
       
   283                                                     const TFloatFixPt& aX,
       
   284                                                     const TFloatFixPt& aY );
       
   285 
       
   286         /*
       
   287          * Apply the given scaling factor for this given point to this matrix.
       
   288          *
       
   289          *
       
   290          * @since 1.0
       
   291          * @param aScaleFactor : scaling factor
       
   292          * @param aX : x value of scaling center.
       
   293          * @param aY : x value of scaling center.
       
   294          * @return
       
   295          */
       
   296        
       
   297          void                       UserZoom( TReal32 aScaleFactor,
       
   298                                                     const TFloatFixPt& aX,
       
   299                                                     const TFloatFixPt& aY );
       
   300 
       
   301         /**
       
   302          * Apply the given scale factors to this matrix.
       
   303          *
       
   304          * @since 1.0
       
   305          * @param aSx : scaling factor in the x axis.
       
   306          * @param aSy : scaling factor in the y axis.
       
   307          * @return
       
   308          */
       
   309          void                       Scale( TReal32 aSx, TReal32 aSy );
       
   310 
       
   311         /**
       
   312          * Apply the given translation values to this matrix.
       
   313          *
       
   314          * @since 1.0
       
   315          * @param aTx : translation value in the x axis.
       
   316          * @param aTy : translation value in the y axis.
       
   317          * @return
       
   318          */
       
   319          void                       Translate( const TFloatFixPt& aTx,
       
   320                                                        const TFloatFixPt& aTy );
       
   321 
       
   322         /**
       
   323          * Apply the given translation values to this matrix.
       
   324          *
       
   325          * @since 1.0
       
   326          * @param aTx : translation value in the x axis.
       
   327          * @param aTy : translation value in the y axis.
       
   328          * @return
       
   329          */
       
   330          void                       UserPan( const TFloatFixPt& aTx,
       
   331                                                        const TFloatFixPt& aTy );
       
   332 
       
   333         /**
       
   334          * Apply the given shearing values to this matrix.
       
   335          *
       
   336          * @since 1.0
       
   337          * @param aTx : shearing value in the x axis.
       
   338          * @param aTy : shearing value in the y axis.
       
   339          * @return
       
   340          */
       
   341          void                       Shear( TReal32 aShX, TReal32 aShY );
       
   342 
       
   343         /**
       
   344          * Set the transformation info of this matrix to the given values.
       
   345          *
       
   346          * @since 1.0
       
   347          * @param aM00 : row 0, column 0 value of matrix.
       
   348          * @param aM10 : row 1, column 0 value of matrix.
       
   349          * @param aM01 : row 0, column 1 value of matrix.
       
   350          * @param aM11 : row 1, column 1 value of matrix.
       
   351          * @param aM02 : row 0, column 2 value of matrix.
       
   352          * @param aM12 : row 1, column 2 value of matrix.
       
   353          * @return
       
   354          */
       
   355          void                       SetTransform( TReal32 aM00,
       
   356                                                           TReal32 aM10,
       
   357                                                           TReal32 aM01,
       
   358                                                           TReal32 aM11,
       
   359                                                           TReal32 aM02,
       
   360                                                           TReal32 aM12 );
       
   361 
       
   362         /**
       
   363          * Apply the transformation described by this matrix to the
       
   364          * array of TGfxPoint2D.
       
   365          *
       
   366          * @since 1.0
       
   367          * @param aSrcPts : array of TGfxPoint2D values to transform.
       
   368          * @param aDstPts : array to store transformed points.
       
   369          * @param aNumPts : number of points to transform.
       
   370          * @return
       
   371          */
       
   372          void                       Transform( TGfxPoint2D* aSrcPts,
       
   373                                                        TGfxPoint2D* aDstPts,
       
   374                                                        TInt32 aNumPts ) const;
       
   375 
       
   376         /**
       
   377          * Apply the transformation described by this matrix to the
       
   378          * array of TFloatFixPt.
       
   379          *
       
   380          * @since 1.0
       
   381          * @param aSrcPts : array of TFloatFixPt values to transform.
       
   382          * @param aDstPts : array to store transformed points.
       
   383          * @param aNumPts : number of points to transform.
       
   384          * @return
       
   385          */
       
   386          void                       Transform( TFloatFixPt* aSrcPts,
       
   387                                                        TFloatFixPt* aDstPts,
       
   388                                                        TInt32 aNumPts ) const;
       
   389 
       
   390         /**
       
   391          * Apply the transformation described by this matrix to the
       
   392          * array of TFloatFixPt.  Old values are replaced.
       
   393          *
       
   394          * @since 1.0
       
   395          * @param aSrcPts : array of TFloatFixPt values to transform.
       
   396          * @param aNumPts : number of points to transform.
       
   397          * @return
       
   398          */
       
   399          void                       Transform( TFloatFixPt* aSrcDstPts,
       
   400                                                        TInt32 aNumPts ) const;
       
   401 
       
   402 
       
   403         /**
       
   404          * Return the transformation type of this matrix.
       
   405          *
       
   406          * @since 1.0
       
   407          * @return transformation type
       
   408          */
       
   409         TUint32 TransformType();
       
   410 
       
   411          void Print();
       
   412 
       
   413         /**
       
   414          * Get the scaling factor set in this transform.  This function returns correctly
       
   415          * for a uniform scaling in both directions only.
       
   416          * @since 1.0
       
   417          * @return
       
   418          */
       
   419          TFloatFixPt ScalingFactor() const;
       
   420 
       
   421     private:
       
   422 
       
   423         /**
       
   424          * Constructor.
       
   425          *
       
   426          * @since 1.0
       
   427          * @param aM00 : row 0, column 0 value of matrix.
       
   428          * @param aM10 : row 1, column 0 value of matrix.
       
   429          * @param aM01 : row 0, column 1 value of matrix.
       
   430          * @param aM11 : row 1, column 1 value of matrix.
       
   431          * @param aM02 : row 0, column 2 value of matrix.
       
   432          * @param aM12 : row 1, column 2 value of matrix.
       
   433          * @param aType : transform type.
       
   434          * @return
       
   435          */
       
   436                             TGfxAffineTransform( TReal32 aM00,
       
   437                                                  TReal32 aM10,
       
   438                                                  TReal32 aM01,
       
   439                                                  TReal32 aM11,
       
   440                                                  TReal32 aM02,
       
   441                                                  TReal32 aM12,
       
   442                                                  TGfxTransformType aType );
       
   443         /**
       
   444          * Update this matrix.
       
   445          *
       
   446          * @since 1.0
       
   447          * @return
       
   448          */
       
   449         void                UpdateState();
       
   450 
       
   451         /**
       
   452          * The the the rotation info to the give angle.
       
   453          *
       
   454          * @since 1.0
       
   455          * @return
       
   456          */
       
   457         void                SetToRotate( TReal32 aTheta );
       
   458 
       
   459 	public:
       
   460 
       
   461         TFloatFixPt       iM00;
       
   462         TFloatFixPt        iM10;
       
   463         TFloatFixPt        iM01;
       
   464         TFloatFixPt        iM11;
       
   465         TFloatFixPt        iM02;
       
   466         TFloatFixPt        iM12;
       
   467 
       
   468         TGfxTransformType   iTransType;
       
   469 
       
   470 
       
   471     };
       
   472 
       
   473 #endif      // GFXAFFINETRANSFORM_H