uiacceltk/hitchcock/coretoolkit/src/HuiShadowBorderBrush.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Implementation of CHuiShadowBorderBrush - Shadow borders for visuals.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "uiacceltk/HuiShadowBorderBrush.h"  // Class definition
       
    21 #include "uiacceltk/HuiDrawing.h"
       
    22 #include "uiacceltk/HuiVisual.h"
       
    23 #include "uiacceltk/HuiUtil.h"
       
    24 
       
    25 /** Default shadow opacity. */
       
    26 const TReal32 KHuiShadowBorderBrushOpacity = 100.f/255.f;
       
    27 
       
    28 
       
    29 EXPORT_C CHuiShadowBorderBrush* CHuiShadowBorderBrush::NewL(TInt aWidth)
       
    30     {
       
    31     CHuiShadowBorderBrush* self = NewLC(aWidth);
       
    32     CleanupStack::Pop();
       
    33     return self;
       
    34     }
       
    35 
       
    36 
       
    37 EXPORT_C CHuiShadowBorderBrush* CHuiShadowBorderBrush::NewLC(TInt aWidth)
       
    38     {
       
    39     CHuiShadowBorderBrush* self = new (ELeave) CHuiShadowBorderBrush(aWidth);
       
    40     CleanupStack::PushL(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 EXPORT_C CHuiShadowBorderBrush* CHuiShadowBorderBrush::NewL(const THuiMetric& aWidth)
       
    45     {
       
    46     CHuiShadowBorderBrush* self = NewLC(aWidth);
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 EXPORT_C CHuiShadowBorderBrush* CHuiShadowBorderBrush::NewLC(const THuiMetric& aWidth)
       
    53     {
       
    54     CHuiShadowBorderBrush* self = new (ELeave) CHuiShadowBorderBrush(aWidth);
       
    55     CleanupStack::PushL(self);
       
    56     return self;
       
    57     }
       
    58  
       
    59 
       
    60 CHuiShadowBorderBrush::CHuiShadowBorderBrush(TInt aWidth)
       
    61         : CHuiBrush(),
       
    62           iWidth(TReal32(aWidth))
       
    63     {
       
    64     SetClipToVisual(EFalse);
       
    65     iOpacity.Set(KHuiShadowBorderBrushOpacity);
       
    66     }
       
    67 
       
    68 CHuiShadowBorderBrush::CHuiShadowBorderBrush(const THuiMetric& aWidth)
       
    69         : CHuiBrush(),
       
    70           iWidth(aWidth.iMagnitude),
       
    71           iMetricWidth(aWidth)
       
    72     {    
       
    73     SetClipToVisual(EFalse);
       
    74     iOpacity.Set(KHuiShadowBorderBrushOpacity);
       
    75     }
       
    76 
       
    77 CHuiShadowBorderBrush::~CHuiShadowBorderBrush()
       
    78     {
       
    79     }
       
    80 
       
    81 
       
    82 void CHuiShadowBorderBrush::ExpandVisualRect(TRect& aRect) const
       
    83     {
       
    84     // We need access to visual to convert metric units into pixels,
       
    85     // currently a pointer to visual is provided through separate
       
    86     // method since we want to avoid breaking binary compatibility 
       
    87     // of this class.
       
    88     TReal32 widthInPixels = WidthInPixels(BrushGuide()); 
       
    89     aRect.Grow(HUI_ROUND_FLOAT_TO_INT(widthInPixels), HUI_ROUND_FLOAT_TO_INT(widthInPixels)); 
       
    90     }
       
    91     
       
    92 TBool CHuiShadowBorderBrush::Changed() const
       
    93     {
       
    94     if ( CHuiBrush::Changed() )
       
    95         {
       
    96         return ETrue;
       
    97         }
       
    98     
       
    99     return iWidth.Changed();
       
   100     }
       
   101 
       
   102 void CHuiShadowBorderBrush::ClearChanged()
       
   103     {
       
   104     CHuiBrush::ClearChanged();
       
   105     iWidth.ClearChanged();
       
   106     }
       
   107 
       
   108 void CHuiShadowBorderBrush::Draw(CHuiGc& aGc, const MHuiBrushGuide& aGuide) const
       
   109     {
       
   110     TRect content = aGuide.BrushRect().Round();
       
   111     TReal32 opacity = aGuide.BrushOpacity() * iOpacity.Now();
       
   112 
       
   113     if(opacity <= 0)
       
   114         {
       
   115         return;
       
   116         }
       
   117 
       
   118     aGc.SetPenAlpha(TInt(opacity * 255));
       
   119     aGc.SetPenColor(TRgb(0, 0, 30));
       
   120 
       
   121     const CHuiTexture* shadowTexture = NULL;
       
   122     TInt err = aGuide.BrushSkin().GetTexture(EHuiSkinShadowTexture, shadowTexture);
       
   123     if (err!=KErrNone)
       
   124     	{
       
   125     	ASSERT(EFalse); // failed to get the shadow texture - unable to proceed!
       
   126     	return;
       
   127 	    }
       
   128     ASSERT(shadowTexture);
       
   129     THuiImage shadowImage(*shadowTexture);
       
   130 
       
   131     aGc.Disable(CHuiGc::EFeatureDepthWrite);
       
   132     
       
   133     TReal32 widthInPixels = WidthInPixels(BrushGuide()); 
       
   134     content.Grow(HUI_ROUND_FLOAT_TO_INT(widthInPixels), HUI_ROUND_FLOAT_TO_INT(widthInPixels)); 
       
   135     
       
   136     // ID:  EHJK-7G5AHB - shadow border leaves artifacts in the display while visual is moved.
       
   137     TReal32 offset = 0.0f; // NOTE: It was 1.f. 
       
   138 
       
   139     // Note: DrawBorders does not (yet) support different widths for every border.
       
   140     aGc.DrawBorders(content, 
       
   141                     widthInPixels-offset, 
       
   142                     widthInPixels+offset, 
       
   143                     widthInPixels-offset, 
       
   144                     widthInPixels+offset, 
       
   145                     CHuiGc::EBorderImage, 
       
   146                     &shadowImage);            
       
   147 
       
   148     aGc.Enable(CHuiGc::EFeatureDepthWrite);
       
   149     }
       
   150     
       
   151 EXPORT_C void CHuiShadowBorderBrush::SetWidth(const THuiMetric& aWidth)
       
   152     {
       
   153     iMetricWidth = aWidth;
       
   154     iWidth.Set(aWidth.iMagnitude);      
       
   155     }
       
   156 
       
   157 
       
   158 TReal32 CHuiShadowBorderBrush::WidthInPixels(const CHuiVisual* aVisual) const
       
   159     {
       
   160     TReal32 widthInPixels = iWidth.Now(); // Default to old pixel width
       
   161     if (aVisual)
       
   162         {
       
   163         THuiMetric metric = iMetricWidth;
       
   164         metric.iMagnitude = widthInPixels;        
       
   165         widthInPixels = aVisual->MetricToPixels(THuiXYMetric(metric, metric)).iX; // Calculate metric width in pixels  
       
   166         }    
       
   167     return widthInPixels;            
       
   168     }
       
   169