Mouse Coordinates

#1

What I am trying to do is make my own tooltip when you selected a point on a chart. The problem I am having is with the placement of the container. My screen is set to maximize on open and the components are set to relative. For some reason the event.source.x and event.source.y are incorrect when I test it out in the application. The coordinates are correct when I am in the designer.

I was thinking if I could get the mouse coordinates relative to the entire window that maybe they would be correct, but do not know how to do this. How should I go about getting accurate coordinates for the placement of the container without changing from relative layout?

0 Likes

#2

What kind of chart is it?

0 Likes

#3

the regular chart.

0 Likes

#4

Ok, and try and describe in what way the coordinates are “incorrect”. What sort of mouse event are you responding to? What are you expecting vs what are you observing?

0 Likes

#5

I will try my best. On the regular chart I have a mouse clicked event that gets the charts x position (event.source.x) and y position (event.source.y). I also get the events current postion with respect to inside the chart (event.x and event.y). I take the two x postions and add them together to get the x coordinate of the point with respect to the entire window. I do the same for the y coordinates and then set the postion of my tooltip container to this point (event.source.x+event.x,event.source.y+event.y).

I have attached one file show that it works correctly in the designer and one picture of what happens in the application window.




0 Likes

#6

Ok, I’m getting the picture now. I assume you’re using the fpmi.gui.moveComponent function to move your tooltip box around. The problem is that when using relative layout, this function expects coordinates relative to the window’s size the last time it was saved in the Designer, whereas you’re giving it the coordinates of the window as they exist in the stretched client.

Can you make just the mouseover popup use anchored layout (north, west)? This will be your path of least resistance…

0 Likes

#7

Found this solution to get mouse co-ordinates relative to entire window (where mouse was clicked on client).
Thought of sharing in case anyone stumbles across this problem again.

windowParent = system.gui.getParentWindow(event)
point = windowParent.mousePosition
x = int(point.getX())
y = int(point.getY())

To open popup/move component where mouse was clicked, use this x and y

1 Like