[GDi+: 2/7] implemented GdipDrawPie, GdipFillPie
Evan Stade
estade at gmail.com
Wed Jun 13 18:41:14 CDT 2007
Hi,
This time, this patch puts the functions in alphabetical order (except
the static functions).
Changelog:
*implemented 2 GDI+ pie functions
*added a lot of helper functions
dlls/gdiplus/gdiplus.spec | 4 +-
dlls/gdiplus/graphics.c | 74 +++++++++++++++++++++++++++++++++++++++++++--
include/gdiplusflat.h | 1 +
3 files changed, 74 insertions(+), 5 deletions(-)
-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index c7a4dc1..80a1928 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -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
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 674bede..7109110 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -27,6 +27,55 @@ #include "gdiplus.h"
#include "gdiplus_private.h"
#include "wine/debug.h"
+static inline INT roundr(REAL x)
+{
+ return (INT) floor(x+0.5);
+}
+static inline REAL deg2rad(REAL degrees)
+{
+ return (M_PI*2.0) * degrees / 360.0;
+}
+
+/* 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;
+}
+
+/* GdipDrawPie/GdipFillPie helper function */
+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, 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);
+
+ deg2xy(startAngle+sweepAngle, x_0, y_0, &x_1, &y_1);
+ deg2xy(startAngle, x_0, y_0, &x_2, &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);
+
+ return Ok;
+}
+
GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
{
if(hdc == NULL)
@@ -35,8 +84,7 @@ GpStatus WINGDIPAPI GdipCreateFromHDC(HD
if(graphics == NULL)
return InvalidParameter;
- *graphics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
- sizeof(GpGraphics));
+ *graphics = GdipAlloc(sizeof(GpGraphics));
(*graphics)->hdc = hdc;
(*graphics)->hwnd = NULL;
@@ -61,7 +109,7 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(G
if(graphics->hwnd)
ReleaseDC(graphics->hwnd, graphics->hdc);
- HeapFree(GetProcessHeap(), 0, graphics);
+ GdipFree(graphics);
return Ok;
}
@@ -82,6 +130,16 @@ GpStatus WINGDIPAPI GdipDrawLineI(GpGrap
return Ok;
}
+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);
+}
+
GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
INT y, INT width, INT height)
{
@@ -113,3 +171,13 @@ GpStatus WINGDIPAPI GdipDrawRectangleI(G
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);
+}
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 7ccae0f..d632bbe 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -32,6 +32,7 @@ GpStatus WINGDIPAPI GdipCreateFromHDC(HD
GpStatus WINGDIPAPI GdipCreateFromHWND(HWND,GpGraphics**);
GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *);
GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics*,GpPen*,INT,INT,INT,INT);
+GpStatus WINGDIPAPI GdipDrawPie(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL,REAL,REAL);
GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics*,GpPen*,INT,INT,INT,INT);
GpStatus WINGDIPAPI GdipFillPie(GpGraphics*,GpBrush*,REAL,REAL,REAL,REAL,REAL,REAL);
--
1.4.1
More information about the wine-patches
mailing list