os/graphics/windowing/windowserver/test/tman/SCALE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tman/SCALE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,135 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Test GDI scaling (pixels<->twips) functions
    1.18 +// You can probably delete this test as it is now done by TMSCRMOD for each screen mode.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include "W32STD.H"
    1.24 +#include "../tlib/testbase.h"
    1.25 +#include "TMAN.H"
    1.26 +
    1.27 +class TScaleTest;
    1.28 +
    1.29 +class CScaleWindow : public CTWin
    1.30 +	{
    1.31 +public:
    1.32 +	CScaleWindow(TScaleTest *aTest);
    1.33 +	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
    1.34 +	void Draw();
    1.35 +	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.36 +private:
    1.37 +	TScaleTest *iTest;
    1.38 +	};
    1.39 +
    1.40 +class TScaleTest : public CTestBase
    1.41 +	{
    1.42 +public:
    1.43 +	TScaleTest();
    1.44 +	~TScaleTest();
    1.45 +	TestState DoTestL();
    1.46 +	void ConstructL();
    1.47 +private:
    1.48 +	CScaleWindow *iWin;
    1.49 +	TSize iWinSize;
    1.50 +	TInt iState;
    1.51 +	};
    1.52 +
    1.53 +GLDEF_C CTestBase *CreateScaleTest()
    1.54 +	{
    1.55 +	return(new(ELeave) TScaleTest());
    1.56 +	}
    1.57 +
    1.58 +CScaleWindow::CScaleWindow(TScaleTest *aTest) : CTWin(), iTest(aTest)
    1.59 +	{}
    1.60 +
    1.61 +void CScaleWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
    1.62 +	{
    1.63 +	ConstructExtLD(*parent,pos,size);
    1.64 +	Activate();
    1.65 +	AssignGC(aGc);
    1.66 +	}
    1.67 +
    1.68 +void CScaleWindow::Draw()
    1.69 +	{
    1.70 +	iGc->Clear();
    1.71 +	TSize twips=Client()->iScreen->SizeInTwips();
    1.72 +	TSize pixels=Client()->iScreen->SizeInPixels();
    1.73 +// Horizontal line
    1.74 +	TInt inches=twips.iWidth/KTwipsPerInch-1;
    1.75 +	TInt lineLen=Client()->iScreen->HorizontalTwipsToPixels(inches*KTwipsPerInch);
    1.76 +	TPoint linePos=TPoint((pixels.iWidth-lineLen)/2,pixels.iHeight/2);
    1.77 +	iGc->DrawLine(linePos,linePos+TPoint(lineLen,0));
    1.78 +	TBuf<0x20> buf;
    1.79 +	buf.Format(TRefByValue<const TDesC>(_L("Width %d\"")),inches);
    1.80 +	iGc->DrawText(buf,TPoint((pixels.iWidth-iFont->TextWidthInPixels(buf))/2,linePos.iY-iFont->HeightInPixels()+iFont->AscentInPixels()-2));
    1.81 +	TInt index;
    1.82 +	for(index=0;index<=inches;index++)
    1.83 +		{
    1.84 +		TInt dx=Client()->iScreen->HorizontalTwipsToPixels(index*KTwipsPerInch);
    1.85 +		TInt dy=Client()->iScreen->VerticalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
    1.86 +		iGc->DrawLine(linePos+TPoint(dx,1), linePos+TPoint(dx,dy));
    1.87 +		}
    1.88 +// Vertical line
    1.89 +	inches=twips.iHeight/KTwipsPerInch;
    1.90 +	lineLen=Client()->iScreen->VerticalTwipsToPixels(inches*KTwipsPerInch);
    1.91 +	linePos.iY=(pixels.iHeight-lineLen)/2;
    1.92 +	iGc->DrawLine(linePos,linePos+TPoint(0,lineLen));
    1.93 +	buf.Format(TRefByValue<const TDesC>(_L("Height %d\"")),inches);
    1.94 +	iGc->DrawText(buf,TPoint(linePos.iX+10, pixels.iHeight/4));
    1.95 +	for(index=0;index<=inches;index++)
    1.96 +		{
    1.97 +		TInt dx=Client()->iScreen->HorizontalTwipsToPixels(KTwipsPerInch/(index==0 || index==inches ? 8 : 16));
    1.98 +		TInt dy=Client()->iScreen->VerticalTwipsToPixels(index*KTwipsPerInch);
    1.99 +		iGc->DrawLine(linePos+TPoint(1,dy), linePos+TPoint(dx,dy));
   1.100 +		}
   1.101 +	}
   1.102 +
   1.103 +void CScaleWindow::WinKeyL(const TKeyEvent &,const TTime &)
   1.104 +	{
   1.105 +	CActiveScheduler::Stop();
   1.106 +	}
   1.107 +
   1.108 +TScaleTest::TScaleTest() : CTestBase(_L("Scale"))
   1.109 +	{}
   1.110 +
   1.111 +TScaleTest::~TScaleTest()
   1.112 +	{
   1.113 +	CTWin::Delete(iWin);
   1.114 +	}
   1.115 +
   1.116 +void TScaleTest::ConstructL()
   1.117 +	{
   1.118 +	CScaleWindow *win=new(ELeave) CScaleWindow(this);
   1.119 +	win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup,*Client()->iGc);
   1.120 +	iWin=win;
   1.121 +	Client()->iGroup->SetCurrentWindow(iWin);
   1.122 +	}
   1.123 +
   1.124 +TestState TScaleTest::DoTestL()
   1.125 +	{
   1.126 +	switch(iState)
   1.127 +		{
   1.128 +		case 0:
   1.129 +			LogSubTest(_L("Scale 1"),1);
   1.130 +			CActiveScheduler::Start();
   1.131 +			iState++;
   1.132 +			break;
   1.133 +		default:
   1.134 +			return(EFinished);
   1.135 +		}
   1.136 +	return(ENext);
   1.137 +	}
   1.138 +