Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 23, 2008, 07:11:37 AM

Title: GDI+: GdipDrawBezier
Post by: José Roca on June 23, 2008, 07:11:37 AM


The following example draws a Bézier curve.

C++


VOID Example_DrawBezier4(HDC hdc)
{
   Graphics graphics(hdc);

   // Set up the pen and curve points.
   Pen greenPen(Color(255, 0, 255, 0));
   REAL startPointx = 100.0f;
   REAL startPointy = 100.0f;
   REAL ctrlPoint1x = 200.0f;
   REAL ctrlPoint1y = 10.0f;
   REAL ctrlPoint2x = 350.0f;
   REAL ctrlPoint2y = 50.0f;
   REAL endPointx = 500.0f;
   REAL endPointy = 100.0f;

   //Draw the curve.
   graphics.DrawBezier(
   &greenPen,
   startPointx,
   startPointy,
   ctrlPoint1x,
   ctrlPoint1y,
   ctrlPoint2x,
   ctrlPoint2y,
   endPointx,
   endPointy);

   //Draw the end points and control points.
   SolidBrush redBrush(Color(255, 255, 0, 0));
   SolidBrush blueBrush(Color(255, 0, 0, 255));
   graphics.FillEllipse(&redBrush, 100 - 5, 100 - 5, 10, 10);
   graphics.FillEllipse(&redBrush, 500 - 5, 100 - 5, 10, 10);
   graphics.FillEllipse(&blueBrush, 200 - 5, 10 - 5, 10, 10);
   graphics.FillEllipse(&blueBrush, 350 - 5, 50 - 5, 10, 10);
}


PowerBASIC


SUB GDIP_DrawBezier (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pGreenPen AS DWORD
   LOCAL pRedBrush AS DWORD
   LOCAL pBlueBrush AS DWORD
   LOCAL startPointx AS SINGLE
   LOCAL startPointy AS SINGLE
   LOCAL ctrlPoint1x AS SINGLE
   LOCAL ctrlPoint1y AS SINGLE
   LOCAL ctrlPoint2x AS SINGLE
   LOCAL ctrlPoint2y AS SINGLE
   LOCAL endPointx AS SINGLE
   LOCAL endPointy AS SINGLE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a green Pen
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 1.0!, %UnitWorld, pGreenPen)

   startPointx = 100.0
   startPointy = 100.0
   ctrlPoint1x = 200.0
   ctrlPoint1y = 10.0
   ctrlPoint2x = 350.0
   ctrlPoint2y = 50.0
   endPointx = 500.0
   endPointy = 100.0

   ' // Draw the curve
   hStatus = GdipDrawBezier(pGraphics, pGreenPen, startPointx, startPointy, ctrlPoint1x, ctrlPoint1y, ctrlPoint2x, ctrlPoint2y, endPointx, endPointy)

  ' // Create the brushes
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pRedBrush)
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 255), pBlueBrush)

   ' //Draw the end points and control points.
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 100 - 5, 100 - 5, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 500 - 5, 100 - 5, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pBlueBrush, 200 - 5, 10 - 5, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pBlueBrush, 350 - 5, 50 - 5, 10, 10)

   ' // Cleanup
   IF pBlueBrush THEN GdipDeleteBrush(pBlueBrush)
   IF pRedBrush THEN GdipDeleteBrush(pRedBrush)
   IF pGreenPen THEN GdipDeletePen(pGreenPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


(http://www.jose.it-berater.org/captures/GdipDrawBezier.png)