uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiRealSize.h
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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __HUIREALSIZE_H__
       
    21 #define __HUIREALSIZE_H__
       
    22 
       
    23 /** 
       
    24  * Rounds a float (TReal32) correctly into an integer (TInt). Takes care of both negative
       
    25  * and positive real number.
       
    26  */
       
    27 #define HUI_ROUND_FLOAT_TO_INT(a) (a < 0 ? (TInt(a - 0.5f)) : (TInt(a + 0.5f)))
       
    28     
       
    29 
       
    30 /**
       
    31  * 2D floating-point size.
       
    32  */
       
    33 NONSHARABLE_CLASS(THuiRealSize)
       
    34     {
       
    35 public:
       
    36     inline THuiRealSize() 
       
    37             : iWidth(0), iHeight(0) 
       
    38         {
       
    39         }
       
    40         
       
    41     inline THuiRealSize(TReal32 aWidth, TReal32 aHeight)
       
    42             : iWidth(aWidth), iHeight(aHeight)
       
    43         {
       
    44         }
       
    45         
       
    46     inline THuiRealSize(const TSize& aSize)
       
    47             : iWidth((TReal32)aSize.iWidth), iHeight((TReal32)aSize.iHeight)
       
    48         {
       
    49         }
       
    50         
       
    51     inline operator TSize() const
       
    52         {
       
    53         // here is a rounding error!
       
    54         return TSize((TInt)iWidth, (TInt)iHeight);
       
    55         }
       
    56         
       
    57     inline TSize Round() const
       
    58         {
       
    59         TSize rounded;
       
    60         rounded.iWidth = HUI_ROUND_FLOAT_TO_INT( iWidth );
       
    61         rounded.iHeight = HUI_ROUND_FLOAT_TO_INT( iHeight );
       
    62         return rounded; 
       
    63         }
       
    64 
       
    65     inline THuiRealSize operator * (TReal32 aFactor) const
       
    66         {
       
    67         return THuiRealSize(iWidth * aFactor, iHeight * aFactor);
       
    68         }
       
    69         
       
    70 public:    
       
    71 
       
    72     /** Width. */    
       
    73     TReal32 iWidth;
       
    74 
       
    75     /** Height. */
       
    76     TReal32 iHeight;
       
    77     
       
    78     };
       
    79 
       
    80 #endif // __HUIREALSIZE_H__