Gadget Screen XY Coords?

BlitzPlus Forums/BlitzPlus Programming/Gadget Screen XY Coords?

Mr Brine(Posted 2003) [#1]
Does anyone know of a way to get the true screen xy coords of the top left hand corner of a specified gadget?

Ta


soja(Posted 2003) [#2]
My first inclination, though a little intricate and more complex than it should have to be, is to get the coords of the specified gadget with GadgetX and GadgetY, then do the same with its parent gadget (use GadgetGroup), add the results, and repeat until you reach the desktop.

Something like this:
Global x%,y%
w = CreateWindow("Test",100,200,300,400)
p = CreatePanel(50,60,200,150,w,1)
l = CreateLabel("Test",10,15,80,20,p,1)
ScreenCoords(l)
Notify x+", "+y
While WaitEvent()<>$0803 : Wend
End

Function ScreenCoords(gadget) 
	While gadget<>0
		x=x+GadgetX(gadget)
		y=y+GadgetY(gadget)
		gadget=GadgetGroup(gadget)
	Wend
End Function



BlitzSupport(Posted 2003) [#3]
This seems to work (uses userlibs):

; -----------------------------------------------------------------------------
; IMPORTANT: Add this line to user32.decls in your userlibs folder...
; -----------------------------------------------------------------------------
; ClientToScreen% (window, point*): ClientToScreen
; -----------------------------------------------------------------------------

window = CreateWindow ("Test", 0, 0, 208, 80, 0, 1)

; Will retrieve screen co-ords of 'gadget', below...

gadget = CreateButton ("My screen co-ords are below!", 0, 0, 200, 25, window)

Type Point
	Field x, y
End Type
	
p.Point = New Point

textfield = CreateTextField (0, 30, 200, 25, window)

Repeat

	; Set point in gadget to be converted:
	
	p\x = 0
	p\y = 0
	
	ClientToScreen (QueryObject (gadget, 1), p)
	
	; p.Point now contains the co-ords 0, 0 in 'gadget', converted to screen space...
	
	SetGadgetText textfield, "X: " + p\x + " -- Y: " + p\y
	
Until WaitEvent () = $803

End