00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "GraphicsControl.h"
00017
00018
00019 #include <grbmap2.mbg>
00020
00021 #include <coemain.h>
00022
00023 _LIT(KTxtCDrive,"\\");
00024 _LIT(KTxtZDrive,"Z:");
00025
00026 void CZoomControl::LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded)
00027 {
00028 TParse mbfn;
00029
00030 mbfn.Set(aPathAndFile,&KTxtCDrive,NULL);
00031 if (!aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded))
00032 return;
00033
00034 mbfn.Set(aPathAndFile,&KTxtZDrive,NULL);
00035 User::LeaveIfError(aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded));
00036 return;
00037 }
00038
00039
00040
00041 _LIT(KTxtFileName,"\\resource\\apps\\grbmap2.mbm");
00042
00043 void CZoomControl::UpdateModelL()
00044 {
00045
00046 TBool shareIfLoaded(ETrue);
00047
00048
00049 iLeftZf.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
00050 iRightZf.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
00051
00052
00053
00054
00055 iLeftZf.SetZoomFactor(TZoomFactor::EZoomOneToOne*2*(Phase()+1)/5);
00056 iRightZf.SetZoomFactor(TZoomFactor::EZoomOneToOne*2*(5-Phase())/5);
00057
00058
00059 iLeftMap=&iLeftZf;
00060 iRightMap=&iRightZf;
00061
00062 if (Phase()==0) {
00063 iBitmap = new (ELeave) CFbsBitmap();
00064 LoadBitmapL(iBitmap,KTxtFileName,EMbmGrbmap2Smiley,shareIfLoaded);
00065 }
00066
00067
00068 _LIT(KFormat1,"Left zoom factor=%1.1f:1 Right zoom factor=%1.1f:1");
00069 TBuf<128> commentaryText;
00070 TReal leftValue = 2*(Phase()+1)/5.0;
00071 TReal rightValue = 2*(5-Phase())/5.0;
00072 commentaryText.Format(KFormat1,leftValue,rightValue);
00073 iGraphObserver->NotifyStatus(commentaryText);
00074 };
00075
00076 void CZoomControl::Draw(const TRect& ) const
00077 {
00078
00079 CWindowGc& gc=SystemGc();
00080 gc.Clear();
00081
00082
00083 TRect screenRect=Rect();
00084 TInt bisect = (screenRect.iBr.iX-screenRect.iTl.iX)/2 + screenRect.iTl.iX;
00085 TRect leftRect(screenRect.iTl,TPoint(bisect,screenRect.iBr.iY));
00086 TRect rightRect(TPoint(bisect,screenRect.iTl.iY),screenRect.iBr);
00087
00088 DrawLeft(leftRect,gc);
00089 DrawRight(rightRect,gc);
00090 }
00091
00092
00093 _LIT(KTxtTimesNewRoman,"Times New Roman");
00094 _LIT(KTxtGrzoomExampleText,"grzoom example text");
00095
00096 void CZoomControl::DrawLeft(TRect screenRect,CWindowGc& SystemGc) const
00097 {
00098
00099 TFontSpec fontSpec(KTxtTimesNewRoman,200);
00100
00101 CFont* screenFont;
00102 iLeftMap->GetNearestFontInTwips(screenFont,fontSpec);
00103
00104 SystemGc.UseFont(screenFont);
00105
00106 TInt screenHeight=screenRect.Height();
00107
00108 TInt textHeight = screenFont->HeightInPixels();
00109
00110 TInt exampleOffset=(screenHeight+textHeight)/2;
00111 TInt exampleMargin=0;
00112 SystemGc.DrawText(KTxtGrzoomExampleText,screenRect,exampleOffset,CGraphicsContext::ECenter,exampleMargin);
00113
00114 SystemGc.DiscardFont();
00115 iLeftMap->ReleaseFont(screenFont);
00116
00117
00118 TRect boxInTwips(TPoint(0,0),TPoint(500,300));
00119
00120 TRect boxInPixels = iLeftMap->TwipsToPixels(boxInTwips);
00121 SystemGc.DrawRect(boxInPixels);
00122
00123
00124 TRect bitmapRectInTwips(TPoint(0,0),TPoint(500,500));
00125 TRect bitmapRectInPixels = iLeftMap->TwipsToPixels(bitmapRectInTwips);
00126 bitmapRectInPixels.iTl.iY+=125;
00127 bitmapRectInPixels.iBr.iY+=125;
00128 bitmapRectInPixels.iTl.iX+=100;
00129 bitmapRectInPixels.iBr.iX+=100;
00130
00131 SystemGc.DrawBitmap(bitmapRectInPixels, iBitmap);
00132 }
00133
00134 void CZoomControl::DrawRight(TRect screenRect,CWindowGc& SystemGc) const
00135 {
00136
00137 TRgb black(0,0,0);
00138 TRgb white(255,255,255);
00139 SystemGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00140 SystemGc.SetBrushColor(black);
00141 SystemGc.SetPenColor(white);
00142
00143
00144 TFontSpec fontSpec(KTxtTimesNewRoman,200);
00145
00146 CFont* commentFont;
00147 iRightMap->GetNearestFontInTwips(commentFont,fontSpec);
00148
00149 SystemGc.UseFont(commentFont);
00150
00151 TInt textHeight = commentFont->HeightInPixels();
00152
00153 TInt boxHeight=screenRect.Height();
00154
00155 TInt commentOffset=(boxHeight+textHeight)/2;
00156 TInt commentMargin=0;
00157
00158 SystemGc.DrawText(KTxtGrzoomExampleText,screenRect,commentOffset,CGraphicsContext::ECenter,commentMargin);
00159
00160 SystemGc.DiscardFont();
00161 iRightMap->ReleaseFont(commentFont);
00162
00163
00164 TRect boxInTwips(TPoint(0,0),TPoint(500,300));
00165
00166 TRect boxInPixels = iRightMap->TwipsToPixels(boxInTwips);
00167 boxInPixels.Move(screenRect.iTl);
00168 SystemGc.DrawRect(boxInPixels);
00169
00170
00171 TRect bitmapRectInTwips(TPoint(0,0),TPoint(500,500));
00172 TRect bitmapRectInPixels = iRightMap->TwipsToPixels(bitmapRectInTwips);
00173 bitmapRectInPixels.Move(screenRect.iTl);
00174 bitmapRectInPixels.iTl.iY+=125;
00175 bitmapRectInPixels.iBr.iY+=125;
00176 bitmapRectInPixels.iTl.iX+=100;
00177 bitmapRectInPixels.iBr.iX+=100;
00178
00179 SystemGc.DrawBitmap(bitmapRectInPixels, iBitmap);
00180 }