1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/windows/tflowwindowscontroller.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,181 @@
1.4 +// Copyright (c) 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 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include "tflowwindowscontroller.h"
1.26 +#include "surfaceutility.h"
1.27 +
1.28 +
1.29 +const TInt KDefaultFlowRate = -1; // by default window is moved by one pixel to the left
1.30 +//const TInt KScreenMode = 1; // Default Screen Mode (used by rotate screen)
1.31 +
1.32 +
1.33 +CTFlowWindowsController* CTFlowWindowsController::NewL (TBool aPreload, RArray<TPtrC>& aFileNames,
1.34 + TSize& aWindowSize, RArray<pTWindowCreatorFunction>& aNewLs,
1.35 + RArray<TPoint>& aInitialPositions, TBool aBouncing, TBool aMoveHorizontal /*= ETrue*/)
1.36 + {
1.37 + CTFlowWindowsController* self = new (ELeave) CTFlowWindowsController(aFileNames.Count(),
1.38 + aPreload, aWindowSize, aBouncing, aMoveHorizontal);
1.39 + CleanupStack::PushL(self);
1.40 + self->ConstructL(aFileNames, aNewLs, aInitialPositions);
1.41 + CleanupStack::Pop(self);
1.42 + return self;
1.43 + }
1.44 +
1.45 +CTFlowWindowsController::CTFlowWindowsController(TInt aNumWindows, TBool aPreload, TSize& aWindowSize,
1.46 + TBool aBouncing, TBool aMoveHorizontal) :
1.47 + iWindowSize (aWindowSize), iPreload (aPreload), iNumWindows (aNumWindows), iBouncing(aBouncing)
1.48 + {
1.49 + iScreenRect = TRect(CTWindow::GetDisplaySizeInPixels());
1.50 + // if screen is heigher than wide movement is vertical otherwise horizontal
1.51 + if (aMoveHorizontal)
1.52 + {
1.53 + iDeltaX = KDefaultFlowRate;
1.54 + iDeltaY = 0;
1.55 + }
1.56 + else
1.57 + {
1.58 + iDeltaX = 0;
1.59 + iDeltaY = KDefaultFlowRate;
1.60 + }
1.61 + }
1.62 +
1.63 +void CTFlowWindowsController::ConstructL(RArray<TPtrC>& aFileNames,
1.64 + RArray<pTWindowCreatorFunction>& aNewLs, RArray<TPoint>& aInitialPositions)
1.65 + {
1.66 + iFileNames = aFileNames;
1.67 + // Connect to windows server session
1.68 + User::LeaveIfError(iWs.Connect());
1.69 + iScreenDev = new (ELeave) CWsScreenDevice(iWs);
1.70 + User::LeaveIfError(iScreenDev->Construct());
1.71 + iUtility = CSurfaceUtility::NewL();
1.72 +
1.73 + iWinGroup = RWindowGroup(iWs);
1.74 + // it's common to use the address of the owning object as an unique window group handle
1.75 + User::LeaveIfError(iWinGroup.Construct(reinterpret_cast<TUint32>(this)));
1.76 +
1.77 + CTWindow* flowWindow;
1.78 + for (TInt w = 0; w < iNumWindows; w++)
1.79 + {
1.80 + flowWindow = aNewLs[w](iWs, iWinGroup, aInitialPositions[w], iWindowSize);
1.81 + iWindowsRegion.AddRect(TRect(aInitialPositions[w], iWindowSize));
1.82 + CleanupStack::PushL(flowWindow);
1.83 + // always preload the first window regardless of iPreload value
1.84 + if (w == 0 || iPreload)
1.85 + {
1.86 + flowWindow->LoadL(iUtility, iFileNames[w]);
1.87 + }
1.88 + iFlowWindows.AppendL(flowWindow);
1.89 + CleanupStack::Pop(flowWindow);
1.90 + }
1.91 + }
1.92 +
1.93 +CTFlowWindowsController::~CTFlowWindowsController()
1.94 + {
1.95 + // windows needs to be deleted seperately
1.96 + for (TInt i = 0; i < iNumWindows; i++)
1.97 + {
1.98 + delete iFlowWindows[i];
1.99 + }
1.100 + iFlowWindows.Close();
1.101 + iWindowsRegion.Close();
1.102 + iWinGroup.Close();
1.103 + delete iUtility;
1.104 + delete iScreenDev;
1.105 + iWs.Close();
1.106 + }
1.107 +
1.108 +/**
1.109 +Move all Windows and draw them to the screen with the window server.
1.110 +
1.111 +*/
1.112 +void CTFlowWindowsController::MoveL()
1.113 + {
1.114 + // Prepare to move block of small windows one step in the right direction.
1.115 + // First check to see if moving them in the current direction would put them off
1.116 + // the screen. If so, change the sign of the offset to make the block move in
1.117 + // the other direction.
1.118 + if (iBouncing)
1.119 + {
1.120 + iWindowsRegion.Offset(iDeltaX, iDeltaY);
1.121 + if (!iWindowsRegion.IsContainedBy(iScreenRect))
1.122 + {
1.123 + iDeltaX = -iDeltaX;
1.124 + iDeltaY = -iDeltaY;
1.125 + iWindowsRegion.Offset(2*iDeltaX, 2*iDeltaY);
1.126 + }
1.127 + }
1.128 +
1.129 + for (TInt w = iNumWindows - 1; w >= 0; --w)
1.130 + {
1.131 + // make sure that a window has loaded it's content before it moves into the screen rectangle
1.132 + if (!iPreload)
1.133 + {
1.134 + if ((iFlowWindows[w]->CurrentPosition().iX == iWindowSize.iWidth - 1)
1.135 + || (iFlowWindows[w]->CurrentPosition().iY == iWindowSize.iHeight - 1))
1.136 + {
1.137 + iFlowWindows[w]->LoadL(iUtility, iFileNames[w]);
1.138 + }
1.139 + }
1.140 + iFlowWindows[w]->Move(iDeltaX, iDeltaY);
1.141 + iFlowWindows[w]->RenderL();
1.142 + if (!iBouncing)
1.143 + {
1.144 + if (iFlowWindows[w]->CurrentPosition().iX < -iWindowSize.iWidth * (iNumWindows - 1))
1.145 + {
1.146 + iFlowWindows[w]->SetPosition(iScreenRect.Width() - 1, 0);
1.147 + }
1.148 + if (iFlowWindows[w]->CurrentPosition().iY < -iWindowSize.iHeight * (iNumWindows - 1))
1.149 + {
1.150 + iFlowWindows[w]->SetPosition(0, iScreenRect.Height() - 1);
1.151 + }
1.152 + }
1.153 + }
1.154 + iWs.Flush();
1.155 + iWs.Finish();
1.156 + }
1.157 +
1.158 +void CTFlowWindowsController::SetWindowsVisibility(TBool aVisible)
1.159 + {
1.160 + for (TInt w = iNumWindows -1; w >= 0; --w)
1.161 + {
1.162 + iFlowWindows[w]->SetVisible(aVisible);
1.163 + }
1.164 + iWs.Flush();
1.165 + iWs.Finish();
1.166 + }
1.167 +
1.168 +/**
1.169 +Rotate the screen to a given orientation. Note that if the screen device
1.170 +and window server session used to display the image aren't used for the
1.171 +rotation then the image will disappear.
1.172 +*/
1.173 +void CTFlowWindowsController::Rotate(CFbsBitGc::TGraphicsOrientation aOrientation)
1.174 + {
1.175 + // Set new screen mode. The mode is defined in wsini_rotate_test.ini.
1.176 + //iScreenDev->SetAppScreenMode(KScreenMode);
1.177 + //iScreenDev->SetScreenMode(KScreenMode);
1.178 +
1.179 + // Set the screen orientation.
1.180 + // todo: check which mode to use
1.181 + iScreenDev->SetCurrentRotations(iScreenDev->CurrentScreenMode(), aOrientation);
1.182 + iWs.Flush();
1.183 + iWs.Finish();
1.184 + }