examples/AppFramework/Clock/ClockExample_AppView.cpp

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

Generated by  doxygen 1.6.2