camerauis/cameraapp/generic/src/cambitmapitem.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 0 1ddebce53859
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Class for rendering bitmap based indicators
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cambitmapitem.h"
       
    20 #include "AknLayout2ScalableDef.h"
       
    21 #include "AknLayoutFont.h"
       
    22 #include "CamUtility.h"
       
    23 #include "CamPanic.h"  
       
    24 
       
    25 #include <AknIconUtils.h>
       
    26 #include <AknsUtils.h>
       
    27 #include <AknsConstants.h>
       
    28 
       
    29 #include <cameraapp.mbg> 
       
    30 
       
    31 _LIT( KCamBitmapFile, "z:\\resource\\apps\\cameraapp.mif" );
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CCamBitmapItem::CCamBitmapItem()
       
    38     {
       
    39     // No implementation required
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CCamBitmapItem::~CCamBitmapItem()
       
    47     {
       
    48     delete iBitmap;
       
    49     delete iMask;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CCamBitmapItem* CCamBitmapItem::NewL(
       
    57         TInt aBitmapId, 
       
    58         TInt aMaskId )
       
    59     {
       
    60     CCamBitmapItem* self = new ( ELeave ) CCamBitmapItem();
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL( aBitmapId, aMaskId );
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CCamBitmapItem* CCamBitmapItem::NewL(
       
    72         TInt aBitmapId,
       
    73         TInt aMaskId,
       
    74         const TAknsItemID& aID )
       
    75     {
       
    76     CCamBitmapItem* self = new ( ELeave ) CCamBitmapItem();
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aBitmapId, aMaskId, aID );
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CCamBitmapItem::ConstructL( TInt aBitmapId, TInt aMaskId )
       
    88     {
       
    89     AknIconUtils::CreateIconL(
       
    90         iBitmap,
       
    91         iMask,
       
    92         KCamBitmapFile,
       
    93         aBitmapId,
       
    94         aMaskId );
       
    95 
       
    96     // If SizeInPixels() return zero size, this is a scalable icon
       
    97     iScalableIcon = iBitmap->SizeInPixels() == TSize( 0, 0 );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CCamBitmapItem::ConstructL(
       
   105     TInt aBitmapId, TInt aMaskId, const TAknsItemID& aID )
       
   106     {
       
   107     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   108     
       
   109     AknsUtils::CreateIconL(
       
   110         skinInstance, 
       
   111         aID,
       
   112         iBitmap,
       
   113         iMask,
       
   114         KCamBitmapFile,
       
   115         aBitmapId,
       
   116         aMaskId );
       
   117 
       
   118     // If SizeInPixels() return zero size, this is a scalable icon
       
   119     iScalableIcon = iBitmap->SizeInPixels() == TSize( 0, 0 );
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CCamBitmapItem::SetLayoutL(
       
   127         const TRect& aParentRect,
       
   128         const TAknWindowComponentLayout& aLayout )
       
   129     {
       
   130     TAknLayoutRect layout;
       
   131     layout.LayoutRect( aParentRect, aLayout.LayoutLine() );
       
   132     SetLayoutL( layout.Rect() );
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CCamBitmapItem::SetLayoutL(
       
   140         const TRect& aRect )
       
   141     {
       
   142     if ( iRect != aRect )
       
   143         {
       
   144         iRect = aRect;
       
   145 		if ( iBitmap && iScalableIcon )
       
   146             {
       
   147             AknIconUtils::SetSize( iBitmap, iRect.Size() );
       
   148             }
       
   149         }
       
   150     }
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CCamBitmapItem::Draw( CBitmapContext& aBitmapContext ) const
       
   156     {
       
   157     TRect cropRect(TPoint(0,0),iRect.Size());
       
   158     DrawPartial( aBitmapContext, iRect, cropRect );
       
   159 	}
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CCamBitmapItem::DrawPartial(
       
   166     CBitmapContext& aBitmapContext,
       
   167     const TRect& aDestRect,
       
   168     const TRect& aCropRect ) const
       
   169     {
       
   170     if ( iBitmap && iMask )
       
   171         {
       
   172         // Alpha channel based rendering
       
   173         aBitmapContext.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   174         aBitmapContext.BitBltMasked(
       
   175             aDestRect.iTl + aCropRect.iTl,
       
   176             iBitmap,
       
   177             aCropRect,
       
   178             iMask,
       
   179             EFalse);
       
   180         }
       
   181     else
       
   182         {
       
   183         // Do nothing
       
   184         }
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CCamBitmapItem::BitmapSize
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TSize CCamBitmapItem::BitmapSize() const
       
   192     {
       
   193     if ( iBitmap )
       
   194         {
       
   195         return iBitmap->SizeInPixels();
       
   196         }
       
   197     else
       
   198         {
       
   199         return iRect.Size();
       
   200         }
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CCamBitmapItem::LayoutRect
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TRect CCamBitmapItem::LayoutRect() const
       
   208     {
       
   209     return iRect;
       
   210     }
       
   211 
       
   212 // end of file