add: switch to use/free the pointer
This commit is contained in:
parent
decd33cafb
commit
a41dae7d23
3 changed files with 34 additions and 5 deletions
|
@ -60,4 +60,6 @@ void input_init(void *mlx_ptr, void *win_ptr)
|
||||||
mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL);
|
mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL);
|
||||||
mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL);
|
mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL);
|
||||||
mlx_hook(win_ptr, MotionNotify, PointerMotionMask, hook_mousemove, NULL);
|
mlx_hook(win_ptr, MotionNotify, PointerMotionMask, hook_mousemove, NULL);
|
||||||
|
mlx_hook(win_ptr, ButtonPress, ButtonPressMask, hook_buttonpress, NULL);
|
||||||
|
printf(MOUSE_UNUSED_MSG);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
static bool g_intercept_mouse = false;
|
||||||
|
|
||||||
int hook_mousemove(int x, int y)
|
int hook_mousemove(int x, int y)
|
||||||
{
|
{
|
||||||
static const t_point_int window_middle = {
|
static const t_point_int window_middle = {
|
||||||
|
@ -23,10 +25,31 @@ int hook_mousemove(int x, int y)
|
||||||
static bool first_call = true;
|
static bool first_call = true;
|
||||||
const int dx = x - window_middle.x;
|
const int dx = x - window_middle.x;
|
||||||
|
|
||||||
|
if (g_intercept_mouse)
|
||||||
|
{
|
||||||
if (!first_call && dx)
|
if (!first_call && dx)
|
||||||
g_input_actions.rotate += dx;
|
g_input_actions.rotate += dx;
|
||||||
first_call = false;
|
first_call = false;
|
||||||
if (x != window_middle.x || y != window_middle.y)
|
if (x != window_middle.x || y != window_middle.y)
|
||||||
mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y);
|
mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int hook_buttonpress(int button)
|
||||||
|
{
|
||||||
|
static const t_point_int window_middle = {
|
||||||
|
SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
|
||||||
|
if (button == Button1)
|
||||||
|
{
|
||||||
|
g_intercept_mouse = !g_intercept_mouse;
|
||||||
|
if (g_intercept_mouse)
|
||||||
|
{
|
||||||
|
mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y);
|
||||||
|
printf(MOUSE_USED_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf(MOUSE_UNUSED_MSG);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
|
|
||||||
# include "input.h"
|
# include "input.h"
|
||||||
|
|
||||||
|
# define MOUSE_UNUSED_MSG "Click in the window to use the pointer.\n"
|
||||||
|
# define MOUSE_USED_MSG "Click again to free the pointer.\n"
|
||||||
|
|
||||||
int hook_mousemove(int x, int y);
|
int hook_mousemove(int x, int y);
|
||||||
|
int hook_buttonpress(int button);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue