uiacceltk/hitchcock/Client/src/alfmeshvisual.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:   Mesh visual
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "alf/alfmeshvisual.h"
       
    21 #include "alf/alfproceduralmesh.h"
       
    22 #include "alf/alfm3gmesh.h"
       
    23 #include "alf/alfcontrol.h"
       
    24 #include "alflogger.h"
       
    25 #include "alf/alfgencomponent.h"
       
    26 #include "alf/alfconstants.h"
       
    27 #include "alf/alfimage.h"
       
    28 #include "alf/alftexture.h"
       
    29 #include "alfskinnableimage.h"
       
    30 #include "alf/alfenv.h"
       
    31 
       
    32 #include <uiacceltk/HuiUtil.h>
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 struct CAlfMeshVisual::TMeshVisualPrivateData
       
    37     {
       
    38     CAlfMesh* iMesh; // own
       
    39     CAlfSkinnableImage* iImage;
       
    40     CAlfSkinnableImage* iSecondaryImage;    
       
    41     CAlfSkinnableImage* iSpecularImage;
       
    42     };
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // ?description_if_needed
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 
       
    49 EXPORT_C CAlfMeshVisual* CAlfMeshVisual::AddNewL(
       
    50     CAlfControl& aOwnerControl,
       
    51     CAlfLayout* aParentLayout )
       
    52     {
       
    53     CAlfMeshVisual* text = STATIC_CAST(CAlfMeshVisual*,
       
    54         aOwnerControl.AppendVisualL(EAlfVisualTypeMesh, aParentLayout));
       
    55     return text;
       
    56     }
       
    57 
       
    58 EXPORT_C CAlfMeshVisual::CAlfMeshVisual()
       
    59     {
       
    60     }
       
    61 
       
    62 EXPORT_C void CAlfMeshVisual::ConstructL(CAlfControl& aOwner)
       
    63     {
       
    64     CAlfVisual::ConstructL(aOwner);
       
    65     
       
    66     iMeshVisualData = new (ELeave) TMeshVisualPrivateData;
       
    67     iMeshVisualData->iMesh = NULL;
       
    68     iMeshVisualData->iImage = NULL;
       
    69     iMeshVisualData->iSecondaryImage = NULL;
       
    70     iMeshVisualData->iSpecularImage = NULL;
       
    71     
       
    72     iMeshVisualData->iImage = new (ELeave) CAlfSkinnableImage(&aOwner.Env());
       
    73     iMeshVisualData->iSecondaryImage = new (ELeave) CAlfSkinnableImage(&aOwner.Env());
       
    74     iMeshVisualData->iSpecularImage = new (ELeave) CAlfSkinnableImage(&aOwner.Env());
       
    75     }
       
    76 
       
    77 EXPORT_C CAlfMeshVisual::~CAlfMeshVisual()
       
    78     {
       
    79     if ( iMeshVisualData )
       
    80         {
       
    81         delete iMeshVisualData->iMesh;
       
    82         iMeshVisualData->iMesh = NULL;
       
    83         
       
    84         delete iMeshVisualData->iImage;
       
    85         iMeshVisualData->iImage = NULL;
       
    86 
       
    87         delete iMeshVisualData->iSecondaryImage;
       
    88         iMeshVisualData->iSecondaryImage = NULL;
       
    89 
       
    90         delete iMeshVisualData->iSpecularImage;
       
    91         iMeshVisualData->iSpecularImage = NULL;
       
    92         }
       
    93         
       
    94     delete iMeshVisualData;
       
    95     iMeshVisualData = NULL;
       
    96     }
       
    97     
       
    98 EXPORT_C void CAlfMeshVisual::CreateMeshL(TInt aMeshType)
       
    99     {
       
   100     // Destroy the old mesh object.
       
   101     if( iMeshVisualData->iMesh )
       
   102         {
       
   103         delete iMeshVisualData->iMesh;
       
   104         iMeshVisualData->iMesh = NULL;
       
   105         }
       
   106     
       
   107     // Create a new mesh object.
       
   108     if ( aMeshType == EAlfMeshTypeProcedural )
       
   109         {
       
   110         iMeshVisualData->iMesh = CAlfProceduralMesh::NewL( *Comms() );
       
   111         }
       
   112     if ( aMeshType == EAlfMeshTypeM3G )
       
   113         {
       
   114         iMeshVisualData->iMesh = CAlfM3GMesh::NewL( *Comms(), Env() );
       
   115         }        
       
   116     }
       
   117     
       
   118 EXPORT_C void CAlfMeshVisual::SetImage(const TAlfImage& aImage)
       
   119     {    
       
   120     iMeshVisualData->iImage->SetImage(aImage);// This texturizes skin graphics if needed
       
   121     
       
   122     TAlfImageParams params(iMeshVisualData->iImage->Image());
       
   123 
       
   124     TPckgC<TAlfImageParams> buf(params);
       
   125     TInt err = Comms()->DoCmdNoReply(EAlfMeshVisualSetImage, buf );
       
   126     
       
   127     if ( err )
       
   128         {
       
   129         __ALFLOGSTRING1( "CAlfMeshVisual::SetImage ignore error %d", err )
       
   130         }
       
   131     }
       
   132     
       
   133 EXPORT_C const TAlfImage& CAlfMeshVisual::Image() const
       
   134     {
       
   135     return iMeshVisualData->iImage->Image();
       
   136     }
       
   137 
       
   138 EXPORT_C void CAlfMeshVisual::SetSecondaryImage(const TAlfImage& aImage)
       
   139     {
       
   140     iMeshVisualData->iSecondaryImage->SetImage(aImage);// This texturizes skin graphics if needed
       
   141     
       
   142     TAlfImageParams params(iMeshVisualData->iSecondaryImage->Image());
       
   143 
       
   144     TPckgC<TAlfImageParams> buf(params);
       
   145     TInt err = Comms()->DoCmdNoReply(EAlfMeshVisualSetSecondaryImage, buf );
       
   146     
       
   147     if ( err )
       
   148         {
       
   149         __ALFLOGSTRING1( "CAlfMeshVisual::SetSecondaryImage ignore error %d", err )
       
   150         }
       
   151     }
       
   152     
       
   153 EXPORT_C const TAlfImage& CAlfMeshVisual::SecondaryImage() const
       
   154     {
       
   155     return iMeshVisualData->iSecondaryImage->Image();
       
   156     }
       
   157 
       
   158 EXPORT_C void CAlfMeshVisual::SetSpecularImage(const TAlfImage& aImage)
       
   159     {
       
   160     // This functionality applies to procedural mesh only.
       
   161     if(Mesh().MeshType() == EAlfMeshTypeProcedural)
       
   162         {    
       
   163         CAlfProceduralMesh& mesh = static_cast<CAlfProceduralMesh&>(Mesh());
       
   164         iMeshVisualData->iSpecularImage->SetImage(aImage);// This texturizes skin graphics if needed
       
   165         
       
   166         TAlfImageParams params(iMeshVisualData->iSpecularImage->Image());
       
   167 
       
   168         TPckgC<TAlfImageParams> buf(params);
       
   169         TInt err = Comms()->DoCmdNoReply(EAlfMeshVisualSetSpecularImage, buf );
       
   170         
       
   171         if ( err )
       
   172             {
       
   173             __ALFLOGSTRING1( "CAlfMeshVisual::SetSpecularImage ignore error %d", err )
       
   174             }
       
   175             
       
   176         mesh.SetSpecularImage( iMeshVisualData->iSpecularImage->Image() );        
       
   177         }
       
   178     }
       
   179     
       
   180 EXPORT_C const TAlfImage& CAlfMeshVisual::SpecularImage() const
       
   181     {
       
   182     return iMeshVisualData->iSpecularImage->Image();
       
   183     }
       
   184 
       
   185 EXPORT_C CAlfMesh& CAlfMeshVisual::Mesh()
       
   186     {
       
   187     // Create a default mesh
       
   188     if ( !iMeshVisualData->iMesh )
       
   189         {
       
   190         TRAPD( err, CreateMeshL(EAlfMeshTypeProcedural) );
       
   191         if ( err )
       
   192             {
       
   193             __ALFLOGSTRING1( "CAlfMeshVisual::Mesh panic error %d", err )
       
   194             USER_INVARIANT();
       
   195             }
       
   196         }
       
   197     return *iMeshVisualData->iMesh;
       
   198     }
       
   199     
       
   200 EXPORT_C CAlfProceduralMesh* CAlfMeshVisual::ProceduralMesh() const
       
   201     {
       
   202     if(iMeshVisualData->iMesh && (iMeshVisualData->iMesh->MeshType() == EAlfMeshTypeProcedural))
       
   203         {
       
   204         return static_cast<CAlfProceduralMesh*>(iMeshVisualData->iMesh);
       
   205         }    
       
   206     return NULL;
       
   207     }
       
   208 
       
   209 EXPORT_C CAlfM3GMesh* CAlfMeshVisual::M3GMesh() const
       
   210     {
       
   211     if(iMeshVisualData->iMesh && (iMeshVisualData->iMesh->MeshType() == EAlfMeshTypeM3G))
       
   212         {
       
   213         return static_cast<CAlfM3GMesh*>(iMeshVisualData->iMesh);
       
   214         }    
       
   215     return NULL;    
       
   216     }
       
   217     
       
   218 EXPORT_C TAlfTimedValue CAlfMeshVisual::SecondaryAlpha() const
       
   219     {
       
   220     TAlfTimedValue result;
       
   221     TPckg<TAlfTimedValue> buf(result);
       
   222     TInt err = Comms()->DoSynchronousCmd( EAlfMeshVisualSecondaryAlpha, KNullDesC8, buf);
       
   223     
       
   224     if (err)
       
   225         {
       
   226         __ALFLOGSTRING1( "CAlfMeshVisual::SecondaryAlpha panic error %d", err )
       
   227         USER_INVARIANT();
       
   228         }
       
   229     
       
   230     return result;  
       
   231     }
       
   232     
       
   233 EXPORT_C void CAlfMeshVisual::SetSecondaryAlpha( const TAlfTimedValue& aSecondaryAlpha )
       
   234     {
       
   235     TPckgC<TAlfTimedValue> buf(aSecondaryAlpha);
       
   236 
       
   237     TInt err = Comms()->DoCmdNoReply( EAlfMeshVisualSetSecondaryAlpha, buf );
       
   238     if (err)
       
   239         {
       
   240         __ALFLOGSTRING1( "CAlfMeshVisual::SetSecondaryAlpha panic error %d", err )
       
   241         USER_INVARIANT();
       
   242         }
       
   243     }
       
   244     
       
   245     
       
   246 EXPORT_C TAlfTimedValue CAlfMeshVisual::YawAngle() const
       
   247     {
       
   248     TAlfTimedValue result;
       
   249     TPckg<TAlfTimedValue> buf(result);
       
   250     TInt err = Comms()->DoSynchronousCmd( EAlfMeshVisualYawAngle, KNullDesC8, buf);
       
   251     
       
   252     if (err)
       
   253         {
       
   254         __ALFLOGSTRING1( "CAlfMeshVisual::YawAngle panic error %d", err )
       
   255         USER_INVARIANT();
       
   256         }
       
   257     
       
   258     return result;  
       
   259     }
       
   260     
       
   261 EXPORT_C void CAlfMeshVisual::SetYawAngle( const TAlfTimedValue& aYawAngle )
       
   262     {
       
   263     TPckgC<TAlfTimedValue> buf(aYawAngle);
       
   264     
       
   265     TInt err = Comms()->DoCmdNoReply( EAlfMeshVisualSetYawAngle, buf );
       
   266     if (err)
       
   267         {
       
   268         __ALFLOGSTRING1( "CAlfMeshVisual::SetYawAngle panic error %d", err )
       
   269         USER_INVARIANT();
       
   270         }
       
   271     }
       
   272     
       
   273     
       
   274 EXPORT_C TAlfTimedValue CAlfMeshVisual::PitchAngle() const
       
   275     {
       
   276     TAlfTimedValue result;
       
   277     TPckg<TAlfTimedValue> buf(result);
       
   278     TInt err = Comms()->DoSynchronousCmd( EAlfMeshVisualPitchAngle, KNullDesC8, buf);
       
   279     
       
   280     if (err)
       
   281         {
       
   282         __ALFLOGSTRING1( "CAlfMeshVisual::PitchAngle panic error %d", err )
       
   283         USER_INVARIANT();
       
   284         }
       
   285     
       
   286     return result; 
       
   287     }
       
   288     
       
   289 EXPORT_C void CAlfMeshVisual::SetPitchAngle( const TAlfTimedValue& aPitchAngle )
       
   290     {
       
   291     TPckgC<TAlfTimedValue> buf(aPitchAngle);
       
   292 
       
   293     TInt err = Comms()->DoCmdNoReply( EAlfMeshVisualSetPitchAngle, buf );
       
   294     if (err)
       
   295         {
       
   296         __ALFLOGSTRING1( "CAlfMeshVisual::SetPitchAngle panic error %d", err )
       
   297         USER_INVARIANT();
       
   298         }
       
   299     }
       
   300     
       
   301     
       
   302 EXPORT_C TAlfTimedValue CAlfMeshVisual::Scale() const
       
   303     {
       
   304     TAlfTimedValue result;
       
   305     TPckg<TAlfTimedValue> buf(result);
       
   306     TInt err = Comms()->DoSynchronousCmd( EAlfMeshVisualScale, KNullDesC8, buf);
       
   307     
       
   308     if (err)
       
   309         {
       
   310         __ALFLOGSTRING1( "CAlfMeshVisual::Scale panic error %d", err )
       
   311         USER_INVARIANT();
       
   312         }
       
   313     
       
   314     return result; 
       
   315     }
       
   316     
       
   317 EXPORT_C void CAlfMeshVisual::SetScale( const TAlfTimedValue& aScale )
       
   318     {
       
   319     TPckgC<TAlfTimedValue> buf(aScale);
       
   320 
       
   321     TInt err = Comms()->DoCmdNoReply( EAlfMeshVisualSetScale, buf );
       
   322     if (err)
       
   323         {
       
   324         __ALFLOGSTRING1( "CAlfMeshVisual::SetScale panic error %d", err )
       
   325         USER_INVARIANT();
       
   326         }
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // Place holder from CAlfVisual
       
   331 // ---------------------------------------------------------------------------
       
   332 //     
       
   333 EXPORT_C void CAlfMeshVisual::RemoveAndDestroyAllD()
       
   334     {
       
   335     CAlfVisual::RemoveAndDestroyAllD();
       
   336     }
       
   337   
       
   338 // ---------------------------------------------------------------------------
       
   339 // Place holder from CAlfVisual
       
   340 // ---------------------------------------------------------------------------
       
   341 //  
       
   342 EXPORT_C void CAlfMeshVisual::UpdateChildrenLayout(TInt aTransitionTime )
       
   343     {
       
   344     CAlfVisual::UpdateChildrenLayout( aTransitionTime );
       
   345     }
       
   346   
       
   347 // ---------------------------------------------------------------------------
       
   348 // Place holder from CAlfVisual
       
   349 // ---------------------------------------------------------------------------
       
   350 //  
       
   351 EXPORT_C CAlfVisual* CAlfMeshVisual::FindTag(const TDesC8& aTag)
       
   352     {
       
   353     return CAlfVisual::FindTag( aTag );
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // Place holder from CAlfVisual
       
   358 // ---------------------------------------------------------------------------
       
   359 //  
       
   360 EXPORT_C void CAlfMeshVisual::DoRemoveAndDestroyAllD()
       
   361     {
       
   362     CAlfVisual::DoRemoveAndDestroyAllD();
       
   363     }
       
   364     
       
   365 // ---------------------------------------------------------------------------
       
   366 //  future proofing  
       
   367 // ---------------------------------------------------------------------------
       
   368 //  
       
   369 EXPORT_C void CAlfMeshVisual::PropertyOwnerExtension(const TUid& aExtensionUid, TAny** aExtensionParams)
       
   370     {
       
   371     CAlfVisual::PropertyOwnerExtension(aExtensionUid,aExtensionParams);
       
   372     }
       
   373     
       
   374 
       
   375