00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "BitmapsGraphicsControl.h"
00017
00018 #include <grbmap.mbg>
00019
00020 _LIT(KTxtZDrive,"Z:");
00021
00022 void CBitmapControl::LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded)
00023 {
00024 TParse mbfn;
00025
00026 TDriveUnit sysDrive (RFs::GetSystemDrive());
00027 TDriveName sysDriveName (sysDrive.Name());
00028 TFileName fileName(sysDriveName);
00029 fileName.Append(aPathAndFile);
00030
00031 mbfn.Set(aPathAndFile,&fileName,NULL);
00032 if (!aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded))
00033 return;
00034
00035 mbfn.Set(aPathAndFile,&KTxtZDrive,NULL);
00036 User::LeaveIfError(aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded));
00037 return;
00038 }
00039
00040
00041
00042 _LIT(KTxtCase0,"draw bitmap, centered on screen using block transfer");
00043 _LIT(KTxtCase1,"draw piece of bitmap using block transfer");
00044 _LIT(KTxtCase2,"draw bitmap described in twips using DrawBitmap()");
00045 _LIT(KTxtCase3,"draw stretched bitmap");
00046 _LIT(KTxtCase4,"tile rectangle, using bitmap as the brush pattern");
00047 _LIT(KTxtCase5,"tile rectangle, tiling around center of screen");
00048 _LIT(KTxtCase6,"masks: the problem of drawing a bitmap on different backgrounds");
00049 _LIT(KTxtCase7,"masks: using a mask to give a bitmap a transparent background");
00050
00051
00052
00053 _LIT(KTxtMBMname,"\\resource\\apps\\grbmap.mbm");
00054
00055 void CBitmapControl::UpdateModelL()
00056 {
00057
00058 TBool shareIfLoaded(ETrue);
00059
00060 switch (Phase())
00061 {
00062 case 0:
00063
00064 iBitmap = new (ELeave) CFbsBitmap();
00065 LoadBitmapL(iBitmap,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
00066 iMaskBitmap = new (ELeave) CFbsBitmap();
00067 LoadBitmapL(iMaskBitmap,KTxtMBMname,EMbmGrbmapSmilmask,shareIfLoaded);
00068 iGraphObserver->NotifyStatus(KTxtCase0);
00069 break;
00070 case 1:
00071 iGraphObserver->NotifyStatus(KTxtCase1);
00072 break;
00073 case 2:
00074 iGraphObserver->NotifyStatus(KTxtCase2);
00075 break;
00076 case 3:
00077 iGraphObserver->NotifyStatus(KTxtCase3);
00078 break;
00079 case 4:
00080 iGraphObserver->NotifyStatus(KTxtCase4);
00081 break;
00082 case 5:
00083 iGraphObserver->NotifyStatus(KTxtCase5);
00084 break;
00085 case 6:
00086 iGraphObserver->NotifyStatus(KTxtCase6);
00087 break;
00088 case 7:
00089 iGraphObserver->NotifyStatus(KTxtCase7);
00090 break;
00091 }
00092 }
00093
00094 void CBitmapControl::Draw(const TRect& ) const
00095 {
00096
00097 CWindowGc& gc=SystemGc();
00098 gc.UseFont(iMessageFont);
00099 gc.Clear();
00100 SystemGc().DrawRect(Rect());
00101 TRect rect=Rect();
00102 TRect bmpPieceRect=Rect();
00103 TInt xDelta=0;
00104 TInt yDelta=0;
00105 TPoint screenCenterPoint=rect.Center();
00106
00107
00108 switch (Phase())
00109 {
00110 case 0:
00111
00112
00113 {
00114
00115 TSize bmpSizeInPixels=iBitmap->SizeInPixels();
00116 xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/2;
00117 yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/2;
00118 TPoint pos=TPoint(xDelta,yDelta);
00119 pos+=rect.iTl;
00120 gc.BitBlt(pos, iBitmap);
00121 }
00122 break;
00123 case 1:
00124
00125
00126 {
00127
00128 TSize bmpSizeInPixels=iBitmap->SizeInPixels();
00129 TSize bmpPieceSize(bmpSizeInPixels.iWidth*2/3,bmpSizeInPixels.iHeight*2/3);
00130 TPoint bmpPieceTopLeft(0,0);
00131 bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
00132
00133 xDelta=(rect.Width()-bmpPieceRect.Width())/2;
00134 yDelta=(rect.Height()-bmpPieceRect.Height())/2;
00135 TPoint pos=TPoint(xDelta,yDelta);
00136 pos+=rect.iTl;
00137 gc.BitBlt(pos, iBitmap, bmpPieceRect);
00138 }
00139 break;
00140 case 2:
00141
00142
00143
00144 {
00145 TSize bmpSizeInTwips(600,600);
00146 iBitmap->SetSizeInTwips(bmpSizeInTwips);
00147 gc.DrawBitmap(rect.iTl, iBitmap);
00148 }
00149 break;
00150 case 3:
00151
00152
00153 {
00154 gc.DrawBitmap(rect, iBitmap);
00155 }
00156 break;
00157 case 4:
00158 {
00159
00160
00161 gc.UseBrushPattern(iBitmap);
00162 gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
00163 gc.DrawRect(rect);
00164 gc.DiscardBrushPattern();
00165 }
00166 break;
00167 case 5:
00168 {
00169
00170
00171 gc.SetBrushOrigin(screenCenterPoint);
00172 gc.UseBrushPattern(iBitmap);
00173 gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
00174 gc.DrawRect(rect);
00175 gc.DiscardBrushPattern();
00176 }
00177 break;
00178 case 6:
00179
00180 {
00181 TRect screenRect=Rect();
00182 TInt bisect = (screenRect.iBr.iX-screenRect.iTl.iX)/2 + screenRect.iTl.iX;
00183 TRect leftRect(screenRect.iTl,TPoint(bisect,screenRect.iBr.iY));
00184 TRect rightRect(TPoint(bisect,screenRect.iTl.iY),screenRect.iBr);
00185 TRgb darkGray(85,85,85);
00186 gc.SetBrushColor(darkGray);
00187 gc.Clear(leftRect);
00188 TRgb black(0,0,0);
00189 gc.SetBrushColor(black);
00190 gc.Clear(rightRect);
00191
00192 TSize bmpSizeInPixels=iBitmap->SizeInPixels();
00193 TSize bmpPieceSize(bmpSizeInPixels.iWidth,bmpSizeInPixels.iHeight);
00194 TPoint bmpPieceTopLeft(0,0);
00195 bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
00196
00197
00198 xDelta=(leftRect.Width()-bmpPieceRect.Width())/2;
00199 yDelta=(leftRect.Height()-bmpPieceRect.Height())/2;
00200 TPoint pos=TPoint(xDelta,yDelta);
00201 pos += leftRect.iTl;
00202 gc.BitBlt(pos,iBitmap);
00203
00204
00205 xDelta=(rightRect.Width()-bmpPieceRect.Width())/2;
00206 yDelta=(rightRect.Height()-bmpPieceRect.Height())/2;
00207 TPoint pos2=TPoint(xDelta,yDelta);
00208 pos2 += rightRect.iTl;
00209 gc.BitBlt(pos2,iBitmap);
00210 }
00211 break;
00212 case 7:
00213
00214 {
00215 TRect screenRect=Rect();
00216 TInt bisect = (screenRect.iBr.iX-screenRect.iTl.iX)/2 + screenRect.iTl.iX;
00217 TRect leftRect(TPoint(screenRect.iTl.iX,screenRect.iTl.iY+50),TPoint(bisect,screenRect.iBr.iY));
00218 TRect rightRect(TPoint(bisect,screenRect.iTl.iY+50),screenRect.iBr);
00219 TRgb darkGray(85,85,85);
00220 gc.SetBrushColor(darkGray);
00221 gc.Clear(leftRect);
00222 TRgb black(0,0,0);
00223 gc.SetBrushColor(black);
00224 gc.Clear(rightRect);
00225
00226 TSize bmpSizeInPixels=iBitmap->SizeInPixels();
00227 TSize bmpPieceSize(bmpSizeInPixels.iWidth,bmpSizeInPixels.iHeight);
00228 TPoint bmpPieceTopLeft(0,0);
00229 bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
00230
00231
00232 xDelta=(leftRect.Width()-bmpPieceRect.Width())/2;
00233 yDelta=(leftRect.Height()-bmpPieceRect.Height())/2;
00234 TPoint pos=TPoint(xDelta,yDelta);
00235 pos += leftRect.iTl;
00236 gc.BitBltMasked(pos,iBitmap,bmpPieceRect,iMaskBitmap,EFalse);
00237
00238
00239 xDelta=(rightRect.Width()-bmpPieceRect.Width())/2;
00240 yDelta=(rightRect.Height()-bmpPieceRect.Height())/2;
00241 TPoint pos2=TPoint(xDelta,yDelta);
00242 pos2 += rightRect.iTl;
00243 gc.BitBltMasked(pos2,iBitmap,bmpPieceRect,iMaskBitmap,EFalse);
00244
00245 _LIT(KTxtTheBitmap,"The bitmap:");
00246 _LIT(KTxtBitmapMask,"The bitmap's mask:");
00247
00248 gc.DrawText(KTxtTheBitmap,TPoint(5,20));
00249 gc.BitBlt(TPoint(130,0),iBitmap);
00250 gc.DrawText(KTxtBitmapMask,TPoint(197,20));
00251 gc.BitBlt(TPoint(400,0),iMaskBitmap);
00252 }
00253 break;
00254 default:
00255 break;
00256 }
00257 }