examples/Graphics/GraphicsShell/Zoom.cpp

00001 /*
00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008 � list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010 � this list of conditions and the following disclaimer in the documentation
00011 � and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013 � may be used to endorse or promote products derived from this software
00014 � without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:� 
00028 */
00029 
00030 
00031 #include "GraphicsControl.h"
00032 
00033 // header for multi-bitmap file grbitmap.mbm containing 2 bitmaps to use
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 // Name of the multi-bitmap file containing the bitmap
00055 // and bitmap mask files
00056 _LIT(KTxtFileName,"\\resource\\apps\\grbmap2.mbm");
00057 
00058 void CZoomControl::UpdateModelL()
00059         {
00060         // set up name for bitmap sharing
00061         TBool shareIfLoaded(ETrue);
00062 
00063         // set up two zoom factor objects (one for examples, one for commentary)
00064         iLeftZf.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
00065         iRightZf.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
00066         //iLeftZf.SetDevice(iCoeEnv->ScreenDevice());
00067         //iRightZf.SetDevice(iCoeEnv->ScreenDevice());
00068         
00069         // set the zoom factor of the objects (example is dependent on phase of example, commentary is fixed)
00070         iLeftZf.SetZoomFactor(TZoomFactor::EZoomOneToOne*2*(Phase()+1)/5);
00071         iRightZf.SetZoomFactor(TZoomFactor::EZoomOneToOne*2*(5-Phase())/5);
00072 
00073         // use graphics device maps for drawing and getting fonts
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         // set up descriptor for commentary area
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& /* aRect */) const
00092         {
00093         // setup screen for example: get graphics context and draw surrounding rectangle
00094         CWindowGc& gc=SystemGc();
00095         gc.Clear();     
00096         
00097         // create a centered rectangle of the default size
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         // set up absolute font-spec and text box for 200 twip Times font
00114         TFontSpec fontSpec(KTxtTimesNewRoman,200);
00115         // find the nearest font to the specified one
00116         CFont* screenFont;                                                                              
00117         iLeftMap->GetNearestFontInTwips(screenFont,fontSpec);
00118         // use it for this graphics context
00119         SystemGc.UseFont(screenFont);
00120         // get height of screen box
00121     TInt screenHeight=screenRect.Height();
00122         // get font height
00123     TInt textHeight = screenFont->HeightInPixels();
00124         // 1/2 font height below halfway down box
00125     TInt exampleOffset=(screenHeight+textHeight)/2;
00126     TInt exampleMargin=0;
00127     SystemGc.DrawText(KTxtGrzoomExampleText,screenRect,exampleOffset,CGraphicsContext::ECenter,exampleMargin);
00128         // discard and release font
00129         SystemGc.DiscardFont();
00130         iLeftMap->ReleaseFont(screenFont);      
00131         
00132         // set up example box in twips
00133         TRect boxInTwips(TPoint(0,0),TPoint(500,300));
00134         // convert rectangle co-ordinates into pixels
00135         TRect boxInPixels = iLeftMap->TwipsToPixels(boxInTwips);
00136         SystemGc.DrawRect(boxInPixels);
00137 
00138         // set up rectangle for bitmap to be stretched into
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         // draw the bitmap, stretched into the rectangle
00146         SystemGc.DrawBitmap(bitmapRectInPixels, iBitmap);
00147         }
00148 
00149 void CZoomControl::DrawRight(TRect screenRect,CWindowGc& SystemGc) const
00150         {
00151         // set up colors: black and a white RGB color
00152         TRgb black(0,0,0);
00153         TRgb white(255,255,255); // appears as blank screen gray-green color
00154     SystemGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00155     SystemGc.SetBrushColor(black);
00156     SystemGc.SetPenColor(white);
00157 
00158         // set up absolute font-spec and text box for 200 twip Times font
00159         TFontSpec fontSpec(KTxtTimesNewRoman,200);
00160         // find the nearest font to the specified one
00161         CFont* commentFont;
00162         iRightMap->GetNearestFontInTwips(commentFont,fontSpec);
00163         // use it for this graphics context
00164         SystemGc.UseFont(commentFont);
00165         // get font height
00166     TInt textHeight = commentFont->HeightInPixels();
00167     // get height of text box
00168     TInt boxHeight=screenRect.Height();
00169         // 1/2 font height below halfway down box
00170     TInt commentOffset=(boxHeight+textHeight)/2;
00171     TInt commentMargin=0;
00172         // draw text
00173     SystemGc.DrawText(KTxtGrzoomExampleText,screenRect,commentOffset,CGraphicsContext::ECenter,commentMargin);
00174         // discard and release font
00175         SystemGc.DiscardFont();
00176         iRightMap->ReleaseFont(commentFont);
00177         
00178         // set up example box in twips
00179         TRect boxInTwips(TPoint(0,0),TPoint(500,300));
00180         // convert rectangle co-ordinates into pixels
00181         TRect boxInPixels = iRightMap->TwipsToPixels(boxInTwips);
00182         boxInPixels.Move(screenRect.iTl);
00183         SystemGc.DrawRect(boxInPixels);
00184 
00185         // set up rectangle for bitmap to be stretched into
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         // draw the bitmap, stretched into the rectangle
00194         SystemGc.DrawBitmap(bitmapRectInPixels, iBitmap);
00195         }

Generated by  doxygen 1.6.2