I have a window with a PanelGadget that contains another PanelGadget as a child. When I call OpenGadgetList on one of the child panel tabs, the top left corner seems to be at 0,0. However, WindowMouseX, WindowMouseY return coordinates based on the main window independent of the gadget below the mouse.
Is there any way to translate the coordinates from WindowMouseX, WindowMouseY to coordinates in a gadget's space? I'm hoping it can be done without dipping into external library calls in Gdk/Gtk,, or WinAPI.
Mouse position in a gadget coordinates?
-
- User
- Posts: 62
- Joined: Mon Jul 18, 2016 6:43 pm
Re: Mouse position in a gadget coordinates?
Code: Select all
GadgetPositionX=WindowMouseX(#Window)-GadgetX(#Gadget)
GadgetPositionY=WindowMouseY(#Window)-GadgetY(#Gadget)
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
-
- User
- Posts: 62
- Joined: Mon Jul 18, 2016 6:43 pm
Re: Mouse position in a gadget coordinates?
Thanks for the quick response. That would work if the gadget was on the main window. Once I start putting containers inside containers things get tricky.
The Form Designer has an option to reparent gadgets which means their x and y are no longer relative to the main window, but their to new parent.
It would be ideal if I could pass a gadget to WindowMouseX and WindowMouseY, or if there was a translate mouse coordinates function. It seem MS Windows API has functions to translate coordinates between screen, client, etc. I'm hoping such functionality is built in to PureBasic since it is to be used on Windows, Linux, and MacOS.
The Form Designer has an option to reparent gadgets which means their x and y are no longer relative to the main window, but their to new parent.
It would be ideal if I could pass a gadget to WindowMouseX and WindowMouseY, or if there was a translate mouse coordinates function. It seem MS Windows API has functions to translate coordinates between screen, client, etc. I'm hoping such functionality is built in to PureBasic since it is to be used on Windows, Linux, and MacOS.
Re: Mouse position in a gadget coordinates?
Hi
I am not familiar with Linux
Next demonstrate the mouse over Button 2
You can adapt for your needs
I am not familiar with Linux
Next demonstrate the mouse over Button 2
You can adapt for your needs
Code: Select all
; Shows using of several panels...
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget (0, 8, 8, 306, 203)
AddGadgetItem (0, -1, "Panel 1")
PanelGadget (1, 5, 5, 290, 166)
AddGadgetItem(1, -1, "Sub-Panel 1")
AddGadgetItem(1, -1, "Sub-Panel 2")
AddGadgetItem(1, -1, "Sub-Panel 3")
CloseGadgetList()
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
CloseGadgetList()
AddWindowTimer(0,125,10)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Timer
mx = WindowMouseX(0)
my = WindowMouseY(0)
If mx >= GadgetX(2,#PB_Gadget_WindowCoordinate) And mx <= (GadgetX(2,#PB_Gadget_WindowCoordinate) + GadgetWidth(2)) And my >= GadgetY(2,#PB_Gadget_WindowCoordinate) And my <= (GadgetY(2,#PB_Gadget_WindowCoordinate)+GadgetHeight(2))
nx = mx - GadgetX(2,#PB_Gadget_WindowCoordinate)
ny = my - GadgetY(2,#PB_Gadget_WindowCoordinate)
Else
nx = 0
ny = 0
EndIf
Debug nx
Debug ny
EndSelect
Until Quit = 1
EndIf
Egypt my love