7 * A couple of macros to fill a single pixel or a line
9 #define PUTPIXEL(x,y,BrushInst) \
10 ret = ret && IntEngLineTo(&psurf->SurfObj, \
12 &BrushInst.BrushObject, \
15 ROP2_TO_MIX(pdcattr->jROP2));
17 #define PUTLINE(x1,y1,x2,y2,BrushInst) \
18 ret = ret && IntEngLineTo(&psurf->SurfObj, \
20 &BrushInst.BrushObject, \
23 ROP2_TO_MIX(pdcattr->jROP2));
25 #define Rsin(d) ((d) == 0.0 ? 0.0 : ((d) == 90.0 ? 1.0 : sin(d*M_PI/180.0)))
26 #define Rcos(d) ((d) == 0.0 ? 1.0 : ((d) == 90.0 ? 0.0 : cos(d*M_PI/180.0)))
43 RECTL RectBounds
, RectSEpts
;
47 LONG PenWidth
, PenOrigWidth
;
48 double AngleStart
, AngleEnd
;
49 LONG RadiusX
, RadiusY
, CenterX
, CenterY
;
50 LONG SfCx
, SfCy
, EfCx
, EfCy
;
54 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
58 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
61 /* Check if the target rect is empty */
62 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
64 // FIXME: this needs to be verified
65 if ((arctype
== GdiTypeChord
) || (arctype
== GdiTypePie
))
67 if ((Right
- Left
== 1) || (Bottom
- Top
== 1))
72 pdcattr
= dc
->pdcattr
;
74 pbrPen
= PEN_ShareLockPen(pdcattr
->hpen
);
77 DPRINT1("Arc Fail 1\n");
78 EngSetLastError(ERROR_INTERNAL_ERROR
);
82 PenOrigWidth
= PenWidth
= pbrPen
->ptPenWidth
.x
;
83 if (pbrPen
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
85 if (pbrPen
->ulPenStyle
== PS_INSIDEFRAME
)
87 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
88 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
90 Right
-= (PenWidth
- 1) / 2;
92 Bottom
-= (PenWidth
- 1) / 2;
95 if (!PenWidth
) PenWidth
= 1;
96 pbrPen
->ptPenWidth
.x
= PenWidth
;
98 RectBounds
.left
= Left
;
99 RectBounds
.right
= Right
;
100 RectBounds
.top
= Top
;
101 RectBounds
.bottom
= Bottom
;
103 RectSEpts
.left
= XRadialStart
;
104 RectSEpts
.top
= YRadialStart
;
105 RectSEpts
.right
= XRadialEnd
;
106 RectSEpts
.bottom
= YRadialEnd
;
108 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
109 IntLPtoDP(dc
, (LPPOINT
)&RectSEpts
, 2);
111 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
112 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
113 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
114 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
116 RectSEpts
.left
+= dc
->ptlDCOrig
.x
;
117 RectSEpts
.top
+= dc
->ptlDCOrig
.y
;
118 RectSEpts
.right
+= dc
->ptlDCOrig
.x
;
119 RectSEpts
.bottom
+= dc
->ptlDCOrig
.y
;
121 DPRINT("1: StartX: %d, StartY: %d, EndX: %d, EndY: %d\n",
122 RectSEpts
.left
,RectSEpts
.top
,RectSEpts
.right
,RectSEpts
.bottom
);
124 DPRINT("1: Left: %d, Top: %d, Right: %d, Bottom: %d\n",
125 RectBounds
.left
,RectBounds
.top
,RectBounds
.right
,RectBounds
.bottom
);
127 RadiusX
= max((RectBounds
.right
- RectBounds
.left
) / 2, 1);
128 RadiusY
= max((RectBounds
.bottom
- RectBounds
.top
) / 2, 1);
129 CenterX
= (RectBounds
.right
+ RectBounds
.left
) / 2;
130 CenterY
= (RectBounds
.bottom
+ RectBounds
.top
) / 2;
131 AngleEnd
= atan2((RectSEpts
.bottom
- CenterY
), RectSEpts
.right
- CenterX
)*(360.0/(M_PI
*2));
132 AngleStart
= atan2((RectSEpts
.top
- CenterY
), RectSEpts
.left
- CenterX
)*(360.0/(M_PI
*2));
134 /* Edge Case: Check if the start segments overlaps(is equal) the end segment */
135 if (AngleEnd
== AngleStart
)
137 AngleStart
= AngleEnd
+ 360.0; // Arc(), ArcTo(), Pie() and Chord() are counterclockwise APIs.
140 SfCx
= (LONG
)(Rcos(AngleStart
) * RadiusX
);
141 SfCy
= (LONG
)(Rsin(AngleStart
) * RadiusY
);
142 EfCx
= (LONG
)(Rcos(AngleEnd
) * RadiusX
);
143 EfCy
= (LONG
)(Rsin(AngleEnd
) * RadiusY
);
145 if ((arctype
== GdiTypePie
) || (arctype
== GdiTypeChord
))
147 ret
= IntFillArc( dc
,
150 abs(RectBounds
.right
-RectBounds
.left
), // Width
151 abs(RectBounds
.bottom
-RectBounds
.top
), // Height
157 ret
= IntDrawArc( dc
,
160 abs(RectBounds
.right
-RectBounds
.left
), // Width
161 abs(RectBounds
.bottom
-RectBounds
.top
), // Height
167 psurf
= dc
->dclevel
.pSurface
;
170 DPRINT1("Arc Fail 2\n");
171 PEN_ShareUnlockPen(pbrPen
);
172 EngSetLastError(ERROR_INTERNAL_ERROR
);
176 if (arctype
== GdiTypePie
)
178 PUTLINE(CenterX
, CenterY
, SfCx
+ CenterX
, SfCy
+ CenterY
, dc
->eboLine
);
179 PUTLINE(EfCx
+ CenterX
, EfCy
+ CenterY
, CenterX
, CenterY
, dc
->eboLine
);
181 if (arctype
== GdiTypeChord
)
182 PUTLINE(EfCx
+ CenterX
, EfCy
+ CenterY
, SfCx
+ CenterX
, SfCy
+ CenterY
, dc
->eboLine
);
184 pbrPen
->ptPenWidth
.x
= PenOrigWidth
;
185 PEN_ShareUnlockPen(pbrPen
);
186 DPRINT("IntArc Exit.\n");
207 DPRINT("StartX: %d, StartY: %d, EndX: %d, EndY: %d\n",
208 XStartArc
,YStartArc
,XEndArc
,YEndArc
);
209 DPRINT("Left: %d, Top: %d, Right: %d, Bottom: %d\n",
210 LeftRect
,TopRect
,RightRect
,BottomRect
);
212 if ((LeftRect
== RightRect
) || (TopRect
== BottomRect
)) return TRUE
;
214 if (PATH_IsPathOpen(dc
->dclevel
))
228 //pdcattr = dc->pdcattr;
230 if (arctype
== GdiTypeArcTo
)
232 if (dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
)
233 IntGdiLineTo(dc
, XEndArc
, YEndArc
);
235 IntGdiLineTo(dc
, XStartArc
, YStartArc
);
249 if (arctype
== GdiTypeArcTo
)
251 if (dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
)
252 IntGdiMoveToEx(dc
, XStartArc
, YStartArc
, NULL
, TRUE
);
254 IntGdiMoveToEx(dc
, XEndArc
, YEndArc
, NULL
, TRUE
);
261 IntGdiAngleArc( PDC pDC
,
268 INT x1
, y1
, x2
, y2
, arcdir
;
271 /* Calculate the end point */
272 x2
= x
+ (INT
)(cos(((eStartAngle
+eSweepAngle
)/360)*(M_PI
*2)) * dwRadius
);
273 y2
= y
- (INT
)(sin(((eStartAngle
+eSweepAngle
)/360)*(M_PI
*2)) * dwRadius
);
275 x1
= x
+ (INT
)(cos((eStartAngle
/360)*(M_PI
*2)) * dwRadius
);
276 y1
= y
- (INT
)(sin((eStartAngle
/360)*(M_PI
*2)) * dwRadius
);
278 arcdir
= pDC
->dclevel
.flPath
& DCPATH_CLOCKWISE
;
279 if (eSweepAngle
>= 0)
280 pDC
->dclevel
.flPath
&= ~DCPATH_CLOCKWISE
;
282 pDC
->dclevel
.flPath
|= DCPATH_CLOCKWISE
;
284 result
= IntGdiArcInternal( GdiTypeArcTo
,
295 pDC
->dclevel
.flPath
|= (arcdir
& DCPATH_CLOCKWISE
);
299 IntGdiMoveToEx(pDC
, x2
, y2
, NULL
, TRUE
);
304 /* FUNCTIONS *****************************************************************/
313 IN DWORD dwStartAngle
,
314 IN DWORD dwSweepAngle
)
318 gxf_long worker
, worker1
;
319 KFLOATING_SAVE FloatSave
;
321 pDC
= DC_LockDc (hDC
);
324 EngSetLastError(ERROR_INVALID_HANDLE
);
327 if (pDC
->dctype
== DC_TYPE_INFO
)
330 /* Yes, Windows really returns TRUE in this case */
334 KeSaveFloatingPointState(&FloatSave
);
336 worker
.l
= dwStartAngle
;
337 worker1
.l
= dwSweepAngle
;
338 DC_vPrepareDCsForBlit(pDC
, NULL
, NULL
, NULL
);
339 if (pDC
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
340 DC_vUpdateFillBrush(pDC
);
341 if (pDC
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
342 DC_vUpdateLineBrush(pDC
);
343 Ret
= IntGdiAngleArc( pDC
, x
, y
, dwRadius
, worker
.f
, worker1
.f
);
344 DC_vFinishBlit(pDC
, NULL
);
347 KeRestoreFloatingPointState(&FloatSave
);
368 KFLOATING_SAVE FloatSave
;
370 dc
= DC_LockDc (hDC
);
373 EngSetLastError(ERROR_INVALID_HANDLE
);
376 if (dc
->dctype
== DC_TYPE_INFO
)
379 /* Yes, Windows really returns TRUE in this case */
383 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
385 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
386 DC_vUpdateFillBrush(dc
);
388 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
389 DC_vUpdateLineBrush(dc
);
391 KeSaveFloatingPointState(&FloatSave
);
393 Ret
= IntGdiArcInternal(
405 KeRestoreFloatingPointState(&FloatSave
);
406 DC_vFinishBlit(dc
, NULL
);