Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "devicemap.h"
17 #include <graphics/wsscreendevice.h>
19 CGraphicsDeviceMap* CGraphicsDeviceMap::NewL(const MWsScreenDevice& aScreenDevice)
21 return new(ELeave) CGraphicsDeviceMap(aScreenDevice);
24 CGraphicsDeviceMap::CGraphicsDeviceMap(const MWsScreenDevice& aScreenDevice) : iScreenDevice(&aScreenDevice)
28 TInt CGraphicsDeviceMap::HorizontalTwipsToPixels(TInt aTwips) const
30 TInt htp = iScreenDevice->SizeInTwips().iWidth; //horizontal twips
31 TInt htptp = (htp * 1000)/ iScreenDevice->SizeInPixels().iWidth; //horizontal twips per thousand pixels
32 return (1000 * aTwips + (htptp >> 1)) / htptp;
35 TInt CGraphicsDeviceMap::VerticalTwipsToPixels(TInt aTwips) const
37 TInt vtp = iScreenDevice->SizeInTwips().iHeight; //vertical twips
38 TInt vtptp = (vtp * 1000)/ iScreenDevice->SizeInPixels().iHeight; //vertical twips per thousand pixels
39 return (1000 * aTwips + (vtptp >> 1)) / vtptp;
42 TInt CGraphicsDeviceMap::HorizontalPixelsToTwips(TInt aPixels) const
44 TInt htp = iScreenDevice->SizeInTwips().iWidth; //horizontal twips
45 TInt htptp = (htp * 1000)/ iScreenDevice->SizeInPixels().iWidth; //horizontal twips per thousand pixels
46 return (htptp * aPixels + 500) / 1000;
49 TInt CGraphicsDeviceMap::VerticalPixelsToTwips(TInt aPixels) const
51 TInt vtp = iScreenDevice->SizeInTwips().iHeight; //vertical twips
52 TInt vtptp = (vtp * 1000)/ iScreenDevice->SizeInPixels().iHeight; //vertical twips per thousand pixels
53 return (vtptp * aPixels + 500) / 1000;
56 TPoint CGraphicsDeviceMap::TwipsToPixels(const TPoint& aTwipPoint) const
58 return TPoint(HorizontalTwipsToPixels(aTwipPoint.iX),VerticalTwipsToPixels(aTwipPoint.iY));
61 TRect CGraphicsDeviceMap::TwipsToPixels(const TRect& aTwipRect) const
63 return TRect(TwipsToPixels(aTwipRect.iTl),TwipsToPixels(aTwipRect.iBr));
66 TPoint CGraphicsDeviceMap::PixelsToTwips(const TPoint& aPixelPoint) const
68 return TPoint(HorizontalPixelsToTwips(aPixelPoint.iX),VerticalPixelsToTwips(aPixelPoint.iY));
71 TRect CGraphicsDeviceMap::PixelsToTwips(const TRect& aPixelRect) const
73 return TRect(PixelsToTwips(aPixelRect.iTl),PixelsToTwips(aPixelRect.iBr));