Syntax
Success = WidgetReleaseMouseCapture()Description
Releases mouse capture that was previously set by WidgetSetMouseCapture(). After this call, mouse events are no longer exclusively directed to the previously capturing widget and normal mouse routing resumes.
Parameters
This command takes no parameters.
Return Value
Returns #True if mouse capture was active and
successfully released. Returns #False if no mouse capture
was currently active.
Remarks
It's essential to call this function when a mouse operation that required capture (like dragging an element) is completed (e.g., on a mouse button up event) to restore normal mouse behavior.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Global DraggingWidget, DragOffsetX.d, DragOffsetY.d
; Custom draw procedure
Procedure DrawDraggableWidget(Widget, EventType, *EventData.PG_EventDraw, *UserData)
DrawBox(0, 0, *EventData\width, *EventData\height, RGB(180, 210, 255), 1)
DrawBoxStroke(0, 0, *EventData\width, *EventData\height, RGB(50, 80, 120))
EndProcedure
; Event handler for dragging
Procedure DragHandler(Widget, EventType, *EventData.PG_EventMouse)
Select EventType
Case #PG_Event_MouseLeftButtonDown
Debug "Mouse Down on Widget - Capturing"
DraggingWidget = Widget
DragOffsetX = *EventData\x ; Store offset relative to widget top-left
DragOffsetY = *EventData\y
WidgetSetMouseCapture(Widget) ; Capture mouse for this widget
Case #PG_Event_MouseMove
If DraggingWidget = Widget
ParentWindow = WidgetGetParentWindow(Widget)
CurrentX.d = *EventData\x + WidgetGetX(Widget) - DragOffsetX
CurrentY.d = *EventData\y + WidgetGetY(Widget) - DragOffsetY
If CurrentX < 0 : CurrentX = 0 : EndIf
If CurrentY < 0 : CurrentY = 0 : EndIf
Debug "Dragging Widget... Window Coords X: " + StrD(CurrentX) + ", Y: " + StrD(CurrentY)
WidgetResize(Widget, CurrentX, CurrentY, #PG_Ignore, #PG_Ignore)
EndIf
Case #PG_Event_MouseLeftButtonUp
If DraggingWidget = Widget
Debug "Mouse Up on Widget - Releasing Capture"
WidgetReleaseMouseCapture()
DraggingWidget = #Null
EndIf
EndSelect
EndProcedure
MyWindow = CreateWindow(0, 0, 400, 300, "Widget Mouse Capture")
If MyWindow
Draggable = CreateWidget(180, 50, 80, 40)
WidgetSetClass(Draggable, "draggable")
AddEventHandler(Draggable, #PG_Event_Draw, @DrawDraggableWidget())
AddEventHandler(Draggable, #PG_Event_MouseLeftButtonDown, @DragHandler())
AddEventHandler(Draggable, #PG_Event_MouseMove, @DragHandler())
AddEventHandler(Draggable, #PG_Event_MouseLeftButtonUp, @DragHandler())
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
WidgetSetMouseCapture, WindowSetMouseCapture, WindowReleaseMouseCapture
Supported OS
Windows, Linux