• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetCustomLineCapStrokeCaps

Started by José Roca, June 22, 2008, 04:09:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a CustomLineCap and sets its start and end stroke caps. It then assigns the custom cap to a Pen and draws a line.

C++


VOID Example_SetStrokeCaps(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 start and end caps for custCap.
   custCap.SetStrokeCaps(LineCapTriangle, LineCapRound);

   // Create a Pen object, assign startStrokeCap and endStrokeCap as the
   // start and end caps, and draw a line.
   Pen strokeCapPen(Color(255, 255, 0, 255), 5.0f);
   strokeCapPen.SetCustomEndCap(&custCap);
   graphics.DrawLine(&strokeCapPen, Point(100, 100), Point(300, 100));
}


PowerBASIC


SUB GDIP_SetStrokeCaps (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pCapPath AS DWORD
   LOCAL pCustCap AS DWORD
   LOCAL pStrokeCapPen 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 start and end caps for custCap.
   hStatus = GdipSetCustomLineCapStrokeCaps(pCustCap, %LineCapTriangle, %LineCapRound)

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

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

END SUB