Re: [AD] Is al_set_mouse_range any useful? |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Coordination of admins/developers of the game programming library Allegro <alleg-developers@xxxxxxxxxx>
- Subject: Re: [AD] Is al_set_mouse_range any useful?
- From: Trent Gamblin <trentg@xxxxxxxxxx>
- Date: Fri, 12 Oct 2007 09:16:22 -0600
Peter Wang wrote:
There may be two features that we want:
1. constraining a mouse cursor inside a window
2. providing infinite mickeys (e.g. for 3d shooters)
I think you can't have (2) without (1), but (1) might be useful without
(2). (1) can be implemented by users given (2), if they draw their own
cursors.
1 can already be achieved with the current api if I'm not mistaken:
#include <allegro.h>
int main(void)
{
allegro_init();
install_keyboard();
install_mouse();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
show_os_cursor(MOUSE_CURSOR_ARROW);
position_mouse(SCREEN_W/2, SCREEN_H/2);
int old_x = mouse_x;
int old_y = mouse_y;
for (;;) {
int mx = mouse_x;
int my = mouse_y;
int mix, miy;
get_mouse_mickeys(&mix, &miy);
if (old_x+mix < 0)
mx = 0;
else if (old_x+mix > SCREEN_W-1)
mx = SCREEN_W-1;
if (old_y+miy < 0)
my = 0;
else if (old_y+miy > SCREEN_H-1)
my = SCREEN_H-1;
position_mouse(mx, my);
if (old_x != mx || old_y != my) {
printf("%d %d\n", mx, my);
old_x = mx;
old_y = my;
}
if (key[KEY_ESC]) break;
}
}
END_OF_MAIN()
2 can be achieved similarly.