[GDI+ implementation: 5/8] Pies

Evan Stade estade at gmail.com
Tue Jun 12 12:58:02 CDT 2007


Hi,

Changelog:
*moved around pie implementation to make it more modular

 dlls/gdiplus/graphics.c |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 8ae82a6..5ca76d2 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -32,11 +32,23 @@ static inline REAL deg2rad(REAL degrees)
     return (M_PI*2.0) * degrees / 360.0;
 }
 
-static inline INT round(REAL x)
+static INT roundr(REAL x)
 {
     return (INT) floor(x+0.5);
 }
 
+/* Converts angle (in degrees) to x/y coordinates */
+static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
+{
+    REAL radAngle, hypotenuse;
+
+    radAngle = deg2rad(angle);
+    hypotenuse = 50.0; /* arbitrary */
+
+    *x = x_0 + cos(radAngle) * hypotenuse;
+    *y = y_0 + sin(radAngle) * hypotenuse;
+}
+
 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
 {
     if(hdc == NULL)
@@ -128,25 +140,22 @@ static GpStatus DrawPie(GpGraphics *grap
     REAL x, REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
 {
     HGDIOBJ old_pen, old_brush;
-    REAL x_0, y_0, radStartAngle, radFinishAngle, hypotenuse, 
-        x_1, y_1, x_2, y_2;
+    REAL x_0, y_0, x_1, y_1, x_2, y_2;
+
+    if(!graphics)
+        return InvalidParameter;
 
     old_pen = SelectObject(graphics->hdc, gdipen);
     old_brush = SelectObject(graphics->hdc, gdibrush);
 
     x_0 = x + (width/2.0);
     y_0 = y + (height/2.0);
-    radStartAngle = deg2rad(startAngle);
-    radFinishAngle = deg2rad(startAngle+sweepAngle);
-    hypotenuse = 50.0; /* arbitrary */
 
-    x_1 = x_0 + cos(radFinishAngle) * hypotenuse;
-    y_1 = y_0 + sin(radFinishAngle) * hypotenuse;
-    x_2 = x_0 + cos(radStartAngle) * hypotenuse;
-    y_2 = y_0 + sin(radStartAngle) * hypotenuse;
+    deg2xy(startAngle+sweepAngle, x_0, y_0, &x_1, &y_1);
+    deg2xy(startAngle, x_0, y_0, &x_2, &y_2);
 
-    Pie(graphics->hdc, round(x), round(y), round(x+width), round(y+height),
-        round(x_1), round(y_1), round(x_2), round(y_2));
+    Pie(graphics->hdc, roundr(x), roundr(y), roundr(x+width), roundr(y+height),
+        roundr(x_1), roundr(y_1), roundr(x_2), roundr(y_2));
 
     SelectObject(graphics->hdc, old_pen);
     SelectObject(graphics->hdc, old_brush);
-- 
1.4.1


More information about the wine-patches mailing list