Page 1 of 1

GadgetMouseX() ?

Posted: Sat Nov 29, 2003 1:27 am
by Shopro
Hello, I have a question.

Is there an API command for returning where the mouse cursor is on a specific gadget?

For example, "WindowMouseX()" returns the cursor location correspondin to the upper left point of the window.

I want to know if there is a way to return the cursor corrseponding to the upper left point of a gadget.

Any advice will be appreciated, thank you

-Shopro

Posted: Sat Nov 29, 2003 10:55 am
by V2
Hi,

you could try it like this (workaround):

Code: Select all

Procedure getRelativeX(myGadget.l)
  ProcedureReturn WindowMouseX()-GadgetX(myGadget)
EndProcedure

Procedure getRelativeY(myGadget.l)
  HeightOfTitleBar = 20
  ProcedureReturn WindowMouseY()-GadgetY(myGadget)-HeightOfTitleBar
EndProcedure
Returns the relative X/Y to your gadget - you just have to be careful with the height of the titlebar and the size of the borders (otherwise you won't get the exact position of the gadget).

Maybe there's a better way but I was too lazy to make an example - check these API functions:
ClientToScreen_
GetCursorPos_

Hope I could help you :)

Posted: Sat Nov 29, 2003 11:15 am
by freedimension

Code: Select all

  p.POINT
  p\x = WindowMouseX()
  p\y = WindowMouseY()
  ScreenToClient_( GadgetID(#Gadget), p)

Posted: Sat Nov 29, 2003 2:47 pm
by GPI
V2 wrote:

Code: Select all

Procedure getRelativeX(myGadget.l)
  ProcedureReturn WindowMouseX()-GadgetX(myGadget)
EndProcedure

Procedure getRelativeY(myGadget.l)
  HeightOfTitleBar = 20
  ProcedureReturn WindowMouseY()-GadgetY(myGadget)-HeightOfTitleBar
EndProcedure
DON'T MAKE IT SO! The height of the Tilebar is not a fixed size. Every user can change this!

Posted: Sat Nov 29, 2003 3:35 pm
by freedimension
Oops, mine is false too.
Use instead this one (it's even shorter and faster)

Code: Select all

GetCursorPos_(p.POINT)
ScreenToClient_( GadgetID(#Gadget), p) 

Posted: Sat Nov 29, 2003 10:47 pm
by Shopro
V2, freedimension, GPI,

thank you all very much for the advice.

I've tried all methods, and decided that freedimension's method works the best for me.

Now I can get on with my project:)

Thank you all again for the quick replies, I really appreciate it.

-Shopro

Thankyou!

Posted: Tue Feb 17, 2004 7:49 pm
by MIZ
Just wanted to say a huge THANKYOU for this post, because its got me out of a really irratating hole. I was so depressed, that I couldn't find a way of doing this reliably.

My concern was that I couldn't work out where the mouse was in relation to a button within a ScrollAreaGadget. But this API call takes care of that too - so yeah, I'm happy! My first project is back on course!

Thanks again! :D