Update contrib.
1 // Copyright (c) 1997-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.
22 #include <graphics/fbsrasterizer.h>
25 Draws and fills a rectangle with rounded corners.
27 The function provides a concrete implementation of the pure virtual
28 function <code>CGraphicsContext::DrawRoundRect()</code>. The function
29 behaviour is the same as documented in that class.
31 EXPORT_C void CFbsBitGc::DrawRoundRect(const TRect& aRect,const TSize& aSize)
33 if (CheckDevice(aRect))
38 ellsize.iHeight <<= 1;
40 if (ellsize.iWidth < 3 || ellsize.iHeight < 3)
46 if (aRect.Width() < ellsize.iWidth && aRect.Height() < ellsize.iHeight)
54 iDevice->TruncateRect(rcpy);
55 ellsize.iWidth = Min(rcpy.Width(),ellsize.iWidth);
56 ellsize.iHeight = Min(rcpy.Height(),ellsize.iHeight);
58 TRect clippedBoundingRect(rcpy);
59 clippedBoundingRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
60 if (!clippedBoundingRect.Intersects(iUserClipRect))
64 iDevice->DrawingBegin(&iBrushBitmap);
65 CFbsRasterizer* brushRasterizer = PrepareRasterizerForExtendedBitmap(iBrushBitmap);
67 if (iBrushStyle != ENullBrush)
68 RoundRectFill(rcpy,ellsize);
70 if (iPenStyle != ENullPen && iPenSize.iWidth > 0 && iPenSize.iHeight > 0)
71 RoundRectOutline(rcpy,ellsize);
75 brushRasterizer->EndBitmap(iBrushBitmap.SerialNumber());
77 iDevice->DrawingEnd(&iBrushBitmap);
80 // if iBrushBitmap is an extended bitmap, PrepareRasterizerForExtendedBitmap() must have been called before this method
81 void CFbsBitGc::RoundRectFill(const TRect& aRect,TSize aSize)
84 if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
88 if (rcpy.iBr.iX - rcpy.iTl.iX < aSize.iWidth)
89 aSize.iWidth = rcpy.Width();
90 if (rcpy.iBr.iY - rcpy.iTl.iY < aSize.iHeight)
91 aSize.iHeight = rcpy.Height();
93 TInt xoff = rcpy.Width() - aSize.iWidth;
94 TInt yoff = rcpy.Height() - aSize.iHeight;
99 const TInt limit = iDefaultRegionPtr->Count();
100 for (TInt count = 0; count < limit; count++)
102 iClipRect = (*iDefaultRegionPtr)[count];
103 if (UserClipRect(iClipRect))
105 if (!iClipRect.Intersects(aRect))
109 iClipRect.Intersection(aRect);
112 ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aSize));
113 ellipse.SingleStep(tl,tr,bl,br);
116 while (!ellipse.SingleStep(tl,tr,bl,br))
118 if (tl.iY == prevlev)
134 iDevice->iDrawDevice->UpdateRegion(iClipRect);
151 RectFill(TRect(tl,br));
154 void CFbsBitGc::RoundRectOutline(const TRect& aRect,TSize aSize)
157 const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
158 const TInt halfpenheight = (iPenSize.iWidth + 1) >> 1;
159 rcpy.Grow(halfpenwidth,halfpenheight);
162 if (aRect.Width() < aSize.iWidth)
163 aSize.iWidth = aRect.Width();
164 if (aRect.Height() < aSize.iHeight)
165 aSize.iHeight = aRect.Height();
168 const TInt xoff = aRect.Width() - aSize.iWidth;
169 const TInt yoff = aRect.Height() - aSize.iHeight;
170 const TInt dotparam = iDotParam;
172 const TInt limit = iDefaultRegionPtr->Count();
173 for (TInt count = 0; count < limit; count++)
175 iClipRect = (*iDefaultRegionPtr)[count];
176 if (!iClipRect.Intersects(rcpy))
178 iClipRect.Intersection(rcpy);
179 if (UserClipRect(iClipRect))
182 iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
183 TInt column = aRect.iTl.iX + (aSize.iWidth >> 1);
184 TInt lastcolumn = aRect.iTl.iX + xoff + (aSize.iWidth >> 1);
186 for (; column < lastcolumn; column++)
188 PenDrawClipped(TPoint(column,aRect.iTl.iY));
189 PenDrawClipped(TPoint(column,aRect.iBr.iY - 1));
190 iDotParam += iDotDirection;
194 ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aSize));
195 while (!ellipse.SingleStep(tl,tr,bl,br))
207 iDotParam += iDotDirection;
218 for (column = tl.iY + 1; column < bl.iY; column++)
220 PenDrawClipped(TPoint(aRect.iTl.iX,column));
221 PenDrawClipped(TPoint(aRect.iBr.iX - 1,column));
222 iDotParam += iDotDirection;
225 iDevice->iDrawDevice->UpdateRegion(iClipRect);
228 iDotParam = dotparam;