• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetCustomLineCapStrokeJoin

Started by José Roca, June 22, 2008, 04:12:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a CustomLineCap object with a stroke join. It then gets the stroke join and assigns it as the line join of a Pen object that it then uses to draw a line.

C++


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

   //Create a Path, and add two lines to it.
   Point points[3] = {Point(-15, -15), Point(0, 0), Point(15, -15)};
   GraphicsPath capPath;
   capPath.AddLines(points, 3);

   // Create a CustomLineCap object.
   CustomLineCap custCap(NULL, &capPath);

   // Set the stroke join for custCap.
   custCap.SetStrokeJoin(LineJoinBevel);

   // Create a Pen object, assign custCap to a Pen object, and draw a line.
   Pen strokeJoinPen(Color(255, 200, 150, 0), 5.0f);
   strokeJoinPen.SetCustomEndCap(&custCap);
   graphics.DrawLine(&strokeJoinPen, Point(0, 0), Point(200, 200));
}


PowerBASIC


SUB GDIP_SetStrokeJoin (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pCapPath AS DWORD
   LOCAL pCustCap AS DWORD
   LOCAL pStrokeJoinPen AS DWORD
   DIM   PointsF(2) AS POINTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a path and add two lines to it.
   PointsF(0).x = -15 : PointsF(0).y = -15
   PointsF(1).x = 0 : PointsF(1).y = 0
   PointsF(2).x = 15 : PointsF(2).y = -15
   hStatus = GdipCreatePath(%FillModeAlternate, pCapPath)
   hStatus = GdipAddPathLine2(pCapPath, PointsF(0), 3)

   ' // Create a CustomLineCap
   hStatus = GdipCreateCustomLineCap(%NULL, pCapPath, %LineCapFlat, 0, pCustCap)

   ' // Set the stroke join for custCap.
   hStatus = GdipSetCustomLineCapStrokeJoin(pCustCap, %LineJoinBevel)

   ' // Create a Pen object, assign custCap to a Pen object, and draw a line.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 200, 150, 0), 5.0!, %UnitWorld, pStrokeJoinPen)
   hStatus = GdipSetPenCustomEndCap(pStrokeJoinPen, pCustCap)
   hStatus = GdipDrawLineI(pGraphics, pStrokeJoinPen, 0, 0, 200, 200)

   ' // Cleanup
   IF pCustCap THEN GdipDeleteCustomLineCap(pCustCap)
   IF pStrokeJoinPen THEN GdipDeletePen(pStrokeJoinPen)
   IF pCapPath THEN GdipDeletePath(pCapPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB