sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "swdirectgdiengine.h" sl@0: #include "swdirectgdiellipse.h" sl@0: sl@0: /** sl@0: @see MDirectGdiEngine::DrawRoundRect() sl@0: */ sl@0: void CSwDirectGdiEngine::DrawRoundRect(const TRect& aRect, const TSize& aCornerSize) sl@0: { sl@0: TSize cornerSize(aCornerSize); sl@0: cornerSize.iWidth <<= 1; sl@0: cornerSize.iHeight <<= 1; sl@0: sl@0: sl@0: TRect rcpy(aRect); sl@0: rcpy.Move(iOrigin); sl@0: TruncateRect(rcpy); sl@0: cornerSize.iWidth = Min(rcpy.Width(),cornerSize.iWidth); sl@0: cornerSize.iHeight = Min(rcpy.Height(),cornerSize.iHeight); sl@0: sl@0: TRect targetRect(rcpy); sl@0: targetRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1); sl@0: sl@0: if (iBrushStyle != DirectGdi::ENullBrush) sl@0: { sl@0: RoundRectFill(rcpy,cornerSize); sl@0: } sl@0: sl@0: if ((iPenStyle != DirectGdi::ENullPen) && ((iPenSize.iWidth > 0) && (iPenSize.iHeight > 0))) sl@0: { sl@0: RoundRectOutline(rcpy, cornerSize); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @see DrawRoundRect() sl@0: */ sl@0: void CSwDirectGdiEngine::RoundRectFill(const TRect& aRect, const TSize& aCornerSize) sl@0: { sl@0: TRect rcpy(aRect); sl@0: if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1) sl@0: { sl@0: rcpy.Grow(1,1); sl@0: } sl@0: sl@0: TInt xoff = rcpy.Width() - aCornerSize.iWidth; sl@0: TInt yoff = rcpy.Height() - aCornerSize.iHeight; sl@0: TPoint tl, tr, bl, br; sl@0: TInt prevlev = 0; sl@0: TBool draw = EFalse; sl@0: sl@0: TRect clipRect(0,0,0,0); sl@0: const TInt limit = iDefaultRegionPtr->Count(); sl@0: for (TInt count = 0; count < limit; count++) sl@0: { sl@0: clipRect = (*iDefaultRegionPtr)[count]; sl@0: if (!clipRect.Intersects(aRect)) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: draw = ETrue; sl@0: clipRect.Intersection(aRect); sl@0: sl@0: TSwDirectGdiEllipse ellipse; sl@0: ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aCornerSize)); sl@0: ellipse.SingleStep(tl, tr, bl, br); sl@0: prevlev = tl.iY; sl@0: sl@0: while (!ellipse.SingleStep(tl, tr, bl, br)) sl@0: { sl@0: if (tl.iY == prevlev) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: tl.iX++; sl@0: tr.iX += xoff - 1; sl@0: bl.iX++; sl@0: bl.iY += yoff; sl@0: br.iX += xoff - 1; sl@0: br.iY += yoff; sl@0: sl@0: ClipFillLine(tl, tr,clipRect); sl@0: ClipFillLine(bl, br,clipRect); sl@0: sl@0: prevlev = tl.iY; sl@0: } sl@0: sl@0: iDrawDevice->UpdateRegion(clipRect); sl@0: } sl@0: sl@0: if (!draw) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: if (tl.iY >= bl.iY) sl@0: { sl@0: tl.iY--; sl@0: br.iY++; sl@0: } sl@0: sl@0: tl.iX++; sl@0: tl.iY++; sl@0: br.iX += xoff; sl@0: br.iY += yoff; sl@0: sl@0: RectFill(TRect(tl,br)); sl@0: } sl@0: sl@0: /** sl@0: @see DrawRoundRect() sl@0: */ sl@0: void CSwDirectGdiEngine::RoundRectOutline(const TRect& aRect, const TSize& aCornerSize) sl@0: { sl@0: TRect rcpy(aRect); sl@0: const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1; sl@0: const TInt halfpenheight = (iPenSize.iHeight + 1) >> 1; sl@0: rcpy.Grow(halfpenwidth,halfpenheight); sl@0: sl@0: TPoint tl, tr, bl, br; sl@0: const TInt xoff = aRect.Width() - aCornerSize.iWidth; sl@0: const TInt yoff = aRect.Height() - aCornerSize.iHeight; sl@0: const TInt dotparam = iDotParam; sl@0: sl@0: TRect clipRect(0,0,0,0); sl@0: const TInt limit = iDefaultRegionPtr->Count(); sl@0: for (TInt count = 0; count < limit; count++) sl@0: { sl@0: clipRect = (*iDefaultRegionPtr)[count]; sl@0: if (!clipRect.Intersects(rcpy)) sl@0: { sl@0: continue; sl@0: } sl@0: clipRect.Intersection(rcpy); sl@0: sl@0: iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1); sl@0: TInt column = aRect.iTl.iX + (aCornerSize.iWidth >> 1); sl@0: TInt lastcolumn = aRect.iTl.iX + xoff + (aCornerSize.iWidth >> 1); sl@0: sl@0: for (; column < lastcolumn; column++) sl@0: { sl@0: PenDrawClipped(TPoint(column,aRect.iTl.iY), clipRect); sl@0: PenDrawClipped(TPoint(column,aRect.iBr.iY - 1), clipRect); sl@0: iDotParam += iDotDirection; sl@0: } sl@0: sl@0: TSwDirectGdiEllipse ellipse; sl@0: ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aCornerSize)); sl@0: while (!ellipse.SingleStep(tl,tr,bl,br)) sl@0: { sl@0: tr.iX += xoff; sl@0: bl.iY += yoff; sl@0: br.iX += xoff; sl@0: br.iY += yoff; sl@0: sl@0: PenDrawClipped(tl, clipRect); sl@0: PenDrawClipped(tr, clipRect); sl@0: PenDrawClipped(bl, clipRect); sl@0: PenDrawClipped(br, clipRect); sl@0: sl@0: iDotParam += iDotDirection; sl@0: } sl@0: sl@0: if (tl.iY >= bl.iY) sl@0: { sl@0: tl.iY--; sl@0: bl.iY++; sl@0: } sl@0: sl@0: bl.iY += yoff; sl@0: sl@0: for (column = tl.iY + 1; column < bl.iY; column++) sl@0: { sl@0: PenDrawClipped(TPoint(aRect.iTl.iX,column), clipRect); sl@0: PenDrawClipped(TPoint(aRect.iBr.iX - 1,column), clipRect); sl@0: iDotParam += iDotDirection; sl@0: } sl@0: sl@0: iDrawDevice->UpdateRegion(clipRect); sl@0: } sl@0: sl@0: iDotParam = dotparam; sl@0: }