uifw/ganes/src/HgVgSkinRenderer.cpp
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     1 /*
       
     2 * Copyright (c) 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "HgVgSkinRenderer.h"
       
    21 #include "HgVgHelper.h"
       
    22 #include "HgVgDrawBuffer.h"
       
    23 
       
    24 #include <ganes.mbg>
       
    25 #include <AknIconUtils.h>
       
    26 #include <avkon.mbg>
       
    27 #include <AknsDrawUtils.h>
       
    28 #include <touchfeedback.h>
       
    29 #include <gulicon.h>
       
    30 #include <AknUtils.h>
       
    31 #include <layoutmetadata.cdl.h>
       
    32 #include <AknLayout2ScalableDef.h>
       
    33 #include <e32math.h>
       
    34 #include <gulcolor.h>
       
    35 
       
    36 #include <AknsDrawUtils.h>
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 // -----------------------------------------------------------------------------
       
    41 // CHgVgSkinRenderer::NewL()
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CHgVgSkinRenderer* CHgVgSkinRenderer::NewL(const TRect& aRect)
       
    46     {
       
    47     CHgVgSkinRenderer* self = new ( ELeave ) CHgVgSkinRenderer(aRect);
       
    48     CleanupStack::PushL (self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop ( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CHgVgSkinRenderer::ConstructL()
       
    56 // Symbian 2nd phase constructor can leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CHgVgSkinRenderer::ConstructL ()
       
    60     {
       
    61         
       
    62     iDrawBuffer = CHgVgDrawBuffer::NewL( TSize(iRect.Width(), iRect.Height()), EColor64K );
       
    63 
       
    64     
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CHgVgSkinRenderer::CHgVgSkinRenderer()
       
    69 // C++ default constructor can NOT contain any code, that might leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CHgVgSkinRenderer::CHgVgSkinRenderer(const TRect& aRect) : iRect(aRect)
       
    73     {
       
    74     
       
    75     }
       
    76         
       
    77 // -----------------------------------------------------------------------------
       
    78 // CHgVgSkinRenderer::~CHgVgSkinRenderer()
       
    79 // Destructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CHgVgSkinRenderer::~CHgVgSkinRenderer ( )
       
    83     {
       
    84 
       
    85     delete iDrawBuffer;
       
    86     
       
    87     vgDestroyImage(iSkinImage);
       
    88 
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CHgVgSkinRenderer::UpdateSkin()
       
    93 // Updates skin image.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CHgVgSkinRenderer::UpdateSkinL(const MObjectProvider* aProvider, 
       
    97         const CCoeControl* aControl)
       
    98     {
       
    99     // render skin to draw buffer
       
   100     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   101     MAknsControlContext* cc = AknsDrawUtils::ControlContext( aProvider );
       
   102     AknsDrawUtils::DrawBackground( skin, cc, aControl, iDrawBuffer->Gc(), TPoint(0,0), 
       
   103             aControl->Rect(), KAknsDrawParamDefault );
       
   104 
       
   105     // destroy old vg image
       
   106     if (iSkinImage != VG_INVALID_HANDLE)
       
   107         {
       
   108         vgDestroyImage(iSkinImage);
       
   109         iSkinImage = VG_INVALID_HANDLE;
       
   110         }
       
   111 
       
   112     // create new image for the skin
       
   113     iSkinImage = vgCreateImage(VG_sRGB_565, 
       
   114             iRect.Width(), iRect.Height(), 
       
   115             VG_IMAGE_QUALITY_NONANTIALIASED);
       
   116     
       
   117     // handle out of memory
       
   118     VGErrorCode error = vgGetError();
       
   119     if (iSkinImage == VG_INVALID_HANDLE || error == VG_OUT_OF_MEMORY_ERROR)
       
   120         {
       
   121         User::Leave(KErrNoMemory);
       
   122         }
       
   123             
       
   124     // Copy to draw buffer to vg image
       
   125     iDrawBuffer->GetDrawBufferToVgImage(TRect(TPoint(0,0), TPoint(iRect.Width(), iRect.Height())), 
       
   126             TPoint(0,0), iSkinImage, VG_sRGB_565);    
       
   127     }
       
   128 
       
   129 void CHgVgSkinRenderer::SetRect( const TRect& aRect )
       
   130     {
       
   131     iRect = aRect;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CHgVgSkinRenderer::Draw
       
   136 // Draws skin.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CHgVgSkinRenderer::Draw() const
       
   140     {
       
   141     HgVgHelper::DrawImage(iSkinImage, TPoint(0, 0), iRect);
       
   142     }
       
   143 
       
   144 // End of File