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 "BitmapsGraphicsControl.h"
00032
00033
00034 #include <grbmap.mbg>
00035
00036
00037
00038
00039 _LIT(KTxtMBMname,"\\resource\\apps\\grbmap.mbm");
00040
00041 CFbsControl::~CFbsControl()
00042 {
00043
00044
00045 if (Phase()==1 || Phase()==7 || Phase()==8) delete(iBitmap1);
00046 if (Phase()==3 || Phase()==4) delete(iBitmap2);
00047 if (Phase()==4 || Phase()==5) delete(iBitmap3);
00048 if (Phase()==8) delete(iBitmap4);
00049 }
00050
00051
00052
00053 _LIT(KTxtUpdateModelCase0,"Load, draw and delete bitmap");
00054 _LIT(KTxtUpdateModelCase1,"Load and draw bitmap");
00055 _LIT(KTxtUpdateModelCase2,"Delete bitmap");
00056 _LIT(KTxtUpdateModelCase3,"Create bitmap2 and draw");
00057 _LIT(KTxtUpdateModelCase4,"Duplicate bitmap 2 as bitmap 3 and draw both");
00058 _LIT(KTxtUpdateModelCase5,"Delete bitmap 2, draw bitmap 3");
00059 _LIT(KTxtUpdateModelCase6,"Delete bitmap 3");
00060 _LIT(KTxtUpdateModelCase7,"Reload and draw bitmap1");
00061 _LIT(KTxtUpdateModelCase8,"Make bitmap 4 as transposed bitmap 1 and draw both");
00062 _LIT(KTxtUpdateModelCase9,"Delete bitmaps 1 and 4");
00063
00064 void CFbsControl::UpdateModelL()
00065 {
00066
00067 TBool shareIfLoaded(ETrue);
00068
00069
00070 CFbsBitmapDevice* iBitmapDevice2;
00071 CGraphicsContext* iBitmapContext2;
00072
00073 switch (Phase())
00074 {
00075 case 0:
00076
00077 iGraphObserver->NotifyStatus(KTxtUpdateModelCase0);
00078 break;
00079 case 1:
00080
00081 iBitmap1 = new (ELeave) CFbsBitmap();
00082 LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
00083 iGraphObserver->NotifyStatus(KTxtUpdateModelCase1);
00084 break;
00085 case 2:
00086
00087 delete iBitmap1;
00088 iGraphObserver->NotifyStatus(KTxtUpdateModelCase2);
00089 break;
00090 case 3:
00091
00092 iBitmap2 = new (ELeave) CFbsBitmap();
00093 iBitmap2->Create(TSize(100,100),EGray4);
00094
00095 iBitmapDevice2 = CFbsBitmapDevice::NewL(iBitmap2);
00096 iBitmapDevice2->CreateContext(iBitmapContext2);
00097
00098 DrawSmiley(*iBitmapContext2);
00099
00100 delete iBitmapContext2;
00101 delete iBitmapDevice2;
00102
00103 iGraphObserver->NotifyStatus(KTxtUpdateModelCase3);
00104 break;
00105 case 4:
00106
00107 iBitmap3 = new (ELeave) CFbsBitmap();
00108 iBitmap3->Duplicate(iBitmap2->Handle());
00109 iGraphObserver->NotifyStatus(KTxtUpdateModelCase4);
00110 break;
00111 case 5:
00112
00113 delete iBitmap2;
00114 iGraphObserver->NotifyStatus(KTxtUpdateModelCase5);
00115 break;
00116 case 6:
00117
00118 delete iBitmap3;
00119 iGraphObserver->NotifyStatus(KTxtUpdateModelCase6);
00120 break;
00121 case 7:
00122
00123 iBitmap1 = new (ELeave) CFbsBitmap();
00124 LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
00125 iGraphObserver->NotifyStatus(KTxtUpdateModelCase7);
00126 break;
00127 case 8:
00128
00129 CreateRotatedBitmapL();
00130 iGraphObserver->NotifyStatus(KTxtUpdateModelCase8);
00131 break;
00132 case 9:
00133
00134 delete iBitmap1;
00135 delete iBitmap4;
00136 iGraphObserver->NotifyStatus(KTxtUpdateModelCase9);
00137 }
00138 }
00139
00140 void CFbsControl::Draw(const TRect& ) const
00141 {
00142
00143 CWindowGc& gc=SystemGc();
00144 gc.UseFont(iMessageFont);
00145 gc.Clear();
00146 TRect rect=Rect();
00147 gc.DrawRect(rect);
00148 TRgb darkGray(85,85,85);
00149
00150
00151 switch (Phase())
00152 {
00153 case 0:
00154 {
00155
00156 TRAP_IGNORE(MUTABLE_CAST(CFbsControl*,this)->DrawL(gc));
00157 }
00158 break;
00159 case 1:
00160
00161
00162 {
00163 DrawSingleBitmap(iBitmap1,gc);
00164 }
00165 break;
00166 case 2:
00167 {
00168
00169 gc.SetBrushColor(darkGray);
00170 gc.Clear(rect);
00171 }
00172 break;
00173 case 3:
00174
00175 {
00176 DrawSingleBitmap(iBitmap2,gc);
00177 }
00178 break;
00179 case 4:
00180
00181 {
00182 DrawTwoBitmaps(iBitmap2,iBitmap3,gc);
00183 }
00184 break;
00185 case 5:
00186
00187 {
00188 DrawSingleBitmap(iBitmap3,gc);
00189 }
00190 break;
00191 case 6:
00192 {
00193
00194 gc.SetBrushColor(darkGray);
00195 gc.Clear(rect);
00196 }
00197 break;
00198 case 7:
00199 {
00200 DrawSingleBitmap(iBitmap1,gc);
00201 }
00202 break;
00203 case 8:
00204
00205 {
00206 DrawTwoBitmaps(iBitmap1,iBitmap4,gc);
00207 }
00208 break;
00209 case 9:
00210 {
00211
00212 gc.SetBrushColor(darkGray);
00213 gc.Clear(rect);
00214 }
00215 break;
00216 default:
00217 break;
00218 }
00219 }
00220
00221
00222 _LIT(KTxtZDrive,"Z:");
00223
00224 void CFbsControl::LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded)
00225 {
00226 TParse mbfn;
00227
00228 TDriveUnit sysDrive (RFs::GetSystemDrive());
00229 TDriveName sysDriveName (sysDrive.Name());
00230 TFileName fileName(sysDriveName);
00231 fileName.Append(aPathAndFile);
00232
00233 mbfn.Set(aPathAndFile,&fileName,NULL);
00234 if (!aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded))
00235 return;
00236
00237 mbfn.Set(aPathAndFile,&KTxtZDrive,NULL);
00238 User::LeaveIfError(aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded));
00239 return;
00240 }
00241
00242
00243 void CFbsControl::DrawL(CWindowGc& aGc)
00244
00245
00246 {
00247
00248 TBool shareIfLoaded(ETrue);
00249
00250
00251 iBitmap1 = new (ELeave) CFbsBitmap();
00252
00253
00254 LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
00255
00256
00257 DrawSingleBitmap(iBitmap1,aGc);
00258
00259
00260 delete(iBitmap1);
00261 }
00262
00263 void CFbsControl::DrawSmiley(CGraphicsContext& aGc)
00264 {
00265
00266 TSize penSizeBold(3,3);
00267 TSize penSizeFat(5,5);
00268 aGc.SetPenSize(penSizeFat);
00269
00270
00271 TInt leftOffset = 22;
00272 TInt rightOffset = 38;
00273 TInt circleSize = 50;
00274 TInt shrinkSize = 10;
00275
00276
00277 TPoint leftEye(leftOffset,21);
00278 TPoint rightEye(rightOffset,21);
00279 aGc.Plot(leftEye);
00280 aGc.Plot(rightEye);
00281 aGc.SetPenSize(penSizeBold);
00282 TRect circle(TPoint(10,10),TPoint(circleSize,circleSize));
00283 aGc.DrawEllipse(circle);
00284
00285
00286 TRect smile = circle;
00287 smile.Shrink(shrinkSize,shrinkSize);
00288 aGc.DrawArc(smile,TPoint(10,circleSize-shrinkSize),TPoint(circleSize,circleSize-shrinkSize));
00289 }
00290
00291 void CFbsControl::CreateRotatedBitmapL()
00292 {
00293
00294 iBitmap4 = new (ELeave) CFbsBitmap();
00295 TSize inSize = iBitmap1->SizeInPixels();
00296 iBitmap4->Create(TSize(inSize.iHeight,inSize.iWidth),iBitmap1->DisplayMode());
00297
00298
00299 TBitmapUtil* iBitmap1Util = new (ELeave) TBitmapUtil(iBitmap1);
00300 TBitmapUtil* iBitmap4Util = new (ELeave) TBitmapUtil(iBitmap4);
00301
00302 iBitmap1Util->Begin(TPoint(0,0));
00303 iBitmap4Util->Begin(TPoint(0,0),*iBitmap1Util);
00304
00305
00306 TInt xPos;
00307 for (TInt yPos=0;yPos<inSize.iHeight;yPos++)
00308 {
00309 iBitmap1Util->SetPos(TPoint(0,yPos));
00310 iBitmap4Util->SetPos(TPoint(yPos,0));
00311 for (xPos=0;xPos<inSize.iWidth;xPos++)
00312 {
00313 iBitmap4Util->SetPixel(*iBitmap1Util);
00314 iBitmap1Util->IncXPos();
00315 iBitmap4Util->IncYPos();
00316 }
00317 }
00318
00319
00320 iBitmap1Util->End();
00321 iBitmap4Util->End();
00322
00323
00324 delete iBitmap1Util;
00325 delete iBitmap4Util;
00326 }
00327
00328 void CFbsControl::DrawSingleBitmap(CFbsBitmap* aDrawBitmap,CWindowGc& aGc) const
00329 {
00330
00331 TSize bmpSizeInPixels=aDrawBitmap->SizeInPixels();
00332 TRect rect=Rect();
00333 TInt xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/2;
00334 TInt yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/2;
00335 TPoint pos=TPoint(xDelta,yDelta);
00336 pos+=rect.iTl;
00337 aGc.BitBlt(pos, aDrawBitmap);
00338 }
00339
00340 void CFbsControl::DrawTwoBitmaps(CFbsBitmap* aBitmap1,CFbsBitmap* aBitmap2,CWindowGc& aGc) const
00341 {
00342
00343 TSize bmpSizeInPixels=aBitmap1->SizeInPixels();
00344 TRect rect=Rect();
00345 TInt xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/4;
00346 TInt yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/4;
00347 TPoint pos=TPoint(xDelta,yDelta);
00348 TPoint pos2=TPoint(xDelta*3,yDelta);
00349 pos+=rect.iTl;
00350 pos2+=rect.iTl;
00351 aGc.BitBlt(pos, aBitmap1);
00352 aGc.BitBlt(pos2, aBitmap2);
00353 }