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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include "coordinatewin.h"
25 const TInt KRegionSize = 3;
28 //static configuration data, definitions and default assignments
29 TBool CCoordinateWin::iEnabled = ETrue;
30 TBool CCoordinateWin::iTransparent = ETrue;
36 CCoordinateWin* CCoordinateWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
38 CCoordinateWin* self = new (ELeave) CCoordinateWin(aWs, aGroup, aParent, aGc);
39 CleanupStack::PushL(self);
44 void CCoordinateWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
46 aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
47 aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
50 CCoordinateWin::CCoordinateWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) :
51 CCompWin(aWs, aGroup, aParent, aGc)
55 CCoordinateWin::~CCoordinateWin()
59 void CCoordinateWin::ConstructL()
61 CCompWin::PreConstructL(iTransparent);
63 CCompWin::PostConstructL();
66 void CCoordinateWin::SetSize(const TSize & aSize)
68 CCompWin::SetSize(aSize);
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));
76 const TInt sizeRange = 50;
77 for (TInt i = 0; i < 4; ++i)
79 TSegment * seg = &iSegments[i];
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)
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);
92 } while (seg->iClippingRegion.CheckError());
98 void CCoordinateWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
100 TPoint origin = iPos + aOrigin;
102 TRect clip(origin, iSize);
103 clip.Intersection(aClip);
106 for (TInt s = 0; s < 4; ++s)
108 TSegment * seg = &iSegments[s];
111 aGc->SetOrigin(origin);
113 segClip.Intersection(seg->iBoundingRect);
114 aGc->SetClippingRect(segClip);
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);
122 aGc->SetOrigin(origin + seg->iOrigin);
123 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
124 aGc->SetBrushColor(KRgbDarkBlue);
125 aGc->SetPenColor(KRgbBlue);
126 aGc->DrawEllipse(seg->iRect);
128 aGc->SetOrigin(origin);
129 aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
130 aGc->SetPenColor(KRgbGreen);
131 DrawRegion(seg->iClippingRegion, *aGc);
132 aGc->SetOrigin(origin + seg->iOrigin);
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()));
141 if (region.CheckError())
146 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
147 aGc->SetBrushColor(KRgbDarkRed);
148 aGc->SetPenColor(KRgbRed);
150 if (!region.IsEmpty())
152 aGc->SetClippingRegion(®ion);
153 aGc->DrawEllipse(seg->iRect);
154 aGc->CancelClippingRegion();
157 TRect rect(seg->iRect);
159 aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
160 aGc->DrawEllipse(rect);
163 CCompWin::DrawBitmap(aGc, aClip, aOrigin);
166 void CCoordinateWin::Redraw(const TRect&)
168 iWsGc.Activate(*iWindow);
169 for (TInt s = 0; s < 4; ++s)
171 TSegment * seg = &iSegments[s];
175 iRedrawWindow->BeginRedraw(seg->iBoundingRect);
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);
183 iWsGc.SetOrigin(seg->iOrigin);
185 iWsGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
186 iWsGc.SetBrushColor(KRgbDarkBlue);
187 iWsGc.SetPenColor(KRgbBlue);
188 iWsGc.DrawEllipse(seg->iRect);
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);
196 //In CWsGc::SetClippingRegion, clipping region is offset based on the CWsGc::iOrigin.
197 iWsGc.SetClippingRegion(seg->iClippingRegion);
199 iWsGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
200 iWsGc.SetBrushColor(KRgbDarkRed);
201 iWsGc.SetPenColor(KRgbRed);
202 iWsGc.DrawEllipse(seg->iRect);
204 iWsGc.CancelClippingRegion();
206 TRect rect(seg->iRect);
208 iWsGc.SetBrushStyle(CGraphicsContext::ENullBrush);
209 iWsGc.DrawEllipse(rect);
210 iRedrawWindow->EndRedraw();
215 void CCoordinateWin::DumpDetails(RFile& aFile, TInt aDepth)
219 for (TInt d = 0; d < aDepth; ++d)
221 buf.Append(_L8(" "));
223 buf.Append(_L8("Transparent = ["));
224 buf.AppendNum((TInt64)iTransparent);
225 buf.Append(_L8("]\r\n"));