DrawDPI

Syntax

DrawDPI(DPI_X, DPI_Y=#Null)

Description

Sets the Dots Per Inch (DPI) value used for scaling subsequent drawing operations within the current drawing context. This affects how coordinates and sizes specified in device-independent pixels (DIPs) are converted to physical pixels for rendering.

Parameters

DPI_X
The horizontal DPI value to use. Can be:

  • A specific DPI value (e.g., 96, 120, 144).
  • #PG_DrawDPI_Auto (-1): Resets the drawing DPI to the default DPI of the current output target (window or image).
  • 0: Sets the DPI to the system default (usually 96 DPI), effectively disabling scaling relative to the output's native DPI.

DPI_Y (optional)
The vertical DPI value to use. If #Null, it defaults to the same value as DPI_X. If #PG_DrawDPI_Auto, it uses the output's default vertical DPI. If 0, it uses 96 DPI.

Return Value

This command does not return a value.

Remarks

ProGUI generally handles DPI scaling automatically based on the window or image output target. This command allows overriding the default scaling behavior for specific drawing sequences. Changing the DPI affects the scale factor used in subsequent drawing commands (e.g., DrawBox(), DrawImg()). Use DrawDPI(#PG_DrawDPI_Auto) to restore the default behavior for the current output target. Setting DPI to 0 effectively means treating input coordinates/sizes as if they were already in physical pixels relative to a 96 DPI baseline.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)

    DrawClear(RGB(255, 255, 255), 1)

    ; Draw a box using the window's native DPI scaling (default)
    DrawBox(10, 10, 50, 50, RGB(255, 0, 0)) ; Size is 50x50 DIPs

    ; Force drawing as if on a 96 DPI screen (no scaling relative to output)
    DrawDPI(0) ; Equivalent to DrawDPI(96) if default is 96
    DrawBox(70, 10, 50, 50, RGB(0, 255, 0)) ; Coordinates/size now treated as 96 DPI pixels

    ; Force drawing as if on a 192 DPI screen (200% scaling relative to 96 DPI)
    DrawDPI(192)
    DrawBox(130, 10, 50, 50, RGB(0, 0, 255)) ; 50x50 DIPs will render larger

    ; Restore default DPI scaling for the window
    DrawDPI(#PG_DrawDPI_Auto)
    DrawBox(10, 70, 50, 50, RGB(255, 0, 255)) ; Back to normal scaling

EndProcedure

MyWindow = CreateWindow(0, 0, 400, 200, "DrawDPI Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

DrawGetDPI, DrawGetDPIScaleX, DrawGetDPIScaleY, BeginDraw, EndDraw

Supported OS

Windows, Linux