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