os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiroundrec.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiroundrec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,199 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "swdirectgdiengine.h"
1.20 +#include "swdirectgdiellipse.h"
1.21 +
1.22 +/**
1.23 +@see MDirectGdiEngine::DrawRoundRect()
1.24 +*/
1.25 +void CSwDirectGdiEngine::DrawRoundRect(const TRect& aRect, const TSize& aCornerSize)
1.26 + {
1.27 + TSize cornerSize(aCornerSize);
1.28 + cornerSize.iWidth <<= 1;
1.29 + cornerSize.iHeight <<= 1;
1.30 +
1.31 +
1.32 + TRect rcpy(aRect);
1.33 + rcpy.Move(iOrigin);
1.34 + TruncateRect(rcpy);
1.35 + cornerSize.iWidth = Min(rcpy.Width(),cornerSize.iWidth);
1.36 + cornerSize.iHeight = Min(rcpy.Height(),cornerSize.iHeight);
1.37 +
1.38 + TRect targetRect(rcpy);
1.39 + targetRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
1.40 +
1.41 + if (iBrushStyle != DirectGdi::ENullBrush)
1.42 + {
1.43 + RoundRectFill(rcpy,cornerSize);
1.44 + }
1.45 +
1.46 + if ((iPenStyle != DirectGdi::ENullPen) && ((iPenSize.iWidth > 0) && (iPenSize.iHeight > 0)))
1.47 + {
1.48 + RoundRectOutline(rcpy, cornerSize);
1.49 + }
1.50 + }
1.51 +
1.52 +/**
1.53 +@see DrawRoundRect()
1.54 +*/
1.55 +void CSwDirectGdiEngine::RoundRectFill(const TRect& aRect, const TSize& aCornerSize)
1.56 + {
1.57 + TRect rcpy(aRect);
1.58 + if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
1.59 + {
1.60 + rcpy.Grow(1,1);
1.61 + }
1.62 +
1.63 + TInt xoff = rcpy.Width() - aCornerSize.iWidth;
1.64 + TInt yoff = rcpy.Height() - aCornerSize.iHeight;
1.65 + TPoint tl, tr, bl, br;
1.66 + TInt prevlev = 0;
1.67 + TBool draw = EFalse;
1.68 +
1.69 + TRect clipRect(0,0,0,0);
1.70 + const TInt limit = iDefaultRegionPtr->Count();
1.71 + for (TInt count = 0; count < limit; count++)
1.72 + {
1.73 + clipRect = (*iDefaultRegionPtr)[count];
1.74 + if (!clipRect.Intersects(aRect))
1.75 + {
1.76 + continue;
1.77 + }
1.78 +
1.79 + draw = ETrue;
1.80 + clipRect.Intersection(aRect);
1.81 +
1.82 + TSwDirectGdiEllipse ellipse;
1.83 + ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aCornerSize));
1.84 + ellipse.SingleStep(tl, tr, bl, br);
1.85 + prevlev = tl.iY;
1.86 +
1.87 + while (!ellipse.SingleStep(tl, tr, bl, br))
1.88 + {
1.89 + if (tl.iY == prevlev)
1.90 + {
1.91 + continue;
1.92 + }
1.93 +
1.94 + tl.iX++;
1.95 + tr.iX += xoff - 1;
1.96 + bl.iX++;
1.97 + bl.iY += yoff;
1.98 + br.iX += xoff - 1;
1.99 + br.iY += yoff;
1.100 +
1.101 + ClipFillLine(tl, tr,clipRect);
1.102 + ClipFillLine(bl, br,clipRect);
1.103 +
1.104 + prevlev = tl.iY;
1.105 + }
1.106 +
1.107 + iDrawDevice->UpdateRegion(clipRect);
1.108 + }
1.109 +
1.110 + if (!draw)
1.111 + {
1.112 + return;
1.113 + }
1.114 +
1.115 + if (tl.iY >= bl.iY)
1.116 + {
1.117 + tl.iY--;
1.118 + br.iY++;
1.119 + }
1.120 +
1.121 + tl.iX++;
1.122 + tl.iY++;
1.123 + br.iX += xoff;
1.124 + br.iY += yoff;
1.125 +
1.126 + RectFill(TRect(tl,br));
1.127 + }
1.128 +
1.129 +/**
1.130 +@see DrawRoundRect()
1.131 +*/
1.132 +void CSwDirectGdiEngine::RoundRectOutline(const TRect& aRect, const TSize& aCornerSize)
1.133 + {
1.134 + TRect rcpy(aRect);
1.135 + const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
1.136 + const TInt halfpenheight = (iPenSize.iHeight + 1) >> 1;
1.137 + rcpy.Grow(halfpenwidth,halfpenheight);
1.138 +
1.139 + TPoint tl, tr, bl, br;
1.140 + const TInt xoff = aRect.Width() - aCornerSize.iWidth;
1.141 + const TInt yoff = aRect.Height() - aCornerSize.iHeight;
1.142 + const TInt dotparam = iDotParam;
1.143 +
1.144 + TRect clipRect(0,0,0,0);
1.145 + const TInt limit = iDefaultRegionPtr->Count();
1.146 + for (TInt count = 0; count < limit; count++)
1.147 + {
1.148 + clipRect = (*iDefaultRegionPtr)[count];
1.149 + if (!clipRect.Intersects(rcpy))
1.150 + {
1.151 + continue;
1.152 + }
1.153 + clipRect.Intersection(rcpy);
1.154 +
1.155 + iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
1.156 + TInt column = aRect.iTl.iX + (aCornerSize.iWidth >> 1);
1.157 + TInt lastcolumn = aRect.iTl.iX + xoff + (aCornerSize.iWidth >> 1);
1.158 +
1.159 + for (; column < lastcolumn; column++)
1.160 + {
1.161 + PenDrawClipped(TPoint(column,aRect.iTl.iY), clipRect);
1.162 + PenDrawClipped(TPoint(column,aRect.iBr.iY - 1), clipRect);
1.163 + iDotParam += iDotDirection;
1.164 + }
1.165 +
1.166 + TSwDirectGdiEllipse ellipse;
1.167 + ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aCornerSize));
1.168 + while (!ellipse.SingleStep(tl,tr,bl,br))
1.169 + {
1.170 + tr.iX += xoff;
1.171 + bl.iY += yoff;
1.172 + br.iX += xoff;
1.173 + br.iY += yoff;
1.174 +
1.175 + PenDrawClipped(tl, clipRect);
1.176 + PenDrawClipped(tr, clipRect);
1.177 + PenDrawClipped(bl, clipRect);
1.178 + PenDrawClipped(br, clipRect);
1.179 +
1.180 + iDotParam += iDotDirection;
1.181 + }
1.182 +
1.183 + if (tl.iY >= bl.iY)
1.184 + {
1.185 + tl.iY--;
1.186 + bl.iY++;
1.187 + }
1.188 +
1.189 + bl.iY += yoff;
1.190 +
1.191 + for (column = tl.iY + 1; column < bl.iY; column++)
1.192 + {
1.193 + PenDrawClipped(TPoint(aRect.iTl.iX,column), clipRect);
1.194 + PenDrawClipped(TPoint(aRect.iBr.iX - 1,column), clipRect);
1.195 + iDotParam += iDotDirection;
1.196 + }
1.197 +
1.198 + iDrawDevice->UpdateRegion(clipRect);
1.199 + }
1.200 +
1.201 + iDotParam = dotparam;
1.202 + }