2DDrawing functions for windows

Share your advanced PureBasic knowledge/code with the community.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

2DDrawing functions for windows

Post by Dr. Dri »

Code updated For 5.20+

i'll try to add more functions ^^
seems to work with any kind of surface (windows, images, sprites, printers...)

Code: Select all

    Procedure IsDrawing()
        CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
            !extern _PB_2DDrawing_Pointer
        CompilerElse
            !extrn _PB_2DDrawing_Pointer
        CompilerEndIf
        !MOV eax, dword [_PB_2DDrawing_Pointer]
        ProcedureReturn
    EndProcedure

Procedure DrawingSurfaceWidth()
  Protected Width.l, Box.Rect
  
  If GetClipBox_(IsDrawing(), @Box)
    Width = Box\right - Box\left
  EndIf
  
  ProcedureReturn Width
EndProcedure

Procedure DrawingSurfaceHeight()
  Protected Height.l, Box.Rect
  
  If GetClipBox_(IsDrawing(), @Box)
    Height = Box\bottom - Box\top
  EndIf
  
  ProcedureReturn Height
EndProcedure

Procedure Triangle(x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  ProcedureReturn Polygon_(IsDrawing(), @x1, 3)
EndProcedure
small example :

Code: Select all

OpenWindow(0, 0, 0, 320, 240, "", 0)

If StartDrawing( WindowOutput(0) )
  
  Debug DrawingSurfaceWidth()
  Debug DrawingSurfaceHeight()
  
  StopDrawing()
EndIf
one more example :

Code: Select all

If PrintRequester()
  If StartPrinting("test")
    If StartDrawing( PrinterOutput() )
      
      Debug DrawingSurfaceWidth()
      Debug DrawingSurfaceHeight()
      
      Debug "---"
      
      Debug PrinterPageWidth()
      Debug PrinterPageHeight()
      
      StopDrawing()
    EndIf
    StopPrinting()
  EndIf
EndIf
Dri ;)