windowing/windowserver/test/t_stress/src/edgedwin.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "edgedwin.h"
       
    23 #include "utils.h"
       
    24 
       
    25 	
       
    26 /**
       
    27 EDGED WIN
       
    28 */
       
    29 
       
    30 //static configuration data, definitions and default assignments
       
    31 TBool CEdgedWin::iEnabled = ETrue;
       
    32 TBool CEdgedWin::iTransparent = ETrue;
       
    33 TBool CEdgedWin::iRandomizeAlpha = EFalse;
       
    34 TBool CEdgedWin::iRandomizePenStyle = EFalse;
       
    35 TBool CEdgedWin::iRandomizeBrushStyle = EFalse;
       
    36 
       
    37 
       
    38 CEdgedWin* CEdgedWin::NewLC(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc)
       
    39 	{
       
    40 	CEdgedWin* self = new (ELeave) CEdgedWin(aWs, aGroup, aParent, aGc);
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 void CEdgedWin::LoadConfiguration(const MTestStepConfigurationContext* aContext)
       
    47 	{
       
    48 	aContext->GetBool(KT_WservStressParamEnabled, iEnabled);
       
    49 	aContext->GetBool(KT_WservStressParamTransparent, iTransparent);
       
    50 	aContext->GetBool(KT_WservStressParamRandomizeAlpha, iRandomizeAlpha);
       
    51 	aContext->GetBool(KT_WservStressParamRandomizePenStyle, iRandomizePenStyle);
       
    52 	aContext->GetBool(KT_WservStressParamRandomizeBrushStyle, iRandomizeBrushStyle);
       
    53 	}
       
    54 
       
    55 CEdgedWin::CEdgedWin(RWsSession& aWs, RWindowGroup* aGroup, CCompWin* aParent, CWindowGc& aGc) :
       
    56 	CCompWin(aWs, aGroup, aParent, aGc)
       
    57 	{
       
    58 	}
       
    59 
       
    60 CEdgedWin::~CEdgedWin()
       
    61 	{
       
    62 	}
       
    63 
       
    64 void CEdgedWin::ConstructL()
       
    65 	{
       
    66 	CCompWin::PreConstructL(iTransparent);
       
    67 	iTransBgColor = TRnd::rnd();
       
    68 	iTransFgColor = TRnd::rnd();
       
    69 	iBgColor = TRnd::rnd();
       
    70 	iFgColor = TRnd::rnd();
       
    71 	if (!iTransparent || !iRandomizeAlpha) //randomizing the alpha will cause bitmap differences
       
    72 		{
       
    73 		iTransBgColor.SetAlpha(0xFF);
       
    74 		iTransFgColor.SetAlpha(0xFF);
       
    75 		}
       
    76 	iBgColor.SetAlpha(0xFF); //inner rectangle should not be transparent
       
    77 	iFgColor.SetAlpha(0xFF); //inner rectangle should not be transparent
       
    78 		
       
    79 	iPenStyle = iRandomizePenStyle ? GetRandomPenStyle() : CGraphicsContext::ESolidPen;
       
    80 	iBrushStyle = iRandomizeBrushStyle ? GetRandomBrushStyle() : CGraphicsContext::ESolidBrush;
       
    81 	CCompWin::PostConstructL();
       
    82 	}
       
    83 
       
    84 void CEdgedWin::SetSize(const TSize & aSize)
       
    85 	{
       
    86 	CCompWin::SetSize(aSize);
       
    87 
       
    88 	iOpaqueRect.iTl.iX = 10;
       
    89 	iOpaqueRect.iTl.iY = 10;
       
    90 	iOpaqueRect.iBr.iX = iSize.iWidth - 10;
       
    91 	iOpaqueRect.iBr.iY = iSize.iHeight - 10;
       
    92 	if (iTransparent)
       
    93 		{
       
    94 		iTransparentRegion.Clear();
       
    95 		iTransparentRegion.AddRect(TRect(TPoint(0,0), iSize));
       
    96 		iTransparentRegion.SubRect(iOpaqueRect);
       
    97 		iRedrawWindow->SetTransparentRegion(iTransparentRegion); //TRANSPARENCY must be defined in wsini.ini
       
    98 		}
       
    99 	}
       
   100 
       
   101 void CEdgedWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
       
   102 	{
       
   103 	aGc->Reset();
       
   104 	TPoint origin = iPos + aOrigin;
       
   105 	aGc->SetOrigin(origin);
       
   106 	
       
   107 	TRect clip(origin, iSize);
       
   108 	clip.Intersection(aClip);
       
   109 	clip.Move(-origin);	
       
   110 	
       
   111 	aGc->SetClippingRect(clip);
       
   112 	aGc->SetPenStyle(iPenStyle);
       
   113 	aGc->SetBrushStyle(iBrushStyle);
       
   114 	//draw outer rectangle
       
   115 	aGc->SetPenColor(iTransFgColor);
       
   116 	aGc->SetBrushColor(iTransBgColor);
       
   117 	aGc->DrawRect(TRect(TPoint(0,0), iSize));
       
   118 		
       
   119 	//draw inner rectangle
       
   120 	aGc->SetPenColor(iFgColor);
       
   121 	aGc->SetBrushColor(iBgColor);
       
   122 	aGc->DrawRect(iOpaqueRect);
       
   123 	
       
   124 	CCompWin::DrawBitmap(aGc, aClip, aOrigin);
       
   125 	}	
       
   126 
       
   127 void CEdgedWin::Redraw(const TRect& aRect)
       
   128 	{
       
   129 	iWsGc.Activate(*iWindow);
       
   130 	iWsGc.Reset();
       
   131 	iWsGc.SetPenStyle(iPenStyle);
       
   132 	iWsGc.SetBrushStyle(iBrushStyle);
       
   133 	TBool redraw = EFalse;
       
   134 	//redraw outer rectangle if in rect
       
   135 	if (aRect.iTl.iX < iOpaqueRect.iTl.iX ||
       
   136 	    aRect.iTl.iY < iOpaqueRect.iTl.iY ||
       
   137 	    aRect.iBr.iX > iOpaqueRect.iBr.iX ||
       
   138 	    aRect.iBr.iY > iOpaqueRect.iBr.iY)
       
   139 	    {
       
   140 	    redraw = ETrue;
       
   141 	    iRedrawWindow->BeginRedraw();
       
   142 		iWsGc.SetPenColor(iTransFgColor);
       
   143 		iWsGc.SetBrushColor(iTransBgColor);
       
   144 		iWsGc.DrawRect(TRect(TPoint(0,0), iSize));
       
   145 	//	iRedrawWindow->EndRedraw() will be taken care of below
       
   146 	    }
       
   147 	//redraw inner rectangle
       
   148 	if (redraw || aRect.Intersects(iOpaqueRect))
       
   149 		{
       
   150 		if (!redraw)
       
   151 			{
       
   152 			iRedrawWindow->BeginRedraw(iOpaqueRect);//iOpaqueRect);
       
   153 			}
       
   154 		iWsGc.SetPenColor(iFgColor);
       
   155 		iWsGc.SetBrushColor(iBgColor);
       
   156 		iWsGc.DrawRect(iOpaqueRect);
       
   157 		iRedrawWindow->EndRedraw();
       
   158 		}
       
   159 	iWsGc.Deactivate();
       
   160 	}
       
   161 
       
   162 void CEdgedWin::DumpDetails(RFile& aFile, TInt aDepth)
       
   163 	{
       
   164 	TBuf8<256> buf;
       
   165 	buf.SetLength(0);
       
   166 	for (TInt d = 0; d < aDepth; ++d)
       
   167 		{
       
   168 		buf.Append(_L8("  "));
       
   169 		}
       
   170 	buf.Append(_L8("Transparent = ["));
       
   171 	buf.AppendNum((TInt64)iTransparent);
       
   172 	buf.Append(_L8("] randomize_alpha = ["));
       
   173 	buf.AppendNum((TInt64)iRandomizeAlpha);
       
   174 	buf.Append(_L8("] pen_style = ["));
       
   175 	buf.AppendNum((TInt64)iPenStyle);
       
   176 	buf.Append(_L8("] brush_style = ["));
       
   177 	buf.AppendNum((TInt64)iBrushStyle);
       
   178 	buf.Append(_L8("] transFgColor = ["));
       
   179 	buf.AppendNum(iTransFgColor.Value());
       
   180 	buf.Append(_L8("] transBgColor = ["));
       
   181 	buf.AppendNum(iTransBgColor.Value());
       
   182 	buf.Append(_L8("] FgColor = ["));
       
   183 	buf.AppendNum(iFgColor.Value());
       
   184 	buf.Append(_L8("] BgColor = ["));
       
   185 	buf.AppendNum(iBgColor.Value());
       
   186 	buf.Append(_L8("]\r\n"));
       
   187 	aFile.Write(buf);
       
   188 	}