PowerBasic Museum 2020-A

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, 10:44:49 AM

Title: GDI+: GdipSetWorldTransform
Post by: José Roca on June 23, 2008, 10:44:49 AM


The following example creates a rotation matrix and passes the address of that matrix to the GdipSetWorldTransform function. The code calls the GdipDrawRectangle function to draw a rotated rectangle.

C++


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

   // Create a rotation matrix.
   Matrix transformMatrix;
   transformMatrix.Rotate(45.0f);

   // Set the transformation matrix of the Graphics object.
   graphics.SetTransform(&transformMatrix);

   // Draw a rotated rectangle.
   Pen pen(Color(255, 0, 0, 0));
   graphics.DrawRectangle(&pen, 120, 0, 100, 50);
}


PowerBASIC


SUB GDIP_SetWorldTransform (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pMatrix AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a rotation matrix.
   hStatus = GdipCreateMatrix(pMatrix)
   hStatus = GdipRotateMatrix(pMatrix, 45.0!, %MatrixOrderPrepend)

   ' // Set the transformation matrix of the Graphics object.
   hStatus = GdipSetWorldTransform(pGraphics, pMatrix)

   ' // Create a Pen
   hStatus = GdipCreatePen1(GDIP_ARGB(255,0, 0, 0), 1, %UnitPixel, pPen)

   ' // // Draw a rotated rectangle.
   hStatus = GdipDrawRectangle(pGraphics, pPen, 120, 0, 100, 50)

   ' // Cleanup
   IF pMatrix THEN GdipDeleteMatrix(pMatrix)
   IF pPen THEN GdipDeletePen(pPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


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