00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "ClockExample.h"
00032
00033
00034
00035 void CExampleAppView::DoExperimentL( TInt aCommand )
00036 {
00037
00038 if( aCommand < ETestDo10 )
00039 {
00040
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
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
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
00147 TMargins margins;
00148 margins.iLeft = 50;
00149 margins.iRight = 50;
00150 margins.iTop = 50;
00151 margins.iBottom = 50;
00152
00153
00154 STimeDeviceShadow analogClockShadow;
00155 analogClockShadow.iIsOn = ETrue;
00156 analogClockShadow.iColor = KRgbGray;
00157 analogClockShadow.iOffset.SetXY( 3, 3 );
00158
00159
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
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
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
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
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();
00194 CleanupStack::PopAndDestroy();
00195
00196 iAnalogClock->SetVisible( ETrue );
00197 }
00198
00199
00200
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
00210 TMargins margins;
00211 margins.iLeft = 50;
00212 margins.iRight = 50;
00213 margins.iTop = 50;
00214 margins.iBottom = 50;
00215
00216
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), 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
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
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();
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
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
00282 void CExampleAppView::ConstructL( const TRect& aRect )
00283 {
00284
00285 iTextBuffer = iEikonEnv->AllocReadResourceL( R_TITLE_TEXT_CLOCK_EXAMPLE );
00286
00287
00288
00289 CreateWindowL();
00290
00291 SetRect(aRect);
00292
00293 ActivateL();
00294
00295 _LIT(KClockDll,"CLOCKA.DLL");
00296 User::LeaveIfError( iAnimDll.Load(KClockDll) );
00297
00298 ConstructDigitalClockL();
00299 ConstructAnalogClockL();
00300 }
00301
00302
00303
00304 void CExampleAppView::Draw(const TRect& ) const
00305 {
00306 const TRect rect = Rect();
00307 CWindowGc& gc = SystemGc();
00308
00309
00310 const CFont* fontUsed;
00311
00312 fontUsed = iEikonEnv->TitleFont();
00313 gc.UseFont( fontUsed );
00314
00315
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 }