• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetCustomLineCapBaseInset

Started by José Roca, June 22, 2008, 04:16:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a CustomLineCap and sets the base inset of the cap. It then assigns the custom cap to a Pen and draws a line.

C++


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

   //Create a Path object.
   GraphicsPath capPath;

   //Create a CustomLineCap object and set its base cap to LineCapRound.
   CustomLineCap custCap(NULL, &capPath, LineCapRound, 5);

   // Create a Pen object, assign custCap as the custom end cap, and then
   // draw a line.
   Pen pen(Color(255, 0, 0, 0), 5.1f);
   pen.SetCustomEndCap(&custCap);
   graphics.DrawLine(&pen, Point(0, 0), Point(100, 100));
}


PowerBASIC


SUB GDIP_SetBaseInset (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pCapPath AS DWORD
   LOCAL pCustCap AS DWORD
   LOCAL pPen 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, %LineCapRound, 5, pCustCap)
   ' // Sets the base inset of the cap.
   GdipSetCustomLineCapBaseInset(pCustCap, 10)

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

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

END SUB