Update contrib.
1 // Copyright (c) 1996-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Interface code for animated DLL's GC
20 #include "playbackgc.h"
23 #include "bitgditomwsgraphicscontextmappings.h"
24 #include "devicemap.h"
26 CWsAnimGc::CWsAnimGc(CWsAnim& aWsAnim) : iOwningWsAnim(aWsAnim), iUserActive(EFalse), iUseDrawingRegion(EFalse)
28 __DECLARE_NAME(_S("CWsAnimGc"));
31 CWsAnimGc::~CWsAnimGc()
33 iDrawingRegion.Close();
36 void CWsAnimGc::Activate(const TRegion* aRegion, MWsGraphicsContext* aGc)
38 iBaseRegion = aRegion ? aRegion : iOwningWsAnim.ClientWindow()->DrawingRegion();
44 void CWsAnimGc::Deactivate()
49 iUseDrawingRegion = EFalse;
50 iDrawingRegion.Close();
53 TBool CWsAnimGc::IsActive() const
55 return (iUserActive || (iGc != NULL));
58 void CWsAnimGc::UserActivate()
64 iOwningWsAnim.SessionPanic();
69 void CWsAnimGc::UserDeactivate()
79 CGraphicsDevice* CWsAnimGc::Device() const
82 iOwningWsAnim.Panic(EWservPanicAnimLeave);
84 return NULL; //deprecated
87 void CWsAnimGc::SetClippingRect(const TRect& aRect)
90 iOwningWsAnim.Panic(EWservPanicAnimLeave);
94 iClippingRect = aRect;
95 iClippingRect.Move(iOwningWsAnim.ClientWindow()->Origin());
96 iClippingRect.Intersection(iOwningWsAnim.ClientWindow()->AbsRect());
99 region.Copy(*iBaseRegion);
100 if (iUseDrawingRegion)
101 region.Intersect(iDrawingRegion);
102 region.ClipRect(iClippingRect);
105 iGc->SetClippingRegion(region);
109 iClippingRect = iOwningWsAnim.ClientWindow()->AbsRect(); // On error revert to the default clipping rect
113 TInt CWsAnimGc::SetClippingRegion(const TRegion &aRegion)
118 TInt error = KErrNone;
122 region.Copy(aRegion);
123 region.Offset(iOwningWsAnim.ClientWindow()->Origin());
124 region.Intersect(*iBaseRegion);
125 region.ClipRect(iClippingRect);
128 iGc->SetClippingRegion(region);
131 error = iGc->GetError();
133 { // Need to keep a copy of the region in screen coordinates
134 iDrawingRegion.Copy(aRegion);
135 iDrawingRegion.Offset(iOwningWsAnim.ClientWindow()->Origin());
136 iUseDrawingRegion = ETrue;
142 void CWsAnimGc::CancelClippingRegion()
145 iOwningWsAnim.Panic(EWservPanicAnimLeave);
149 iDrawingRegion.Close();
150 iUseDrawingRegion = EFalse;
153 region.Copy(*iBaseRegion);
154 region.ClipRect(iClippingRect);
156 iGc->SetClippingRegion(region);
161 void CWsAnimGc::CancelClippingRect()
164 iOwningWsAnim.Panic(EWservPanicAnimLeave);
168 iClippingRect = iOwningWsAnim.ClientWindow()->AbsRect(); // Revert to the default clipping rect
171 region.Copy(*iBaseRegion);
172 if (iUseDrawingRegion)
173 region.Intersect(iDrawingRegion);
174 region.ClipRect(iClippingRect);
176 iGc->SetClippingRegion(region);
181 void CWsAnimGc::SetDrawMode(TDrawMode aDrawingMode)
184 iOwningWsAnim.Panic(EWservPanicAnimLeave);
187 iGc->SetDrawMode(BitGdiToMWsGraphicsContextMappings::LossyConvert(aDrawingMode));
190 void CWsAnimGc::UseFont(const CFont *aFont)
193 iFont=(CAnimFbsFont *)aFont;
196 iOwningWsAnim.Panic(EWservPanicAnimLeave);
198 iGc->SetFontNoDuplicate(iFont);
201 void CWsAnimGc::DiscardFont()
205 iOwningWsAnim.Panic(EWservPanicAnimLeave);
210 void CWsAnimGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
213 iOwningWsAnim.Panic(EWservPanicAnimLeave);
215 iGc->SetUnderlineStyle(BitGdiToMWsGraphicsContextMappings::Convert(aUnderlineStyle));
218 void CWsAnimGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
221 iOwningWsAnim.Panic(EWservPanicAnimLeave);
223 iGc->SetStrikethroughStyle(BitGdiToMWsGraphicsContextMappings::Convert(aStrikethroughStyle));
226 void CWsAnimGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
229 iOwningWsAnim.Panic(EWservPanicAnimLeave);
231 iGc->SetWordJustification(aExcessWidth,aNumGaps);
234 void CWsAnimGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
237 iOwningWsAnim.Panic(EWservPanicAnimLeave);
239 iGc->SetCharJustification(aExcessWidth,aNumChars);
242 void CWsAnimGc::SetPenColor(const TRgb &aColor)
245 iOwningWsAnim.Panic(EWservPanicAnimLeave);
247 iGc->SetPenColor(aColor);
250 void CWsAnimGc::SetPenStyle(TPenStyle aPenStyle)
253 iOwningWsAnim.Panic(EWservPanicAnimLeave);
255 iGc->SetPenStyle(BitGdiToMWsGraphicsContextMappings::Convert(aPenStyle));
258 void CWsAnimGc::SetPenSize(const TSize& aSize)
261 iOwningWsAnim.Panic(EWservPanicAnimLeave);
263 iGc->SetPenSize(aSize);
266 void CWsAnimGc::SetBrushColor(const TRgb &aColor)
269 iOwningWsAnim.Panic(EWservPanicAnimLeave);
271 iGc->SetBrushColor(aColor);
274 void CWsAnimGc::SetBrushStyle(TBrushStyle aBrushStyle)
277 iOwningWsAnim.Panic(EWservPanicAnimLeave);
279 iGc->SetBrushStyle(BitGdiToMWsGraphicsContextMappings::Convert(aBrushStyle));
282 void CWsAnimGc::SetBrushOrigin(const TPoint &aOrigin)
285 iOwningWsAnim.Panic(EWservPanicAnimLeave);
287 iGc->SetBrushOrigin(aOrigin);
290 void CWsAnimGc::UseBrushPattern(const CFbsBitmap *aBitmap)
293 iOwningWsAnim.Panic(EWservPanicAnimLeave);
295 iGc->SetBrushPattern(*aBitmap);
298 void CWsAnimGc::DiscardBrushPattern()
301 iOwningWsAnim.Panic(EWservPanicAnimLeave);
303 iGc->ResetBrushPattern();
306 void CWsAnimGc::SetFaded(TBool /*aFaded*/) // Deprecated
309 iOwningWsAnim.Panic(EWservPanicAnimLeave);
313 void CWsAnimGc::SetFadingParameters(TUint8 /*aBlackMap*/,TUint8 /*aWhiteMap*/) // Deprecated
316 iOwningWsAnim.Panic(EWservPanicAnimLeave);
321 // Drawing commands //
324 void CWsAnimGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
327 iOwningWsAnim.Panic(EWservPanicAnimLeave);
329 iGc->DrawArc(aRect,aStart,aEnd);
332 void CWsAnimGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
335 iOwningWsAnim.Panic(EWservPanicAnimLeave);
337 iGc->DrawPie(aRect,aStart,aEnd);
340 void CWsAnimGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
343 iOwningWsAnim.Panic(EWservPanicAnimLeave);
345 iGc->DrawLine(aPoint1, aPoint2);
348 void CWsAnimGc::DrawLineTo(const TPoint &aPoint)
351 iOwningWsAnim.Panic(EWservPanicAnimLeave);
353 iGc->DrawLineTo(aPoint);
356 void CWsAnimGc::DrawLineBy(const TPoint &aPoint)
359 iOwningWsAnim.Panic(EWservPanicAnimLeave);
361 iGc->DrawLineBy(aPoint);
364 void CWsAnimGc::DrawEllipse(const TRect &aRect)
367 iOwningWsAnim.Panic(EWservPanicAnimLeave);
369 iGc->DrawEllipse(aRect);
372 void CWsAnimGc::DrawRect(const TRect &aRect)
375 iOwningWsAnim.Panic(EWservPanicAnimLeave);
377 iGc->DrawRect(aRect);
380 void CWsAnimGc::DrawRoundRect(const TRect &aRect,const TSize &aCornerSize)
383 iOwningWsAnim.Panic(EWservPanicAnimLeave);
385 iGc->DrawRoundRect(aRect, aCornerSize);
388 void CWsAnimGc::Clear(const TRect &aRect)
391 iOwningWsAnim.Panic(EWservPanicAnimLeave);
396 void CWsAnimGc::Clear()
399 iOwningWsAnim.Panic(EWservPanicAnimLeave);
404 void CWsAnimGc::BitBlt(const TPoint &aPoint,const CFbsBitmap *aBitmap)
407 iOwningWsAnim.Panic(EWservPanicAnimLeave);
409 iGc->BitBlt(aPoint, *aBitmap);
412 void CWsAnimGc::BitBlt(const TPoint &aDestination,const CFbsBitmap *aBitmap,const TRect &aSource)
415 iOwningWsAnim.Panic(EWservPanicAnimLeave);
417 iGc->BitBlt(aDestination, *aBitmap, aSource);
420 void CWsAnimGc::BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask)
423 iOwningWsAnim.Panic(EWservPanicAnimLeave);
425 iGc->BitBltMasked(aPoint, *aBitmap, aSourceRect, *aMaskBitmap, aInvertMask);
428 void CWsAnimGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aSource)
431 iOwningWsAnim.Panic(EWservPanicAnimLeave);
434 // DrawBitmap(TPoint&, ) uses the size of the bitmap in twips, but
435 // MWsGraphicsContext::DrawBitmap() takes a TRect in pixels, so we need to convert
436 TRect destRect(iOwningWsAnim.ClientWindow()->Screen()->DeviceMap().TwipsToPixels(aSource->SizeInTwips()));
437 destRect.Move(aTopLeft); //aTopLeft is defined in pixels, that's why we're not converting it
438 iGc->DrawBitmap(destRect, *aSource);
442 void CWsAnimGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aSource)
445 iOwningWsAnim.Panic(EWservPanicAnimLeave);
447 iGc->DrawBitmap(aDestRect, *aSource);
450 void CWsAnimGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aSource, const TRect &aSrcRect)
453 iOwningWsAnim.Panic(EWservPanicAnimLeave);
455 iGc->DrawBitmap(aDestRect, *aSource, aSrcRect);
458 void CWsAnimGc::DrawBitmapMasked(const TRect &aDestRect, const CFbsBitmap *aBitmap, const TRect &aSrcRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
461 iOwningWsAnim.Panic(EWservPanicAnimLeave);
463 iGc->DrawBitmapMasked(aDestRect, *aBitmap, aSrcRect, *aMaskBitmap, aInvertMask);
466 void CWsAnimGc::DrawBitmapMasked(const TRect& aDestRect,const CWsBitmap* aBitmap,const TRect& aSrcRect,const CWsBitmap* aMaskBitmap, TBool aInvertMask)
469 iOwningWsAnim.Panic(EWservPanicAnimLeave);
471 iGc->DrawBitmapMasked(aDestRect, *aBitmap, aSrcRect, *aMaskBitmap, aInvertMask);
474 void CWsAnimGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
477 iOwningWsAnim.Panic(EWservPanicAnimLeave);
480 TArrayWrapper<TPoint> points(aPointList, aNumPoints);
481 iGc->DrawPolyLine(points);
485 void CWsAnimGc::DrawPolyLine(const CArrayFix<TPoint> *aPointList)
488 iOwningWsAnim.Panic(EWservPanicAnimLeave);
490 iGc->DrawPolyLine(aPointList->Array());
493 TInt CWsAnimGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
495 TInt result = KErrGeneral;
497 iOwningWsAnim.Panic(EWservPanicAnimLeave);
500 TArrayWrapper<TPoint> pointsArray(aPointList, aNumPoints);
501 iGc->DrawPolygon(pointsArray, BitGdiToMWsGraphicsContextMappings::Convert(aFillRule));
502 result = iGc->GetError();
507 TInt CWsAnimGc::DrawPolygon(const CArrayFix<TPoint> *aPointList,TFillRule aFillRule)
510 iOwningWsAnim.Panic(EWservPanicAnimLeave);
513 TInt result = KErrGeneral;
516 iGc->DrawPolygon(aPointList->Array(), BitGdiToMWsGraphicsContextMappings::Convert(aFillRule));
517 result = iGc->GetError();
522 void CWsAnimGc::DrawText(const TDesC &aString,const TPoint &aPosition)
525 iOwningWsAnim.Panic(EWservPanicNoFont);
527 iGc->DrawText(aString, NULL, aPosition);
530 void CWsAnimGc::DrawText(const TDesC &aString,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
533 iOwningWsAnim.Panic(EWservPanicNoFont);
535 iGc->DrawText(aString, NULL, aBox, aBaselineOffset, BitGdiToMWsGraphicsContextMappings::Convert(aHoriz), aLeftMrg);
538 void CWsAnimGc::MoveTo(const TPoint &aPoint)
541 iOwningWsAnim.Panic(EWservPanicAnimLeave);
546 void CWsAnimGc::MoveBy(const TPoint &aPoint)
549 iOwningWsAnim.Panic(EWservPanicAnimLeave);
554 void CWsAnimGc::Plot(const TPoint &aPoint)
557 iOwningWsAnim.Panic(EWservPanicAnimLeave);
562 void CWsAnimGc::SetOrigin(const TPoint &aPoint)
565 iOwningWsAnim.Panic(EWservPanicAnimLeave);
567 iGc->SetOrigin(iOwningWsAnim.ClientWindow()->Origin() + aPoint);
570 void CWsAnimGc::CopyRect(const TPoint& aOffset,const TRect& aRect)
573 iOwningWsAnim.Panic(EWservPanicAnimLeave);
575 iGc->CopyRect(aOffset, aRect);
578 void CWsAnimGc::Reset()
582 iOwningWsAnim.Panic(EWservPanicAnimLeave);
585 SetOrigin(TPoint(0,0));
586 CancelClippingRect();
587 CancelClippingRegion();
590 void CWsAnimGc::CloseCurrentFont()
600 @see CBitmapContext::AlphaBlendBitmaps()*/
601 TInt CWsAnimGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
603 TInt result = KErrGeneral;
605 iOwningWsAnim.Panic(EWservPanicAnimLeave);
608 iGc->BitBltMasked(aDestPt, *aSrcBmp, aSrcRect, *aAlphaBmp, aAlphaPt);
609 result = iGc->GetError();
614 /*Body stub implementation. The alternate AlphaBlendBitmap function using CFbsBitmaps should instead be used*/
615 TInt CWsAnimGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CWsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CWsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/)
621 @see CGraphicsContext::MapColors()*/
622 void CWsAnimGc::MapColors(const TRect& /*aRect*/,const TRgb* /*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/)
625 iOwningWsAnim.Panic(EWservPanicAnimLeave);
629 @see CGraphicsContext::DrawTextVertical()*/
630 void CWsAnimGc::DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp)
633 iOwningWsAnim.Panic(EWservPanicNoFont);
635 iGc->DrawTextVertical(aText, NULL, aPos, aUp);
639 @see CGraphicsContext::DrawTextVertical()*/
640 void CWsAnimGc::DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
643 iOwningWsAnim.Panic(EWservPanicNoFont);
645 iGc->DrawTextVertical(aText, NULL, aBox, aBaselineOffset, aUp, BitGdiToMWsGraphicsContextMappings::Convert(aVert), aMargin);