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
00034 #include "ticker.h"
00035 #include <openfont.h>
00036
00040 CTicker::CTicker(const TRect& aRect, const TDesC& aString):
00041 iRect(aRect),
00042 iString(aString)
00043 {
00044 #ifdef PORTRAIT_MODE
00045 iPos = TPoint(KFontHeight, 0);
00046 #else
00047 iPos = TPoint(aRect.iBr.iX, KFontHeight);
00048 #endif
00049 }
00050
00057 CTicker* CTicker::NewL(const TRect& aRect, const TDesC& aString)
00058 {
00059 CTicker* self = new(ELeave) CTicker(aRect, aString);
00060 CleanupStack::PushL(self);
00061 self->ConstructL();
00062 CleanupStack::Pop(self);
00063 return self;
00064 }
00065
00069 void CTicker::ConstructL()
00070 {
00071
00072 User::LeaveIfError(iWs.Connect());
00073
00074
00075 iScr = new(ELeave) CWsScreenDevice(iWs);
00076 User::LeaveIfError(iScr->Construct());
00077
00078
00079 iGc = new(ELeave) CWindowGc(iScr);
00080 User::LeaveIfError(iGc->Construct());
00081
00082
00083 iGrp = RWindowGroup(iWs);
00084 User::LeaveIfError(iGrp.Construct(0xdeadface, EFalse));
00085 iGrp.SetOrdinalPositionErr(0, 100);
00086
00087
00088 iWin = RWindow(iWs);
00089 User::LeaveIfError(iWin.Construct(iGrp, (TInt)this));
00090
00091
00092 iWin.SetTransparencyAlphaChannel();
00093
00094
00095 iWin.SetBackgroundColor(TRgb(0,0,0,0));
00096
00097
00098 iWin.SetExtent(iRect.iTl, iRect.Size());
00099
00100
00101 iWin.Activate();
00102
00103
00104 iWin.SetOrdinalPosition(-1);
00105
00106
00107 iWin.SetVisible(EFalse);
00108
00109
00110 iWs.Flush();
00111
00112
00113 TOpenFontSpec openSpec;
00114
00115
00116 openSpec.SetBitmapType(EAntiAliasedGlyphBitmap);
00117
00118
00119 TFontSpec fs;
00120
00121
00122 openSpec.GetTFontSpec(fs);
00123
00124
00125 fs.iTypeface.iName = _L("SwissA");
00126 fs.iHeight = KFontHeight;
00127
00128
00129 User::LeaveIfError(iScr->GetNearestFontInPixels(iFont, fs));
00130 iLen = iFont->TextWidthInPixels(iString);
00131
00132
00133 iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
00134 }
00135
00139 CTicker::~CTicker()
00140 {
00141 Stop();
00142 delete iTimer;
00143 if(iScr)
00144 {
00145
00146 iScr->ReleaseFont(iFont);
00147 }
00148 delete iGc;
00149 delete iScr;
00150
00151
00152 iWin.Close();
00153 iGrp.Close();
00154 iWs.Close();
00155 }
00156
00160 void CTicker::Start()
00161 {
00162
00163 iWin.SetVisible(ETrue);
00164 if (!iTimer->IsActive())
00165 {
00166
00167 iTimer->Start(0, 20*1000, TCallBack(CTicker::OnTick, this));
00168 }
00169 }
00170
00174 void CTicker::Stop()
00175 {
00176
00177 iWin.SetVisible(EFalse);
00178
00179
00180 iWs.Flush();
00181
00182
00183 iTimer->Cancel();
00184 }
00185
00189 TInt CTicker::OnTick(TAny* aArg)
00190 {
00191 CTicker* self = (CTicker*)aArg;
00192
00193
00194 self->iWin.Invalidate();
00195
00196
00197 self->iWin.BeginRedraw();
00198
00199
00200 self->iGc->Activate(self->iWin);
00201 self->Draw();
00202
00203
00204 self->iGc->Deactivate();
00205
00206
00207 self->iWin.EndRedraw();
00208
00209
00210 self->iWs.Flush();
00211
00212 return 0;
00213 }
00214
00218 TBool CTicker::Draw()
00219 {
00220 #ifdef PORTRAIT_MODE
00221 ++iPos.iY;
00222
00223 if (iPos.iY > iLen)
00224 {
00225 iPos.iY = 0;
00226 return ETrue;
00227 }
00228 #else
00229 --iPos.iX;
00230
00231 if (iPos.iX < -iLen)
00232 {
00233 iPos.iX = iRect.iBr.iX;
00234 return ETrue;
00235 }
00236
00237 #endif
00238
00239
00240 iGc->SetPenSize(TSize(1,1));
00241
00242
00243 iGc->SetPenColor(TRgb(255,255,255,255));
00244
00245
00246 iGc->SetPenStyle(CGraphicsContext::ESolidPen);
00247
00248
00249 iGc->UseFont(iFont);
00250
00251 #ifdef PORTRAIT_MODE
00252 iGc->DrawTextVertical(iString, iPos, ETrue);
00253 #else
00254 iGc->DrawText(iString, iPos);
00255 #endif
00256
00257
00258 iGc->DiscardFont();
00259
00260 return EFalse;
00261 }