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 22, 2008, 10:29:01 AM

Title: GDI+: GdipSetAdjustableArrowCapHeight
Post by: José Roca on June 22, 2008, 10:29:01 AM


The following example creates an AdjustableArrowCap, pMyArrowCap, and sets the height of the cap to 15 pixels. The code then creates a Pen and assigns pMyArrowCap as the ending line cap for this Pen. Next, the code draws a capped line.

C++


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

   // Create an AdjustableArrowCap with a width of 10 pixels.
   AdjustableArrowCap myArrow(10, 5, true);

   // Create a Pen, and assign myArrow as the end cap.
   Pen arrowPen(Color(255, 0, 0, 0));
   arrowPen.SetCustomEndCap(&myArrow);

   // Get the width of the arrow.
   REAL width = myArrow.GetWidth();
   
   // Draw a line using arrowPen.
   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));

   // Set height equal to width and draw another line.
   myArrow.SetHeight(width);
   arrowPen.SetCustomEndCap(&myArrow);
   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 140));
}


PowerBASIC


SUB GDIP_SetHeight(BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pArrowPen AS DWORD
   LOCAL pMyArrowCap AS DWORD
   LOCAL nWidth AS SINGLE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create an AdjustableArrowCap with a width of 10 pixels.
   hStatus = GdipCreateAdjustableArrowCap(10, 5, %TRUE, pMyArrowCap)

   ' // Create a Pen, and assign pMyArrowCap as the end cap.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0!, %UnitWorld, pArrowPen)
   hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)

   ' // Draw a line using pArrowPen.
   hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 0, 100, 100)

   ' // Get the width of the arrow.
   hStatus = GdipGetAdjustableArrowCapWidth(pMyArrowCap, nWidth)

   ' // Set height equal to width and draw another line.
   hStatus = GdipSetAdjustableArrowCapHeight(pMyArrowCap, nWidth)
   hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)
   hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 40, 100, 140)

   ' // Cleanup
   IF pMyArrowCap THEN GdipDeleteCustomLineCap(pMyArrowCap)
   IF pArrowPen THEN GdipDeletePen(pArrowPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


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