os/graphics/graphicsdeviceinterface/directgdi/test/tcontext_bitgdi.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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 //
    15 
    16 #include "tcontextbase.h"
    17 #include <gdi.h>
    18 #include <bitdev.h>
    19 
    20 CTBitGdiContext::CTBitGdiContext() :
    21     iError(KErrNone)
    22 	{
    23 
    24 	}
    25 
    26 CTBitGdiContext* CTBitGdiContext::NewL(CFbsBitmapDevice* aDevice, TBool aActivate)
    27 	{
    28 	CTBitGdiContext* self = new (ELeave) CTBitGdiContext;
    29 	CleanupStack::PushL (self);
    30 	self->ConstructL (aDevice, aActivate);
    31 	CleanupStack::Pop ();
    32 	return self;
    33 	}
    34 
    35 void CTBitGdiContext::ConstructL(CFbsBitmapDevice* aDevice, TBool aActivate)
    36 	{
    37 	if(aActivate)
    38 		{
    39 		User::LeaveIfError(aDevice->CreateContext (iGc));
    40 		}
    41 	else
    42 		{
    43 		iGc = CFbsBitGc::NewL();
    44 		}
    45 	}
    46 
    47 CTBitGdiContext::~CTBitGdiContext()
    48 	{
    49 	delete iGc;
    50 	}
    51 
    52 TInt CTBitGdiContext::Activate(CBitmapDevice *aDevice)
    53 	{
    54 	CFbsDevice* device = (CFbsDevice *)aDevice;
    55 	iGc->Activate(device);
    56 	return KErrNone;
    57 	}
    58 
    59 void CTBitGdiContext::SetOrigin(const TPoint& aOrigin)
    60 	{
    61 	iGc->SetOrigin (aOrigin);
    62 	}
    63 
    64 void CTBitGdiContext::SetClippingRegion(const TRegion& aRegion)
    65 	{
    66 	TInt result = iGc->SetClippingRegion (aRegion);
    67 	SetError(result);
    68 	}
    69 
    70 void CTBitGdiContext::ResetClippingRegion()
    71 	{
    72 	iGc->CancelClipping();
    73 	}
    74 
    75 void CTBitGdiContext::SetDrawMode(DirectGdi::TDrawMode aMode)
    76 	{
    77 	CGraphicsContext::TDrawMode mode = CGraphicsContext::EDrawModePEN;	
    78 	if (aMode == DirectGdi::EDrawModeWriteAlpha)
    79 		{
    80 		mode = CGraphicsContext::EDrawModeWriteAlpha;
    81 		}	
    82 	iGc->SetDrawMode(mode);
    83 	}
    84 
    85 void CTBitGdiContext::SetPenColor(const TRgb& aColor)
    86 	{
    87 	iGc->SetPenColor (aColor);
    88 	}
    89 
    90 void CTBitGdiContext::SetPenStyle(DirectGdi::TPenStyle aStyle)
    91 	{
    92 	// The CGraphicsContext::TPenStyle enumeration has the same values as the
    93 	// DirectGdi::TPenStyle. If these change then this function will need to be updated.
    94 	iGc->SetPenStyle(static_cast<CGraphicsContext::TPenStyle>(aStyle));
    95 	}
    96 
    97 void CTBitGdiContext::SetPenSize(const TSize& aSize)
    98 	{	
    99 	iGc->SetPenSize (aSize);
   100 	}
   101 
   102 void CTBitGdiContext::SetTextShadowColor(const TRgb& aColor)
   103 	{
   104 	iGc->SetShadowColor(aColor);
   105 	}
   106 
   107 void CTBitGdiContext::SetBrushColor(const TRgb& aColor)
   108 	{
   109 	iGc->SetBrushColor (aColor);
   110 	}
   111 
   112 void CTBitGdiContext::SetBrushStyle(DirectGdi::TBrushStyle aStyle)
   113 	{
   114 	// The CGraphicsContext::TBrushStyle enumeration has the same values as the
   115 	// DirectGdi::TBrushStyle. If these change then this function will need to be updated.
   116 	iGc->SetBrushStyle(static_cast<CGraphicsContext::TBrushStyle>(aStyle));
   117 	}
   118 
   119 void CTBitGdiContext::SetBrushOrigin(const TPoint& aOrigin)
   120 	{
   121 	iGc->SetBrushOrigin (aOrigin);
   122 	}
   123 
   124 void CTBitGdiContext::SetBrushPattern(const CFbsBitmap& aPattern)
   125 	{
   126 	iGc->UseBrushPattern (&aPattern);
   127 	}
   128 
   129 void CTBitGdiContext::SetBrushPattern(TInt aHandle)
   130 	{
   131 	TInt result = iGc->UseBrushPattern(aHandle);
   132 	SetError(result);
   133 	}
   134 
   135 void CTBitGdiContext::ResetBrushPattern()
   136 	{
   137 	iGc->DiscardBrushPattern ();
   138 	}
   139 
   140 void CTBitGdiContext::SetFont(const CFont* aFont)
   141 	{
   142 	iGc->UseFont (aFont);
   143 	}
   144 
   145 void CTBitGdiContext::ResetFont()
   146 	{
   147 	iGc->DiscardFont ();
   148 	}
   149 
   150 void CTBitGdiContext::Reset()
   151 	{
   152 	iGc->Reset ();
   153 	}
   154 
   155 TRgb CTBitGdiContext::BrushColor()
   156 	{
   157 	return iGc->BrushColor ();
   158 	}
   159 
   160 TRgb CTBitGdiContext::PenColor()
   161 	{
   162 	return iGc->PenColor ();
   163 	}
   164 
   165 TRgb CTBitGdiContext::TextShadowColor()
   166 	{
   167 	TRgb shadowColor;
   168 	iGc->GetShadowColor(shadowColor);
   169 	return shadowColor;
   170 	}
   171 
   172 void CTBitGdiContext::Clear(const TRect& aRect)
   173 	{
   174 	iGc->Clear (aRect);
   175 	}
   176 
   177 void CTBitGdiContext::Clear()
   178 	{
   179 	iGc->Clear ();
   180 	}
   181 
   182 void CTBitGdiContext::MoveTo(const TPoint& aPoint)
   183 	{
   184 	iGc->MoveTo (aPoint);
   185 	}
   186 
   187 void CTBitGdiContext::MoveBy(const TPoint& aVector)
   188 	{
   189 	iGc->MoveBy (aVector);
   190 	}
   191 
   192 void CTBitGdiContext::Plot(const TPoint& aPoint)
   193 	{
   194 	iGc->Plot (aPoint);
   195 	}
   196 
   197 void CTBitGdiContext::DrawLine(const TPoint& aStart, const TPoint& aEnd)
   198 	{
   199 	iGc->DrawLine (aStart, aEnd);
   200 	}
   201 
   202 void CTBitGdiContext::DrawLineTo(const TPoint& aPoint)
   203 	{
   204 	iGc->DrawLineTo (aPoint);
   205 	}
   206 
   207 void CTBitGdiContext::DrawLineBy(const TPoint& aVector)
   208 	{
   209 	iGc->DrawLineBy (aVector);
   210 	}
   211 
   212 void CTBitGdiContext::DrawRect(const TRect& aRect)
   213 	{
   214 	iGc->DrawRect (aRect);
   215 	}
   216 
   217 void CTBitGdiContext::DrawRoundRect(const TRect& aRect,
   218 		const TSize& aCornerSize)
   219 	{
   220 	iGc->DrawRoundRect (aRect, aCornerSize);
   221 	}
   222 
   223 void CTBitGdiContext::DrawPolyLine(const CArrayFix<TPoint>& aPointList)
   224 	{
   225 	iGc->DrawPolyLine(&aPointList);
   226 	}
   227 
   228 void CTBitGdiContext::DrawPolyLineNoEndPoint(const CArrayFix<TPoint>& aPointList)
   229 	{
   230 	iGc->DrawPolyLineNoEndPoint(&aPointList);
   231 	}
   232 
   233 void CTBitGdiContext::DrawPolygon(const CArrayFix<TPoint>& aPoints, DirectGdi::TFillRule aRule)
   234 	{
   235 	TInt result = iGc->DrawPolygon(&aPoints, static_cast<CGraphicsContext::TFillRule>(aRule));
   236 	SetError(result);
   237 	}
   238 
   239 void CTBitGdiContext::DrawArc(const TRect& aRect, const TPoint& aStart,
   240 		const TPoint& aEnd)
   241 	{
   242 	iGc->DrawArc (aRect, aStart, aEnd);
   243 	}
   244 
   245 void CTBitGdiContext::DrawPie(const TRect& aRect, const TPoint& aStart,
   246 		const TPoint& aEnd)
   247 	{
   248 	iGc->DrawPie (aRect, aStart, aEnd);
   249 	}
   250 
   251 void CTBitGdiContext::DrawEllipse(const TRect& aRect)
   252 	{
   253 	iGc->DrawEllipse (aRect);
   254 	}
   255 
   256 void CTBitGdiContext::BitBltMasked(const TPoint& aDestPos, 
   257 		const CFbsBitmap& aBitmap, const TRect& aSourceRect, 
   258 		const CFbsBitmap& aAlpha, const TPoint& aAlphaPos)
   259 	{
   260 	// This overload of BitBltMasked maps to AlphaBlendBitmaps in BitGDI, which has the same signiature.
   261 	TInt result = iGc->AlphaBlendBitmaps(aDestPos, &aBitmap, aSourceRect, &aAlpha, aAlphaPos);
   262 	SetError(result);
   263 	}
   264 
   265 void CTBitGdiContext::BitBlt(const TPoint& aPoint, const CFbsBitmap& aBitmap)
   266 	{
   267 	iGc->BitBlt (aPoint, &aBitmap);
   268 	}
   269 
   270 void CTBitGdiContext::DrawBitmap(const TRect& aDestRect,
   271 		const CFbsBitmap& aSource)
   272 	{
   273 	iGc->DrawBitmap (aDestRect, &aSource);
   274 	}
   275 
   276 void CTBitGdiContext::BitBlt(const TPoint& aDestPos,
   277 		const CFbsBitmap& aBitmap, const TRect& aSrcRect)
   278 	{
   279 	iGc->BitBlt (aDestPos, &aBitmap, aSrcRect);
   280 	}
   281 
   282 void CTBitGdiContext::BitBltMasked(const TPoint& aDestPos,
   283 		const CFbsBitmap& aBitmap, const TRect& aSrcRect,
   284 		const CFbsBitmap& aMask, TBool aInvertMask)
   285 	{
   286 	iGc->BitBltMasked (aDestPos, &aBitmap, aSrcRect, &aMask, aInvertMask);
   287 	}
   288 
   289 void CTBitGdiContext::DrawBitmap(const TRect& aDestRect,
   290 		const CFbsBitmap& aBitmap, const TRect& aSrcRect)
   291 	{
   292 	iGc->DrawBitmap (aDestRect, &aBitmap, aSrcRect);
   293 	}
   294 
   295 void CTBitGdiContext::DrawBitmapMasked(const TRect& aDestRect,
   296 		const CFbsBitmap& aBitmap, const TRect& aSrcRect,
   297 		const CFbsBitmap& aMask, TBool aInvertMask)
   298 	{
   299 	iGc->DrawBitmapMasked (aDestRect, &aBitmap, aSrcRect, &aMask, aInvertMask);
   300 	}
   301 
   302 void CTBitGdiContext::CopyRect(const TPoint& aOffset, const TRect& aRect)
   303 	{
   304 	iGc->CopyRect (aOffset, aRect);
   305 	}
   306 
   307 TBool CTBitGdiContext::HasBrushPattern() const
   308 	{
   309 	return iGc->IsBrushPatternUsed ();
   310 	}
   311 
   312 TBool CTBitGdiContext::HasFont() const
   313 	{
   314 	return iGc->IsFontUsed ();
   315 	}
   316 
   317 void CTBitGdiContext::ExternalizeL(RWriteStream& aWriteStream)
   318 	{
   319 	iGc->ExternalizeL (aWriteStream);
   320 	}
   321 
   322 void CTBitGdiContext::InternalizeL(RReadStream& aReadStream)
   323 	{
   324 	iGc->InternalizeL (aReadStream);
   325 	}
   326 
   327 void CTBitGdiContext::SetCharJustification(TInt aExcessWidth, TInt aNumGaps)
   328 	{
   329 	iGc->SetCharJustification (aExcessWidth, aNumGaps);
   330 	}
   331 
   332 void CTBitGdiContext::SetWordJustification(TInt aExcessWidth, TInt aNumChars)
   333 	{
   334 	iGc->SetWordJustification (aExcessWidth, aNumChars);
   335 	}
   336 
   337 void CTBitGdiContext::SetUnderlineStyle(DirectGdi::TFontUnderline aUnderlineStyle)
   338 	{
   339 	iGc->SetUnderlineStyle (static_cast<TFontUnderline>(aUnderlineStyle));
   340 	}
   341 
   342 void CTBitGdiContext::SetStrikethroughStyle(DirectGdi::TFontStrikethrough aStrikethroughStyle)
   343 	{
   344 	iGc->SetStrikethroughStyle (static_cast<TFontStrikethrough>(aStrikethroughStyle));
   345 	}
   346 
   347 void CTBitGdiContext::UpdateJustification(const TDesC& aText, const DirectGdi::TTextParameters* aParam)
   348 	{
   349 	iGc->UpdateJustification(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam));
   350 	}
   351 
   352 void CTBitGdiContext::UpdateJustificationVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, TBool aUp)
   353 	{
   354 	iGc->UpdateJustificationVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aUp);
   355 	}
   356 
   357 void CTBitGdiContext::SetFontNoDuplicate(const CFont* /*aFont*/)
   358 	{
   359 	}
   360 
   361 void CTBitGdiContext::SetError(TInt aErr)
   362 	{
   363 	if (KErrNone == iError)
   364 		{
   365 		iError = aErr;
   366 		}	
   367 	}
   368 
   369 
   370 TInt CTBitGdiContext::GetError()
   371 	{
   372 	TInt err = iError;
   373 	iError = KErrNone;
   374 	return err;
   375 	}
   376 
   377 // text drawing
   378 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam)
   379 	{
   380 	iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam));
   381 	}
   382 
   383 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TPoint& aPosition)
   384 	{
   385 	iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aPosition);
   386 	}
   387 
   388 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox)
   389 	{
   390 	iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox);
   391 	}
   392 
   393 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset, 
   394 		DirectGdi::TTextAlign aAlignment, TInt aMargin)
   395 	{
   396 	iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, static_cast<CGraphicsContext::TTextAlign>(aAlignment), aMargin);
   397 	}
   398 
   399 void CTBitGdiContext::DrawText(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset, 
   400 		TInt aTextWidth, DirectGdi::TTextAlign aAlignment, TInt aMargin)
   401 	{
   402 	iGc->DrawText(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aTextWidth, static_cast<CGraphicsContext::TTextAlign>(aAlignment), aMargin);
   403 	}
   404 
   405 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, TBool aUp)
   406 	{
   407 	iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aUp);
   408 	}
   409 
   410 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TPoint& aPosition, TBool aUp)
   411 	{
   412 	iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aPosition, aUp);
   413 	}
   414 
   415 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TBool aUp)
   416 	{
   417 	iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aUp);
   418 	}
   419 
   420 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset, 
   421 			TBool aUp, DirectGdi::TTextAlign aVerticalAlignment, TInt aMargin)
   422 	{
   423 	iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aUp,
   424 			static_cast<CGraphicsContext::TTextAlign>(aVerticalAlignment), aMargin);
   425 	}
   426 
   427 void CTBitGdiContext::DrawTextVertical(const TDesC& aText, const DirectGdi::TTextParameters* aParam, const TRect& aBox, TInt aBaselineOffset, 
   428 		TInt aTextWidth, TBool aUp, DirectGdi::TTextAlign aVerticalAlignment, TInt aMargin)
   429 	{
   430 	iGc->DrawTextVertical(aText, reinterpret_cast<const CGraphicsContext::TTextParameters*>(aParam), aBox, aBaselineOffset, aTextWidth, aUp,
   431 			static_cast<CGraphicsContext::TTextAlign>(aVerticalAlignment), aMargin);
   432 	}
   433 
   434 void CTBitGdiContext::DrawResource(const TPoint& aPos, 
   435 								const TDrawableSourceAndEquivRotatedBmps& aSource, 
   436 								DirectGdi::TGraphicsRotation aRotation)
   437 	{
   438 	switch (aRotation)
   439 		{
   440 		case DirectGdi::EGraphicsRotation90:
   441 			iGc->BitBlt(aPos, aSource.iBmpRot90);
   442 			break;
   443 			
   444 		case DirectGdi::EGraphicsRotation180:
   445 			iGc->BitBlt(aPos, aSource.iBmpRot180);
   446 			break;
   447 			
   448 		case DirectGdi::EGraphicsRotation270:
   449 			iGc->BitBlt(aPos, aSource.iBmpRot270);
   450 			break;
   451 			
   452 		default: // DirectGdi::EGraphicsRotationNone		
   453 			iGc->BitBlt(aPos, aSource.iBmpRotNone);
   454 			break;
   455 		}
   456 	}
   457 
   458 void CTBitGdiContext::DrawResource(const TRect& aDestRect, 
   459 								const TDrawableSourceAndEquivRotatedBmps& aSource,
   460 								DirectGdi::TGraphicsRotation aRotation)
   461 	{
   462 	switch (aRotation)
   463 		{
   464 		case DirectGdi::EGraphicsRotation90:
   465 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot90);
   466 			break;
   467 			
   468 		case DirectGdi::EGraphicsRotation180:
   469 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot180);
   470 			break;
   471 			
   472 		case DirectGdi::EGraphicsRotation270:
   473 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot270);
   474 			break;
   475 			
   476 		default: // DirectGdi::EGraphicsRotationNone
   477 			iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone);
   478 			break;
   479 		}
   480 	}
   481 
   482 void CTBitGdiContext::DrawResource(const TRect& aDestRect, 
   483 								const TDrawableSourceAndEquivRotatedBmps& aSource, 
   484 								const TRect& aSrcRect,
   485 								DirectGdi::TGraphicsRotation aRotation)
   486 	{
   487 	switch (aRotation)
   488 		{
   489 		case DirectGdi::EGraphicsRotation90:
   490 			{
   491 			// Adjust the src rect to take account of the rotated bitmap			
   492 			TRect rect = aSrcRect;
   493 			rect.iBr.iX = aSrcRect.iTl.iX + aSrcRect.Height();
   494 			rect.iBr.iY = aSrcRect.iTl.iY + aSrcRect.Width();
   495 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot90, rect);
   496 			break;
   497 			}
   498 			
   499 		case DirectGdi::EGraphicsRotation180:
   500 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot180, aSrcRect);
   501 			break;
   502 			
   503 		case DirectGdi::EGraphicsRotation270:
   504 			{
   505 			// Adjust the src rect to take account of the rotated bitmap			
   506 			TRect rect = aSrcRect;
   507 			rect.iBr.iX = aSrcRect.iTl.iX + aSrcRect.Height();
   508 			rect.iBr.iY = aSrcRect.iTl.iY + aSrcRect.Width();
   509 			iGc->DrawBitmap(aDestRect, aSource.iBmpRot270, rect);
   510 			break;
   511 			}
   512 			
   513 		default: // DirectGdi::EGraphicsRotationNone
   514 			iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone, aSrcRect);
   515 			break;
   516 		}
   517 	}
   518 
   519 void CTBitGdiContext::DrawResource(const TRect& aDestRect, 
   520 								const TDrawableSourceAndEquivRotatedBmps& aSource, 
   521 								const TDesC8& /*aParam*/)
   522 	{			
   523 	// NB we only support drawing drawable sources as images currently
   524 	iGc->DrawBitmap(aDestRect, aSource.iBmpRotNone);		
   525 	}
   526 
   527 TInt CTBitGdiContext::GetInterface(TUid /*aInterfaceId*/, TAny*& aInterface)
   528 	{
   529 	aInterface = NULL;
   530 	return KErrNotSupported;	
   531 	}
   532 
   533 void CTBitGdiContext::CopySettings(const CTContextBase& aGc)
   534 	{
   535 	CTBitGdiContext* gc = (CTBitGdiContext*)&aGc;
   536 	iGc->CopySettings(*(gc->iGc));
   537 	}