Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

sidplay_view.cpp

Go to the documentation of this file.
00001 // sidplay_view.cpp
00002 //
00003 // Copyright (c) 2001-2002 Alfred E. Heggestad
00004 //
00005 //    This program is free software; you can redistribute it and/or modify
00006 //    it under the terms of the GNU General Public License as published by
00007 //    the Free Software Foundation; either version 2 of the License, or
00008 //    (at your option) any later version.
00009 //
00010 
00017 #include "sidplay_view.h"
00018 #include <sidplay.rsg>
00019 
00020 // Eikon
00021 #include <eikclbd.h>
00022 
00023 //
00024 // implementation of CSidPlayerStatusView
00025 //
00026 
00027 
00028 void CSidPlayerStatusView::ConstructL(const TRect& aRect, CCoeControl* aParent)
00032         {
00033         CTOR(CSidPlayerStatusView);
00034         iParent = aParent;
00035 
00036         CreateWindowL(aParent);
00037 #if defined(__ER6__)
00038         SetRect(aRect);
00039 #else
00040         SetRectL(aRect);
00041 #endif
00042 
00043         // standard font
00044 //      iNormalFont=iEikonEnv->NormalFont();
00045         }
00046 
00047 
00048 CSidPlayerStatusView::~CSidPlayerStatusView()
00052         {
00053         DTOR(CSidPlayerStatusView);
00054         }
00055 
00056 
00057 void CSidPlayerStatusView::Draw(const TRect& /*aRect*/) const
00061         {
00062         ELOG1(_L8("CSidPlayerStatusView::Draw\n"));
00063 
00064         const TInt offset_x = 10;   // X position of e.g. "Name"
00065         const TInt offset_x2 = 100; // X position of e.g. "Commando"
00066         const TInt offset_y = 20;
00067         const TInt distance_y = 20;
00068         TInt pos_y = offset_y;
00069 
00070         sidTune& tune = ((CSidPlayAppView*)iParent)->SidPlayer()->CurrentSidTune();
00071         struct sidTuneInfo mySidInfo;
00072         tune.getInfo(mySidInfo);
00073 
00074         CWindowGc& gc = SystemGc();
00075         // surrounding rectangle
00076         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00077         gc.SetBrushColor(KRgbWhite);
00078         gc.SetPenStyle(CGraphicsContext::ESolidPen);
00079         gc.SetPenColor(KRgbBlack);
00080         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
00081 
00082         // some handy variables
00083         TBuf<128> buf;
00084         TBuf<128> rs; // for reading resources
00085 
00086         // Area in which we shall draw
00087         TRect drawRect = Rect();
00088 
00089         // Font used for drawing text
00090         const CFont* fontUsed;
00091 
00092         // UI environment
00093         CEikonEnv* eikonEnv = CEikonEnv::Static();
00094 
00095         // Start with a clear screen
00096         gc.Clear();
00097 
00098         // Draw an outline rectangle (the default pen
00099         // and brush styles ensure this) slightly
00100         // smaller than the drawing area.
00101         drawRect.Shrink(5, 5);
00102         gc.DrawRect(drawRect);
00103 
00104         // Use the title font supplied by the UI
00105         fontUsed = eikonEnv->TitleFont();
00106         gc.UseFont(fontUsed);
00107 
00108         if(mySidInfo.nameString)
00109                 {
00110                 gc.DrawText(_L("Name"), TPoint(offset_x, pos_y));
00111                 buf.Copy(TPtrC8((TUint8*)mySidInfo.nameString));
00112                 gc.DrawText(buf, TPoint(offset_x2, pos_y));
00113                 pos_y += distance_y;
00114                 }
00115 
00116         if(mySidInfo.authorString)
00117                 {
00118                 gc.DrawText(_L("Author"), TPoint(offset_x, pos_y));
00119                 buf.Copy(TPtrC8((TUint8*)mySidInfo.authorString));
00120                 gc.DrawText(buf, TPoint(offset_x2, pos_y));
00121                 pos_y += distance_y;
00122                 }
00123 
00124         if(mySidInfo.copyrightString)
00125                 {
00126                 gc.DrawText(_L("Copyright"), TPoint(offset_x, pos_y));
00127                 buf.Copy(TPtrC8((TUint8*)mySidInfo.copyrightString));
00128                 gc.DrawText(buf, TPoint(offset_x2, pos_y));
00129                 pos_y += distance_y;
00130                 }
00131 
00132         gc.DrawText(_L("Subtune"), TPoint(offset_x, pos_y));
00133         rs.Format(_L("%d/%d"), mySidInfo.currentSong, mySidInfo.songs);
00134         gc.DrawText(rs, TPoint(offset_x2, pos_y));
00135         pos_y += distance_y;
00136 
00137         // clear GC's font
00138         gc.DiscardFont();
00139         }
00140 
00141 
00142 //
00143 // implementation of CSidPlayerTimeView
00144 //
00145 
00146 
00147 TInt SidPlayerTimeViewPeriodicUpdate(TAny* aPtr)
00151         {
00152         CSidPlayerTimeView* view = (CSidPlayerTimeView*)aPtr;
00153         if(((CSidPlayAppView*)(view->iParent))->SidPlayer()->iIdlePlay)
00154                 view->DrawNow();
00155         return ETrue;
00156         }
00157 
00158 
00159 void CSidPlayerTimeView::ConstructL(const TRect& aRect, CCoeControl* aParent)
00163         {
00164         iParent = aParent;
00165 
00166         CreateWindowL(aParent);
00167 #if defined(__ER6__)
00168         SetRect(aRect);
00169 #else
00170         SetRectL(aRect);
00171 #endif
00172 
00173         iPeriodic = CPeriodic::NewL(CActive::EPriorityLow);
00174         TCallBack cb(SidPlayerTimeViewPeriodicUpdate, this);
00175         iPeriodic->Start(TTimeIntervalMicroSeconds32(0),
00176                         TTimeIntervalMicroSeconds32(500000),
00177                                 cb);
00178         }
00179 
00180 
00181 CSidPlayerTimeView::~CSidPlayerTimeView()
00185         {
00186         if(iPeriodic)
00187                 {
00188                 delete iPeriodic;
00189                 iPeriodic = NULL;
00190                 }
00191         }
00192 
00193 
00194 void CSidPlayerTimeView::Draw(const TRect& /*aRect*/) const
00198         {
00199         const TInt offset_x = 10;   // X position of e.g. "Name"
00200         const TInt offset_x2 = 60; // X position of e.g. "Commando"
00201         const TInt offset_y = 20;
00202         const TInt distance_y = 20;
00203         TInt pos_y = offset_y;
00204 
00205         emuEngine* ee = ((CSidPlayAppView*)iParent)->SidPlayer()->iEmuEngine;
00206 
00207         CWindowGc& gc = SystemGc();
00208         // surrounding rectangle
00209         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00210         gc.SetBrushColor(KRgbWhite);
00211         gc.SetPenStyle(CGraphicsContext::ESolidPen);
00212         gc.SetPenColor(KRgbRed);
00213         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
00214 
00215         // some handy variables
00216         TBuf<128> buf;
00217         TBuf<128> rs; // for reading resources
00218 
00219         // Area in which we shall draw
00220         TRect drawRect = Rect();
00221 
00222         // Font used for drawing text
00223         const CFont* fontUsed;
00224 
00225         // UI environment
00226         CEikonEnv* eikonEnv = CEikonEnv::Static();
00227 
00228         // Start with a clear screen
00229         gc.Clear();
00230 
00231         // Draw an outline rectangle (the default pen
00232         // and brush styles ensure this) slightly
00233         // smaller than the drawing area.
00234         drawRect.Shrink(5, 5);
00235         gc.DrawRect(drawRect);
00236 
00237         // Use the title font supplied by the UI
00238         fontUsed = eikonEnv->TitleFont();
00239         gc.UseFont(fontUsed);
00240 
00241         gc.DrawText(_L("Time"), TPoint(offset_x, pos_y));
00242         rs.Format(_L("%d:%02d"), ee->getSecondsThisSong() / 60, ee->getSecondsThisSong() % 60);
00243         gc.DrawText(rs, TPoint(offset_x2, pos_y));
00244         pos_y += distance_y;
00245 
00246         gc.DrawText(_L("Total"), TPoint(offset_x, pos_y));
00247         rs.Format(_L("%d:%02d"), ee->getSecondsTotal() / 60, ee->getSecondsTotal() % 60);
00248         gc.DrawText(rs, TPoint(offset_x2, pos_y));
00249         pos_y += distance_y;
00250 
00251         // clear GC's font
00252         gc.DiscardFont();
00253         }
00254 
00255 
00256 //
00257 // implementation of CSidPlayAppView
00258 //
00259 
00260 
00261 void CSidPlayAppView::ConstructL(const TRect& aRect, CSidPlayer* aThePlayer)
00265         {
00266         CTOR(CSidPlayAppView);
00267 
00268         iThePlayer = aThePlayer;
00269         CreateWindowL();
00270 
00271 #if defined(__CRYSTAL__)
00272         HBufC* appName = CEikonEnv::Static()->AllocReadResourceLC(R_SIDPLAY_APPNAME);
00273 
00274         // Application title
00275         iAppTitle = CCknAppTitle::NewL();
00276         iAppTitle->SetTextL(*appName,CCknAppTitle::EMainTitle);
00277         CleanupStack::PopAndDestroy();//appName;
00278         TSize titleSize(aRect.Width(),iAppTitle->MinimumSize().iHeight);
00279         TRect titleRect(TPoint(0,0),titleSize);
00280 
00281         iAppTitle->SetRect(titleRect);
00282         iAppTitle->SetFocus(ETrue);
00283 #else
00284         TRect titleRect(TPoint(0,0), TPoint(0,0));
00285 #endif // __CRYSTAL__
00286 
00287         /*
00288          * UI layout
00289          */
00290 #if defined(__SERIES60__)
00291         const TRect status_view = TRect(1, 1, aRect.Width(), aRect.Height()-60);
00292         const TRect time_view = TRect(1, aRect.Height()-60+1, aRect.Width(), aRect.Height()-20);
00293 #else // CRYSTAL
00294         const TRect status_view = TRect(1, titleRect.Height(), 360, aRect.Height());
00295         const TRect time_view = TRect(360, titleRect.Height(), aRect.Width(), titleRect.Height()+60);
00296         const TRect volumeRect = TRect(400, titleRect.Height()+60 , aRect.Width()-1, aRect.Height()-1-20);
00297 #endif
00298 
00299 
00300         //
00301         // set up status view
00302         //
00303         iStatusView = new (ELeave) CSidPlayerStatusView;
00304         iStatusView->ConstructL(status_view, this);
00305 
00306         //
00307         // set up time view
00308         //
00309         iTimeView = new (ELeave) CSidPlayerTimeView;
00310         iTimeView->ConstructL(time_view, this);
00311 
00312 
00313         //
00314         // set up volume view
00315         //
00316 #if defined(__CRYSTAL__)
00317         CCknControlBar::SControlBarData v;
00318         v.iHeight = aRect.Width() - 1 - 441; // x
00319         v.iWidth = aRect.Height() - 1 - 81 - 20;  // y
00320         v.iFinalValue = KVolumeSteps - 1;
00321 
00322         iVolumeView = new (ELeave) CCknControlBar(v, EFalse);
00323 
00324         CleanupStack::PushL(iVolumeView);
00325         iVolumeView->SetContainerWindowL(*this);
00326         CleanupStack::Pop(iVolumeView);
00327 
00328         iVolumeView->ActivateL();
00329         iVolumeView->SetRect(volumeRect);
00330 
00331         _LIT(KVolumeIcon, "\\system\\apps\\sidplay\\e32frodo.mbm");
00332         CGulIcon* icon = iEikonEnv->CreateIconL(KVolumeIcon, 0 /* bitmap ID */);
00333         iVolumeView->SetIcon(icon,ETrue); // let the control bar own the icon
00334 
00335         const TInt vol = iThePlayer->VolumeDelta(0);
00336         iVolumeView->SetAndDraw(vol);
00337 #endif // __CRYSTAL__
00338 
00339 #if defined(__ER6__)
00340         SetRect(aRect);
00341 #else
00342         SetRectL(aRect);
00343 #endif
00344 
00345         // activate
00346         ActivateL(); // ready for drawing etc
00347         }
00348 
00349 
00350 CSidPlayAppView::~CSidPlayAppView()
00354         {
00355         DTOR(CSidPlayAppView);
00356         delete iTimeView;
00357         delete iStatusView;
00358 #if defined(__CRYSTAL__)
00359         delete iAppTitle;
00360         delete iVolumeView;
00361 #endif
00362         }
00363 
00364 
00365 void CSidPlayAppView::Draw(const TRect& /*aRect*/) const
00369         {
00370         }
00371 
00372 
00373 TKeyResponse CSidPlayAppView::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
00374         {
00375         // don't handle keys when this view is hidden
00376 //      if (!IsVisible())
00377                 return EKeyWasNotConsumed;
00378         }
00379 
00380 
00381 TInt CSidPlayAppView::CountComponentControls() const
00385         {
00386 #if defined(__CRYSTAL__)
00387         return 4;
00388 #else
00389         return 2;
00390 #endif
00391         }
00392 
00393 
00394 CCoeControl* CSidPlayAppView::ComponentControl(TInt aIndex) const
00398         {
00399         switch (aIndex)
00400                 {
00401         case 0: return iStatusView;
00402         case 1: return iTimeView;
00403 #if defined(__CRYSTAL__)
00404         case 2: return iAppTitle;
00405         case 3: return iVolumeView;
00406 #endif
00407                 }
00408         return 0;
00409         }

Generated on Tue Feb 8 04:14:13 2005 for Esidplay by doxygen 1.3.3