Sign in to follow this  
Kincaid

WM_MOUSEMOVING ??

Recommended Posts

Hello, I need the mouse to stay within a (rectangle) window. I do this by catching WM_MOUSEMOVE, and checking the position. if outside, I simply set it back inside. However, ideally I would like to catch this message earlier, before the mouse actually moves. like WM_WINDOWPOSCHANGING, where you can check to coordinates before actually moving there. There is no WM_MOUSEMOVING, but something like that maybe ?? The way it is has the drawback of 'jerkiness' in the mouse on borders (jumping back to the region), which I would like to get rid of. thanx in advance.

Share this post


Link to post
Share on other sites
Try ClipCursor() instead, it does exactly what you want.

http://msdn.microsoft.com/en-us/library/ms648383(VS.85).aspx

Share this post


Link to post
Share on other sites
Thanx
Though it fixes my problem only halfway :)
The cursor stays neatly inside my rectangle, but I also dont receive any coordinates outside that.

I want to 'scroll' my view by 'bumping' at the edges of the screen with the mouse (like some strategy games have)
So I would like to register a move e.g. [-3, 0] (outside the rectangle) so I know I should scroll -3 over the 'x-axis', but then not project the mouse outside it.

ClipCursor also alters the value to the corrected position being 0 instead of -3.

Share this post


Link to post
Share on other sites
Make the rectangle you pass to ClipCursor slightly bigger than it needs to be (10 pixels on each side should work well). Then just check if you are inside that "border" zone when getting the cursor position, and you have all you need for scrolling [smile]

Share this post


Link to post
Share on other sites
yes, and i have considered that, though picky as I am :), thats not what I want.
Its fine and works great, but it would be a border-zone in which the camera starts scrolling when the mouse is there (basically like a button around the screen).
I would like to have the user explicitly (while pressing the right mouse button) scroll against the sides, and only when he keeps moving 'outside' pan camera. the real 'bump-scroll' version of it.
(as I mentoined, just as with the POSCHANGING message, I really need the actual coordinates, but then have ability to alter those to utlimatly position the mouse)
thanx though.

Share this post


Link to post
Share on other sites
Do you want the scroll speed to be determined by the distance the mouse is moved outside the view? i.e. You say that if the mouse is at [-3, 0] relative to the window/view/rectangle then it should scroll 3 pixels to the left, so i assume you mean that if the mouse was further out then it will scroll more.
Have you tried using SetCapture with ClipCursor? That may solve the problem of having the coords also clipped. I think that only works when the mouse button is pressed but you said that you only want it to scroll when the button is pressed so that should be ok

Share this post


Link to post
Share on other sites
yes exactly, the more/faster you move outside / bump at the side, the more/faster it should scroll.
(giving the user an intuitive way the pan the view over the map in a controlled manner)

I use SetCapture all over the place, and you're suggesting that when ClipCursor is active, AND the window also has the capture, then the coordinates passed to lParam of WM_MOUSEMOVE are not clipped (but normal/usual) ?
(i dont see why the mousebutton should have to pressed though ..)

This sounds exactly right/what I need, and Ill try that asap

thanx

edit:
I have tried it (had it captured to begin with) but it seems that ClipCursor clips the coordinates and then hands them off to the message... :(

any more suggestions ?

Share this post


Link to post
Share on other sites
When my mouse at the border, e.g. the left side (x=0), and I scroll further to the left, when ClipCursor is enabled, no mousemoves are generated.
But I must have that information

So I guess clipcursor wont do it :(

So it looks like I have ot use SetCursor (like I did), simply putting the cursor back in his place after he has crossed the border...

It seems to be the only (& ugly) way for it work like I described..

thnx

Share this post


Link to post
Share on other sites
The easy solution would be to set a flag when the mouse moves into the "scroll region." When this flag is active, you grab the mouse cursor position via GetCursorPos each frame, and use that position to decide how much to scroll. If that position is outside the hot zone, you clear the flag, and proceed as normal.

Share this post


Link to post
Share on other sites
Quote:
Original post by ApochPiQ
The easy solution would be to set a flag when the mouse moves into the "scroll region." When this flag is active, you grab the mouse cursor position via GetCursorPos each frame, and use that position to decide how much to scroll. If that position is outside the hot zone, you clear the flag, and proceed as normal.


the problem is that I want no 'scroll region', but more like a 'scroll-functionality', namely when dragging against a side -> pan view.
e.g. the user could pan (exactly) left by (exactly) dragging into the left side, but also left and a little up or down depending on the mousedrag movement.
So I must get the (2d)vector last-position-in-rect to first-position-out-rect
which cant be done with ClipCursor (coordinates are clipped). So i must allow to mouse to travel there, to get the coordinate, and then explicitly set it back to the rectangle (to where it exitted), which results in jerkiness ....


Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
I hate applications that hijack my cursor. It's mine - I paid for it, leave it alone.


:D
ok, but let explain why this is perfectly reasonable and desirable.
I have an editor in which you have some geometry, e.g. a sphere, which you can translate, rotate and scale by dragging it with the mouse.
In the case of translation, you are able to translate/drag it outside the screen (when not clipping etc).
In this case an object is moved outside the view, but to keep view (and keep editing) I translate/rotate the view along in these cases.
Otherwise, if e.g. the user has a little modelhouse on the map, looking at it from above, and wants to drag it to the other side of the map he doesnt have to drag-pan-drag-pan etc untill its there (or zoom out first or something), but can simply drag, and keep dragging, as the view travels along with it.



Share this post


Link to post
Share on other sites
Quote:
Original post by Kincaid
Quote:
Original post by Antheus
I hate applications that hijack my cursor. It's mine - I paid for it, leave it alone.


:D
ok, but let explain why this is perfectly reasonable and desirable...

Yeah, i hate that too but this case is different because (from what i understand) the application only has control of the cursor when the user is controlling it by dragging it. Kind of like a drag-drop operation.

Share this post


Link to post
Share on other sites
yes, its not like im starting to move the mouse for them or something. It just an extra drag functionality (dragging against the sides), one which is very normal in games/editors and as I said, very desirable.

But thats the why,
now the how :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this