|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <fntstore.h> |
|
17 #include <bitmap.h> |
|
18 #include <bitstd.h> |
|
19 #include <bitdev.h> |
|
20 #include "BITPANIC.H" |
|
21 #include <bitdraw.h> |
|
22 #include <graphics/fbsrasterizer.h> |
|
23 |
|
24 /** |
|
25 Draws and fills a rectangle with rounded corners. |
|
26 |
|
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. |
|
30 */ |
|
31 EXPORT_C void CFbsBitGc::DrawRoundRect(const TRect& aRect,const TSize& aSize) |
|
32 { |
|
33 if (CheckDevice(aRect)) |
|
34 return; |
|
35 |
|
36 TSize ellsize(aSize); |
|
37 ellsize.iWidth <<= 1; |
|
38 ellsize.iHeight <<= 1; |
|
39 |
|
40 if (ellsize.iWidth < 3 || ellsize.iHeight < 3) |
|
41 { |
|
42 DrawRect(aRect); |
|
43 return; |
|
44 } |
|
45 |
|
46 if (aRect.Width() < ellsize.iWidth && aRect.Height() < ellsize.iHeight) |
|
47 { |
|
48 DrawEllipse(aRect); |
|
49 return; |
|
50 } |
|
51 |
|
52 TRect rcpy(aRect); |
|
53 rcpy.Move(iOrigin); |
|
54 iDevice->TruncateRect(rcpy); |
|
55 ellsize.iWidth = Min(rcpy.Width(),ellsize.iWidth); |
|
56 ellsize.iHeight = Min(rcpy.Height(),ellsize.iHeight); |
|
57 |
|
58 TRect clippedBoundingRect(rcpy); |
|
59 clippedBoundingRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1); |
|
60 if (!clippedBoundingRect.Intersects(iUserClipRect)) |
|
61 return; |
|
62 |
|
63 SetupDevice(); |
|
64 iDevice->DrawingBegin(&iBrushBitmap); |
|
65 CFbsRasterizer* brushRasterizer = PrepareRasterizerForExtendedBitmap(iBrushBitmap); |
|
66 |
|
67 if (iBrushStyle != ENullBrush) |
|
68 RoundRectFill(rcpy,ellsize); |
|
69 |
|
70 if (iPenStyle != ENullPen && iPenSize.iWidth > 0 && iPenSize.iHeight > 0) |
|
71 RoundRectOutline(rcpy,ellsize); |
|
72 |
|
73 if (brushRasterizer) |
|
74 { |
|
75 brushRasterizer->EndBitmap(iBrushBitmap.SerialNumber()); |
|
76 } |
|
77 iDevice->DrawingEnd(&iBrushBitmap); |
|
78 } |
|
79 |
|
80 // if iBrushBitmap is an extended bitmap, PrepareRasterizerForExtendedBitmap() must have been called before this method |
|
81 void CFbsBitGc::RoundRectFill(const TRect& aRect,TSize aSize) |
|
82 { |
|
83 TRect rcpy(aRect); |
|
84 if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1) |
|
85 rcpy.Grow(1,1); |
|
86 AddRect(rcpy); |
|
87 |
|
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(); |
|
92 |
|
93 TInt xoff = rcpy.Width() - aSize.iWidth; |
|
94 TInt yoff = rcpy.Height() - aSize.iHeight; |
|
95 TPoint tl,tr,bl,br; |
|
96 TInt prevlev = 0; |
|
97 TBool draw = EFalse; |
|
98 |
|
99 const TInt limit = iDefaultRegionPtr->Count(); |
|
100 for (TInt count = 0; count < limit; count++) |
|
101 { |
|
102 iClipRect = (*iDefaultRegionPtr)[count]; |
|
103 if (UserClipRect(iClipRect)) |
|
104 continue; |
|
105 if (!iClipRect.Intersects(aRect)) |
|
106 continue; |
|
107 |
|
108 draw = ETrue; |
|
109 iClipRect.Intersection(aRect); |
|
110 |
|
111 TEllipse ellipse; |
|
112 ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aSize)); |
|
113 ellipse.SingleStep(tl,tr,bl,br); |
|
114 prevlev = tl.iY; |
|
115 |
|
116 while (!ellipse.SingleStep(tl,tr,bl,br)) |
|
117 { |
|
118 if (tl.iY == prevlev) |
|
119 continue; |
|
120 |
|
121 tl.iX++; |
|
122 tr.iX += xoff - 1; |
|
123 bl.iX++; |
|
124 bl.iY += yoff; |
|
125 br.iX += xoff - 1; |
|
126 br.iY += yoff; |
|
127 |
|
128 ClipFillLine(tl,tr); |
|
129 ClipFillLine(bl,br); |
|
130 |
|
131 prevlev = tl.iY; |
|
132 } |
|
133 |
|
134 iDevice->iDrawDevice->UpdateRegion(iClipRect); |
|
135 } |
|
136 |
|
137 if (!draw) |
|
138 return; |
|
139 |
|
140 if (tl.iY >= bl.iY) |
|
141 { |
|
142 tl.iY--; |
|
143 br.iY++; |
|
144 } |
|
145 |
|
146 tl.iX++; |
|
147 tl.iY++; |
|
148 br.iX += xoff; |
|
149 br.iY += yoff; |
|
150 |
|
151 RectFill(TRect(tl,br)); |
|
152 } |
|
153 |
|
154 void CFbsBitGc::RoundRectOutline(const TRect& aRect,TSize aSize) |
|
155 { |
|
156 TRect rcpy(aRect); |
|
157 const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1; |
|
158 const TInt halfpenheight = (iPenSize.iWidth + 1) >> 1; |
|
159 rcpy.Grow(halfpenwidth,halfpenheight); |
|
160 AddRect(rcpy); |
|
161 |
|
162 if (aRect.Width() < aSize.iWidth) |
|
163 aSize.iWidth = aRect.Width(); |
|
164 if (aRect.Height() < aSize.iHeight) |
|
165 aSize.iHeight = aRect.Height(); |
|
166 |
|
167 TPoint tl,tr,bl,br; |
|
168 const TInt xoff = aRect.Width() - aSize.iWidth; |
|
169 const TInt yoff = aRect.Height() - aSize.iHeight; |
|
170 const TInt dotparam = iDotParam; |
|
171 |
|
172 const TInt limit = iDefaultRegionPtr->Count(); |
|
173 for (TInt count = 0; count < limit; count++) |
|
174 { |
|
175 iClipRect = (*iDefaultRegionPtr)[count]; |
|
176 if (!iClipRect.Intersects(rcpy)) |
|
177 continue; |
|
178 iClipRect.Intersection(rcpy); |
|
179 if (UserClipRect(iClipRect)) |
|
180 continue; |
|
181 |
|
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); |
|
185 |
|
186 for (; column < lastcolumn; column++) |
|
187 { |
|
188 PenDrawClipped(TPoint(column,aRect.iTl.iY)); |
|
189 PenDrawClipped(TPoint(column,aRect.iBr.iY - 1)); |
|
190 iDotParam += iDotDirection; |
|
191 } |
|
192 |
|
193 TEllipse ellipse; |
|
194 ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aSize)); |
|
195 while (!ellipse.SingleStep(tl,tr,bl,br)) |
|
196 { |
|
197 tr.iX += xoff; |
|
198 bl.iY += yoff; |
|
199 br.iX += xoff; |
|
200 br.iY += yoff; |
|
201 |
|
202 PenDrawClipped(tl); |
|
203 PenDrawClipped(tr); |
|
204 PenDrawClipped(bl); |
|
205 PenDrawClipped(br); |
|
206 |
|
207 iDotParam += iDotDirection; |
|
208 } |
|
209 |
|
210 if (tl.iY >= bl.iY) |
|
211 { |
|
212 tl.iY--; |
|
213 bl.iY++; |
|
214 } |
|
215 |
|
216 bl.iY += yoff; |
|
217 |
|
218 for (column = tl.iY + 1; column < bl.iY; column++) |
|
219 { |
|
220 PenDrawClipped(TPoint(aRect.iTl.iX,column)); |
|
221 PenDrawClipped(TPoint(aRect.iBr.iX - 1,column)); |
|
222 iDotParam += iDotDirection; |
|
223 } |
|
224 |
|
225 iDevice->iDrawDevice->UpdateRegion(iClipRect); |
|
226 } |
|
227 |
|
228 iDotParam = dotparam; |
|
229 } |
|
230 |