[GDI+ implementation: 4/8] GdipDrawPie, GdipFillPie

Evan Stade estade at gmail.com
Tue Jun 12 12:55:45 CDT 2007


Hi,

Changelog:
*implemented GdipDrawPie, GdipFillPie

 dlls/gdiplus/gdiplus.spec |   10 ++++----
 dlls/gdiplus/graphics.c   |   60 +++++++++++++++++++++++++++++++++++++++++++++
 include/gdiplusflat.h     |    1 +
 3 files changed, 66 insertions(+), 5 deletions(-)

-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index dfb4e63..b60107a 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -119,7 +119,7 @@
 @ stub GdipCreateRegionRect
 @ stub GdipCreateRegionRectI
 @ stub GdipCreateRegionRgnData
-@ stub GdipCreateSolidFill
+@ stdcall GdipCreateSolidFill(long ptr)
 @ stub GdipCreateStreamOnFile
 @ stub GdipCreateStringFormat
 @ stub GdipCreateTexture2
@@ -127,7 +127,7 @@
 @ stub GdipCreateTexture
 @ stub GdipCreateTextureIA
 @ stub GdipCreateTextureIAI
-@ stub GdipDeleteBrush
+@ stdcall GdipDeleteBrush(ptr)
 @ stub GdipDeleteCachedBitmap
 @ stub GdipDeleteCustomLineCap
 @ stub GdipDeleteFont
@@ -179,7 +179,7 @@
 @ stub GdipDrawLines
 @ stub GdipDrawLinesI
 @ stub GdipDrawPath
-@ stub GdipDrawPie
+@ stdcall GdipDrawPie(ptr ptr long long long long long long)
 @ stub GdipDrawPieI
 @ stub GdipDrawPolygon
 @ stub GdipDrawPolygonI
@@ -209,7 +209,7 @@
 @ stub GdipFillEllipse
 @ stub GdipFillEllipseI
 @ stub GdipFillPath
-@ stub GdipFillPie
+@ stdcall GdipFillPie(ptr ptr long long long long long long)
 @ stub GdipFillPieI
 @ stub GdipFillPolygon2
 @ stub GdipFillPolygon2I
@@ -228,7 +228,7 @@
 @ stub GdipGetAdjustableArrowCapMiddleInset
 @ stub GdipGetAdjustableArrowCapWidth
 @ stub GdipGetAllPropertyItems
-@ stub GdipGetBrushType
+@ stdcall GdipGetBrushType(ptr ptr)
 @ stub GdipGetCellAscent
 @ stub GdipGetCellDescent
 @ stub GdipGetClip
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index d2a4317..8ae82a6 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -27,6 +27,16 @@ #include "gdiplus.h"
 #include "gdiplus_private.h"
 #include "wine/debug.h"
 
+static inline REAL deg2rad(REAL degrees)
+{
+    return (M_PI*2.0) * degrees / 360.0;
+}
+
+static inline INT round(REAL x)
+{
+    return (INT) floor(x+0.5);
+}
+
 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
 {
     if(hdc == NULL)
@@ -113,3 +123,53 @@ GpStatus WINGDIPAPI GdipDrawRectangleI(G
 
     return Ok;
 }
+
+static GpStatus DrawPie(GpGraphics *graphics, HBRUSH gdibrush, HPEN gdipen,
+    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;
+
+    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;
+
+    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));
+
+    SelectObject(graphics->hdc, old_pen);
+    SelectObject(graphics->hdc, old_brush);
+
+    return Ok;
+}
+
+GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x, 
+    REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
+{
+    if(!brush)
+        return InvalidParameter;
+
+    return DrawPie(graphics, brush->gdibrush, GetStockObject(NULL_PEN), x, y, 
+        width, height, startAngle, sweepAngle);
+}
+
+GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x, 
+    REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
+{
+    if(!pen)
+        return InvalidParameter;
+
+    return DrawPie(graphics, GetStockObject(NULL_BRUSH), pen->gdipen, x, y, 
+        width, height, startAngle, sweepAngle);
+}
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 7ccae0f..2d4e13f 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -34,6 +34,7 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(G
 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics*,GpPen*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics*,GpPen*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipFillPie(GpGraphics*,GpBrush*,REAL,REAL,REAL,REAL,REAL,REAL);
+GpStatus WINGDIPAPI GdipDrawPie(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL,REAL,REAL);
 
 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB,GpSolidFill**);
 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush*,GpBrushType*);
-- 
1.4.1


More information about the wine-patches mailing list