I'm using engine which uses SDL 1.2.5. I can't change SDL version or not use this engine. I need custom mouse cursor. I loaded cur file properly and used the SetCursor method but every time I call SDL_PumpEvents my custom cursor is replaced by SDL's default black one. I could turn off system cursor and draw it manually but that way cursor is delayed and it's noticeable. I'm programming a game so any cursor delays are unwelcome. Is there any way to tell SDL to not changing cursor? Or to lock the SetCursor method?
You could place the SetCursor function in your gameloop so it sets the cursor after the events get handled
Related
I'm trying to get and set the cursor position before the system(Windows) update the cursor position or somehow set a limit to where the cursor can move.
Tried GetCursorPos(), It execute too late.
Tried WH_MOUSE_LL hook, It slowed down the cursor movement (basically introduced massive lags), and I couldn't change the mouse position..
Call ClipCursor inside your low-level mouse hook. This is rather evil because the mouse is a shared resource.
A nice application only calls ClipCursor when it is the foreground application.
WH_MOUSE is more effective (WH_MOUSE_LL may significantly slow down your computer) but hook programs must be placed in DLL.
This allows hook processes to be loaded and run in each process.
On the other hand, the WH_MOUSE_LL process must switch back to the original process each time to run outside the process. This is a very slow operation.
I have a large application with many widgets and windows.
At some moment I restore the cursor for entire application.
I need to keep it "customised" (as it was) for one frame.
I set it for the frame to be "customised" again, but it still restores for 1 millisecond and it is noticeable.
So the states of my cursor are: "Customised" - "Normal" - "Customised".
How can I skip changing cursor for one(current) frame? But restore it for all other windows (so it is normal again)?
Restore override cursor for all application, but set cursor to your frame.
Use setCursor() method.
http://qt-project.org/doc/qt-4.8/qwidget.html#cursor-prop
As documentation said about setOverrideCursor():
This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.
http://qt-project.org/doc/qt-4.8/qapplication.html#setOverrideCursor
So you can't restore cursor for all widgets instead of one, you should use setCursor() method.
I'm writing a mouse emulation program for Linux based on input from external hardware (Leap Motion Controller). For proper operation, I want to change the shape of the cursor to convey status information to the user related to their operation of the cursor. I'm currently writing a user space program to handle this. Mouse movement and mouse clicks are handled using the XTest library, but right now I can't find a way to change the shape of the cursor.
Using XDefineCursor() I've been able to change the cursor to a custom shape on a window owned by my program, but I need it in the full graphical environment, since this program will remain
hidden in the background most of the time.
I'd also prefer to not write a device driver and stay in user space for now if possible. Also I'd prefer to not have to change the code for the Display manager (ie Unity or LXDE).
Edit:
The hardware is the Leap Motion Controller. I need to display to the user if they are still in the sensor's range, or outside the range.
You can watch for cursor changes with XFixes protocol and then modify cursor each time it is changed adding your graphics to whatever window tried to set it ( SelectCursorInput/GetCursorImage/CursorNotify event)
At the moment I simply use the WM_MOUSEMOVE message, but it limits the mouse movement to the maximum resolution. So what's the best way of capturing the mouse with Win32 (on a OpenGl window)? I don't want to use freeglut or any extra library.
For games and realtime DirectInput is very suitable, it's moderately hard to use.
That is not core win32 api, the winapi way of getting the input is either GetCursorPos/SetCursorPos driven by your own update loop, so you query and reset with your own frequency.
Or SetCapture and then upon WM_MOUSEMOVE you call SetCursorPos.
The point of setting the cursor pos is to give room for movement so you can get the delta, the amount the cursor moved since the last update and then put it back the cursor into the center of your window.
If you want to be able to capture mouse events after the mouse has existed the window, then you might want to look into the SetCapture function
If your problem is that you want to make a FPS game and you want your character to be able to spin in a continuous motion, then you want to set the mouse position to the center of the window after each mouse move event and handle input based on the difference between the position of the cursor when the mouse move event is fired and the center of the screen. To set the position of the mouse you can use the SetCursorPos function.
Your best bets are to either use DirectInput (which can be a bit of a pain to set up) or RawInput.
There is a fairly comprehensive example available in the Using RawInput page (See example 2).
I want to have a red line instead of mouse pointer in my (written in C++ with OpenGL) application. For example when I move the mouse over an OpenGL window, I would like the cursor to become a red line. How can I do that?
Also, how can I call the mouse related functions (OpenGL) for that line and specify the functionality?
As Nicol Bolas said in his comment, OpenGL knows nothing of the mouse. You'll need to interact with the windowing system one way or another (via direct Win32/X11/etc. API or via a portable windowing library a la Qt, wxWidgets, etc) to monitor mouse position.
If the cursor you're trying to draw is a bitmap, your best bet is likely to handle mouse enter/leave events sent to your window and respond to them by using an API function to change the cursor. This will handle automatically updating the cursor as the mouse moves around and will add minimal overhead to your application (windowing system cursors generally draw in an overlay plane that avoids sending redraw events to your window every time the mouse moves).
If you have a more procedural description of your cursor (that is, you intend to draw it with OpenGL drawing commands), you'll instead want to handle the mouse enter/leave events by using HideCursor()/ShowCursor() commands or the equivalent to turn off the windowing system's native cursor when the mouse is over your window. Then, you'll hook the mouse move callbacks and redraw your scene, adding whatever commands you need to draw the cursor at the position specified in the mouse move event.
The first approach is definitely preferred for performance & latency reasons--but there are some cursor types (think full screen crosshairs) that can't be accomodated that way.