Archived

This topic is now archived and is closed to further replies.

Qoy

Small mouse flicker

Recommended Posts

I''m working on a graphic effect program in which sometimes I track the mouse by hiding the cursor, putting it in the center of the window, and every frame getting the x and y deltas and putting it back in the center. When I stop tracking the mouse, I set its position to where it was before I started tracking (which was stored) and then show it *in that order*. Sometimes, despite the fact that I position it before I show it, it appears for a split second in the middle of the window before it goes to where I''ve set its position. I know this doesn''t matter all that much, but it''s one of those annoying little things that bug programmers.. It''s weird because logically it seems that if I make the SetCursorPos() call before the ShowCursor() call, when it appears it should appear in its new position, but sometimes (often) it doesn''t. Is there something I have to do to ensure that the cursor gets positioned before it gets shown (since making the calls in that order doesn''t seem to work)? Thanks!

Share this post


Link to post
Share on other sites
From MSDN:
quote:
The cursor is a shared resource. A window should move the cursor only when the cursor is in its client area.

The calling process must have WINSTA_WRITEATTRIBUTES access to the window station.

Do you guarantee that the cursor is still within the client area when you position it? Note that there is no such similar restriction on showing/hiding the cursor.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Is it necessary to track the mouse cursor using such a complex method? May be there is a better solution which could eliminate your problem. Explain what do you want to do exactly. I cannot help you more without knowing that.

Share this post


Link to post
Share on other sites
This isn''t a complex method...

The purpose of hiding the cursor is so it will not be visible. The purpose of moving it back to the center of the window is so that it doesn''t get moved out of the client area. In the mode where the cursor is hidden I want it to be like the mouse isn''t controlling the cursor, but just acting as an input device to control whatever is being controlled by the effect that''s using it.

So yeah, the cursor is guaranteed to be in the client area when I reposition it because I keep it in the center after I measure it''s movement deltas.

All I want is to be able to take mouse input without showing cursor movement. The best/easiest way I could think of was to hide the cursor and keep it in the center of the window after measuring movement. It''s not complex. It basically goes like this every frame:

GetCursorPos();
// store deltas based on movement of the cursor from center of window
SetCursorPos(/*window center*/);

The only issue is that when I want to stop tracking the mouse (when the user exits this mode where the mouse controls the world rather than the cursor), I place the cursor back where it was before tracking started. When I do this, the cursor often flickers in the center of the window for a split second before moving back to its original position, despite the fact that I call SetCursorPos() before ShowCursor().

Any ideas?

Share this post


Link to post
Share on other sites
So do a bounds check Check wether the mouse has moved out of the client area at all times, this way you do not have to center the mouse...

I really dont see the point of centering the mouse. Just hide it when you dont want to see it and show when you want to...

Share this post


Link to post
Share on other sites
A boundscheck will let the mouse move around the window, but it will still flash when I re-show it because it won''t be in the place where it originally was.

The point of keeping it in the center is because if I don''t, and it moves out of the window, then it will be visible again. It''s easier to just check it and put it in the window center than to keep it within window bounds if I don''t want it going outside the window.

I am aware of DirectInput.

Does anybody have any idea about the real problem? Thanks for the suggestions, but I have thought over my method, and it seems to me to be fine. I just don''t know why the mouse isn''t positioned and shown in the order that the calls are made.

Share this post


Link to post
Share on other sites
It is very simple...

Mouse moves
Check for bounds
If within bounds
If mouse moves beyond the bounds place back within the bounds.

Hide mouse

Show mouse should show it at latest position

You can still track the mouse movent even if it''s hidden or not.

ShowCursor(WM_SHOW/WM_HIDE) only hides the icon it does not stop the message loop from reading the mouse movements.

Share this post


Link to post
Share on other sites
...

I understand what you''re saying, it''s trivial, I know that. However, the method I have chosen involves keeping it in the center.

If I check for bounds etc and show the mouse, effectively the user would have done something to hide the mouse and begin tracking it *hidden* at some point, and when they do something to show it again, it would have moved. That is not what I want.

I know you can track movement if it''s not hidden, what I''m doing requires it to be hidden.

And actually, you pass TRUE and FALSE to ShowCursor, not the windows messages for show and hide. I understand how that works.

I am not asking for critiques on what I''m doing, when I haven''t even explained the exact scenario for which I''m using this. There''s no need to, because my question is simply:

Does anyone know why the mouse would be shown before being moved if you call SetCursorPos() before ShowCursor()? And if so, can any solutions be suggested?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think it has to do with the frame updates. What I believe is happening is that when you setCursorPos() and then followed by showCursor() they are both executed on the same frame. Internally, the mouse location is changed before the show command is processed, but since it''s done almost simultaneously, the mouse would appear first before the frame updates to the correct location in the next frame - that would account for your flicker. Try to see if you can showCursor() in the following frame and hopefully that solves your problem.

Share this post


Link to post
Share on other sites
That''s what I was thinking too, but I didn''t think of showing the cursor on the following frame. That''s a good idea, I''ll try it.

Thanks!

Share this post


Link to post
Share on other sites