photosgallery/viewframework/layouts/src/glxblendlayout.cpp
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:    Layout blender
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxblendlayout.h" 
       
    22 #include <glxpanic.h> // Panic codes
       
    23 
       
    24 // LOCAL METHODS
       
    25 namespace
       
    26 	{
       
    27 	// helper method to calculate coefficiency for given field
       
    28 	TReal32 GetCoefficiency(
       
    29 		TGlxLayoutInfo& aBaseInfo, 
       
    30 		TGlxLayoutInfo& aDeltaInfo, 
       
    31 		TGlxLayoutInfo::TLayoutType aType, 
       
    32 		TInt aIndex )
       
    33 		{
       
    34 		/*
       
    35 		// position, get coefficients
       
    36 		//TReal32 new_coeff = aDeltaInfo.Coefficient( aType );
       
    37 		//TReal32 combined_coeff = aBaseInfo.Coefficient( aType );
       
    38 		// check if this is the first layout chain in the blender
       
    39 		// and full coefficiency has not been yet reached
       
    40 		if( aIndex == 0 && combined_coeff < 1.0 )
       
    41 			{
       
    42 			// increase the coefficient to reach 1.0
       
    43 			new_coeff = 1.0 - combined_coeff;
       
    44 			aBaseInfo.SetCoefficient( aType, 1.0 );
       
    45 			}
       
    46 		// if the coefficient was bigger than zero
       
    47 		// and full coefficiency has not been yet reached
       
    48 		else if( new_coeff > 0.0 && combined_coeff < 1.0 )
       
    49 			{
       
    50 			// dont allow coefficient to exceed 1.0
       
    51 			if( new_coeff > ( 1.0 - combined_coeff ) )
       
    52 				{
       
    53 				new_coeff = 1.0 - combined_coeff;
       
    54 				}
       
    55 			// increase the coefficient
       
    56 			aBaseInfo.SetCoefficient( aType, combined_coeff + new_coeff );
       
    57 			}
       
    58 		else
       
    59 			{
       
    60 			// coefficient over or underflow
       
    61 			new_coeff = 0;
       
    62 			}
       
    63 		return new_coeff;*/
       
    64 		} 
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // Constructor
       
    69 // -----------------------------------------------------------------------------
       
    70 EXPORT_C TGlxBlendLayout::TGlxBlendLayout()
       
    71 	: iChanged( EFalse )	// blender not is changed by default
       
    72 	{
       
    73 	__DEBUG_ONLY( _iName = _L( "TGlxBlendLayout" ) );
       
    74 	}
       
    75 	
       
    76 // -----------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // -----------------------------------------------------------------------------
       
    79 EXPORT_C TGlxBlendLayout::~TGlxBlendLayout () 
       
    80 	{
       
    81 	iLayouts.Close();
       
    82 	}
       
    83 	
       
    84 // -----------------------------------------------------------------------------
       
    85 // AddLayoutL
       
    86 // -----------------------------------------------------------------------------
       
    87 EXPORT_C void TGlxBlendLayout::AddLayoutL( MGlxLayout* aLayout )
       
    88 	{
       
    89 	// layout must not be null
       
    90 	__ASSERT_DEBUG( aLayout, Panic( EGlxPanicNullLayout ) );
       
    91 	// create layout struct
       
    92 	TLayout cache;
       
    93 	cache.iLayout = aLayout;
       
    94 	__ASSERT_DEBUG( 
       
    95 		iLayouts.Find( cache, TLayout::Match ) == KErrNotFound, 
       
    96 		Panic( EGlxPanicAlreadyAdded ) );
       
    97 
       
    98 	// cant set anything sane to layout info at this point
       
    99 	iLayouts.AppendL( cache );
       
   100 	iChanged = ETrue;
       
   101 	}
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // RemoveLayout
       
   105 // -----------------------------------------------------------------------------
       
   106 EXPORT_C void TGlxBlendLayout::RemoveLayout( const MGlxLayout* aLayout )
       
   107 	{
       
   108 	TInt count = iLayouts.Count();
       
   109 	for( TInt i = 0; i < count; i++ )
       
   110 		{
       
   111 		if( iLayouts[ i ].iLayout == aLayout )
       
   112 			{
       
   113 			// Found it, remove
       
   114 			iLayouts.Remove( i );
       
   115 			iChanged = ETrue;
       
   116 			return;
       
   117 			}
       
   118 		}
       
   119 	// its ok to remove a layout that was already gone, no harm done there
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // RemoveAllLayouts
       
   124 // -----------------------------------------------------------------------------
       
   125 EXPORT_C void TGlxBlendLayout::RemoveAllLayouts()
       
   126 	{
       
   127 	iLayouts.Close();
       
   128 	}
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // MapValue
       
   132 // -----------------------------------------------------------------------------
       
   133 void TGlxBlendLayout::DoSetLayoutValues( TGlxLayoutInfo& aInfo )
       
   134 	{
       
   135 	/*
       
   136 	TInt count = iLayouts.Count();
       
   137 	// first set each layouts info fields correctly
       
   138 	for( TInt i = 0; i < count; i++ )
       
   139 		{
       
   140 		// reset the values for the layout info
       
   141 		//iLayouts[ i ].iLayoutInfo.Reset( aInfo.Index() );
       
   142 		//iLayouts[ i ].iLayoutInfo.SetVisual( aInfo.Visual() );
       
   143 		//iLayouts[ i ].iLayoutInfo.SetScreenInfo( aInfo.ScreenInfo() );
       
   144 		}
       
   145 
       
   146 	// process each layout
       
   147 	for( TInt i = 0; i < count; i++ )
       
   148 		{
       
   149 		// call the layout (chain) to perform the processing for their own info
       
   150 		iLayouts[ i ].iLayout->SetLayoutValues( iLayouts[ i ].iLayoutInfo );
       
   151 		}
       
   152 
       
   153 	// reset completely the aInfo fields and its coefficients
       
   154 	// we use the coefficient fields to know when we have enough values for
       
   155 	// certain field (coefficient reaches 1.0)
       
   156 	// we need to reset the base values as the cached values in layout chains
       
   157 	// had default values (which may not ne 0 for all fields)
       
   158 	aInfo.iPosition.iX = 0;
       
   159 	aInfo.iPosition.iY = 0;
       
   160 	aInfo.SetCoefficient( TGlxLayoutInfo::EPosition, 0 );
       
   161 	aInfo.iSize.iX = 0;
       
   162 	aInfo.iSize.iY = 0;
       
   163 	aInfo.SetCoefficient( TGlxLayoutInfo::ESize, 0 );
       
   164 	aInfo.iOpacity = 0;
       
   165 	aInfo.SetCoefficient( TGlxLayoutInfo::EOpacity, 0 );
       
   166 	aInfo.iRotation = 0;
       
   167 	aInfo.SetCoefficient( TGlxLayoutInfo::ERotation, 0 );
       
   168 
       
   169 	// then merge the values according to coefficients
       
   170 	// need to process in reverse order since layout in index 0
       
   171 	// has the strongest effect
       
   172 	for( TInt i = count - 1; i >= 0; i-- )
       
   173 		{
       
   174 		// position, get coefficient
       
   175 		TReal32 new_coeff = GetCoefficiency( 
       
   176 				aInfo, iLayouts[ i ].iLayoutInfo, 
       
   177 				TGlxLayoutInfo::EPosition, i );
       
   178 		// if the coefficient was bigger than zero
       
   179 		if( new_coeff > 0.0 )
       
   180 			{
       
   181 			// add new position, multiplied with the coefficient
       
   182 			aInfo.iPosition.iX += 
       
   183 				iLayouts[ i ].iLayoutInfo.iPosition.iX * new_coeff;
       
   184 			aInfo.iPosition.iY += 
       
   185 				iLayouts[ i ].iLayoutInfo.iPosition.iY * new_coeff;
       
   186 			}
       
   187 
       
   188 		// size, get coefficient
       
   189 		new_coeff = GetCoefficiency( 
       
   190 				aInfo, iLayouts[ i ].iLayoutInfo, 
       
   191 				TGlxLayoutInfo::ESize, i );
       
   192 		// if the coefficient was bigger than zero
       
   193 		if( new_coeff > 0.0 )
       
   194 			{
       
   195 			// add new size, multiplied with the coefficient
       
   196 			aInfo.iSize.iX += 
       
   197 				iLayouts[ i ].iLayoutInfo.iSize.iX * new_coeff;
       
   198 			aInfo.iSize.iY += 
       
   199 				iLayouts[ i ].iLayoutInfo.iSize.iY * new_coeff;
       
   200 			}
       
   201 
       
   202 		// opacity, get coefficient
       
   203 		new_coeff = GetCoefficiency( 
       
   204 				aInfo, iLayouts[ i ].iLayoutInfo, 
       
   205 				TGlxLayoutInfo::EOpacity, i );
       
   206 		if( new_coeff > 0.0 )
       
   207 			{
       
   208 			// add new opacity, multiplied with the coefficient
       
   209 			aInfo.iOpacity += 
       
   210 				iLayouts[ i ].iLayoutInfo.iOpacity * new_coeff;
       
   211 			}
       
   212 
       
   213 		// rotation, get coefficient
       
   214 		new_coeff = GetCoefficiency( 
       
   215 				aInfo, iLayouts[ i ].iLayoutInfo, 
       
   216 				TGlxLayoutInfo::ERotation, i );
       
   217 		if( new_coeff > 0.0 )
       
   218 			{
       
   219 			// add new rotation, multiplied with the coefficient
       
   220 			aInfo.iRotation += 
       
   221 				iLayouts[ i ].iLayoutInfo.iRotation * new_coeff;
       
   222 			}
       
   223 		} */
       
   224 	}
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // DoChanged
       
   228 // -----------------------------------------------------------------------------
       
   229 TBool TGlxBlendLayout::DoChanged() const
       
   230 	{
       
   231 	// See if even one layout has changed
       
   232 	/// @todo consider adding the index of current visual to the Changed call
       
   233 /*	TInt count = iLayouts.Count();
       
   234 	for( TInt i = 0; i < count; i++ )
       
   235 		{
       
   236 		if( iLayouts[ i ].iLayout->Changed() )
       
   237 			{
       
   238 			return ETrue;
       
   239 			}
       
   240 		}
       
   241 
       
   242 	return iChanged;
       
   243 */	}
       
   244 	
       
   245 // -----------------------------------------------------------------------------
       
   246 // DoClearChanged
       
   247 // -----------------------------------------------------------------------------
       
   248 void TGlxBlendLayout::DoClearChanged() 
       
   249 	{
       
   250 	TInt count = iLayouts.Count();
       
   251 	for( TInt i = 0; i < count; i++ )
       
   252 		{
       
   253 //		iLayouts[ i ].iLayout->ClearChanged();
       
   254 		}
       
   255 		
       
   256 	iChanged = EFalse;
       
   257 	}
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // TLayout::Match
       
   261 // -----------------------------------------------------------------------------
       
   262 TBool TGlxBlendLayout::TLayout::Match( const TLayout& aLhs, const TLayout& aRhs )
       
   263 	{
       
   264 	return aLhs.iLayout == aRhs.iLayout;
       
   265 	}