uiacceltk/hitchcock/coretoolkit/src/huicanvasbackground.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "huicanvasbackground.h"
       
    21 #include "huicanvasgc.h"
       
    22 #include <uiacceltk/HuiSkin.h>
       
    23 #include <uiacceltk/HuiS60Skin.h>
       
    24 #include <uiacceltk/HuiCanvasVisual.h>
       
    25 #include <uiacceltk/HuiDisplay.h>
       
    26 #include <uiacceltk/HuiStatic.h>
       
    27 #include <uiacceltk/HuiEnv.h>
       
    28 
       
    29 #include <e32cmn.h>
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Constructor
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CHuiCanvasBackground::CHuiCanvasBackground()
       
    37     {	    
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CHuiCanvasBackground::~CHuiCanvasBackground()
       
    45     {
       
    46     iBackgroundItems.Close();
       
    47     }
       
    48     
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CHuiCanvasBackground* CHuiCanvasBackground::NewL()
       
    54     {
       
    55     CHuiCanvasBackground* self = CHuiCanvasBackground::NewLC();
       
    56     CleanupStack::Pop(self);
       
    57     return self;        
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CHuiCanvasBackground* CHuiCanvasBackground::NewLC()
       
    65     {
       
    66     CHuiCanvasBackground* self = new (ELeave) CHuiCanvasBackground();
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CHuiCanvasBackground::ConstructL()
       
    78     {
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CHuiCanvasBackground::SetVisual(CHuiCanvasVisual* aVisual)
       
    86     {
       
    87     iCanvasVisual = aVisual;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // 
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CHuiCanvasBackground::SetClearBackground(CHuiDisplay::TClearMode aClearBackground)
       
    95     {
       
    96     iClearBackground = aClearBackground;    
       
    97     iBackgroundItems.Reset();
       
    98     if(aClearBackground == CHuiDisplay::EClearWithSkinBackground)
       
    99         {
       
   100         TRAP_IGNORE(CHuiStatic::Env().Skin().TextureL(EHuiSkinBackgroundTexture));
       
   101         }
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TInt CHuiCanvasBackground::ClearBackground()
       
   109     {
       
   110     return iClearBackground;        
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 
       
   118 TInt CHuiCanvasBackground::BackgroundItemsCount()
       
   119     {
       
   120     return iBackgroundItems.Count();        
       
   121     }
       
   122 // ---------------------------------------------------------------------------
       
   123 // 
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CHuiCanvasBackground::SetBackgroundColor(const TRgb& aBackgroundColor)
       
   127     {
       
   128     iBackgroundColor = aBackgroundColor;    
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 TRgb CHuiCanvasBackground::BackgroundColor() const
       
   136     {
       
   137     return iBackgroundColor;    
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CHuiCanvasBackground::SetBackgroundItems(const RArray<THuiDisplayBackgroundItem>& aItems)
       
   145     {
       
   146     iClearBackground = CHuiDisplay::EClearNone;
       
   147     iBackgroundItems.Reset();
       
   148     for(TInt i = 0; i < aItems.Count(); ++i)
       
   149         {
       
   150         iBackgroundItems.Append(aItems[i]);
       
   151         }   
       
   152     if (!CHuiStatic::Env().Renderer() == EHuiRendererBitgdi)
       
   153         {
       
   154         CHuiS60Skin* s60skin = static_cast<CHuiS60Skin*>(&CHuiStatic::Env().Skin());
       
   155         TRAP_IGNORE(s60skin->UpdateBackgroundsL(iBackgroundItems));
       
   156         }
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CHuiCanvasBackground::GetBackgroundItems(RArray<THuiDisplayBackgroundItem>& aItems)
       
   164     {
       
   165     aItems.Reset();
       
   166     for(TInt i = 0; i < iBackgroundItems.Count(); ++i)
       
   167         {
       
   168         aItems.Append(aItems[i]);
       
   169         }   
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CHuiCanvasBackground::DrawSelf(CHuiGc& aGc, const TRect& aDisplayRect)
       
   177     {
       
   178 	iCanvasVisual->CanvasGc().SetGc(aGc);
       
   179 	    
       
   180     // Clear background for the dirty area
       
   181     if (iBackgroundItems.Count() != 0)
       
   182         {
       
   183         ClearWithBackgroundItems(aDisplayRect);    
       
   184         }
       
   185     else
       
   186         {
       
   187         switch (iClearBackground)
       
   188             {
       
   189             case CHuiDisplay::EClearWithColor:
       
   190                 {
       
   191                 ClearWithColor(aGc, aDisplayRect);                            
       
   192                 break;    
       
   193                 }
       
   194             case CHuiDisplay::EClearWithSkinBackground:
       
   195                 {
       
   196                 ClearWithSkinBackground(aDisplayRect);                                                    
       
   197                 break;    
       
   198                 }
       
   199             case CHuiDisplay::EClearNone:
       
   200             default:
       
   201                 {
       
   202                 // Don't do anything
       
   203                 break;    
       
   204                 }                                                
       
   205             }                                    
       
   206         }                                                
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // 
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CHuiCanvasBackground::ClearWithBackgroundItems(const TRect& aDisplayRect)
       
   214     {    
       
   215     if (!iCanvasVisual)
       
   216         {
       
   217         return;    
       
   218         }
       
   219 
       
   220     CHuiCanvasGc& canvasGc = iCanvasVisual->CanvasGc();
       
   221     canvasGc.ClearWithBackgroundItems(aDisplayRect, iBackgroundItems);    
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // 
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CHuiCanvasBackground::ClearWithSkinBackground(const TRect& aDisplayRect)
       
   229     {    
       
   230     if (!iCanvasVisual)
       
   231         {
       
   232         return;    
       
   233         }
       
   234 
       
   235     CHuiCanvasGc& canvasGc = iCanvasVisual->CanvasGc();
       
   236     canvasGc.ClearWithSkinBackground(aDisplayRect);    
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // 
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CHuiCanvasBackground::ClearWithColor(CHuiGc& /*aGc*/, const TRect& aDisplayRect)
       
   244     {    
       
   245     if (!iCanvasVisual)
       
   246         {
       
   247         return;    
       
   248         }
       
   249 
       
   250     CHuiCanvasGc& canvasGc = iCanvasVisual->CanvasGc();
       
   251             
       
   252     canvasGc.SetPenColor(iBackgroundColor);
       
   253     canvasGc.SetOpacity(TReal32(iBackgroundColor.Alpha()) / 255.f);    
       
   254     canvasGc.Clear(aDisplayRect);    
       
   255     }
       
   256     
       
   257