sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Test GDI scaling (pixels<->twips) functions
|
sl@0
|
15 |
// You can probably delete this test as it is now done by TMSCRMOD for each screen mode.
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include "W32STD.H"
|
sl@0
|
21 |
#include "../tlib/testbase.h"
|
sl@0
|
22 |
#include "TMAN.H"
|
sl@0
|
23 |
|
sl@0
|
24 |
class TScaleTest;
|
sl@0
|
25 |
|
sl@0
|
26 |
class CScaleWindow : public CTWin
|
sl@0
|
27 |
{
|
sl@0
|
28 |
public:
|
sl@0
|
29 |
CScaleWindow(TScaleTest *aTest);
|
sl@0
|
30 |
void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
|
sl@0
|
31 |
void Draw();
|
sl@0
|
32 |
void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
|
sl@0
|
33 |
private:
|
sl@0
|
34 |
TScaleTest *iTest;
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
class TScaleTest : public CTestBase
|
sl@0
|
38 |
{
|
sl@0
|
39 |
public:
|
sl@0
|
40 |
TScaleTest();
|
sl@0
|
41 |
~TScaleTest();
|
sl@0
|
42 |
TestState DoTestL();
|
sl@0
|
43 |
void ConstructL();
|
sl@0
|
44 |
private:
|
sl@0
|
45 |
CScaleWindow *iWin;
|
sl@0
|
46 |
TSize iWinSize;
|
sl@0
|
47 |
TInt iState;
|
sl@0
|
48 |
};
|
sl@0
|
49 |
|
sl@0
|
50 |
GLDEF_C CTestBase *CreateScaleTest()
|
sl@0
|
51 |
{
|
sl@0
|
52 |
return(new(ELeave) TScaleTest());
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
CScaleWindow::CScaleWindow(TScaleTest *aTest) : CTWin(), iTest(aTest)
|
sl@0
|
56 |
{}
|
sl@0
|
57 |
|
sl@0
|
58 |
void CScaleWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
ConstructExtLD(*parent,pos,size);
|
sl@0
|
61 |
Activate();
|
sl@0
|
62 |
AssignGC(aGc);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
void CScaleWindow::Draw()
|
sl@0
|
66 |
{
|
sl@0
|
67 |
iGc->Clear();
|
sl@0
|
68 |
TSize twips=Client()->iScreen->SizeInTwips();
|
sl@0
|
69 |
TSize pixels=Client()->iScreen->SizeInPixels();
|
sl@0
|
70 |
// Horizontal line
|
sl@0
|
71 |
TInt inches=twips.iWidth/KTwipsPerInch-1;
|
sl@0
|
72 |
TInt lineLen=Client()->iScreen->HorizontalTwipsToPixels(inches*KTwipsPerInch);
|
sl@0
|
73 |
TPoint linePos=TPoint((pixels.iWidth-lineLen)/2,pixels.iHeight/2);
|
sl@0
|
74 |
iGc->DrawLine(linePos,linePos+TPoint(lineLen,0));
|
sl@0
|
75 |
TBuf<0x20> buf;
|
sl@0
|
76 |
buf.Format(TRefByValue<const TDesC>(_L("Width %d\"")),inches);
|
sl@0
|
77 |
iGc->DrawText(buf,TPoint((pixels.iWidth-iFont->TextWidthInPixels(buf))/2,linePos.iY-iFont->HeightInPixels()+iFont->AscentInPixels()-2));
|
sl@0
|
78 |
TInt index;
|
sl@0
|
79 |
for(index=0;index<=inches;index++)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TInt dx=Client()->iScreen->HorizontalTwipsToPixels(index*KTwipsPerInch);
|
sl@0
|
82 |
TInt dy=Client()->iScreen->VerticalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
|
sl@0
|
83 |
iGc->DrawLine(linePos+TPoint(dx,1), linePos+TPoint(dx,dy));
|
sl@0
|
84 |
}
|
sl@0
|
85 |
// Vertical line
|
sl@0
|
86 |
inches=twips.iHeight/KTwipsPerInch;
|
sl@0
|
87 |
lineLen=Client()->iScreen->VerticalTwipsToPixels(inches*KTwipsPerInch);
|
sl@0
|
88 |
linePos.iY=(pixels.iHeight-lineLen)/2;
|
sl@0
|
89 |
iGc->DrawLine(linePos,linePos+TPoint(0,lineLen));
|
sl@0
|
90 |
buf.Format(TRefByValue<const TDesC>(_L("Height %d\"")),inches);
|
sl@0
|
91 |
iGc->DrawText(buf,TPoint(linePos.iX+10, pixels.iHeight/4));
|
sl@0
|
92 |
for(index=0;index<=inches;index++)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
TInt dx=Client()->iScreen->HorizontalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
|
sl@0
|
95 |
TInt dy=Client()->iScreen->VerticalTwipsToPixels(index*KTwipsPerInch);
|
sl@0
|
96 |
iGc->DrawLine(linePos+TPoint(1,dy), linePos+TPoint(dx,dy));
|
sl@0
|
97 |
}
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
void CScaleWindow::WinKeyL(const TKeyEvent &,const TTime &)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
CActiveScheduler::Stop();
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
TScaleTest::TScaleTest() : CTestBase(_L("Scale"))
|
sl@0
|
106 |
{}
|
sl@0
|
107 |
|
sl@0
|
108 |
TScaleTest::~TScaleTest()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
CTWin::Delete(iWin);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
void TScaleTest::ConstructL()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
CScaleWindow *win=new(ELeave) CScaleWindow(this);
|
sl@0
|
116 |
win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup,*Client()->iGc);
|
sl@0
|
117 |
iWin=win;
|
sl@0
|
118 |
Client()->iGroup->SetCurrentWindow(iWin);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
TestState TScaleTest::DoTestL()
|
sl@0
|
122 |
{
|
sl@0
|
123 |
switch(iState)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
case 0:
|
sl@0
|
126 |
LogSubTest(_L("Scale 1"),1);
|
sl@0
|
127 |
CActiveScheduler::Start();
|
sl@0
|
128 |
iState++;
|
sl@0
|
129 |
break;
|
sl@0
|
130 |
default:
|
sl@0
|
131 |
return(EFinished);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
return(ENext);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|