openvg/openvgrefimplementation/sfopenvg/test/src/tigerContainer.cpp
branchNewGraphicsArchitecture
changeset 6 250ac10a3d98
equal deleted inserted replaced
5:8448d8896a16 6:250ac10a3d98
       
     1 /*
       
     2 * Copyright (c) 2009 Symbian Foundation Ltd
       
     3 * This component and the accompanying materials are made available
       
     4 * under the terms of the License "Eclipse Public License v1.0"
       
     5 * which accompanies this distribution, and is available
       
     6 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 *
       
     8 * Initial Contributors:
       
     9 * Symbian Foundation Ltd - initial contribution.
       
    10 * 
       
    11 * Contributors:
       
    12 *
       
    13 * Description:
       
    14 * Implementation of CTigerContainer class
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "TigerContainer.h"
       
    20 
       
    21 // ================= MEMBER FUNCTIONS =======================
       
    22 
       
    23 // ---------------------------------------------------------
       
    24 // CTigerContainer::ConstructL(const TRect& aRect)
       
    25 // EPOC two phased constructor
       
    26 // ---------------------------------------------------------
       
    27 //
       
    28 void CTigerContainer::ConstructL(const TRect& /*aRect*/)
       
    29     {
       
    30 //    iOpenGlInitialized = EFalse;
       
    31     CreateWindowL();
       
    32 
       
    33     SetExtentToWholeScreen();                // Take the whole screen into use
       
    34     ActivateL();
       
    35             
       
    36     TSize size;
       
    37     size = this->Size();
       
    38 
       
    39     iTiger = CTiger::NewL(size.iWidth, size.iHeight ); // Create an instance of Tiger
       
    40     
       
    41     iTiger->AppInit(Window());
       
    42     
       
    43     return;
       
    44     }
       
    45 
       
    46 // Destructor
       
    47 CTigerContainer::~CTigerContainer()
       
    48     {
       
    49     /* AppExit call is made to release
       
    50        any allocations made in AppInit. */
       
    51     if ( iTiger )
       
    52         {
       
    53         iTiger->AppExit();
       
    54         delete iTiger;
       
    55         }
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CTigerContainer::SizeChanged()
       
    60 // Called by framework when the view size is changed
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CTigerContainer::SizeChanged()
       
    64     {
       
    65     if( iTiger )
       
    66         {
       
    67         TSize size;
       
    68         size = this->Size();
       
    69         iTiger->SetScreenSize( size.iWidth, size.iHeight );
       
    70         }
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CTigerContainer::HandleResourceChange(
       
    76 //     TInt aType)
       
    77 // Dynamic screen resize changes by calling the
       
    78 // SetExtentToWholeScreen() method again.
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81  void CTigerContainer::HandleResourceChange(TInt aType)
       
    82     {
       
    83 	switch( aType )
       
    84     	{
       
    85 	    case KEikDynamicLayoutVariantSwitch:
       
    86 		    SetExtentToWholeScreen();
       
    87 		    break;
       
    88 	    }
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CTigerContainer::CountComponentControls() const
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 TInt CTigerContainer::CountComponentControls() const
       
    96     {
       
    97     return 0;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CTigerContainer::ComponentControl(TInt aIndex) const
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 CCoeControl* CTigerContainer::ComponentControl(TInt /*aIndex*/ ) const
       
   105     {
       
   106     return NULL;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CTigerContainer::Draw(const TRect& aRect) const
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 void CTigerContainer::Draw(const TRect& aRect ) const
       
   114     {
       
   115     
       
   116     CWindowGc& gc = SystemGc();
       
   117     TRgb color(KRgbRed);
       
   118     gc.SetBrushColor(color);
       
   119 	gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   120 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   121 	gc.DrawRect(Rect());
       
   122 	
       
   123 	//set up destination CFbsBitmap object
       
   124 	CFbsBitmap* bitmap=NULL;
       
   125 	TRAPD(err, bitmap = new(ELeave)CFbsBitmap;);
       
   126 	if(bitmap)
       
   127 		{
       
   128 		const TDisplayMode dispMode = Window().DisplayMode();
       
   129 			//copy from source (EGL) to target(CFbsBitmap) buffer
       
   130 		iTiger->AppRender(aRect, bitmap);		
       
   131 		RenderBitmap(gc, bitmap);
       
   132 		delete bitmap;
       
   133 		}
       
   134 	}
       
   135 
       
   136 void  CTigerContainer::RenderBitmap(CWindowGc& aGc, CFbsBitmap* aBitmap) const
       
   137 	{
       
   138 	//draw bitmap
       
   139 	// calculate position for top left of bitmap so it is centered
       
   140 	TSize bmpSizeInPixels=aBitmap->SizeInPixels();
       
   141 	TRect rect=Rect(); // a centered rectangle of the default size
       
   142 	TInt xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/2;
       
   143 	TInt yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/2;
       
   144 	TPoint pos=TPoint(xDelta,yDelta); // displacement vector
       
   145 	pos+=rect.iTl; // bitmap top left corner position
       
   146 	aGc.BitBlt(pos, aBitmap); // CWindowGc member function	
       
   147 	}
       
   148 
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CTigerContainer::HandleControlEventL(
       
   153 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 void CTigerContainer::HandleControlEventL(
       
   157     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   158     {
       
   159     }
       
   160 
       
   161 // End of File