sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "swdirectgdiengine.h"
|
sl@0
|
17 |
#include "swdirectgdiellipse.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
@see MDirectGdiEngine::DrawRoundRect()
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
void CSwDirectGdiEngine::DrawRoundRect(const TRect& aRect, const TSize& aCornerSize)
|
sl@0
|
23 |
{
|
sl@0
|
24 |
TSize cornerSize(aCornerSize);
|
sl@0
|
25 |
cornerSize.iWidth <<= 1;
|
sl@0
|
26 |
cornerSize.iHeight <<= 1;
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
TRect rcpy(aRect);
|
sl@0
|
30 |
rcpy.Move(iOrigin);
|
sl@0
|
31 |
TruncateRect(rcpy);
|
sl@0
|
32 |
cornerSize.iWidth = Min(rcpy.Width(),cornerSize.iWidth);
|
sl@0
|
33 |
cornerSize.iHeight = Min(rcpy.Height(),cornerSize.iHeight);
|
sl@0
|
34 |
|
sl@0
|
35 |
TRect targetRect(rcpy);
|
sl@0
|
36 |
targetRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
|
sl@0
|
37 |
|
sl@0
|
38 |
if (iBrushStyle != DirectGdi::ENullBrush)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
RoundRectFill(rcpy,cornerSize);
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
if ((iPenStyle != DirectGdi::ENullPen) && ((iPenSize.iWidth > 0) && (iPenSize.iHeight > 0)))
|
sl@0
|
44 |
{
|
sl@0
|
45 |
RoundRectOutline(rcpy, cornerSize);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
@see DrawRoundRect()
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
void CSwDirectGdiEngine::RoundRectFill(const TRect& aRect, const TSize& aCornerSize)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
TRect rcpy(aRect);
|
sl@0
|
55 |
if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
rcpy.Grow(1,1);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
TInt xoff = rcpy.Width() - aCornerSize.iWidth;
|
sl@0
|
61 |
TInt yoff = rcpy.Height() - aCornerSize.iHeight;
|
sl@0
|
62 |
TPoint tl, tr, bl, br;
|
sl@0
|
63 |
TInt prevlev = 0;
|
sl@0
|
64 |
TBool draw = EFalse;
|
sl@0
|
65 |
|
sl@0
|
66 |
TRect clipRect(0,0,0,0);
|
sl@0
|
67 |
const TInt limit = iDefaultRegionPtr->Count();
|
sl@0
|
68 |
for (TInt count = 0; count < limit; count++)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
clipRect = (*iDefaultRegionPtr)[count];
|
sl@0
|
71 |
if (!clipRect.Intersects(aRect))
|
sl@0
|
72 |
{
|
sl@0
|
73 |
continue;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
draw = ETrue;
|
sl@0
|
77 |
clipRect.Intersection(aRect);
|
sl@0
|
78 |
|
sl@0
|
79 |
TSwDirectGdiEllipse ellipse;
|
sl@0
|
80 |
ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aCornerSize));
|
sl@0
|
81 |
ellipse.SingleStep(tl, tr, bl, br);
|
sl@0
|
82 |
prevlev = tl.iY;
|
sl@0
|
83 |
|
sl@0
|
84 |
while (!ellipse.SingleStep(tl, tr, bl, br))
|
sl@0
|
85 |
{
|
sl@0
|
86 |
if (tl.iY == prevlev)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
continue;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
tl.iX++;
|
sl@0
|
92 |
tr.iX += xoff - 1;
|
sl@0
|
93 |
bl.iX++;
|
sl@0
|
94 |
bl.iY += yoff;
|
sl@0
|
95 |
br.iX += xoff - 1;
|
sl@0
|
96 |
br.iY += yoff;
|
sl@0
|
97 |
|
sl@0
|
98 |
ClipFillLine(tl, tr,clipRect);
|
sl@0
|
99 |
ClipFillLine(bl, br,clipRect);
|
sl@0
|
100 |
|
sl@0
|
101 |
prevlev = tl.iY;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
iDrawDevice->UpdateRegion(clipRect);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
if (!draw)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
return;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
if (tl.iY >= bl.iY)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
tl.iY--;
|
sl@0
|
115 |
br.iY++;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
tl.iX++;
|
sl@0
|
119 |
tl.iY++;
|
sl@0
|
120 |
br.iX += xoff;
|
sl@0
|
121 |
br.iY += yoff;
|
sl@0
|
122 |
|
sl@0
|
123 |
RectFill(TRect(tl,br));
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
@see DrawRoundRect()
|
sl@0
|
128 |
*/
|
sl@0
|
129 |
void CSwDirectGdiEngine::RoundRectOutline(const TRect& aRect, const TSize& aCornerSize)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
TRect rcpy(aRect);
|
sl@0
|
132 |
const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
|
sl@0
|
133 |
const TInt halfpenheight = (iPenSize.iHeight + 1) >> 1;
|
sl@0
|
134 |
rcpy.Grow(halfpenwidth,halfpenheight);
|
sl@0
|
135 |
|
sl@0
|
136 |
TPoint tl, tr, bl, br;
|
sl@0
|
137 |
const TInt xoff = aRect.Width() - aCornerSize.iWidth;
|
sl@0
|
138 |
const TInt yoff = aRect.Height() - aCornerSize.iHeight;
|
sl@0
|
139 |
const TInt dotparam = iDotParam;
|
sl@0
|
140 |
|
sl@0
|
141 |
TRect clipRect(0,0,0,0);
|
sl@0
|
142 |
const TInt limit = iDefaultRegionPtr->Count();
|
sl@0
|
143 |
for (TInt count = 0; count < limit; count++)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
clipRect = (*iDefaultRegionPtr)[count];
|
sl@0
|
146 |
if (!clipRect.Intersects(rcpy))
|
sl@0
|
147 |
{
|
sl@0
|
148 |
continue;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
clipRect.Intersection(rcpy);
|
sl@0
|
151 |
|
sl@0
|
152 |
iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
|
sl@0
|
153 |
TInt column = aRect.iTl.iX + (aCornerSize.iWidth >> 1);
|
sl@0
|
154 |
TInt lastcolumn = aRect.iTl.iX + xoff + (aCornerSize.iWidth >> 1);
|
sl@0
|
155 |
|
sl@0
|
156 |
for (; column < lastcolumn; column++)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
PenDrawClipped(TPoint(column,aRect.iTl.iY), clipRect);
|
sl@0
|
159 |
PenDrawClipped(TPoint(column,aRect.iBr.iY - 1), clipRect);
|
sl@0
|
160 |
iDotParam += iDotDirection;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
TSwDirectGdiEllipse ellipse;
|
sl@0
|
164 |
ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aCornerSize));
|
sl@0
|
165 |
while (!ellipse.SingleStep(tl,tr,bl,br))
|
sl@0
|
166 |
{
|
sl@0
|
167 |
tr.iX += xoff;
|
sl@0
|
168 |
bl.iY += yoff;
|
sl@0
|
169 |
br.iX += xoff;
|
sl@0
|
170 |
br.iY += yoff;
|
sl@0
|
171 |
|
sl@0
|
172 |
PenDrawClipped(tl, clipRect);
|
sl@0
|
173 |
PenDrawClipped(tr, clipRect);
|
sl@0
|
174 |
PenDrawClipped(bl, clipRect);
|
sl@0
|
175 |
PenDrawClipped(br, clipRect);
|
sl@0
|
176 |
|
sl@0
|
177 |
iDotParam += iDotDirection;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
if (tl.iY >= bl.iY)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
tl.iY--;
|
sl@0
|
183 |
bl.iY++;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
bl.iY += yoff;
|
sl@0
|
187 |
|
sl@0
|
188 |
for (column = tl.iY + 1; column < bl.iY; column++)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
PenDrawClipped(TPoint(aRect.iTl.iX,column), clipRect);
|
sl@0
|
191 |
PenDrawClipped(TPoint(aRect.iBr.iX - 1,column), clipRect);
|
sl@0
|
192 |
iDotParam += iDotDirection;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
iDrawDevice->UpdateRegion(clipRect);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
iDotParam = dotparam;
|
sl@0
|
199 |
}
|