javauis/lcdui_akn/lcdgd/src/lcdtransform.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2005 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "lcdtransform.h"
       
    19 
       
    20 EXPORT_C TPoint TLcdTransform::operator()(const TPoint& aPoint) const
       
    21 {
       
    22     return TPoint
       
    23            (
       
    24                aPoint.iX*iDuDx + aPoint.iY*iDuDy + iU0,
       
    25                aPoint.iX*iDvDx + aPoint.iY*iDvDy + iV0
       
    26            );
       
    27 }
       
    28 
       
    29 EXPORT_C TLcdTransform TLcdTransform::operator *(const TLcdTransform& aT) const
       
    30 {
       
    31     TLcdTransform t;
       
    32 
       
    33     t.iDuDx = iDuDx*aT.iDuDx + iDuDy*aT.iDvDx;
       
    34     t.iDuDy = iDuDx*aT.iDuDy + iDuDy*aT.iDvDy;
       
    35     t.iDvDx = iDvDx*aT.iDuDx + iDvDy*aT.iDvDx;
       
    36     t.iDvDy = iDvDx*aT.iDuDy + iDvDy*aT.iDvDy;
       
    37     t.iU0   = iDuDx*aT.iU0   + iDuDy*aT.iV0 + iU0;
       
    38     t.iV0   = iDvDx*aT.iU0   + iDvDy*aT.iV0 + iV0;
       
    39 
       
    40     ASSERT(Abs(t.iDuDx) <= 1);
       
    41     ASSERT(Abs(t.iDuDy) <= 1);
       
    42     ASSERT(Abs(t.iDvDx) <= 1);
       
    43     ASSERT(Abs(t.iDvDy) <= 1);
       
    44     ASSERT(Abs(t.iDuDx*t.iDvDy - t.iDuDy*t.iDvDx) == 1);
       
    45 
       
    46     return t;
       
    47 }
       
    48 
       
    49 EXPORT_C TBool TLcdTransform::operator == (const TLcdTransform& aT) const
       
    50 {
       
    51     return (iDuDx == aT.iDuDx) &&
       
    52            (iDuDy == aT.iDuDy) &&
       
    53            (iDvDx == aT.iDvDx) &&
       
    54            (iDvDy == aT.iDvDy) &&
       
    55            (iU0   == aT.iU0) &&
       
    56            (iV0   == aT.iV0)  ;
       
    57 }
       
    58 
       
    59 EXPORT_C TLcdTransform TLcdTransform::Inverse() const
       
    60 {
       
    61     TLcdTransform t;
       
    62 
       
    63     TInt det = iDuDx*iDvDy - iDuDy*iDvDx;
       
    64 
       
    65     ASSERT(Abs(det) == 1);
       
    66 
       
    67     TInt a = iDuDx;
       
    68     TInt b = iDuDy;
       
    69     TInt c = iDvDx;
       
    70     TInt d = iDvDy;
       
    71     TInt u = iU0;
       
    72     TInt v = iV0;
       
    73 
       
    74     t.iDuDx = d * det;
       
    75     t.iDuDy = - b * det;
       
    76     t.iDvDx = - c * det;
       
    77     t.iDvDy = a * det;
       
    78 
       
    79     t.iU0 = (b * v - d * u) * det;
       
    80     t.iV0 = (c * u - a * v) * det;
       
    81 
       
    82     return t;
       
    83 }
       
    84 
       
    85 EXPORT_C TLcdTransform Transform(TTransformType aType, const TSize& aSize)
       
    86 {
       
    87     TLcdTransform t = TLcdTransform();
       
    88 
       
    89     switch (aType)
       
    90     {
       
    91     case ETransNone:
       
    92     {
       
    93         t.iDuDx = 1;
       
    94         t.iDvDx = 0;
       
    95         t.iDuDy = 0;
       
    96         t.iDvDy = 1;
       
    97         t.iU0   = 0;
       
    98         t.iV0   = 0;
       
    99     }
       
   100     break;
       
   101     case ETransMirrorRot180:    // EReflectVert
       
   102     {
       
   103         t.iDuDx = 1;
       
   104         t.iDvDx = 0;
       
   105         t.iDuDy = 0;
       
   106         t.iDvDy = -1;
       
   107         t.iU0   = 0;
       
   108         t.iV0   = aSize.iHeight - 1;
       
   109     }
       
   110     break;
       
   111     case ETransMirror:          // EReflectHorz
       
   112     {
       
   113         t.iDuDx = -1;
       
   114         t.iDvDx = 0;
       
   115         t.iDuDy = 0;
       
   116         t.iDvDy = 1;
       
   117         t.iU0   = aSize.iWidth - 1;
       
   118         t.iV0   = 0;
       
   119     }
       
   120     break;
       
   121     case ETransRot180:          // EReflectVert|EReflectHorz
       
   122     {
       
   123         t.iDuDx = -1;
       
   124         t.iDvDx = 0;
       
   125         t.iDuDy = 0;
       
   126         t.iDvDy = -1;
       
   127         t.iU0 = aSize.iWidth - 1;
       
   128         t.iV0 = aSize.iHeight - 1;
       
   129     }
       
   130     break;
       
   131     case ETransMirrorRot270:    // EReflectDiag
       
   132     {
       
   133         t.iDuDx = 0;
       
   134         t.iDvDx = 1;
       
   135         t.iDuDy = 1;
       
   136         t.iDvDy = 0;
       
   137         t.iU0   = 0;
       
   138         t.iV0   = 0;
       
   139     }
       
   140     break;
       
   141     case ETransRot90:           // EReflectVert|EReflectDiag
       
   142     {
       
   143         t.iDuDx = 0;
       
   144         t.iDvDx = 1;
       
   145         t.iDuDy = -1;
       
   146         t.iDvDy = 0;
       
   147         t.iU0   = aSize.iHeight-1;
       
   148         t.iV0   = 0;
       
   149     }
       
   150     break;
       
   151 
       
   152     case ETransRot270:          // EReflectHorz|EReflectDiag
       
   153     {
       
   154         t.iDuDx = 0;
       
   155         t.iDvDx = -1;
       
   156         t.iDuDy = 1;
       
   157         t.iDvDy = 0;
       
   158         t.iU0   = 0;
       
   159         t.iV0   = aSize.iWidth - 1;
       
   160     }
       
   161     break;
       
   162 
       
   163     case ETransMirrorRot90:     // EReflectVert|EReflectHorz|EReflectDiag
       
   164     {
       
   165         t.iDuDx = 0;
       
   166         t.iDvDx = -1;
       
   167         t.iDuDy = -1;
       
   168         t.iDvDy = 0;
       
   169         t.iU0 = aSize.iHeight - 1;
       
   170         t.iV0 = aSize.iWidth  - 1;
       
   171     }
       
   172     break;
       
   173     default:
       
   174         ASSERT(aType != aType);     // unknown type.
       
   175         break;
       
   176     }
       
   177 
       
   178     return t;
       
   179 }
       
   180 
       
   181 
       
   182 EXPORT_C TLcdTransform Identity()
       
   183 {
       
   184     TLcdTransform t;
       
   185     t.iDuDx = 1;
       
   186     t.iDuDy = 0;
       
   187     t.iDvDx = 0;
       
   188     t.iDvDy = 1;
       
   189     t.iU0   = 0;
       
   190     t.iV0   = 0;
       
   191     return t;
       
   192 }
       
   193 
       
   194 /**
       
   195  * Compose the vertical reflection.
       
   196  *
       
   197  * Maps from source (image) coords to destination (graphics) coords.
       
   198  */
       
   199 EXPORT_C TLcdTransform ReflectVert(const TSize& aSize)
       
   200 {
       
   201     return Transform((TTransformType)EReflectVert, aSize);
       
   202 }
       
   203 
       
   204 /**
       
   205  * Compose the horizontal reflection.
       
   206  *
       
   207  * Maps from source (image) coords to destination (graphics) coords.
       
   208  */
       
   209 EXPORT_C TLcdTransform ReflectHorz(const TSize& aSize)
       
   210 {
       
   211     return Transform((TTransformType)EReflectHorz, aSize);
       
   212 }
       
   213 
       
   214 /**
       
   215  * Compose the diagonal reflection.
       
   216  *
       
   217  * Maps from source (image) coords to destination (graphics) coords.
       
   218  */
       
   219 EXPORT_C TLcdTransform ReflectDiag()
       
   220 {
       
   221     return Transform((TTransformType)EReflectDiag, TSize(0,0));
       
   222 }
       
   223 
       
   224 /**
       
   225  * Compose translation.
       
   226  *
       
   227  * Maps from source (image) coords to destination (graphics) coords.
       
   228  *
       
   229  */
       
   230 EXPORT_C TLcdTransform Translate(const TPoint& aPoint)
       
   231 {
       
   232     TLcdTransform t;
       
   233     t.iDuDx = 1;
       
   234     t.iDuDy = 0;
       
   235     t.iDvDx = 0;
       
   236     t.iDvDy = 1;
       
   237     t.iU0   = aPoint.iX;
       
   238     t.iV0   = aPoint.iY;
       
   239     return t;
       
   240 }