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