|
|
Re: Limiting mouse cursor movement to a box/window?
[Re: Zyro_Falcon]
#422538
05/12/13 08:17
05/12/13 08:17
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
do you want to keep the mouse-coordinates in the window or do you want to modify the windows cursor position?
POTATO-MAN saves the day! - Random
|
|
|
Re: Limiting mouse cursor movement to a box/window?
[Re: Zyro_Falcon]
#422545
05/12/13 13:51
05/12/13 13:51
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
for the second one you have to use the windows api, (windows.h) but I have no idea, how the functions you need are called. the first method is very easy, you can use simple macros for that:
#define mouse_x_limited clamp(mouse_cursor.x, 0, screen_size.x)
#define mouse_y_limited clamp(mouse_cursor.y, 0, screen_size.y)
if you defined these two in your code you can access the mouse position by using mouse_x_limited and mouse_y_limited
POTATO-MAN saves the day! - Random
|
|
|
Re: Limiting mouse cursor movement to a box/window?
[Re: lemming]
#422563
05/12/13 20:35
05/12/13 20:35
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
@lemming: it only needs to be called once  (edit: well if the position changes it has to be called again) ...this should be a bit easier:
byte mouse_lock_on_off = 0;
void lock_mouse(var on_off)
{
mouse_lock_on_off = (byte)(on_off != NULL);
byte _toggle = window_focus;
RECT temp_rect;
GetClientRect(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect.right);
if(_toggle)
{
ClipCursor(&temp_rect);
}
while(mouse_lock_on_off)
{
GetClientRect(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect.right);
if(_toggle && !window_focus)
{
_toggle = 0;
ClipCursor(NULL);
}
if(!_toggle && window_focus)
{
_toggle = 1;
ClipCursor(&temp_rect);
}
wait(1);
}
ClipCursor(NULL);
}
clipping can be enabled or disabled by calling the function with 1 or 0, it will be disabled automatically if the window looses focus (and it gets enabled again if the engine window is the active window)
Last edited by Kartoffel; 05/12/13 20:42.
POTATO-MAN saves the day! - Random
|
|
|
Re: Limiting mouse cursor movement to a box/window?
[Re: Zyro_Falcon]
#422572
05/13/13 05:21
05/13/13 05:21
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
mouse_cursor is the position of the windows cursor (read only, synced automatically) mouse_pos is used as internal mouse position for buttons and mouse events and has to be either set manually or automatically by using mouse_mode = 4. also, buttons and mouse events only work if mouse_mode is enabled. [...] The predefined variables named mouse_pos.x and mouse_pos.y control the position of the mouse pointer on the screen; if I set mouse_pos.x = 200 and mouse_pos.y = 300 (just an example), the pointer appears on the screen just like in the picture below: [...] This is not said very clear but this only sets the engine mouse position, not the windows cursor.
POTATO-MAN saves the day! - Random
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|