examples/Graphics/coverflow/src/dialogbox.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008 � list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010 � this list of conditions and the following disclaimer in the documentation
00011 � and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013 � may be used to endorse or promote products derived from this software
00014 � without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:� 
00028 */
00034 #include "dialogbox.h"
00035 
00039 CDialogBox::CDialogBox(const TRect& aRect):
00040         iRect(aRect)
00041         {
00042         }
00043 
00049 CDialogBox* CDialogBox::NewL(const TRect& aRect)
00050         {
00051         CDialogBox* self = new(ELeave) CDialogBox(aRect);
00052         CleanupStack::PushL(self);
00053         self->ConstructL();
00054         CleanupStack::Pop(self);
00055         return self;
00056         }
00057 
00061 void CDialogBox::ConstructL()
00062         {
00063         // Connects the client session to the window server.
00064         User::LeaveIfError(iWs.Connect());
00065         
00066         // Constructs a new screen device attached to a particular window server session.
00067         iScr = new(ELeave) CWsScreenDevice(iWs);
00068         User::LeaveIfError(iScr->Construct());
00069         
00070         // Constructs a graphics context.
00071         iGc = new(ELeave) CWindowGc(iScr);
00072         User::LeaveIfError(iGc->Construct());
00073         
00074         // Creates a sessionless, uninitialised window group handle.
00075         iGrp = RWindowGroup(iWs);
00076         User::LeaveIfError(iGrp.Construct(0xdeadface, EFalse));
00077         iGrp.SetOrdinalPositionErr(0, 100);
00078         
00079         // Creates a sessionless, uninitialised window handle.
00080         iWin = RWindow(iWs);
00081         User::LeaveIfError(iWin.Construct(iGrp, (TInt)this));
00082         
00083         // Sets the window to be transparent using the alpha channel.
00084         iWin.SetTransparencyAlphaChannel();
00085         
00086         // Sets the background colour used for clearing in server-initiated redraws.
00087         iWin.SetBackgroundColor(TRgb(0,0,0,0));
00088         
00089         // Sets the size and position of a window.
00090         iWin.SetExtent(iRect.iTl, iRect.Size());
00091         
00092         // Displays the window and enables it to receive events.
00093         iWin.Activate();
00094         
00095         // Sets the ordinal position of a window.
00096         iWin.SetOrdinalPosition(-1);
00097         
00098         // Sets the window's visibility.
00099         iWin.SetVisible(EFalse);
00100         
00101         // Sends all pending commands in the buffer to the window server.
00102         iWs.Flush();
00103         
00104         // Allocates and constructs a CPeriodic object. Assign a priority to it.
00105         iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
00106         
00107         // Appends CLoader objects in to the array.
00108         iLoaders.AppendL(CLoader::NewL(KCallBitmaps1));
00109         iLoaders.AppendL(CLoader::NewL(KCallBitmaps2));
00110         iLoaders.AppendL(CLoader::NewL(KCallBitmaps3));
00111         iLoaders.AppendL(CLoader::NewL(KCallBitmaps4));
00112         iLoaders.AppendL(CLoader::NewL(KCallBitmaps5));
00113         iLoaders.AppendL(CLoader::NewL(KCallBitmaps6));
00114 
00115         for (TInt ii=0; ii < 6; ii++)
00116                 {
00117                 iLoaders[ii]->Decode();
00118                 iCallBuffer.AppendL(iLoaders[ii]->iBitmap);
00119                 iCallBuffer.AppendL(iLoaders[ii]->iMask);
00120                 }
00121 
00122         iImageCounter = 0;
00123         iSemiTransFlag = EFalse;
00124 
00125         }
00126         
00130 CDialogBox::~CDialogBox()
00131         {
00132         Stop();
00133         delete iTimer;
00134         
00135         iCallBuffer.ResetAndDestroy();
00136         iLoaders.ResetAndDestroy();
00137 
00138         delete iGc;
00139         delete iScr;
00140         
00141         // Close the nodes.
00142         iWin.Close();
00143         iGrp.Close();
00144         iWs.Close();
00145         }
00146         
00150 void CDialogBox::Start()
00151         {
00152         // Sets the window's visibility.
00153         iWin.SetVisible(ETrue);
00154         if (!iTimer->IsActive())
00155                 {
00156                 // Starts generating periodic events. Pass the OnTick() function to call when the CPeriodic is scheduled after a timer event.
00157                 iTimer->Start(0, 150*1000, TCallBack(CDialogBox::OnTick, this));
00158                 }
00159         }
00160         
00164 void CDialogBox::Stop()
00165         {
00166         // Sets the window's visibility.
00167         iWin.SetVisible(EFalse);
00168         
00169         // Sends all pending commands in the buffer to the window server.
00170         iWs.Flush();
00171         
00172         // Cancels the wait for completion of an outstanding request.
00173         iTimer->Cancel();
00174         }
00175         
00179 TInt CDialogBox::OnTick(TAny* aArg)
00180         {
00181         CDialogBox* self = (CDialogBox*)aArg;
00182         
00183         // Invalidates the entire window.
00184         self->iWin.Invalidate();
00185         
00186         // Begins redrawing the window's invalid region
00187         self->iWin.BeginRedraw();
00188         
00189         // Activates the context for a given window 
00190         self->iGc->Activate(self->iWin);
00191         self->Draw();
00192         
00193         // Frees the graphics context to be used with another window.
00194         self->iGc->Deactivate();
00195         
00196         // Ends the current redraw.
00197         self->iWin.EndRedraw();
00198         
00199         // Sends all pending commands in the buffer to the window server.
00200         self->iWs.Flush();
00201 
00202         return 0;
00203         }
00204         
00208 TBool CDialogBox::Draw()
00209         {
00210         if(iImageCounter == 12)
00211                 iImageCounter = 0;
00212         iCallFrame = iCallBuffer[iImageCounter++];
00213         iCallMaskFrame = iCallBuffer[iImageCounter++];
00214         
00215         // Performs a masked bitmap block transfer of a memory resident source bitmap.
00216         iGc->BitBltMasked(TPoint(10,10), iCallFrame, iCallFrame->SizeInPixels(), iCallMaskFrame, EFalse);
00217 
00218         return EFalse;
00219         }
00223 void CDialogBox::SetSemiTransparency()
00224         {
00225         iWin.SetBackgroundColor(TRgb(24,255,0,128));
00226         iSemiTransFlag = ETrue;
00227         }
00228         
00232 void CDialogBox::RemoveSemiTransparency()
00233         {
00234         iWin.SetBackgroundColor(TRgb(0,0,0,0));
00235         iSemiTransFlag = EFalse;
00236         }
00237 
00241 CLoader* CLoader::NewL(const TDesC& aFn)
00242         {
00243         CLoader* self = new(ELeave) CLoader;
00244         CleanupStack::PushL(self);
00245         self->ConstructL(aFn);
00246         CleanupStack::Pop();
00247         return self;
00248         }
00249         
00253 void CLoader::ConstructL(const TDesC& aFn)
00254         {
00255         iBitmap = new(ELeave) CFbsBitmap;
00256         User::LeaveIfError(iBitmap->Load(aFn, 0));
00257 
00258         iMask = new(ELeave) CFbsBitmap;
00259         User::LeaveIfError(iMask->Load(aFn, 1));
00260 
00261 #ifdef PORTRAIT_MODE
00262         RotateL(*iBitmap);
00263         RotateL(*iMask);
00264 #endif
00265         }
00266 
00267 CLoader::CLoader()
00268         {
00269         }
00270 
00274 CLoader::~CLoader()
00275         {
00276         // no need to destroy bitmaps because caller take ownership of them
00277         }
00278 
00279 void CLoader::Decode()
00280         {
00281         }
00282 
00283 #ifdef PORTRAIT_MODE
00284 
00288 void CLoader::RotateL(CFbsBitmap& aBitmap)
00289         {
00290         CFbsBitmap* tmp = new(ELeave) CFbsBitmap;
00291         CleanupStack::PushL(tmp);
00292         
00293         // Gets the pixel-size of the bitmap. 
00294         const TSize bSz = aBitmap.SizeInPixels();
00295         
00296         // Gets the display mode of the bitmap. 
00297         const TDisplayMode bMode = aBitmap.DisplayMode();
00298         const TSize tSz(bSz.iHeight, bSz.iWidth);
00299         
00300         // Creates a bitmap with the specified size and display mode
00301         User::LeaveIfError(tmp->Create(tSz, bMode));
00302         
00303         // Gets the address of the first pixel in the bitmap
00304         TUint8* pTmp = (TUint8*)tmp->DataAddress();
00305 
00306         TInt y = tSz.iHeight - 1;
00307         TInt scanLineLength = tmp->ScanLineLength(tSz.iWidth,bMode);
00308         for (TInt x=0; x<bSz.iWidth; ++x)
00309                 {
00310                 TPtr8 buf(pTmp + (y * scanLineLength), scanLineLength);
00311                 
00312                 // Gets the bitmap's vertical scanline starting at the specified x co-ordinate.
00313                 aBitmap.GetVerticalScanLine(buf, x, bMode);
00314 
00315                 --y;
00316                 }
00317 
00318         // Swaps the bitmap's width and height.
00319         User::LeaveIfError(aBitmap.SwapWidthAndHeight());
00320         Mem::Move(aBitmap.DataAddress(), tmp->DataAddress(), scanLineLength * tSz.iHeight);
00321 
00322         CleanupStack::PopAndDestroy(tmp);
00323         }
00324 
00325 #endif

Generated by  doxygen 1.6.2