From 72ab72c50c370372b214bb72814109637db88733 Mon Sep 17 00:00:00 2001 From: Evan Stade Date: Mon, 18 Jun 2007 16:55:51 -0700 Subject: [PATCH] gdiplus: Implemented GdipDrawPie/GdipFillPie. --- dlls/gdiplus/gdiplus.spec | 4 +-- dlls/gdiplus/graphics.c | 65 +++++++++++++++++++++++++++++++++++++++ include/gdiplusflat.h | 1 + 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec index 483c3f446f2..4916853bfb2 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 b45293f6ff1..b455cc40765 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -32,6 +32,51 @@ 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 draw_pie(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) @@ -106,6 +151,16 @@ GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1, 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 draw_pie(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) { @@ -137,3 +192,13 @@ GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x, 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 draw_pie(graphics, brush->gdibrush, GetStockObject(NULL_PEN), x, y, + width, height, startAngle, sweepAngle); +} diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h index 3220cb22978..e949301bef2 100644 --- a/include/gdiplusflat.h +++ b/include/gdiplusflat.h @@ -34,6 +34,7 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *); GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL,REAL, REAL,REAL,REAL); 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);