WindowRedraw

Syntax

Success = WindowRedraw(Window, *Rect.RECT=#Null)

Description

Invalidates a specified rectangular area of the window's client area, queuing it for redrawing during the next rendering cycle. If no rectangle is specified, the entire window client area is invalidated.

Parameters

Window
The handle of the ProGUI window to redraw.

*Rect.RECT (optional)
A pointer to a RECT structure defining the area to invalidate, specified in device-independent pixels (DIPs) relative to the window's client area (top-left is 0,0). If #Null, the entire window is invalidated. The RECT structure should contain left, top, right, and bottom coordinates.

Return Value

Returns #True if the redraw request was successfully queued, or #False if the window handle was invalid or the rectangle dimensions were invalid (e.g., zero width/height, left >= right, top >= bottom).

Remarks

This function is asynchronous. It flags the specified region (or the whole window) as needing an update. The actual drawing occurs later in the ProGUI render thread (triggered indirectly by the OS paint messages or the animation loop). Multiple calls to WindowRedraw() before a redraw occurs will result in the union of all invalidated rectangles being redrawn. To force an immediate update cycle, use WindowUpdate(). The coordinates in the RECT structure are in DIPs relative to the client area.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Event handler for drawing
Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  ; Draw something simple
  DrawBox(10, 10, *EventData\width - 20, *EventData\height - 20, RGB(200, 220, 255))
  ; Assuming Text 0 is created elsewhere or handle appropriately
  ; DrawTxt(0, 20, 20, RGB(0,0,0))
EndProcedure

; Event handler to trigger the second redraw after animation ends
Procedure DelayedRedrawHandler(Window, EventType, *EventData.PG_EventAnimate, *UserData)
  If EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_End
    Debug "Animation finished, triggering full redraw..."
    WindowRedraw(Window) ; Invalidate the whole window
  EndIf
EndProcedure

MyWindow = CreateWindow(0, 0, 400, 300, "Redraw Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
  AddEventHandler(MyWindow, #PG_Event_Animate, @DelayedRedrawHandler()) ; Add handler for animation end

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Define MyRect.RECT
  MyRect\left = 50
  MyRect\top = 50
  MyRect\right = 150
  MyRect\bottom = 100

  ; Invalidate only a specific area (in DIPs) initially
  WindowRedraw(MyWindow, MyRect)
  Debug "Partial redraw requested"

  ; Start a 2-second animation. When it ends, the handler will trigger the full redraw.
  StartAnimation(MyWindow, 1, 2000) ; ID 1, Duration 2000ms
  Debug "Waiting 2 seconds via animation for full redraw..."

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

StopProGUI()

See Also

WidgetRedraw, WindowUpdate, StartAnimation, AddEventHandler

Supported OS

Windows, Linux