Mouse Position with and without MaxGUI...

BlitzMax Forums/BlitzMax Programming/Mouse Position with and without MaxGUI...

TaskMaster(Posted 2009) [#1]
How would I get the mouse position if I do not know if the app is runnign MaxGUI or not?

If it is a graphics app, I can just use MouseX() and MouseY(). If I am using MaxGUI, the I can use the MouseMove event on the canvas. But, what if I do not know of the program is using MaxGUI or not?

Is there a sure fire way to get the mouse position from the top left corner of the current graphics object whether it be a plain graphics window, or a MaxGUI canvas on a window?


SebHoll(Posted 2009) [#2]
If you add EnablePolledInput() to the top of your MaxGUI apps, MouseX() and MouseY() will work for MaxGUI canvases, just like with the Max2D graphics contexts.


TaskMaster(Posted 2009) [#3]
I thought there was a command that turned those functions on, I just couldn't remember it.

Thanks SebHoll.


JoshK(Posted 2009) [#4]
This does not seem to return the correct coordinates. It seems relative to the window, not the the active canvas.


TaskMaster(Posted 2009) [#5]
I just tested it and even though my canvas is at 20, 20 in the window (not at 0,0), MouseX and MouseY are returning coords relative to the top left corner of the canvas, not the window.


Corum(Posted 2009) [#6]
@Taskmaster: are you perhaps working on a canvas gadget for your GUI? :P


TaskMaster(Posted 2009) [#7]
You keep asking that, but it makes no sense to me. You can draw anywhere you want?!?!

Tell me exactly what you want it to do and how you would use it, and I will either make it for you or explain how you could do it with what is already there.

If you really want to draw to an image and have it displayed in a panel or a window, then just use a panel or a window, createan image and set it is the background of the panel/window. Then if you want to draw on it, just draw to the pixmap of the image. That functionality already exists in ifsoGUI.

If you need something more specific or something, you will have ot explain to me in a lot more detail what you are trying to do.

In your radar request, all you have to do is extend a panel gadget, then in the draw() method, call super.draw(), then draw your radar graphics. Very easy to do.


JoshK(Posted 2009) [#8]
What about MoveMouse?


TaskMaster(Posted 2009) [#9]
Leadwerks, MoveMouse...

Here is what i found and the fix I used.

The MoveMouse function does not send the event required for the Canvas, which causes the canvas to get screwy. So, I sent the event myself. Here is my MoveMouse function.



Without the event being emitted, the Canvas does not know the mouse position has changed, which causes lots of weird things to happen.


JoshK(Posted 2009) [#10]
Yeah, I think this should be added internally. If a hook was added inside the MoveMouse function, MaxGUI could access this and emit the event.


Corum(Posted 2009) [#11]
In your radar request, all you have to do is extend a panel gadget, then in the draw() method, call super.draw(), then draw your radar graphics. Very easy to do.

100% agree with you. I have no doubts related to visualization part.
The "problem" is I need to catch an input too: relative mouse coordinates when a sort of MouseClick event occurs on the gadget. ;-)
Mouse coords data are used at internal library level: no related properties seem to be publically exposed to final user, if I don't get wrong.
I've no problems to extend the panel gadget, adding a MouseClick event, like button gadget has, but I'm opened to some hint for a clean management of mouse X and Y coords.
Thanks, and sorry for this boring OT. ;)


TaskMaster(Posted 2009) [#12]
ifsoGUI Panels and Windows emit MouseMove and MouseDown/Up events.


Corum(Posted 2009) [#13]
Ok, thanks for this info.
I'm going to use a standard Panel and manually calculate the relative mouse position inside it. :-)


TaskMaster(Posted 2009) [#14]
Not hard to do, if you use GetAbsoluteXY, you will get the X,Y position of the panel, then you should be able to easily calculate the relative mouse position from there.


Corum(Posted 2009) [#15]
Yes, I did this way.
Thanks again!