MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_mouse.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* :::::::: */
4/* mlx_mouse.c :+: :+: */
5/* +:+ */
6/* By: W2Wizard <main@w2wizard.dev> +#+ */
7/* +#+ */
8/* Created: 2022/01/01 23:20:13 by W2Wizard #+# #+# */
9/* Updated: 2022/06/29 15:34:25 by lde-la-h ######## odam.nl */
10/* */
11/* ************************************************************************** */
12
13#include "MLX42/MLX42_Int.h"
14
15//= Private =//
16
17static void mlx_scroll_cb(GLFWwindow* window, double xoffset, double yoffset)
18{
19 const mlx_t* mlx = glfwGetWindowUserPointer(window);
20 const mlx_scroll_t scroll_hook = ((mlx_ctx_t*)mlx->context)->scroll_hook;
21
22 scroll_hook.func(xoffset, yoffset, scroll_hook.param);
23}
24
26{
27 const mlx_t* mlx = glfwGetWindowUserPointer(window);
28 const mlx_mouse_t mouse_hook = ((mlx_ctx_t*)mlx->context)->mouse_hook;
29
30 mouse_hook.func(button, action, mods, mouse_hook.param);
31}
32
33static void mlx_cursor_cb(GLFWwindow* window, double xpos, double ypos)
34{
35 const mlx_t* mlx = glfwGetWindowUserPointer(window);
36 const mlx_cursor_t cursor_hook = ((mlx_ctx_t*)mlx->context)->cursor_hook;
37
38 cursor_hook.func(xpos, ypos, cursor_hook.param);
39}
40
41//= Public =//
42
44{
47
48 mlx_ctx_t* const mlxctx = mlx->context;
49 mlxctx->scroll_hook.func = func;
50 mlxctx->scroll_hook.param = param;
52}
53
55{
58
59 mlx_ctx_t* const mlxctx = mlx->context;
60 mlxctx->mouse_hook.func = func;
61 mlxctx->mouse_hook.param = param;
63}
64
66{
69
70 mlx_ctx_t* const mlxctx = mlx->context;
71 mlxctx->cursor_hook.func = func;
72 mlxctx->cursor_hook.param = param;
74}
75
77{
79
80 return (glfwGetMouseButton(mlx->window, key) == GLFW_PRESS);
81}
82
84{
86
87 glfwSetCursorPos(mlx->window, (double)x, (double)y);
88}
89
91{
95
96 double xd, yd;
98 *x = (int32_t)xd;
99 *y = (int32_t)yd;
100}
enum mouse_key mouse_key_t
action
Definition MLX42.h:54
void(* mlx_mousefunc)(mouse_key_t button, action_t action, modifier_key_t mods, void *param)
Definition MLX42.h:424
void(* mlx_scrollfunc)(double xdelta, double ydelta, void *param)
Definition MLX42.h:414
void(* mlx_cursorfunc)(double xpos, double ypos, void *param)
Definition MLX42.h:433
#define MLX_NONNULL(var)
Definition MLX42_Int.h:46
GLenum func
Definition glad.h:3336
GLint y
Definition glad.h:1965
GLint GLint GLint yoffset
Definition glad.h:2890
GLdouble x
Definition glad.h:2847
GLuint GLsizei GLsizei * length
Definition glad.h:3372
GLint GLint xoffset
Definition glad.h:2887
GLenum GLfloat param
Definition glad.h:1968
void mlx_scroll_hook(mlx_t *mlx, mlx_scrollfunc func, void *param)
Definition mlx_mouse.c:43
void mlx_mouse_hook(mlx_t *mlx, mlx_mousefunc func, void *param)
Definition mlx_mouse.c:54
static void mlx_mouse_cb(GLFWwindow *window, int32_t button, int32_t action, int32_t mods)
Definition mlx_mouse.c:25
void mlx_get_mouse_pos(mlx_t *mlx, int32_t *x, int32_t *y)
Definition mlx_mouse.c:90
void mlx_cursor_hook(mlx_t *mlx, mlx_cursorfunc func, void *param)
Definition mlx_mouse.c:65
void mlx_set_mouse_pos(mlx_t *mlx, int32_t x, int32_t y)
Definition mlx_mouse.c:83
bool mlx_is_mouse_down(mlx_t *mlx, mouse_key_t key)
Definition mlx_mouse.c:76
static void mlx_cursor_cb(GLFWwindow *window, double xpos, double ypos)
Definition mlx_mouse.c:33
static void mlx_scroll_cb(GLFWwindow *window, double xoffset, double yoffset)
Definition mlx_mouse.c:17
void * param
Definition MLX42_Int.h:128
mlx_cursorfunc func
Definition MLX42_Int.h:129
mlx_mousefunc func
Definition MLX42_Int.h:123
void * param
Definition MLX42_Int.h:122
void * param
Definition MLX42_Int.h:116
mlx_scrollfunc func
Definition MLX42_Int.h:117
Definition MLX42.h:361
void * context
Definition MLX42.h:363
void * window
Definition MLX42.h:362