OutputID = WindowOutput(#Window)Description
Returns the OutputID of the given window to perform 2D rendering operation on it. It will use the PureBasic 2DDrawing library and can only be used within a StartDrawing() / StopDrawing() block. The memory allocated in WindowOutput() is released on StopDrawing().
#Window The window to use.
The OutputID of the given window to perform 2D rendering operation on it using StartDrawing().
If OpenWindow(0, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) Repeat Event = WaitWindowEvent() If Event = #PB_Event_Repaint ; Redraw on the window every time the window is repainted StartDrawing(WindowOutput(0)) Box(10, 10, 50, 50, RGB(255, 0, 0)) StopDrawing() EndIf Until Event = #PB_Event_CloseWindow EndIf
Content drawn on a window will be erased whenever the window or a part of it is covered by another window, moved outside of the screen or when the window is hidden or minimized. So to keep the drawn content visible, it must be redrawn after every #PB_Event_Repaint event. A more convenient alternative is to draw the content to an image via ImageOutput() and display it as ImageGadget() in the application window and if necessary, update it with SetGadgetState(). This way all needed refreshing will be handled by the ImageGadget.
If OpenWindow(0, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) ButtonGadget (1, 10, 60, 200, 30, "Draw on window") Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_Gadget Select EventGadget() Case 1 ; Draw a red box on the window If StartDrawing(WindowOutput(0)) Box(10,10, 200, 30, RGB(255, 0, 0)) StopDrawing() EndIf EndSelect EndSelect Until Event = #PB_Event_CloseWindow EndIf