GadgetMouseX() ?

Windows specific forum
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

GadgetMouseX() ?

Post 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
V2
User
User
Posts: 53
Joined: Wed Oct 15, 2003 4:53 pm

Post 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 :)
V2
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Code: Select all

  p.POINT
  p\x = WindowMouseX()
  p\y = WindowMouseY()
  ScreenToClient_( GadgetID(#Gadget), p)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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!
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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) 
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post 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
MIZ
New User
New User
Posts: 4
Joined: Tue Feb 17, 2004 7:45 pm
Location: England
Contact:

Thankyou!

Post 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
There are 10 types of people in life. Those who understand binary, and those that don't.
Post Reply