Mouse Behaviour
Monkey Targets Forums/Desktop/Mouse Behaviour
| ||
Hi all, it appears to me that a full screen GLFW app doesn't clamp the mouse coords on the screen. That is, you can end up with a mouse position of -1000,1251255. Would this be considered a bug?Import mojo #GLFW_USE_MINGW=True #GLFW_WINDOW_TITLE="Mouse Position Test" #GLFW_WINDOW_WIDTH=1280 #GLFW_WINDOW_HEIGHT=720 #GLFW_WINDOW_RESIZABLE=false #GLFW_WINDOW_FULLSCREEN=true Class TestApp Extends App Method OnCreate() SetUpdateRate(60) End Method OnUpdate() If KeyHit(KEY_ESCAPE) Error "" End End Method OnRender() Cls DrawText(MouseX()+":"+MouseY(),100,100) End End Function Main() New TestApp End |
| ||
This behavior doesn't happen with XNA |
| ||
Change thisDrawText(MouseX()+":"+MouseY(),100,100)To read DrawText(MouseX() + ":" + MouseY(), MouseX(), MouseY())When I first run this code the text displayed is 0.0:0.0. Then as soon as the mouse is moved it jumps to the centre. Which is where the mouse is placed when the screen switches to full screen mode. I think this is a bug as the location of the mouse should be returned as soon as MouseX/Y is called. It could even be an issue with GLFW. Are you using a dual monitor setup? |
| ||
Hi Dawlane thanks, before I move the mouse it,s at 0:0 but as soon as I move it it sorts itself out but i am still able to move the mouse WAY off the screen. I am not using a dual screen setup. |
| ||
i am still able to move the mouse WAY off the screen. Yeah I get the same thing.Ha found out why it does it for glfw it's in the GLFW User guid.pdf section 4.3.4. GLFW Users Guide API version 2.7 Page 18/39 4.3.4 Hiding the mouse cursor It is possible to hide the mouse cursor with the function call: glfwDisable( GLFW_MOUSE_CURSOR ); Hiding the mouse cursor has three effects: 1. The cursor becomes invisible. 2. The cursor is guaranteed to be confined to the window. 3. Mouse coordinates are not limited to the window size. To show the mouse cursor again, call glfwEnable with the argument GLFW_MOUSE_CURSOR: glfwEnable( GLFW_MOUSE_CURSOR ); By default the mouse cursor is hidden if a window is opened in full screen mode, otherwise it is not hidden. So it's not a bug. But if you show the mouse you get some weird behaviour when moving it the edges. Got to the bottom and keep dragging down and the mouse will move along the x-axis same thing for the y-axis as well. |
| ||
Thanks for digging Dawlane :) I'm sure there is logic to it, but I can't understand why? I guess I'm going to have to add my own layer for keeping a mouse cursor within the screen. |
| ||
If you haven't already solved it here's how. Make a file named mouse.cpp in you project folder and add this code void SetMousePos(int x, int y){ glfwSetMousePos( x,y ); }Next Make another file named mouse.monkey in your project folder and add this code Import "mouse.cpp" Extern Function SetMousePos:Void(x:Int, y:Int) = "SetMousePos" Then just add to your main project file #If TARGET="glfw" Import "mouse" #EndIFAnd you can trap the mouse on screen with something like Import mojo #If TARGET="glfw" Import os Import mouse #EndIF #GLFW_USE_MINGW=True #GLFW_WINDOW_TITLE="Mouse Position Test" #GLFW_WINDOW_WIDTH=800 #GLFW_WINDOW_HEIGHT=600 #GLFW_WINDOW_RESIZABLE=false #GLFW_WINDOW_FULLSCREEN=true Class TestApp Extends App Field x:Int Field y:Int Field mx:Int Field my:Int Method OnCreate() SetUpdateRate(60) End Method OnUpdate() Self.x = MouseX() Self.y = MouseY() #If TARGET="glfw" If KeyHit(KEY_ESCAPE) Then ExitApp(0) If Self.x < 0 Or Self.x > DeviceWidth Or Self.y < 0 Or Self.y > DeviceHeight If Self.x < 0 Then Self.x = 0 If Self.x > DeviceWidth Then Self.x = DeviceWidth If Self.y < 0 Then Self.y = 0 If Self.y > DeviceHeight Then Self.y = DeviceHeight SetMousePos(Self.x, Self.y) EndIf #EndIF Self.mx = MouseX() Self.my = MouseY() End Method OnRender() Cls DrawText(Self.x + ":" + Self.y, Self.x, Self.y) DrawText(Self.mx + ":" + Self.my, DeviceWidth / 2, DeviceHeight / 2) End End Function Main() New TestApp End If you feel more adventurous you could do away with using the monkey functions and just write your own code. |