absolute position of a gadget on a panelgadget
absolute position of a gadget on a panelgadget
gadgets are drawn relative to the window 0,0 coordinate, now let's assume i have a panelgadget and i have drawn gadgets on top of that panel gadget... how do i find their real coordinates in relation to the window 0,0 position?
i have no clue... anybody?
i have no clue... anybody?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Relative to the window position, this should do:
Relative to the desktop, add the WindowX() and WindowY() in there too.
Code: Select all
If OpenWindow(0, 0, 0, 322, 220,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"PanelGadget") And CreateGadgetList(WindowID(0))
PanelGadget (0, 8, 8, 306, 203)
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(1, 100, 110, 80, 24,"Button 1")
Debug GadgetX(0)+GadgetX(1)
Debug GadgetY(0)+GadgetY(1)
CloseGadgetList()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
thx, but euh... well, how to get the bordersize then of a panelgadget then?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
ah yes, thank you edwin, i actually used getwinrect_() in the past, but forgot to apply it to this case 

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: absolute position of a gadget on a panelgadget
Hello,
Basically I have the same question - but I need a crossplatform solution
This can't be achieved through the solution proposed by netmaestro, as it doesn't take into account the panel menu height.
Does anyone know how to achieve this?
Basically I have the same question - but I need a crossplatform solution

This can't be achieved through the solution proposed by netmaestro, as it doesn't take into account the panel menu height.
Does anyone know how to achieve this?
Re: absolute position of a gadget on a panelgadget
Code: Select all
EnableExplicit
Define posx, posy
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(0, 8, 8, 306, 203)
AddGadgetItem(0, -1,"Panel 2")
ButtonGadget(1, 100, 110, 80, 24,"Button 1")
CloseGadgetList()
posx = GadgetX(0) + GadgetX(1) + 3
posy = GadgetY(0) + GadgetY(1) + GetGadgetAttribute(0, #PB_Panel_TabHeight) + 1
ButtonGadget(2, posx, posy, 80, 24, "Button 2")
HideGadget(2, #True)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1
HideGadget(0, #True)
HideGadget(2, #False)
Case 2
HideGadget(0, #False)
HideGadget(2, #True)
EndSelect
EndSelect
ForEver
EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: absolute position of a gadget on a panelgadget
Thanks, didn't know there was that attribute. I wanted some "universal" solution that worked without having to know which is the parent gadget (as this can't be retrieved programmatically).
Anyway I found a solution, as I use the canvas gadget I just compare the mouse position returned by the gadget to the windows position, minus the gadget position, and that does what I want
Anyway I found a solution, as I use the canvas gadget I just compare the mouse position returned by the gadget to the windows position, minus the gadget position, and that does what I want

Re: absolute position of a gadget on a panelgadget
@ts-soft,
Thomas, you should NEVER assume that source code is cross-platform
only because it doesn't use API functions. Nothing beats a real test...
I had to modify your code to be indeed cross-platform and verified it in
Windows 7 x86, andLinux/Kubuntu 9.04 x86, Linux Mint 12 x86 and
Mac OS X 10.6.8 (Snow Leopard):
Thomas, you should NEVER assume that source code is cross-platform
only because it doesn't use API functions. Nothing beats a real test...

I had to modify your code to be indeed cross-platform and verified it in
Windows 7 x86, andLinux/Kubuntu 9.04 x86, Linux Mint 12 x86 and
Mac OS X 10.6.8 (Snow Leopard):
Code: Select all
EnableExplicit
Define posx, posy
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(0, 8, 8, 306, 203)
AddGadgetItem(0, -1,"Panel 2")
ButtonGadget(1, 100, 110, 80, 24,"Button 1")
CloseGadgetList()
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
posx = GadgetX(0) + GadgetX(1)
posy = GadgetY(0) + GadgetY(1)
CompilerCase #PB_OS_MacOS
posx = GadgetX(0) + GadgetX(1) + 3
posy = GadgetY(0) + GadgetY(1) + GetGadgetAttribute(0, #PB_Panel_TabHeight)
CompilerCase #PB_OS_Windows
posx = GadgetX(0) + GadgetX(1) + 3
posy = GadgetY(0) + GadgetY(1) + GetGadgetAttribute(0, #PB_Panel_TabHeight) + 1
CompilerEndSelect
ButtonGadget(2, posx, posy, 80, 24, "Button 2")
HideGadget(2, #True)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1
HideGadget(0, #True)
HideGadget(2, #False)
Case 2
HideGadget(0, #False)
HideGadget(2, #True)
EndSelect
EndSelect
ForEver
EndIf