lafagnosticuifoundation/cone/tef/TTransGc.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "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 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Testing of GC behaviour overrides
       
    15 // This class map a CWindowGc to a CFbsBitGc class. The majority of these functions are one to one mappings, 
       
    16 // with the exception  of "application specific" implementations.
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent - Internal Symbian test code 
       
    23 */
       
    24 
       
    25 #include "TTransGc.h"
       
    26 
       
    27 #define KAlphaOpaque 255
       
    28 
       
    29 EXPORT_C CTransGc* CTransGc::NewL(CWsScreenDevice& aDevice,CFbsBitGc& aFbsBitGc)
       
    30 	{
       
    31 	CTransGc* self = new(ELeave) CTransGc(aDevice,aFbsBitGc);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CTransGc::~CTransGc()
       
    36 	{
       
    37 	}
       
    38 
       
    39 //====================Functions from GDI.H===============================
       
    40 
       
    41 CGraphicsDevice* CTransGc::Device() const
       
    42 	{
       
    43 	return (iFbsBitGc.Device());
       
    44 	}
       
    45 
       
    46 
       
    47 void CTransGc::SetOrigin(const TPoint &aPoint)
       
    48 	{
       
    49 	iFbsBitGc.SetOrigin(aPoint);
       
    50 	}
       
    51 
       
    52 void CTransGc::SetClippingRect(const TRect& aRect)
       
    53 	{
       
    54 	iFbsBitGc.SetClippingRect(aRect);
       
    55 	}
       
    56 
       
    57 void CTransGc::CancelClippingRect()
       
    58 	{
       
    59 	iFbsBitGc.CancelClippingRect();
       
    60 	}
       
    61 
       
    62 TInt CTransGc::SetClippingRegion(const TRegion &aRegion)
       
    63 	{
       
    64 	iFbsBitGc.SetClippingRegion(&aRegion);
       
    65 	return 0;
       
    66 	}
       
    67 
       
    68 void CTransGc::CancelClippingRegion()
       
    69 	{
       
    70 	iFbsBitGc.CancelClippingRegion();
       
    71 	}
       
    72 
       
    73 void CTransGc::SetDrawMode(TDrawMode aDrawingMode)
       
    74 	{
       
    75 	iFbsBitGc.SetDrawMode(aDrawingMode);
       
    76 	}
       
    77 
       
    78 void CTransGc::UseFont(const CFont *aFont)
       
    79 	{
       
    80 	iFbsBitGc.UseFont(aFont);
       
    81 	}
       
    82 
       
    83 void CTransGc::DiscardFont()
       
    84 	{
       
    85 	iFbsBitGc.DiscardFont();
       
    86 	}
       
    87 
       
    88 void CTransGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
       
    89 	{
       
    90 	iFbsBitGc.SetUnderlineStyle(aUnderlineStyle);
       
    91 	}
       
    92 
       
    93 void CTransGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
       
    94 	{
       
    95 	iFbsBitGc.SetStrikethroughStyle(aStrikethroughStyle);
       
    96 	}
       
    97 
       
    98 void CTransGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
       
    99 	{
       
   100 	iFbsBitGc.SetWordJustification(aExcessWidth,aNumGaps);
       
   101 	}
       
   102 
       
   103 void CTransGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
       
   104 	{
       
   105 	iFbsBitGc.SetCharJustification(aExcessWidth,aNumChars);
       
   106 	}
       
   107 
       
   108 
       
   109 void CTransGc::SetPenStyle(TPenStyle aPenStyle)
       
   110 	{
       
   111 	iFbsBitGc.SetPenStyle(aPenStyle);
       
   112 	}
       
   113 
       
   114 void CTransGc::SetPenSize(const TSize& aSize)
       
   115 	{
       
   116 	iFbsBitGc.SetPenSize(aSize);
       
   117 	}
       
   118 
       
   119 
       
   120 void CTransGc::SetBrushStyle(TBrushStyle aBrushStyle)
       
   121 	{
       
   122 	iFbsBitGc.SetBrushStyle(aBrushStyle);
       
   123 	}
       
   124 
       
   125 void CTransGc::SetBrushOrigin(const TPoint &aOrigin)
       
   126 	{
       
   127 	iFbsBitGc.SetBrushOrigin(aOrigin);
       
   128 	}
       
   129 
       
   130 void CTransGc::UseBrushPattern(const CFbsBitmap *aDevice)
       
   131 	{
       
   132 	iFbsBitGc.UseBrushPattern(aDevice);
       
   133 	}
       
   134 
       
   135 void CTransGc::DiscardBrushPattern()
       
   136 	{
       
   137 	iFbsBitGc.DiscardBrushPattern();
       
   138 	}
       
   139 
       
   140 void CTransGc::Plot(const TPoint &aPoint)
       
   141 	{
       
   142 	iFbsBitGc.Plot(aPoint);
       
   143 	}
       
   144 
       
   145 void CTransGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
       
   146 	{
       
   147 	iFbsBitGc.DrawLine(aPoint1,aPoint2);
       
   148 	}
       
   149 
       
   150 void CTransGc::MoveTo(const TPoint &aPoint)
       
   151 	{
       
   152 	iFbsBitGc.MoveTo(aPoint);
       
   153 	}
       
   154 
       
   155 void CTransGc::MoveBy(const TPoint &aPoint)
       
   156 	{
       
   157 	iFbsBitGc.MoveBy(aPoint);
       
   158 	}
       
   159 
       
   160 void CTransGc::DrawLineTo(const TPoint &aPoint)
       
   161 	{
       
   162 	iFbsBitGc.DrawLineTo(aPoint);
       
   163 	}
       
   164 
       
   165 void CTransGc::DrawLineBy(const TPoint &aPoint)
       
   166 	{
       
   167 	iFbsBitGc.DrawLineBy(aPoint);
       
   168 	}
       
   169 
       
   170 void CTransGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
       
   171 	{
       
   172 	iFbsBitGc.DrawPolyLine(aPointList,aNumPoints);
       
   173 	}
       
   174 
       
   175 void CTransGc::DrawPolyLine(const CArrayFix<TPoint> *aPointArray)
       
   176 	{
       
   177 	iFbsBitGc.DrawPolyLine(aPointArray);
       
   178 	}
       
   179 
       
   180 TInt CTransGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
       
   181 	{
       
   182 	return (iFbsBitGc.DrawPolygon(aPointList,aNumPoints,aFillRule));
       
   183 	}
       
   184 
       
   185 TInt CTransGc::DrawPolygon(const CArrayFix<TPoint> *aPointArray,TFillRule aFillRule)
       
   186 	{
       
   187 	return (iFbsBitGc.DrawPolygon(aPointArray,aFillRule));
       
   188 	}
       
   189 
       
   190 void CTransGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
   191 	{
       
   192 	iFbsBitGc.DrawArc(aRect,aStart,aEnd);
       
   193 	}
       
   194 
       
   195 void CTransGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
       
   196 	{
       
   197 	iFbsBitGc.DrawPie(aRect,aStart,aEnd);
       
   198 	}
       
   199 
       
   200 void CTransGc::DrawEllipse(const TRect &aRect)
       
   201 	{
       
   202 	iFbsBitGc.DrawEllipse(aRect);
       
   203 	}
       
   204 
       
   205 void CTransGc::DrawRect(const TRect &aRect)
       
   206 	{
       
   207 	iFbsBitGc.DrawRect(aRect);
       
   208 	}
       
   209 
       
   210 void CTransGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse)
       
   211 	{
       
   212 	iFbsBitGc.DrawRoundRect(aRect,aEllipse);
       
   213 	}
       
   214 
       
   215 void CTransGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
       
   216 	{
       
   217 	iFbsBitGc.DrawBitmap(aTopLeft,aDevice);
       
   218 	}
       
   219 
       
   220 void CTransGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
       
   221 	{
       
   222 	iFbsBitGc.DrawBitmap(aDestRect,aDevice);
       
   223 	}
       
   224 
       
   225 void CTransGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
       
   226 	{
       
   227 	iFbsBitGc.DrawBitmap(aDestRect,aDevice,aSourceRect);
       
   228 	}
       
   229 
       
   230 void CTransGc::DrawText(const TDesC &aBuf, const TPoint &aPos)
       
   231 	{
       
   232 	iFbsBitGc.DrawText(aBuf,aPos);
       
   233 	}
       
   234 
       
   235 void CTransGc::DrawText(const TDesC &aBuf,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
       
   236 	{
       
   237 	iFbsBitGc.DrawText(aBuf,aBox,aBaselineOffset,aHoriz,aLeftMrg);
       
   238 	}
       
   239 
       
   240 void CTransGc::DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp)
       
   241 	{
       
   242 	iFbsBitGc.DrawTextVertical(aText,aPos,aUp);
       
   243 	}
       
   244 
       
   245 void CTransGc::DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
       
   246 	{
       
   247 	iFbsBitGc.DrawTextVertical(aText,aBox,aBaselineOffset,aUp,aVert,aMargin);
       
   248 	}
       
   249 
       
   250 //========================Extra functions============================
       
   251 
       
   252 void CTransGc::CopyRect(const TPoint &anOffset,const TRect &aRect)
       
   253 	{
       
   254 	iFbsBitGc.CopyRect(anOffset,aRect);
       
   255 	}
       
   256 
       
   257 void CTransGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap)
       
   258 	{
       
   259 	iFbsBitGc.BitBlt(aPoint,aBitmap);
       
   260 	}
       
   261 
       
   262 void CTransGc::BitBlt(const TPoint &aDestination,const CFbsBitmap *aBitmap,const TRect &aSource)
       
   263 	{
       
   264 	iFbsBitGc.BitBlt(aDestination,aBitmap,aSource);
       
   265 	}
       
   266 
       
   267 void CTransGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
       
   268 	{
       
   269 	iFbsBitGc.BitBltMasked(aPoint,aBitmap,aSourceRect,aMaskBitmap,aInvertMask);
       
   270 	}
       
   271 
       
   272 void CTransGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap)
       
   273 	{
       
   274 	iFbsBitGc.BitBlt(aPoint,aBitmap);
       
   275 	}
       
   276 
       
   277 void CTransGc::BitBlt(const TPoint &aDestination,const CWsBitmap  *aBitmap,const TRect &aSource)
       
   278 	{
       
   279 	iFbsBitGc.BitBlt(aDestination,aBitmap,aSource);
       
   280 	}
       
   281 
       
   282 void CTransGc::BitBltMasked(const TPoint& aPoint,const CWsBitmap * aBitmap,const TRect& aSourceRect,const CWsBitmap * aMaskBitmap,TBool aInvertMask)
       
   283 	{
       
   284 	iFbsBitGc.BitBltMasked(aPoint,aBitmap,aSourceRect,aMaskBitmap,aInvertMask);
       
   285 	}
       
   286 
       
   287 void CTransGc::MapColors(const TRect &aRect,const TRgb *aColors,TInt aNumPairs,TBool aMapForwards)
       
   288 	{
       
   289 	iFbsBitGc.MapColors(aRect,aColors,aNumPairs,aMapForwards);
       
   290 	}
       
   291 
       
   292 void CTransGc::Clear(const TRect &aRect)
       
   293 	{
       
   294 	iFbsBitGc.Clear(aRect);
       
   295 	}
       
   296 
       
   297 void CTransGc::Clear()
       
   298 	{
       
   299 	iFbsBitGc.Clear();
       
   300 	}
       
   301 
       
   302 void CTransGc::SetDitherOrigin(const TPoint& aPoint)
       
   303 	{
       
   304 	iFbsBitGc.SetDitherOrigin(aPoint);
       
   305 	}
       
   306 
       
   307 
       
   308 void CTransGc::SetFaded(TBool aFaded)
       
   309 	{
       
   310 	iFbsBitGc.SetFaded(aFaded);
       
   311 	}
       
   312 
       
   313 void CTransGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap)
       
   314 	{
       
   315 	iFbsBitGc.SetFadingParameters(aBlackMap,aWhiteMap);
       
   316 	}
       
   317 
       
   318 
       
   319 /** Application specific */
       
   320 
       
   321 CTransGc::CTransGc(CWsScreenDevice& aDevice, CFbsBitGc& aFbsBitGc)
       
   322 		: CWindowGc(&aDevice), iFbsBitGc(aFbsBitGc)
       
   323 	{
       
   324 		//Default alpha value is opaque
       
   325 		iAlpha = KAlphaOpaque; 
       
   326 	}
       
   327 
       
   328 void CTransGc::SetWindowOrigin(TPoint aOrigin)
       
   329 {
       
   330 	//The window origin is reference offset so that multiple windows can composite into an offscreen Gc 
       
   331 	iWindowOrigin = aOrigin;
       
   332 }
       
   333 
       
   334 //The Gc activate function ensures the correct window refreshing (clearing) and relative placement of origin for offscreen
       
   335 //bitmap images.
       
   336 void CTransGc::Activate(RDrawableWindow& aWindow)
       
   337 	{				
       
   338 		CancelClippingRect();
       
   339 								
       
   340 		//Alpha clear the redraw rect;
       
   341 		iFbsBitGc.SetBrushColor(TRgb(0,0,0,0)); //Alpha transparent 			
       
   342 		SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);	
       
   343 		
       
   344 		//The new Gc Origin is the current window position relative to our main iWindowOrigin
       
   345 		TPoint p = aWindow.AbsPosition();	
       
   346 		p -= iWindowOrigin;
       
   347 		iGcOrigin = p;
       
   348 		
       
   349 		//ensure the drawing functions to draw to the correct origin
       
   350 		iFbsBitGc.SetOrigin(p);
       
   351 
       
   352 		//Only clear this Gc if a new window (and hence different rect) is applied 
       
   353 		if (iWin!=&aWindow)		
       
   354 			{
       
   355 			//Save the window 
       
   356 			iWin = &aWindow;
       
   357 			TRect rect;
       
   358 			//Get the redraw rectangle
       
   359 			rect = aWindow.GetDrawRect();		
       
   360 			//Clear the drawing region
       
   361 			Clear(rect); 
       
   362 
       
   363 			}			
       
   364 		
       
   365 		SetDrawMode(CGraphicsContext::EDrawModePEN);		
       
   366 	}
       
   367 
       
   368 void CTransGc::Reset()
       
   369 	{	
       
   370 		iFbsBitGc.Reset();
       
   371 		
       
   372 		//Make sure the current origin is maintained.
       
   373 		iFbsBitGc.SetOrigin(iGcOrigin);
       
   374 	}
       
   375 
       
   376 void CTransGc::Deactivate()
       
   377 	{	
       
   378 		CancelClippingRect();
       
   379 	}
       
   380 
       
   381 //Set the current alpha level component
       
   382 void CTransGc::SetAlphaLevel(TInt aAlpha)
       
   383 	{
       
   384 	iAlpha = aAlpha;
       
   385 	}
       
   386 
       
   387 //Ensure the pen colour is set in the bitmap with the correct alpha blending level
       
   388 void CTransGc::SetPenColor(const TRgb &aColor)
       
   389 	{
       
   390 	TRgb Color = aColor;
       
   391 	Color.SetAlpha(iAlpha);
       
   392 	iFbsBitGc.SetPenColor(Color);
       
   393 	
       
   394 	}
       
   395 //Ensure the brush colour is set in the bitmap with the correct alpha blending level
       
   396 void CTransGc::SetBrushColor(const TRgb &aColor)
       
   397 	{
       
   398 	TRgb Color = aColor;
       
   399 	Color.SetAlpha(iAlpha);
       
   400 	iFbsBitGc.SetBrushColor(Color);
       
   401 	}