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