Syntax
Success = WidgetReleaseMouseCapture()
Description
Releases mouse capture that was previously set by either WidgetSetMouseCapture() or WindowSetMouseCapture(). After this call, mouse events are no longer exclusively directed to the previously capturing widget or window, 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. This function internally calls WindowReleaseMouseCapture().
Example
IncludeFile "ProGUI_PB.pbi"
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
; Calculate new absolute position in window coordinates
ParentWindow = WidgetGetParentWindow(Widget)
CurrentX.d = *EventData\x + WidgetGetX(Widget) - DragOffsetX
CurrentY.d = *EventData\y + WidgetGetY(Widget) - DragOffsetY
Debug "Dragging Widget... Window Coords X: " + StrD(CurrentX) + ", Y: " + StrD(CurrentY)
; NOTE: To actually move the widget, you'd need more complex logic
; involving its layout or absolute positioning if available.
; This example just shows the capture/release mechanism.
; For simplicity, we'll just redraw the parent.
WindowRedraw(ParentWindow)
EndIf
Case #PG_Event_MouseLeftButtonUp
If DraggingWidget = Widget
Debug "Mouse Up on Widget - Releasing Capture"
WidgetReleaseMouseCapture()
DraggingWidget = #Null
EndIf
EndSelect
EndProcedure
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Widget Mouse Capture")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Basic) ; Use Basic layout for simplicity
LayoutSetPadding(RootLayout, 10)
If MyWindow
Draggable = CreateWidget(50, 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_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetSetMouseCapture, WindowSetMouseCapture, WindowReleaseMouseCapture
Supported OS
Windows, Linux