camerauis/cameraapp/generic/src/CamDecorator.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 0 1ddebce53859
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Camera UI decorator*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <gdi.h>
       
    20 #include <eikenv.h>
       
    21 #include <barsread.h>
       
    22 #include <AknsSkinInstance.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <AknsDrawUtils.h>
       
    25 #include <layoutmetadata.cdl.h>
       
    26 #include <aknlayoutscalable_apps.cdl.h>
       
    27 
       
    28 #include "Cam.hrh"
       
    29 #include "CamAppController.h"
       
    30 #include "CamAppUi.h"
       
    31 #include "CamObservable.h"
       
    32 #include "CamRecordingIconDecoration.h"
       
    33 #include "CamDecorator.h"
       
    34 #include "camlogging.h"
       
    35 #include "CameraUiConfigManager.h"
       
    36 #include "CamUtility.h" 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CCamDecorator::CCamDecorator()
       
    40 // Default constructor
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CCamDecorator::CCamDecorator( CCamAppController& aController )
       
    44   : iController( aController )
       
    45   {
       
    46   }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCamDecorator::NewL
       
    50 // Factory method to safely create a new instance
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CCamDecorator* 
       
    54 CCamDecorator::NewL( CCamAppController& aController,
       
    55                      TInt               aResourceId, 
       
    56                      MCamObserver*      aObserver /*=NULL*/ )
       
    57   {
       
    58   CCamDecorator* me = 
       
    59       new (ELeave) CCamDecorator( aController );
       
    60 
       
    61   CleanupStack::PushL( me );
       
    62   me->ConstructL( aResourceId, aObserver );
       
    63   CleanupStack::Pop( me );
       
    64 
       
    65   return me;
       
    66   }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CCamDecorator::ConstructL
       
    70 // Initializes a new instance
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CCamDecorator::ConstructL(TInt aResourceId, MCamObserver* aObserver)
       
    74     {
       
    75     if ( aResourceId )
       
    76         {
       
    77         iPossibleObserver = aObserver;
       
    78         
       
    79         TResourceReader reader;
       
    80         CEikonEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); 
       
    81 
       
    82         TInt numDecorations = reader.ReadInt16();
       
    83         
       
    84         TInt currentDecoration = 0;
       
    85         TScreenDecorationType decorationType;
       
    86         for ( currentDecoration = 0; currentDecoration < numDecorations; currentDecoration++ )
       
    87             {
       
    88             decorationType = static_cast<TScreenDecorationType>(reader.ReadInt16());
       
    89             
       
    90             switch(decorationType)
       
    91                 {
       
    92             case ECamScreenDecorationBlendedBackground:
       
    93                 CreateBlendedBackgroundL(reader);
       
    94                 break;
       
    95                 
       
    96             case ECamScreenDecorationDVFBlanker:
       
    97                 CreateDVFBlankerL(reader);
       
    98                 break;
       
    99                 
       
   100             case ECamScreenDecorationRecordingIcon:
       
   101                 CreateRecordingIconL(reader);
       
   102                 break;
       
   103                 
       
   104             default:
       
   105                 break;
       
   106                 }
       
   107             }
       
   108             
       
   109         CleanupStack::PopAndDestroy();
       
   110         
       
   111         }
       
   112     else
       
   113         {
       
   114         iDrawNothing = ETrue;
       
   115         }
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CCamDecorator::~CCamDecorator()
       
   120 // Destructor
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 CCamDecorator::~CCamDecorator()
       
   124   {
       
   125   PRINT( _L("Camera => ~CCamDecorator") );
       
   126   iDVFBlankers.Reset();
       
   127   iRecordingIcons.ResetAndDestroy();
       
   128   PRINT( _L("Camera <= ~CCamDecorator") );
       
   129   }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CCamDecorator::Draw
       
   133 // Draws all the decorations
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CCamDecorator::Draw( CBitmapContext& aGc, const TRect& aDrawRect, const TBool aForceBlankers )
       
   137     {
       
   138     if ( !iDrawNothing )
       
   139         {
       
   140         TInt element = 0;
       
   141         TInt count = 0;
       
   142 
       
   143         // Draw the blankers
       
   144         count = iDVFBlankers.Count();
       
   145         
       
   146         if ( count > 0 )
       
   147             {
       
   148             TRgb blankerColour( KRgbWhite );     
       
   149             CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
   150             if ( appUi && appUi->IsDirectViewfinderActive())
       
   151                 {
       
   152                 blankerColour = KRgbWhite;
       
   153                 
       
   154                 aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   155                 aGc.SetBrushColor( blankerColour );
       
   156                 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   157                     
       
   158                 for ( element = 0; element < count; element++ )
       
   159                     {
       
   160                     aGc.DrawRect( iDVFBlankers[element] );
       
   161                     }
       
   162                     
       
   163                 aGc.Reset();                
       
   164                 }
       
   165             }
       
   166     
       
   167         if ( aForceBlankers )
       
   168             {
       
   169             count = iDVFBlankers.Count();
       
   170             if ( count > 0 )
       
   171                 {
       
   172                 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   173                 CWindowGc& gc = CCoeEnv::Static()->SystemGc();
       
   174                 for ( element = 0; element < count; element++ )
       
   175                     {
       
   176                     AknsDrawUtils::Background( skin, NULL, gc, iDVFBlankers[element] );
       
   177                     }
       
   178                 }
       
   179             }
       
   180            
       
   181         // Draw the recording icons
       
   182         count = iRecordingIcons.Count();
       
   183         for ( element = 0; element < count; element++ )
       
   184             {
       
   185             iRecordingIcons[element]->Draw( aGc, aDrawRect );
       
   186             }
       
   187         }
       
   188     }
       
   189     
       
   190 // -----------------------------------------------------------------------------
       
   191 // CCamDecorator::CreateBlendedBackgroundL
       
   192 // Create a new blended background decoration based on resource
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CCamDecorator::CreateBlendedBackgroundL(TResourceReader& aResourceReader)
       
   196     {
       
   197     PRINT( _L("Camera => CCamDecorator::CreateBlendedBackgroundL") );	
       
   198     aResourceReader.ReadInt16(); // tl_x
       
   199     aResourceReader.ReadInt16(); // tl_y
       
   200     aResourceReader.ReadInt16(); // width
       
   201 
       
   202     /*
       
   203     CBlendedBackground* blendedBackground = CBlendedBackground::NewL( TPoint(tl_x, tl_y), width, KBlendedBackgroundDisplayMode );
       
   204 
       
   205     CleanupStack::PushL( blendedBackground );
       
   206     
       
   207     User::LeaveIfError(iBlendedBackgrounds.Append(blendedBackground));
       
   208 
       
   209     CleanupStack::Pop( blendedBackground );
       
   210     */
       
   211 
       
   212     PRINT( _L("Camera <= CCamDecorator::CreateBlendedBackgroundL") );	
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CCamDecorator::CreateDVFBlankerL
       
   217 // Create a new dvf blanker decoration based on resource
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CCamDecorator::CreateDVFBlankerL(TResourceReader& aResourceReader)
       
   221     {
       
   222     PRINT( _L("Camera => CCamDecorator::CreateDVFBlankerL") );		
       
   223     TInt tl_x = aResourceReader.ReadInt16();
       
   224     TInt tl_y = aResourceReader.ReadInt16();
       
   225     TInt width = aResourceReader.ReadInt16();
       
   226     TInt height = aResourceReader.ReadInt16();
       
   227 
       
   228     TRect blanker(TPoint(tl_x, tl_y), TSize(width, height));
       
   229     
       
   230     User::LeaveIfError(iDVFBlankers.Append(blanker));
       
   231     PRINT( _L("Camera <= CCamDecorator::CreateDVFBlankerL") );		
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CCamDecorator::CreateRecordingIconL
       
   236 // Create a new recording icon decoration based on resource
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CCamDecorator::CreateRecordingIconL(TResourceReader& /* aResourceReader */)  
       
   240     {
       
   241     PRINT( _L("Camera => CCamDecorator::CreateRecordingIconL") );	
       
   242     
       
   243     TRect screenRect;
       
   244     if ( Layout_Meta_Data::IsLandscapeOrientation() || CamUtility::IsNhdDevice() )
       
   245         {
       
   246         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
   247         }
       
   248     else
       
   249         {
       
   250         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, screenRect );
       
   251         }
       
   252     
       
   253     TAknLayoutRect progressPaneLayout;
       
   254     TAknLayoutRect recIconLayout;
       
   255     TInt vari = Layout_Meta_Data::IsLandscapeOrientation();
       
   256     if ( CamUtility::IsNhdDevice() )
       
   257         {
       
   258          progressPaneLayout.LayoutRect( screenRect,
       
   259              AknLayoutScalable_Apps::vid4_progress_pane( vari ) );
       
   260             
       
   261          recIconLayout.LayoutRect( progressPaneLayout.Rect(),
       
   262              AknLayoutScalable_Apps::vid4_progress_pane_g3( !vari ) ); 
       
   263         }
       
   264     else
       
   265         {
       
   266         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   267             {
       
   268             progressPaneLayout.LayoutRect( screenRect,
       
   269                 AknLayoutScalable_Apps::vid6_indi_pane( !vari ) );
       
   270             recIconLayout.LayoutRect( progressPaneLayout.Rect(),
       
   271                 AknLayoutScalable_Apps::vid6_indi_pane_g5( vari ) );
       
   272 
       
   273             }
       
   274         else
       
   275             {
       
   276             progressPaneLayout.LayoutRect( screenRect,
       
   277                 AknLayoutScalable_Apps::vid6_indi_pane( 3 ) );
       
   278             recIconLayout.LayoutRect( progressPaneLayout.Rect(),
       
   279                 AknLayoutScalable_Apps::vid6_indi_pane_g5( 2 ) );
       
   280             }
       
   281         }
       
   282         
       
   283     TRect location = recIconLayout.Rect();  
       
   284     
       
   285     CCamRecordingIconDecoration* recIcon = 
       
   286         CCamRecordingIconDecoration::NewL( location, iController );
       
   287     
       
   288     CleanupStack::PushL( recIcon );
       
   289 
       
   290     if ( iPossibleObserver )
       
   291         {
       
   292         recIcon->RegisterObserverL(iPossibleObserver);
       
   293         }
       
   294         
       
   295     User::LeaveIfError(iRecordingIcons.Append(recIcon));
       
   296 
       
   297     CleanupStack::Pop( recIcon );
       
   298     PRINT( _L("Camera <= CCamDecorator::CreateRecordingIconL") );			
       
   299     }
       
   300 
       
   301 // End of File