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