DrawTxt

Syntax

DrawTxt(Text.i, x.d, y.d, Color.l, Opacity.f=1)

Description

Draws text onto the current drawing target using a pre-created text object, a specified solid color, and opacity. The text object defines the content, font, size, layout constraints, and formatting.

Parameters

Text.i
The handle of the text object (created with CreateText()) to draw.

x.d
The horizontal coordinate of the text layout's top-left corner in device-independent pixels (DIPs).

y.d
The vertical coordinate of the text layout's top-left corner in DIPs.

Color.l
The color of the text in RGB format (e.g., using RGB(r, g, b)).

Opacity.f (optional)
The opacity of the text, ranging from 0.0 (fully transparent) to 1.0 (fully opaque). Default is 1.0.

Return Value

This command does not return a value. It returns internally if Opacity is zero or less or the Text handle is invalid.

Remarks

The text object should be created beforehand using CreateText() and configured using various TextSet*() functions. The coordinates are specified in DIPs but are converted internally to physical pixels based on the current output's DPI before drawing. The text is rendered using an internal solid color brush. Font size within the text object is automatically scaled based on the drawing context's DPI. To draw text with gradients or image patterns, use DrawTxtFill().

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create a text object
Global MyText = CreateText("Hello ProGUI!", "Tahoma", 24)
TextSetWidth(MyText, 200) ; Set layout width for wrapping/alignment
TextSetAlign(MyText, #PG_Text_Align_Center)
TextSetJustify(MyText, #PG_Text_Justify_Center)

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

    DrawClear(RGB(220, 220, 220), 1)

    ; Draw the text in blue at position (10, 10)
    DrawTxt(MyText, 10, 10, RGB(0, 0, 200))

    ; Draw the same text semi-transparently below
    DrawTxt(MyText, 10, 80, RGB(0, 0, 0), 0.5)

EndProcedure

MyWindow = CreateWindow(0, 0, 220, 150, "DrawTxt Example")

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

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

FreeText(MyText)
StopProGUI()

See Also

CreateText, FreeText, TextSetContent, TextSetWidth, TextSetAlign, TextSetJustify, DrawTxtFill, BeginDraw, EndDraw

Supported OS

Windows, Linux