examples/AppFramework/Clock/ClockExample_AppView.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "ClockExample.h"
00017 
00018 
00019 // Menu operations
00020 void CExampleAppView::DoExperimentL( TInt aCommand )
00021         {
00022 
00023         if( aCommand < ETestDo10 )
00024                 {
00025                 // Digital clock commands
00026                 switch( aCommand )
00027                         {
00028                 case ETestDo0:
00029                         iDigitalClockPosition.iX -= 5;
00030                         iDigitalClock->SetPosition( iDigitalClockPosition );
00031                         break;
00032                         
00033                 case ETestDo1:
00034                         iDigitalClockPosition.iX += 5;
00035                         iDigitalClock->SetPosition( iDigitalClockPosition );
00036                         break;
00037                         
00038                 case ETestDo2:
00039                         iDigitalClock->SetVisible( EFalse );
00040                         break;
00041 
00042                 case ETestDo3:
00043                         iAnalogClock->SetVisible( EFalse );
00044                         iDigitalClock->SetVisible( ETrue );                     
00045                         break;
00046 
00047                 case ETestDo4:
00048                         iDigitalClockUniversalTimeOffset += ( EUTOffsetOneHour );
00049                         iDigitalClock->SetUniversalTimeOffset( iDigitalClockUniversalTimeOffset );
00050                         break;
00051                 case ETestDo5:
00052                         iDigitalClockUniversalTimeOffset += ( EUTOffsetHalfHour );
00053                         iDigitalClock->SetUniversalTimeOffset( iDigitalClockUniversalTimeOffset );
00054                         break;
00055                         
00056                 case ETestDo6:
00057                         iDigitalClockUniversalTimeOffset += ( EUTOffsetOneMinute );
00058                         iDigitalClock->SetUniversalTimeOffset( iDigitalClockUniversalTimeOffset );
00059                         break;
00060 
00061                 case ETestDo7:
00062                         iDigitalClockUniversalTimeOffset += ( EUTOffsetOneSecond );
00063                         iDigitalClock->SetUniversalTimeOffset( iDigitalClockUniversalTimeOffset );
00064                         break;
00065                                                                         
00066                 default:
00067                         break;  
00068                         }
00069                 }
00070         else
00071                 {
00072                 // Analogue clock commands
00073                 switch( aCommand )
00074                         {
00075                                 
00076                 case ETestDo10:
00077                         iAnalogClockPosition.iX -= 5;
00078                         iAnalogClock->SetPosition( iAnalogClockPosition );              
00079                         break;
00080                         
00081                 case ETestDo11:
00082                         iAnalogClockPosition.iX += 5;
00083                         iAnalogClock->SetPosition( iAnalogClockPosition );              
00084                         break;
00085                         
00086                 case ETestDo12: 
00087                         iAnalogClock->SetVisible( EFalse );
00088                         break;
00089 
00090                 case ETestDo13:
00091                         iDigitalClock->SetVisible( EFalse );
00092                         iAnalogClock->SetVisible( ETrue );
00093                         break;
00094 
00095                 case ETestDo14:
00096                         iAnalogClockUniversalTimeOffset += ( EUTOffsetOneHour );
00097                         iAnalogClock->SetUniversalTimeOffset( iAnalogClockUniversalTimeOffset );                
00098                         break;
00099 
00100                 case ETestDo15:
00101                         iAnalogClockUniversalTimeOffset += ( EUTOffsetHalfHour );
00102                         iAnalogClock->SetUniversalTimeOffset( iAnalogClockUniversalTimeOffset );                
00103                         break;
00104                         
00105                 case ETestDo16:
00106                         iAnalogClockUniversalTimeOffset += ( EUTOffsetOneMinute );
00107                         iAnalogClock->SetUniversalTimeOffset( iAnalogClockUniversalTimeOffset );                
00108                         break;
00109                         
00110                 case ETestDo17:
00111                         iAnalogClockUniversalTimeOffset += ( EUTOffsetOneSecond );
00112                         iAnalogClock->SetUniversalTimeOffset( iAnalogClockUniversalTimeOffset );                
00113                         break;                  
00114                         
00115                 default:
00116                         break;  
00117                         }
00118                 }
00119         }
00120 
00121 // Construct an Analog clock
00122 void CExampleAppView::ConstructAnalogClockL()
00123         {
00124         
00125         iAnalogClockPosition.SetXY( 150, 20 );
00126         iAnalogClockSize.SetSize( 300, 222 );
00127         iAnalogClockUniversalTimeOffset = EUTOffsetBangalore;
00128         
00129         CWsScreenDevice* screenDevice = iCoeEnv->ScreenDevice();
00130         
00131         // Set the margins for cropping the picture
00132         TMargins margins;
00133         margins.iLeft = 50;
00134         margins.iRight = 50;
00135         margins.iTop = 50;
00136         margins.iBottom = 50;
00137         
00138         // Set shadow for analog clock
00139         STimeDeviceShadow  analogClockShadow;
00140         analogClockShadow.iIsOn = ETrue;
00141         analogClockShadow.iColor = KRgbGray;
00142         analogClockShadow.iOffset.SetXY( 3, 3 );
00143 
00144         // Load the bitmap image of an analog clock 
00145         CFbsBitmap* analogClockDial=new( ELeave ) CFbsBitmap;
00146         CleanupStack::PushL( analogClockDial );
00147         User::LeaveIfError( analogClockDial->Load( KMyMBS, CLOCK ) );
00148         analogClockDial->SetSizeInTwips( screenDevice );
00149         
00150         
00151         CFbsBitmap* analogClockDialMask = new( ELeave ) CFbsBitmap;
00152         CleanupStack::PushL( analogClockDialMask );
00153         User::LeaveIfError( analogClockDialMask->Load(KMyMBS, CLOCKMSK) );
00154         analogClockDialMask->SetSizeInTwips( screenDevice );
00155 
00156         // Create an analog clock
00157         iAnalogClock=new( ELeave ) RAnalogClock( iAnimDll, Window() );
00158         iAnalogClock->ConstructL( TTimeIntervalSeconds( iAnalogClockUniversalTimeOffset ), iAnalogClockPosition, 
00159                                                           iAnalogClockSize, margins, analogClockShadow,
00160                                                           analogClockDial->Handle(), analogClockDialMask->Handle(), 3 );
00161 
00162 
00163         // Set the hour hand 
00164         TAnalogDisplayHand analogClockHourHand(EAnalogDisplayHandOneRevPer12Hours);
00165         analogClockHourHand.AddLine(CGraphicsContext::ESolidPen, KRgbBlack, TSize(4, 4), TPoint(0, 10), TPoint(0, -55));
00166         iAnalogClock->AddHandL(analogClockHourHand);
00167 
00168         // Set the minute hand
00169         TAnalogDisplayHand analogClockMinuteHand(EAnalogDisplayHandOneRevPerHour);
00170         analogClockMinuteHand.AddLine(CGraphicsContext::ESolidPen, KRgbBlack, TSize(3, 3), TPoint(0, 10), TPoint(0, -87));
00171         iAnalogClock->AddHandL(analogClockMinuteHand);
00172 
00173         // Set the second hand
00174         TAnalogDisplayHand analogClockSecondsHand(EAnalogDisplayHandOneRevPerMinute);
00175         analogClockSecondsHand.AddLine( CGraphicsContext::ESolidPen, KRgbBlack, TSize(1, 1), TPoint(0, 10), TPoint(0, -90) );
00176         iAnalogClock->AddHandL(analogClockSecondsHand); 
00177         
00178         CleanupStack::PopAndDestroy(); // analogClockDialMask
00179         CleanupStack::PopAndDestroy(); // analogClockDial
00180                 
00181         iAnalogClock->SetVisible( ETrue );      
00182         }
00183         
00184         
00185 // Construct a Digital clock
00186 void CExampleAppView::ConstructDigitalClockL()
00187         {
00188         iDigitalClockPosition.SetXY( 200, 100 );
00189         iDigitalClockSize.SetSize( 200, 70 );
00190         iDigitalClockUniversalTimeOffset = EUTOffsetBangalore;
00191                 
00192         CWsScreenDevice* screenDevice = iCoeEnv->ScreenDevice();
00193         
00194         // Set the margins for cropping the picture
00195         TMargins margins;
00196         margins.iLeft = 50;
00197         margins.iRight = 50;
00198         margins.iTop = 50;
00199         margins.iBottom = 50;
00200         
00201         // Set shadow for digital clock
00202         STimeDeviceShadow digitalClockShadow;
00203         digitalClockShadow.iIsOn = ETrue;
00204         digitalClockShadow.iColor = KRgbGray;
00205         digitalClockShadow.iOffset.SetXY( 3, 3 );
00206 
00207         iDigitalClock = new(ELeave) RDigitalClock( iAnimDll, Window() );
00208         iDigitalClock->ConstructL( TTimeIntervalSeconds( iDigitalClockUniversalTimeOffset ), iDigitalClockPosition, iDigitalClockSize, margins, digitalClockShadow, TRgb(170, 170, 170),/*1*/ 2 );
00209 
00210         CDestructableFont* digitalClockFont = new( ELeave ) CDestructableFont( screenDevice );
00211         CleanupStack::PushL( digitalClockFont );
00212         
00213         _LIT(KArial,"arial");
00214         TFontSpec digitalClockFontSpec( KArial, screenDevice->VerticalPixelsToTwips(25) );
00215         digitalClockFontSpec.iFontStyle.SetPosture( EPostureItalic );
00216         digitalClockFontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightBold );
00217         
00218         digitalClockFont->ConstructL( digitalClockFontSpec );
00219         
00220         // Set the time format
00221         _LIT(KDigitalClockTimeFormat,"%-B%J%:1%T:%S% %+B");
00222         iDigitalClock->AddTextSectionL( TDigitalDisplayTextSection(digitalClockFont->Handle(), TRgb(0, 0, 0),
00223                                                                                                                                 EDigitalDisplayHorizontalTextAlignmentLeft,
00224                                                                                                                                 EDigitalDisplayVerticalTextAlignmentTop,
00225                                                                                                                                 30, 15, KDigitalClockTimeFormat) );
00226 
00227         // Set the date format
00228         _LIT(KDigitalClockDateFormat,"%*E %F%*D %Y");
00229         iDigitalClock->AddTextSectionL( TDigitalDisplayTextSection(digitalClockFont->Handle(), TRgb(0, 0, 0),
00230                                                                                                                                 EDigitalDisplayHorizontalTextAlignmentLeft,
00231                                                                                                                                 EDigitalDisplayVerticalTextAlignmentBottomExclDescent,
00232                                                                                                                                 30, 15, KDigitalClockDateFormat) );
00233 
00234 
00235         CleanupStack::PopAndDestroy(); // digitalClockFont
00236         
00237         iDigitalClock->SetBackgroundColor( KRgbDarkGray, KRgbBlack );
00238         iDigitalClock->SetTextColor( KRgbWhite );
00239         iDigitalClock->SetVisible( EFalse );
00240         }
00241 
00242 
00243 CExampleAppView::CExampleAppView()
00244 : iAnimDll( iCoeEnv->WsSession() )
00245         {}
00246 
00247 // Static function wraps up two-phase construction for the view.
00248 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
00249         {
00250         CExampleAppView* self = new(ELeave) CExampleAppView();
00251         CleanupStack::PushL(self);
00252         self->ConstructL(aRect);
00253         CleanupStack::Pop();
00254         return self;
00255         }
00256 
00257 CExampleAppView::~CExampleAppView()
00258         {
00259         delete iTextBuffer;
00260         delete iAnalogClock;
00261         delete iDigitalClock;
00262                 
00263         iAnimDll.Close();
00264         }
00265 
00266 // Standard initialisation for a window-owning control.
00267 void CExampleAppView::ConstructL( const TRect& aRect )
00268     {
00269         // Fetch the text from the resource file.
00270         iTextBuffer = iEikonEnv->AllocReadResourceL( R_TITLE_TEXT_CLOCK_EXAMPLE );
00271 
00272    
00273         // Create the window owned by the view.
00274         CreateWindowL();
00275         // Set the view's size and position.
00276         SetRect(aRect);
00277         // Activate the view.
00278         ActivateL();
00279         
00280         _LIT(KClockDll,"CLOCKA.DLL");
00281         User::LeaveIfError( iAnimDll.Load(KClockDll) );
00282         
00283         ConstructDigitalClockL();
00284         ConstructAnalogClockL();
00285         }
00286 
00287 // Draws the view with a simple outline rectangle and then
00288 // draws the welcome text centred.
00289 void CExampleAppView::Draw(const TRect& /*aRect*/) const
00290         {
00291         const TRect rect = Rect();
00292         CWindowGc& gc = SystemGc();
00293                 
00294         // Font used for drawing text
00295         const CFont*     fontUsed;
00296         // Use the title font supplied by the UI
00297         fontUsed = iEikonEnv->TitleFont();
00298         gc.UseFont( fontUsed );
00299 
00300         // Draw the title text.
00301         gc.DrawText( *iTextBuffer, rect, 
00302                                  0+ fontUsed->HeightInPixels(), 
00303                                  CGraphicsContext::ECenter, 0 );
00304         
00305         gc.DiscardFont();
00306         }
00307 
00308 
00309 CDestructableFont::CDestructableFont(CWsScreenDevice* aScreenDevice)
00310         :iScreenDevice(aScreenDevice)
00311         {}
00312 
00313 void CDestructableFont::ConstructL(const TFontSpec& aFontSpec)
00314         {
00315         User::LeaveIfError(iScreenDevice->GetNearestFontInTwips((CFont*&)iFont, aFontSpec));
00316         }
00317 
00318 CDestructableFont::~CDestructableFont()
00319         {
00320         iScreenDevice->ReleaseFont(iFont); 
00321         }
00322 
00323 TInt CDestructableFont::Handle() const
00324         {
00325         return iFont->Handle();
00326         }

Generated by  doxygen 1.6.2