os/graphics/windowing/windowserver/test/t_stress/src/coordinatewin.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent
    20 */
    21 
    22 #include "coordinatewin.h"
    23 #include "utils.h"
    24 
    25 const TInt KRegionSize = 3;
    26 
    27 
    28 //static configuration data, definitions and default assignments
    29 TBool CCoordinateWin::iEnabled = ETrue;
    30 TBool CCoordinateWin::iTransparent = ETrue;
    31 
    32 
    33 /**
    34 COORDINATE SPACE WIN
    35 */
    36 CCoordinateWin* CCoordinateWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
    37 	{
    38 	CCoordinateWin* self = new (ELeave) CCoordinateWin(aWs, aGroup, aParent, aGc);
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL();
    41 	return self;
    42 	}
    43 
    44 void CCoordinateWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
    45 	{
    46 	aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
    47 	aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
    48 	}
    49 
    50 CCoordinateWin::CCoordinateWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) :
    51 	CCompWin(aWs, aGroup, aParent, aGc)
    52 	{
    53 	}
    54 
    55 CCoordinateWin::~CCoordinateWin()
    56 	{
    57 	}
    58 
    59 void CCoordinateWin::ConstructL()
    60 	{
    61 	CCompWin::PreConstructL(iTransparent);
    62 	
    63 	CCompWin::PostConstructL();
    64 	}
    65 
    66 void CCoordinateWin::SetSize(const TSize & aSize)
    67 	{
    68 	CCompWin::SetSize(aSize);
    69 
    70 	TPoint mid(iSize.iWidth / 2, iSize.iHeight / 2);
    71 	iSegments[0].iBoundingRect.SetRect(TPoint(0,0), mid);
    72 	iSegments[1].iBoundingRect.SetRect(TPoint(mid.iX, 0), TPoint(iSize.iWidth, mid.iY));
    73 	iSegments[2].iBoundingRect.SetRect(TPoint(0,mid.iY), TPoint(mid.iX, iSize.iHeight));
    74 	iSegments[3].iBoundingRect.SetRect(mid, TPoint(iSize.iWidth, iSize.iHeight));
    75 
    76 	const TInt sizeRange = 50;
    77 	for (TInt i = 0; i < 4; ++i)
    78 		{
    79 		TSegment * seg = &iSegments[i];
    80 		do
    81 			{
    82 			seg->iRect.SetRect(seg->iBoundingRect.iTl.iX + TRnd::rnd(sizeRange), seg->iBoundingRect.iTl.iY + TRnd::rnd(sizeRange), seg->iBoundingRect.iTl.iX + TRnd::rnd(sizeRange) + sizeRange, seg->iBoundingRect.iTl.iY + TRnd::rnd(sizeRange) + sizeRange);
    83 			seg->iOrigin.SetXY(TRnd::rnd(sizeRange) - (sizeRange/2), TRnd::rnd(sizeRange) - (sizeRange/2));
    84 			seg->iClippingRegion.Clear();
    85 			for (TInt r = 0; r < KRegionSize; ++r)
    86 				{
    87 				TInt x = seg->iBoundingRect.iTl.iX + TRnd::rnd(sizeRange * 2);
    88 				TInt y = seg->iBoundingRect.iTl.iY + TRnd::rnd(sizeRange * 2);
    89 				TRect rect(x, y, x + TRnd::rnd(sizeRange / 2), y + TRnd::rnd(sizeRange / 2));
    90 				seg->iClippingRegion.AddRect(rect);
    91 				}
    92 			} while (seg->iClippingRegion.CheckError());
    93 		}	
    94 
    95 	Redraw(iSize);
    96 	}
    97 
    98 void CCoordinateWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
    99 	{
   100 	TPoint origin = iPos + aOrigin;
   101 	
   102 	TRect clip(origin, iSize);
   103 	clip.Intersection(aClip);
   104 	clip.Move(-origin);
   105 	
   106 	for (TInt s = 0; s < 4; ++s)
   107 		{
   108 		TSegment * seg = &iSegments[s];
   109 
   110 		aGc->Reset();
   111 		aGc->SetOrigin(origin);
   112 		TRect segClip(clip);
   113 		segClip.Intersection(seg->iBoundingRect);
   114 		aGc->SetClippingRect(segClip);
   115 		
   116 		aGc->SetPenStyle(CGraphicsContext::ESolidPen);
   117 		aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   118 		aGc->SetPenColor(KRgbWhite);
   119 		aGc->SetBrushColor(TRgb(0,0,0,iTransparent ? 128 : 255));
   120 		aGc->DrawRect(seg->iBoundingRect);
   121 		
   122 		aGc->SetOrigin(origin + seg->iOrigin);
   123 		aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   124 		aGc->SetBrushColor(KRgbDarkBlue);
   125 		aGc->SetPenColor(KRgbBlue);
   126 		aGc->DrawEllipse(seg->iRect);
   127 
   128 		aGc->SetOrigin(origin);
   129 		aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
   130 		aGc->SetPenColor(KRgbGreen);
   131 		DrawRegion(seg->iClippingRegion, *aGc);
   132 		aGc->SetOrigin(origin + seg->iOrigin);
   133 		
   134 		TRegionFix<KRegionSafe> region;
   135 		region.Copy(seg->iClippingRegion);
   136 		//In CFbsBitGc::SetClippingRegion, Offset is not done on the clipping region,
   137 		//This is different with CWsGc::SetClippingRegion. Need to call the Offset here.
   138 		region.Offset(origin + seg->iOrigin);
   139 		region.ClipRect(TRect(TPoint(0,0), aGc->Device()->SizeInPixels()));
   140 		
   141 		if (region.CheckError())
   142 			{
   143 			__DEBUGGER();
   144 			}
   145 		
   146 		aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   147 		aGc->SetBrushColor(KRgbDarkRed);
   148 		aGc->SetPenColor(KRgbRed);
   149 		
   150 		if (!region.IsEmpty())
   151 			{
   152 			aGc->SetClippingRegion(&region);
   153 			aGc->DrawEllipse(seg->iRect);
   154 			aGc->CancelClippingRegion();
   155 			}
   156 
   157 		TRect rect(seg->iRect);
   158 		rect.Shrink(8,8);
   159 		aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
   160 		aGc->DrawEllipse(rect);
   161 		}
   162 	
   163 	CCompWin::DrawBitmap(aGc, aClip, aOrigin);
   164 	}	
   165 
   166 void CCoordinateWin::Redraw(const TRect&)
   167 	{
   168 	iWsGc.Activate(*iWindow);
   169 	for (TInt s = 0; s < 4; ++s)
   170 		{
   171 		TSegment * seg = &iSegments[s];
   172 
   173 		iWsGc.Reset();
   174 
   175 		iRedrawWindow->BeginRedraw(seg->iBoundingRect);
   176 
   177 		iWsGc.SetPenStyle(CGraphicsContext::ESolidPen);
   178 		iWsGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
   179 		iWsGc.SetPenColor(KRgbWhite);
   180 		iWsGc.SetBrushColor(TRgb(0,0,0,iTransparent ? 128 : 255)); //if transparency not set this will be opaque
   181 		iWsGc.DrawRect(seg->iBoundingRect);
   182 
   183 		iWsGc.SetOrigin(seg->iOrigin);
   184 
   185 		iWsGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
   186 		iWsGc.SetBrushColor(KRgbDarkBlue);
   187 		iWsGc.SetPenColor(KRgbBlue);
   188 		iWsGc.DrawEllipse(seg->iRect);
   189 
   190 		iWsGc.SetOrigin(TPoint(0,0));
   191 		iWsGc.SetBrushStyle(CGraphicsContext::ENullBrush);
   192 		iWsGc.SetPenColor(KRgbGreen);
   193 		DrawRegion(seg->iClippingRegion, iWsGc);
   194 		iWsGc.SetOrigin(seg->iOrigin);
   195 
   196 		//In CWsGc::SetClippingRegion, clipping region is offset based on the CWsGc::iOrigin.
   197 		iWsGc.SetClippingRegion(seg->iClippingRegion);
   198 		
   199 		iWsGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
   200 		iWsGc.SetBrushColor(KRgbDarkRed);
   201 		iWsGc.SetPenColor(KRgbRed);
   202 		iWsGc.DrawEllipse(seg->iRect);
   203 		
   204 		iWsGc.CancelClippingRegion();
   205 		
   206 		TRect rect(seg->iRect);
   207 		rect.Shrink(8,8);
   208 		iWsGc.SetBrushStyle(CGraphicsContext::ENullBrush);
   209 		iWsGc.DrawEllipse(rect);
   210 		iRedrawWindow->EndRedraw();
   211 		}
   212 	iWsGc.Deactivate();
   213 	}
   214 
   215 void CCoordinateWin::DumpDetails(RFile& aFile, TInt aDepth)
   216 	{
   217 	TBuf8<256> buf;
   218 	buf.SetLength(0);
   219 	for (TInt d = 0; d < aDepth; ++d)
   220 		{
   221 		buf.Append(_L8("  "));
   222 		}
   223 	buf.Append(_L8("Transparent = ["));
   224 	buf.AppendNum((TInt64)iTransparent);
   225 	buf.Append(_L8("]\r\n"));
   226 	aFile.Write(buf);
   227 	}