uiacceltk/hitchcock/Client/src/alfcurvepath.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Curve paths are composed of path segments
       
    15 *                and can be used as mapping functions, and in line visuals.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include "alf/alfcurvepath.h"
       
    22 #include "alf/alfgencomponent.h"
       
    23 #include "alf/alfconstants.h"
       
    24 #include "alflogger.h"
       
    25 
       
    26 #include <uiacceltk/HuiUtil.h>
       
    27 
       
    28 struct CAlfCurvePath::TPrivateData
       
    29     {
       
    30     CAlfGenComponent* iComms; // Own
       
    31     TAlfTimedPoint iOffset; // Own.
       
    32     };
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CAlfCurvePath::CAlfCurvePath()
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Second phase constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void CAlfCurvePath::ConstructL( CAlfEnv& aEnv, TInt aCurvePathProviderHandle )
       
    48     {
       
    49     iData = new (ELeave) TPrivateData;
       
    50 
       
    51     iData->iComms = NULL;
       
    52     
       
    53     TPckgC<TInt> constructionParamBuf( aCurvePathProviderHandle );
       
    54     iData->iComms = CAlfGenComponent::NewL(
       
    55         aEnv,
       
    56         EAlfCurvePathCreate, 
       
    57         0, 
       
    58         constructionParamBuf );
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // Constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CAlfCurvePath* CAlfCurvePath::NewL( CAlfEnv& aEnv, TInt aCurvePathProviderHandle )
       
    67     {
       
    68     CAlfCurvePath* self = CAlfCurvePath::NewLC(aEnv, aCurvePathProviderHandle);
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Constructor, leave on cleanup stack
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CAlfCurvePath* CAlfCurvePath::NewLC( CAlfEnv& aEnv, TInt aCurvePathProviderHandle )
       
    79     {
       
    80     CAlfCurvePath* self = new( ELeave ) CAlfCurvePath;
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL(aEnv,aCurvePathProviderHandle);
       
    83     return self;
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Destructor
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C CAlfCurvePath::~CAlfCurvePath()
       
    92     {
       
    93     if ( iData )
       
    94         {
       
    95         delete iData->iComms;
       
    96         iData->iComms = NULL;
       
    97         }
       
    98         
       
    99     delete iData;
       
   100     iData = NULL;
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Reset path
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C void CAlfCurvePath::Reset()
       
   109     {
       
   110     TBufC8<1> inDummy;
       
   111     TBuf8<1> outDummy;
       
   112     
       
   113     TInt err = iData->iComms->DoSynchronousCmd(
       
   114         EAlfCurvePathReset, 
       
   115         inDummy, 
       
   116         outDummy );
       
   117         
       
   118     if ( err )
       
   119         {
       
   120         __ALFLOGSTRING1( "CAlfCurvePath::Reset panic error %d", err )
       
   121         USER_INVARIANT();
       
   122         }
       
   123     }
       
   124     
       
   125 // ---------------------------------------------------------------------------
       
   126 // Enable closed loop path
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C void CAlfCurvePath::EnableLoop(TBool aEnable)
       
   130     {
       
   131     TPckgC<TBool> inBuf( aEnable );
       
   132     TBuf8<1> outDummy;
       
   133     
       
   134     TInt err = iData->iComms->DoSynchronousCmd(
       
   135         EAlfCurvePathEnableLoop, 
       
   136         inBuf, 
       
   137         outDummy );
       
   138         
       
   139     if ( err )
       
   140         {
       
   141         __ALFLOGSTRING1( "CAlfCurvePath::EnableLoop panic error %d", err )
       
   142         USER_INVARIANT();
       
   143         }
       
   144     }
       
   145     
       
   146 // ---------------------------------------------------------------------------
       
   147 // Is path a loop
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C TBool CAlfCurvePath::Loop() const
       
   151     {
       
   152     TBool result = EFalse;
       
   153     TPckg<TBool> outBuf( result );
       
   154     
       
   155     TInt err = iData->iComms->DoSynchronousCmd(
       
   156         EAlfCurvePathLoop, 
       
   157         KNullDesC8(), 
       
   158         outBuf );
       
   159         
       
   160     if ( err )
       
   161         {
       
   162         __ALFLOGSTRING1( "CAlfCurvePath::Loop panic error %d", err )
       
   163         USER_INVARIANT();
       
   164         }
       
   165     
       
   166     return result;
       
   167     }
       
   168     
       
   169 // ---------------------------------------------------------------------------
       
   170 // Set origin of path
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C void CAlfCurvePath::SetOrigin(TReal32 aPosOrigin) __SOFTFP
       
   174     {
       
   175     TPckgC<TReal32> inBuf( aPosOrigin );
       
   176     TBuf8<1> outDummy;
       
   177     
       
   178     TInt err = iData->iComms->DoSynchronousCmd(
       
   179         EAlfCurvePathSetOrigin, 
       
   180         inBuf, 
       
   181         outDummy );
       
   182         
       
   183     if ( err )
       
   184         {
       
   185         __ALFLOGSTRING1( "CAlfCurvePath::SetOrigin panic error %d", err )
       
   186         USER_INVARIANT();
       
   187         }
       
   188     }
       
   189    
       
   190 // ---------------------------------------------------------------------------
       
   191 // Add line segment
       
   192 // @deprecated
       
   193 // ---------------------------------------------------------------------------
       
   194 // 
       
   195 EXPORT_C void CAlfCurvePath::AppendLineL(
       
   196     const TPoint& aStart, 
       
   197     const TPoint& aEnd,
       
   198     TReal32 aLength ) __SOFTFP
       
   199     {
       
   200     TAlfCurvePathLineParams params;
       
   201     params.iStart = aStart;
       
   202     params.iEnd = aEnd;
       
   203     params.iLength = aLength;
       
   204     
       
   205     TPckgC<TAlfCurvePathLineParams> inBuf( params );
       
   206     TBuf8<1> outDummy;
       
   207     
       
   208     TInt err = iData->iComms->DoSynchronousCmd(
       
   209         EAlfCurvePathAppendLine, 
       
   210         inBuf, 
       
   211         outDummy );
       
   212         
       
   213     if ( err )
       
   214         {
       
   215         __ALFLOGSTRING1( "CAlfCurvePath::AppendLineL panic error %d", err )
       
   216         USER_INVARIANT();
       
   217         }
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // Add line segment
       
   222 // ---------------------------------------------------------------------------
       
   223 // 
       
   224 EXPORT_C void CAlfCurvePath::AppendLineL(
       
   225     const TAlfRealPoint& aStart, 
       
   226     const TAlfRealPoint& aEnd,
       
   227     TReal32 aLength ) __SOFTFP
       
   228     {
       
   229     TAlfCurvePathLineRealParams params;
       
   230     params.iStart = aStart;
       
   231     params.iEnd = aEnd;
       
   232     params.iLength = aLength;
       
   233     
       
   234     TPckgC<TAlfCurvePathLineRealParams> inBuf( params );
       
   235     TBuf8<1> outDummy;
       
   236     
       
   237     TInt err = iData->iComms->DoSynchronousCmd(
       
   238         EAlfCurvePathAppendLine2, 
       
   239         inBuf, 
       
   240         outDummy );
       
   241         
       
   242     if ( err )
       
   243         {
       
   244         __ALFLOGSTRING1( "CAlfCurvePath::AppendLineL panic error %d", err )
       
   245         USER_INVARIANT();
       
   246         }
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Add arc
       
   251 // @deprecated
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 EXPORT_C void CAlfCurvePath::AppendArcL(
       
   255     const TPoint& aOrigin, 
       
   256     const TSize& aSize,
       
   257     TReal32 aStartAngle, 
       
   258     TReal32 aEndAngle,
       
   259     TReal32 aLength ) __SOFTFP
       
   260     {
       
   261     TAlfCurvePathArcParams params;
       
   262     params.iOrigin = aOrigin;
       
   263     params.iSize = aSize;
       
   264     params.iStartAngle = aStartAngle;
       
   265     params.iEndAngle = aEndAngle;
       
   266     params.iLength = aLength;
       
   267     
       
   268     TPckgC<TAlfCurvePathArcParams> inBuf( params );
       
   269     TBuf8<1> outDummy;
       
   270     
       
   271     TInt err = iData->iComms->DoSynchronousCmd(
       
   272         EAlfCurvePathAppendArc, 
       
   273         inBuf, 
       
   274         outDummy );
       
   275         
       
   276     if ( err )
       
   277         {
       
   278         __ALFLOGSTRING1( "CAlfCurvePath::AppendArcL panic error %d", err )
       
   279         USER_INVARIANT();
       
   280         }
       
   281     }
       
   282  
       
   283 // ---------------------------------------------------------------------------
       
   284 // Add arc
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C void CAlfCurvePath::AppendArcL(
       
   288     const TAlfRealPoint& aOrigin, 
       
   289     const TAlfRealSize& aSize,
       
   290     TReal32 aStartAngle, 
       
   291     TReal32 aEndAngle,
       
   292     TReal32 aLength ) __SOFTFP
       
   293     {
       
   294     TAlfCurvePathArcRealParams params;
       
   295     params.iOrigin = aOrigin;
       
   296     params.iSize = aSize;
       
   297     params.iStartAngle = aStartAngle;
       
   298     params.iEndAngle = aEndAngle;
       
   299     params.iLength = aLength;
       
   300     
       
   301     TPckgC<TAlfCurvePathArcRealParams> inBuf( params );
       
   302     TBuf8<1> outDummy;
       
   303     
       
   304     TInt err = iData->iComms->DoSynchronousCmd(
       
   305         EAlfCurvePathAppendArc2, 
       
   306         inBuf, 
       
   307         outDummy );
       
   308         
       
   309     if ( err )
       
   310         {
       
   311         __ALFLOGSTRING1( "CAlfCurvePath::AppendArcL panic error %d", err )
       
   312         USER_INVARIANT();
       
   313         }
       
   314     }
       
   315  
       
   316 // ---------------------------------------------------------------------------
       
   317 // Get length of curved path
       
   318 // ---------------------------------------------------------------------------
       
   319 //   
       
   320 EXPORT_C TReal32 CAlfCurvePath::Length() const __SOFTFP
       
   321     {
       
   322     TReal32 result = 0.0;
       
   323     TPckg<TReal32> outBuf( result );
       
   324     
       
   325     TInt err = iData->iComms->DoSynchronousCmd(
       
   326         EAlfCurvePathLength, 
       
   327         KNullDesC8(), 
       
   328         outBuf );
       
   329         
       
   330     if ( err )
       
   331         {
       
   332         __ALFLOGSTRING1( "CAlfCurvePath::Length panic error %d", err )
       
   333         USER_INVARIANT();
       
   334         }
       
   335     
       
   336     return result;
       
   337     }
       
   338    
       
   339 // ---------------------------------------------------------------------------
       
   340 // Calculate a point on the path
       
   341 // ---------------------------------------------------------------------------
       
   342 // 
       
   343 EXPORT_C void CAlfCurvePath::Evaluate(TReal32 aPos, TAlfRealPoint& aPoint) const __SOFTFP
       
   344     {
       
   345     TPckgC<TReal32> inBuf( aPos );
       
   346     TPckg<TAlfRealPoint> outBuf( aPoint );
       
   347     
       
   348     TInt err = iData->iComms->DoSynchronousCmd(
       
   349         EAlfCurvePathEvaluate, 
       
   350         inBuf, 
       
   351         outBuf );
       
   352         
       
   353     if ( err )
       
   354         {
       
   355         __ALFLOGSTRING1( "CAlfCurvePath::Evaluate panic error %d", err )
       
   356         USER_INVARIANT();
       
   357         }
       
   358     }
       
   359     
       
   360 // ---------------------------------------------------------------------------
       
   361 // Get offset of path
       
   362 // ---------------------------------------------------------------------------
       
   363 //    
       
   364 EXPORT_C const TAlfTimedPoint& CAlfCurvePath::Offset() const
       
   365     {
       
   366     TPckg<TAlfTimedPoint> outBuf( iData->iOffset );
       
   367     
       
   368     TInt err = iData->iComms->DoSynchronousCmd(
       
   369         EAlfCurvePathOffset, 
       
   370         KNullDesC8(), 
       
   371         outBuf );
       
   372         
       
   373     if ( err )
       
   374         {
       
   375         __ALFLOGSTRING1( "CAlfCurvePath::Offset panic error %d", err )
       
   376         USER_INVARIANT();
       
   377         }
       
   378     
       
   379     return iData->iOffset;
       
   380     }
       
   381     
       
   382 // ---------------------------------------------------------------------------
       
   383 // Set offset of path
       
   384 // ---------------------------------------------------------------------------
       
   385 //    
       
   386 EXPORT_C void CAlfCurvePath::SetOffset( const TAlfTimedPoint& aOffset )
       
   387     {
       
   388     TPckgC<TAlfTimedPoint> inBuf( aOffset );
       
   389     TBuf8<1> outDummy;
       
   390     
       
   391     TInt err = iData->iComms->DoSynchronousCmd(
       
   392         EAlfCurvePathSetOffset, 
       
   393         inBuf, 
       
   394         outDummy );
       
   395         
       
   396     if ( err )
       
   397         {
       
   398         __ALFLOGSTRING1( "CAlfCurvePath::SetOffset panic error %d", err )
       
   399         USER_INVARIANT();
       
   400         }
       
   401     
       
   402     iData->iOffset = aOffset;
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // Get the mapping function ID of this path
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 EXPORT_C TInt CAlfCurvePath::MappingFunctionIdentifier() const
       
   410     {
       
   411     return iData->iComms->Identifier();
       
   412     }
       
   413   
       
   414 // ---------------------------------------------------------------------------
       
   415 // Evaluate an x/y value on the path
       
   416 // ---------------------------------------------------------------------------
       
   417 //  
       
   418 EXPORT_C TReal32 CAlfCurvePath::MapValue(TReal32 aValue, TInt aMode) const __SOFTFP
       
   419     {
       
   420     TIntTReal mapValues( aMode, aValue );
       
   421     TPckgC<TIntTReal> mapValuesPckg( mapValues );
       
   422     
       
   423     TReal32 returnValue = aValue;
       
   424     TPckg<TReal32> returnBuf(returnValue);
       
   425     
       
   426     TInt err = iData->iComms->DoSynchronousCmd(
       
   427         EAlfCurvePathMapValue, 
       
   428         mapValuesPckg, 
       
   429         returnBuf );
       
   430     
       
   431     if ( err )
       
   432         {
       
   433         __ALFLOGSTRING1( "CAlfCurvePath::MapValue panic error %d", err )
       
   434         USER_INVARIANT();
       
   435         }
       
   436     
       
   437     return returnValue;
       
   438     }
       
   439