1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/bitgdi/sbit/ROUNDREC.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,230 @@
1.4 +// Copyright (c) 1997-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 <fntstore.h>
1.20 +#include <bitmap.h>
1.21 +#include <bitstd.h>
1.22 +#include <bitdev.h>
1.23 +#include "BITPANIC.H"
1.24 +#include <bitdraw.h>
1.25 +#include <graphics/fbsrasterizer.h>
1.26 +
1.27 +/**
1.28 +Draws and fills a rectangle with rounded corners.
1.29 +
1.30 +The function provides a concrete implementation of the pure virtual
1.31 +function <code>CGraphicsContext::DrawRoundRect()</code>. The function
1.32 +behaviour is the same as documented in that class.
1.33 +*/
1.34 +EXPORT_C void CFbsBitGc::DrawRoundRect(const TRect& aRect,const TSize& aSize)
1.35 + {
1.36 + if (CheckDevice(aRect))
1.37 + return;
1.38 +
1.39 + TSize ellsize(aSize);
1.40 + ellsize.iWidth <<= 1;
1.41 + ellsize.iHeight <<= 1;
1.42 +
1.43 + if (ellsize.iWidth < 3 || ellsize.iHeight < 3)
1.44 + {
1.45 + DrawRect(aRect);
1.46 + return;
1.47 + }
1.48 +
1.49 + if (aRect.Width() < ellsize.iWidth && aRect.Height() < ellsize.iHeight)
1.50 + {
1.51 + DrawEllipse(aRect);
1.52 + return;
1.53 + }
1.54 +
1.55 + TRect rcpy(aRect);
1.56 + rcpy.Move(iOrigin);
1.57 + iDevice->TruncateRect(rcpy);
1.58 + ellsize.iWidth = Min(rcpy.Width(),ellsize.iWidth);
1.59 + ellsize.iHeight = Min(rcpy.Height(),ellsize.iHeight);
1.60 +
1.61 + TRect clippedBoundingRect(rcpy);
1.62 + clippedBoundingRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
1.63 + if (!clippedBoundingRect.Intersects(iUserClipRect))
1.64 + return;
1.65 +
1.66 + SetupDevice();
1.67 + iDevice->DrawingBegin(&iBrushBitmap);
1.68 + CFbsRasterizer* brushRasterizer = PrepareRasterizerForExtendedBitmap(iBrushBitmap);
1.69 +
1.70 + if (iBrushStyle != ENullBrush)
1.71 + RoundRectFill(rcpy,ellsize);
1.72 +
1.73 + if (iPenStyle != ENullPen && iPenSize.iWidth > 0 && iPenSize.iHeight > 0)
1.74 + RoundRectOutline(rcpy,ellsize);
1.75 +
1.76 + if (brushRasterizer)
1.77 + {
1.78 + brushRasterizer->EndBitmap(iBrushBitmap.SerialNumber());
1.79 + }
1.80 + iDevice->DrawingEnd(&iBrushBitmap);
1.81 + }
1.82 +
1.83 +// if iBrushBitmap is an extended bitmap, PrepareRasterizerForExtendedBitmap() must have been called before this method
1.84 +void CFbsBitGc::RoundRectFill(const TRect& aRect,TSize aSize)
1.85 + {
1.86 + TRect rcpy(aRect);
1.87 + if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
1.88 + rcpy.Grow(1,1);
1.89 + AddRect(rcpy);
1.90 +
1.91 + if (rcpy.iBr.iX - rcpy.iTl.iX < aSize.iWidth)
1.92 + aSize.iWidth = rcpy.Width();
1.93 + if (rcpy.iBr.iY - rcpy.iTl.iY < aSize.iHeight)
1.94 + aSize.iHeight = rcpy.Height();
1.95 +
1.96 + TInt xoff = rcpy.Width() - aSize.iWidth;
1.97 + TInt yoff = rcpy.Height() - aSize.iHeight;
1.98 + TPoint tl,tr,bl,br;
1.99 + TInt prevlev = 0;
1.100 + TBool draw = EFalse;
1.101 +
1.102 + const TInt limit = iDefaultRegionPtr->Count();
1.103 + for (TInt count = 0; count < limit; count++)
1.104 + {
1.105 + iClipRect = (*iDefaultRegionPtr)[count];
1.106 + if (UserClipRect(iClipRect))
1.107 + continue;
1.108 + if (!iClipRect.Intersects(aRect))
1.109 + continue;
1.110 +
1.111 + draw = ETrue;
1.112 + iClipRect.Intersection(aRect);
1.113 +
1.114 + TEllipse ellipse;
1.115 + ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aSize));
1.116 + ellipse.SingleStep(tl,tr,bl,br);
1.117 + prevlev = tl.iY;
1.118 +
1.119 + while (!ellipse.SingleStep(tl,tr,bl,br))
1.120 + {
1.121 + if (tl.iY == prevlev)
1.122 + continue;
1.123 +
1.124 + tl.iX++;
1.125 + tr.iX += xoff - 1;
1.126 + bl.iX++;
1.127 + bl.iY += yoff;
1.128 + br.iX += xoff - 1;
1.129 + br.iY += yoff;
1.130 +
1.131 + ClipFillLine(tl,tr);
1.132 + ClipFillLine(bl,br);
1.133 +
1.134 + prevlev = tl.iY;
1.135 + }
1.136 +
1.137 + iDevice->iDrawDevice->UpdateRegion(iClipRect);
1.138 + }
1.139 +
1.140 + if (!draw)
1.141 + return;
1.142 +
1.143 + if (tl.iY >= bl.iY)
1.144 + {
1.145 + tl.iY--;
1.146 + br.iY++;
1.147 + }
1.148 +
1.149 + tl.iX++;
1.150 + tl.iY++;
1.151 + br.iX += xoff;
1.152 + br.iY += yoff;
1.153 +
1.154 + RectFill(TRect(tl,br));
1.155 + }
1.156 +
1.157 +void CFbsBitGc::RoundRectOutline(const TRect& aRect,TSize aSize)
1.158 + {
1.159 + TRect rcpy(aRect);
1.160 + const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
1.161 + const TInt halfpenheight = (iPenSize.iWidth + 1) >> 1;
1.162 + rcpy.Grow(halfpenwidth,halfpenheight);
1.163 + AddRect(rcpy);
1.164 +
1.165 + if (aRect.Width() < aSize.iWidth)
1.166 + aSize.iWidth = aRect.Width();
1.167 + if (aRect.Height() < aSize.iHeight)
1.168 + aSize.iHeight = aRect.Height();
1.169 +
1.170 + TPoint tl,tr,bl,br;
1.171 + const TInt xoff = aRect.Width() - aSize.iWidth;
1.172 + const TInt yoff = aRect.Height() - aSize.iHeight;
1.173 + const TInt dotparam = iDotParam;
1.174 +
1.175 + const TInt limit = iDefaultRegionPtr->Count();
1.176 + for (TInt count = 0; count < limit; count++)
1.177 + {
1.178 + iClipRect = (*iDefaultRegionPtr)[count];
1.179 + if (!iClipRect.Intersects(rcpy))
1.180 + continue;
1.181 + iClipRect.Intersection(rcpy);
1.182 + if (UserClipRect(iClipRect))
1.183 + continue;
1.184 +
1.185 + iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
1.186 + TInt column = aRect.iTl.iX + (aSize.iWidth >> 1);
1.187 + TInt lastcolumn = aRect.iTl.iX + xoff + (aSize.iWidth >> 1);
1.188 +
1.189 + for (; column < lastcolumn; column++)
1.190 + {
1.191 + PenDrawClipped(TPoint(column,aRect.iTl.iY));
1.192 + PenDrawClipped(TPoint(column,aRect.iBr.iY - 1));
1.193 + iDotParam += iDotDirection;
1.194 + }
1.195 +
1.196 + TEllipse ellipse;
1.197 + ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aSize));
1.198 + while (!ellipse.SingleStep(tl,tr,bl,br))
1.199 + {
1.200 + tr.iX += xoff;
1.201 + bl.iY += yoff;
1.202 + br.iX += xoff;
1.203 + br.iY += yoff;
1.204 +
1.205 + PenDrawClipped(tl);
1.206 + PenDrawClipped(tr);
1.207 + PenDrawClipped(bl);
1.208 + PenDrawClipped(br);
1.209 +
1.210 + iDotParam += iDotDirection;
1.211 + }
1.212 +
1.213 + if (tl.iY >= bl.iY)
1.214 + {
1.215 + tl.iY--;
1.216 + bl.iY++;
1.217 + }
1.218 +
1.219 + bl.iY += yoff;
1.220 +
1.221 + for (column = tl.iY + 1; column < bl.iY; column++)
1.222 + {
1.223 + PenDrawClipped(TPoint(aRect.iTl.iX,column));
1.224 + PenDrawClipped(TPoint(aRect.iBr.iX - 1,column));
1.225 + iDotParam += iDotDirection;
1.226 + }
1.227 +
1.228 + iDevice->iDrawDevice->UpdateRegion(iClipRect);
1.229 + }
1.230 +
1.231 + iDotParam = dotparam;
1.232 + }
1.233 +