|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "devicemap.h" |
|
17 #include <graphics/wsscreendevice.h> |
|
18 |
|
19 CGraphicsDeviceMap* CGraphicsDeviceMap::NewL(const MWsScreenDevice& aScreenDevice) |
|
20 { |
|
21 return new(ELeave) CGraphicsDeviceMap(aScreenDevice); |
|
22 } |
|
23 |
|
24 CGraphicsDeviceMap::CGraphicsDeviceMap(const MWsScreenDevice& aScreenDevice) : iScreenDevice(&aScreenDevice) |
|
25 { |
|
26 } |
|
27 |
|
28 TInt CGraphicsDeviceMap::HorizontalTwipsToPixels(TInt aTwips) const |
|
29 { |
|
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; |
|
33 } |
|
34 |
|
35 TInt CGraphicsDeviceMap::VerticalTwipsToPixels(TInt aTwips) const |
|
36 { |
|
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; |
|
40 } |
|
41 |
|
42 TInt CGraphicsDeviceMap::HorizontalPixelsToTwips(TInt aPixels) const |
|
43 { |
|
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; |
|
47 } |
|
48 |
|
49 TInt CGraphicsDeviceMap::VerticalPixelsToTwips(TInt aPixels) const |
|
50 { |
|
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; |
|
54 } |
|
55 |
|
56 TPoint CGraphicsDeviceMap::TwipsToPixels(const TPoint& aTwipPoint) const |
|
57 { |
|
58 return TPoint(HorizontalTwipsToPixels(aTwipPoint.iX),VerticalTwipsToPixels(aTwipPoint.iY)); |
|
59 } |
|
60 |
|
61 TRect CGraphicsDeviceMap::TwipsToPixels(const TRect& aTwipRect) const |
|
62 { |
|
63 return TRect(TwipsToPixels(aTwipRect.iTl),TwipsToPixels(aTwipRect.iBr)); |
|
64 } |
|
65 |
|
66 TPoint CGraphicsDeviceMap::PixelsToTwips(const TPoint& aPixelPoint) const |
|
67 { |
|
68 return TPoint(HorizontalPixelsToTwips(aPixelPoint.iX),VerticalPixelsToTwips(aPixelPoint.iY)); |
|
69 } |
|
70 |
|
71 TRect CGraphicsDeviceMap::PixelsToTwips(const TRect& aPixelRect) const |
|
72 { |
|
73 return TRect(PixelsToTwips(aPixelRect.iTl),PixelsToTwips(aPixelRect.iBr)); |
|
74 } |