00001
00002
00003
00004
00010 #include "ticker.h"
00011 #include <openfont.h>
00012
00016 CTicker::CTicker(const TRect& aRect, const TDesC& aString):
00017 iRect(aRect),
00018 iString(aString)
00019 {
00020 #ifdef PORTRAIT_MODE
00021 iPos = TPoint(KFontHeight, 0);
00022 #else
00023 iPos = TPoint(aRect.iBr.iX, KFontHeight);
00024 #endif
00025 }
00026
00033 CTicker* CTicker::NewL(const TRect& aRect, const TDesC& aString)
00034 {
00035 CTicker* self = new(ELeave) CTicker(aRect, aString);
00036 CleanupStack::PushL(self);
00037 self->ConstructL();
00038 CleanupStack::Pop(self);
00039 return self;
00040 }
00041
00045 void CTicker::ConstructL()
00046 {
00047
00048 User::LeaveIfError(iWs.Connect());
00049
00050
00051 iScr = new(ELeave) CWsScreenDevice(iWs);
00052 User::LeaveIfError(iScr->Construct());
00053
00054
00055 iGc = new(ELeave) CWindowGc(iScr);
00056 User::LeaveIfError(iGc->Construct());
00057
00058
00059 iGrp = RWindowGroup(iWs);
00060 User::LeaveIfError(iGrp.Construct(0xdeadface, EFalse));
00061 iGrp.SetOrdinalPositionErr(0, 100);
00062
00063
00064 iWin = RWindow(iWs);
00065 User::LeaveIfError(iWin.Construct(iGrp, (TInt)this));
00066
00067
00068 iWin.SetTransparencyAlphaChannel();
00069
00070
00071 iWin.SetBackgroundColor(TRgb(0,0,0,0));
00072
00073
00074 iWin.SetExtent(iRect.iTl, iRect.Size());
00075
00076
00077 iWin.Activate();
00078
00079
00080 iWin.SetOrdinalPosition(-1);
00081
00082
00083 iWin.SetVisible(EFalse);
00084
00085
00086 iWs.Flush();
00087
00088
00089 TOpenFontSpec openSpec;
00090
00091
00092 openSpec.SetBitmapType(EAntiAliasedGlyphBitmap);
00093
00094
00095 TFontSpec fs;
00096
00097
00098 openSpec.GetTFontSpec(fs);
00099
00100
00101 fs.iTypeface.iName = _L("SwissA");
00102 fs.iHeight = KFontHeight;
00103
00104
00105 User::LeaveIfError(iScr->GetNearestFontInPixels(iFont, fs));
00106 iLen = iFont->TextWidthInPixels(iString);
00107
00108
00109 iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
00110 }
00111
00115 CTicker::~CTicker()
00116 {
00117 Stop();
00118 delete iTimer;
00119 if(iScr)
00120 {
00121
00122 iScr->ReleaseFont(iFont);
00123 }
00124 delete iGc;
00125 delete iScr;
00126
00127
00128 iWin.Close();
00129 iGrp.Close();
00130 iWs.Close();
00131 }
00132
00136 void CTicker::Start()
00137 {
00138
00139 iWin.SetVisible(ETrue);
00140 if (!iTimer->IsActive())
00141 {
00142
00143 iTimer->Start(0, 20*1000, TCallBack(CTicker::OnTick, this));
00144 }
00145 }
00146
00150 void CTicker::Stop()
00151 {
00152
00153 iWin.SetVisible(EFalse);
00154
00155
00156 iWs.Flush();
00157
00158
00159 iTimer->Cancel();
00160 }
00161
00165 TInt CTicker::OnTick(TAny* aArg)
00166 {
00167 CTicker* self = (CTicker*)aArg;
00168
00169
00170 self->iWin.Invalidate();
00171
00172
00173 self->iWin.BeginRedraw();
00174
00175
00176 self->iGc->Activate(self->iWin);
00177 self->Draw();
00178
00179
00180 self->iGc->Deactivate();
00181
00182
00183 self->iWin.EndRedraw();
00184
00185
00186 self->iWs.Flush();
00187
00188 return 0;
00189 }
00190
00194 TBool CTicker::Draw()
00195 {
00196 #ifdef PORTRAIT_MODE
00197 ++iPos.iY;
00198
00199 if (iPos.iY > iLen)
00200 {
00201 iPos.iY = 0;
00202 return ETrue;
00203 }
00204 #else
00205 --iPos.iX;
00206
00207 if (iPos.iX < -iLen)
00208 {
00209 iPos.iX = iRect.iBr.iX;
00210 return ETrue;
00211 }
00212
00213 #endif
00214
00215
00216 iGc->SetPenSize(TSize(1,1));
00217
00218
00219 iGc->SetPenColor(TRgb(255,255,255,255));
00220
00221
00222 iGc->SetPenStyle(CGraphicsContext::ESolidPen);
00223
00224
00225 iGc->UseFont(iFont);
00226
00227 #ifdef PORTRAIT_MODE
00228 iGc->DrawTextVertical(iString, iPos, ETrue);
00229 #else
00230 iGc->DrawText(iString, iPos);
00231 #endif
00232
00233
00234 iGc->DiscardFont();
00235
00236 return EFalse;
00237 }