examples/Graphics/coverflow/src/dialogbox.cpp

Go to the documentation of this file.
00001 // dialogbox.cpp
00002 //
00003 // Copyright (c) 2005-2008 Symbian Ltd.  All rights reserved.
00004 //
00010 #include "dialogbox.h"
00011 
00015 CDialogBox::CDialogBox(const TRect& aRect):
00016         iRect(aRect)
00017         {
00018         }
00019 
00025 CDialogBox* CDialogBox::NewL(const TRect& aRect)
00026         {
00027         CDialogBox* self = new(ELeave) CDialogBox(aRect);
00028         CleanupStack::PushL(self);
00029         self->ConstructL();
00030         CleanupStack::Pop(self);
00031         return self;
00032         }
00033 
00037 void CDialogBox::ConstructL()
00038         {
00039         // Connects the client session to the window server.
00040         User::LeaveIfError(iWs.Connect());
00041         
00042         // Constructs a new screen device attached to a particular window server session.
00043         iScr = new(ELeave) CWsScreenDevice(iWs);
00044         User::LeaveIfError(iScr->Construct());
00045         
00046         // Constructs a graphics context.
00047         iGc = new(ELeave) CWindowGc(iScr);
00048         User::LeaveIfError(iGc->Construct());
00049         
00050         // Creates a sessionless, uninitialised window group handle.
00051         iGrp = RWindowGroup(iWs);
00052         User::LeaveIfError(iGrp.Construct(0xdeadface, EFalse));
00053         iGrp.SetOrdinalPositionErr(0, 100);
00054         
00055         // Creates a sessionless, uninitialised window handle.
00056         iWin = RWindow(iWs);
00057         User::LeaveIfError(iWin.Construct(iGrp, (TInt)this));
00058         
00059         // Sets the window to be transparent using the alpha channel.
00060         iWin.SetTransparencyAlphaChannel();
00061         
00062         // Sets the background colour used for clearing in server-initiated redraws.
00063         iWin.SetBackgroundColor(TRgb(0,0,0,0));
00064         
00065         // Sets the size and position of a window.
00066         iWin.SetExtent(iRect.iTl, iRect.Size());
00067         
00068         // Displays the window and enables it to receive events.
00069         iWin.Activate();
00070         
00071         // Sets the ordinal position of a window.
00072         iWin.SetOrdinalPosition(-1);
00073         
00074         // Sets the window's visibility.
00075         iWin.SetVisible(EFalse);
00076         
00077         // Sends all pending commands in the buffer to the window server.
00078         iWs.Flush();
00079         
00080         // Allocates and constructs a CPeriodic object. Assign a priority to it.
00081         iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
00082         
00083         // Appends CLoader objects in to the array.
00084         iLoaders.AppendL(CLoader::NewL(KCallBitmaps1));
00085         iLoaders.AppendL(CLoader::NewL(KCallBitmaps2));
00086         iLoaders.AppendL(CLoader::NewL(KCallBitmaps3));
00087         iLoaders.AppendL(CLoader::NewL(KCallBitmaps4));
00088         iLoaders.AppendL(CLoader::NewL(KCallBitmaps5));
00089         iLoaders.AppendL(CLoader::NewL(KCallBitmaps6));
00090 
00091         for (TInt ii=0; ii < 6; ii++)
00092                 {
00093                 iLoaders[ii]->Decode();
00094                 iCallBuffer.AppendL(iLoaders[ii]->iBitmap);
00095                 iCallBuffer.AppendL(iLoaders[ii]->iMask);
00096                 }
00097 
00098         iImageCounter = 0;
00099         iSemiTransFlag = EFalse;
00100 
00101         }
00102         
00106 CDialogBox::~CDialogBox()
00107         {
00108         Stop();
00109         delete iTimer;
00110         
00111         iCallBuffer.ResetAndDestroy();
00112         iLoaders.ResetAndDestroy();
00113 
00114         delete iGc;
00115         delete iScr;
00116         
00117         // Close the nodes.
00118         iWin.Close();
00119         iGrp.Close();
00120         iWs.Close();
00121         }
00122         
00126 void CDialogBox::Start()
00127         {
00128         // Sets the window's visibility.
00129         iWin.SetVisible(ETrue);
00130         if (!iTimer->IsActive())
00131                 {
00132                 // Starts generating periodic events. Pass the OnTick() function to call when the CPeriodic is scheduled after a timer event.
00133                 iTimer->Start(0, 150*1000, TCallBack(CDialogBox::OnTick, this));
00134                 }
00135         }
00136         
00140 void CDialogBox::Stop()
00141         {
00142         // Sets the window's visibility.
00143         iWin.SetVisible(EFalse);
00144         
00145         // Sends all pending commands in the buffer to the window server.
00146         iWs.Flush();
00147         
00148         // Cancels the wait for completion of an outstanding request.
00149         iTimer->Cancel();
00150         }
00151         
00155 TInt CDialogBox::OnTick(TAny* aArg)
00156         {
00157         CDialogBox* self = (CDialogBox*)aArg;
00158         
00159         // Invalidates the entire window.
00160         self->iWin.Invalidate();
00161         
00162         // Begins redrawing the window's invalid region
00163         self->iWin.BeginRedraw();
00164         
00165         // Activates the context for a given window 
00166         self->iGc->Activate(self->iWin);
00167         self->Draw();
00168         
00169         // Frees the graphics context to be used with another window.
00170         self->iGc->Deactivate();
00171         
00172         // Ends the current redraw.
00173         self->iWin.EndRedraw();
00174         
00175         // Sends all pending commands in the buffer to the window server.
00176         self->iWs.Flush();
00177 
00178         return 0;
00179         }
00180         
00184 TBool CDialogBox::Draw()
00185         {
00186         if(iImageCounter == 12)
00187                 iImageCounter = 0;
00188         iCallFrame = iCallBuffer[iImageCounter++];
00189         iCallMaskFrame = iCallBuffer[iImageCounter++];
00190         
00191         // Performs a masked bitmap block transfer of a memory resident source bitmap.
00192         iGc->BitBltMasked(TPoint(10,10), iCallFrame, iCallFrame->SizeInPixels(), iCallMaskFrame, EFalse);
00193 
00194         return EFalse;
00195         }
00199 void CDialogBox::SetSemiTransparency()
00200         {
00201         iWin.SetBackgroundColor(TRgb(24,255,0,128));
00202         iSemiTransFlag = ETrue;
00203         }
00204         
00208 void CDialogBox::RemoveSemiTransparency()
00209         {
00210         iWin.SetBackgroundColor(TRgb(0,0,0,0));
00211         iSemiTransFlag = EFalse;
00212         }
00213 
00217 CLoader* CLoader::NewL(const TDesC& aFn)
00218         {
00219         CLoader* self = new(ELeave) CLoader;
00220         CleanupStack::PushL(self);
00221         self->ConstructL(aFn);
00222         CleanupStack::Pop();
00223         return self;
00224         }
00225         
00229 void CLoader::ConstructL(const TDesC& aFn)
00230         {
00231         iBitmap = new(ELeave) CFbsBitmap;
00232         User::LeaveIfError(iBitmap->Load(aFn, 0));
00233 
00234         iMask = new(ELeave) CFbsBitmap;
00235         User::LeaveIfError(iMask->Load(aFn, 1));
00236 
00237 #ifdef PORTRAIT_MODE
00238         RotateL(*iBitmap);
00239         RotateL(*iMask);
00240 #endif
00241         }
00242 
00243 CLoader::CLoader()
00244         {
00245         }
00246 
00250 CLoader::~CLoader()
00251         {
00252         // no need to destroy bitmaps because caller take ownership of them
00253         }
00254 
00255 void CLoader::Decode()
00256         {
00257         }
00258 
00259 #ifdef PORTRAIT_MODE
00260 
00264 void CLoader::RotateL(CFbsBitmap& aBitmap)
00265         {
00266         CFbsBitmap* tmp = new(ELeave) CFbsBitmap;
00267         CleanupStack::PushL(tmp);
00268         
00269         // Gets the pixel-size of the bitmap. 
00270         const TSize bSz = aBitmap.SizeInPixels();
00271         
00272         // Gets the display mode of the bitmap. 
00273         const TDisplayMode bMode = aBitmap.DisplayMode();
00274         const TSize tSz(bSz.iHeight, bSz.iWidth);
00275         
00276         // Creates a bitmap with the specified size and display mode
00277         User::LeaveIfError(tmp->Create(tSz, bMode));
00278         
00279         // Gets the address of the first pixel in the bitmap
00280         TUint8* pTmp = (TUint8*)tmp->DataAddress();
00281 
00282         TInt y = tSz.iHeight - 1;
00283         TInt scanLineLength = tmp->ScanLineLength(tSz.iWidth,bMode);
00284         for (TInt x=0; x<bSz.iWidth; ++x)
00285                 {
00286                 TPtr8 buf(pTmp + (y * scanLineLength), scanLineLength);
00287                 
00288                 // Gets the bitmap's vertical scanline starting at the specified x co-ordinate.
00289                 aBitmap.GetVerticalScanLine(buf, x, bMode);
00290 
00291                 --y;
00292                 }
00293 
00294         // Swaps the bitmap's width and height.
00295         User::LeaveIfError(aBitmap.SwapWidthAndHeight());
00296         Mem::Move(aBitmap.DataAddress(), tmp->DataAddress(), scanLineLength * tSz.iHeight);
00297 
00298         CleanupStack::PopAndDestroy(tmp);
00299         }
00300 
00301 #endif

Generated by  doxygen 1.6.2