MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_mouse.c File Reference
#include "MLX42/MLX42_Int.h"
Include dependency graph for mlx_mouse.c:

Go to the source code of this file.

Functions

static void mlx_scroll_cb (GLFWwindow *window, double xoffset, double yoffset)
 
static void mlx_mouse_cb (GLFWwindow *window, int32_t button, int32_t action, int32_t mods)
 
static void mlx_cursor_cb (GLFWwindow *window, double xpos, double ypos)
 
void mlx_scroll_hook (mlx_t *mlx, mlx_scrollfunc func, void *param)
 
void mlx_mouse_hook (mlx_t *mlx, mlx_mousefunc func, void *param)
 
void mlx_cursor_hook (mlx_t *mlx, mlx_cursorfunc func, void *param)
 
bool mlx_is_mouse_down (mlx_t *mlx, mouse_key_t key)
 
void mlx_set_mouse_pos (mlx_t *mlx, int32_t x, int32_t y)
 
void mlx_get_mouse_pos (mlx_t *mlx, int32_t *x, int32_t *y)
 

Function Documentation

◆ mlx_cursor_cb()

static void mlx_cursor_cb ( GLFWwindow window,
double  xpos,
double  ypos 
)
static

Definition at line 33 of file mlx_mouse.c.

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}
GLuint GLsizei GLsizei * length
Definition glad.h:3372
void * param
Definition MLX42_Int.h:128
mlx_cursorfunc func
Definition MLX42_Int.h:129
Definition MLX42.h:361
void * context
Definition MLX42.h:363
Here is the caller graph for this function:

◆ mlx_cursor_hook()

void mlx_cursor_hook ( mlx_t mlx,
mlx_cursorfunc  func,
void param 
)

This function sets the cursor callback, which is called when the mouse position changes. Position is relative to the window.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe cursor callback function.
[in]paramAn additional optional parameter.

Definition at line 65 of file mlx_mouse.c.

66{
69
70 mlx_ctx_t* const mlxctx = mlx->context;
71 mlxctx->cursor_hook.func = func;
72 mlxctx->cursor_hook.param = param;
74}
#define MLX_NONNULL(var)
Definition MLX42_Int.h:46
GLenum func
Definition glad.h:3336
GLenum GLfloat param
Definition glad.h:1968
static void mlx_cursor_cb(GLFWwindow *window, double xpos, double ypos)
Definition mlx_mouse.c:33
void * window
Definition MLX42.h:362
Here is the call graph for this function:

◆ mlx_get_mouse_pos()

void mlx_get_mouse_pos ( mlx_t mlx,
int32_t x,
int32_t y 
)

Returns the current, relative, mouse cursor position on the window, starting from the top left corner.

Negative values or values greater than window width or height indicate that it is outside the window.

Parameters
[in]mlxThe MLX instance handle.
[out]xThe position.
[out]yThe position.

Definition at line 90 of file mlx_mouse.c.

91{
95
96 double xd, yd;
98 *x = (int32_t)xd;
99 *y = (int32_t)yd;
100}
GLint y
Definition glad.h:1965
GLdouble x
Definition glad.h:2847

◆ mlx_is_mouse_down()

bool mlx_is_mouse_down ( mlx_t mlx,
mouse_key_t  key 
)

Checks whether a mouse button is pressed or not.

Parameters
[in]mlxThe MLX instance handle.
[in]keyA specific mouse key. e.g MLX_MOUSE_BUTTON_0
Returns
True or false if the mouse key is down or not.

Definition at line 76 of file mlx_mouse.c.

77{
79
80 return (glfwGetMouseButton(mlx->window, key) == GLFW_PRESS);
81}

◆ mlx_mouse_cb()

static void mlx_mouse_cb ( GLFWwindow window,
int32_t  button,
int32_t  action,
int32_t  mods 
)
static

Definition at line 25 of file mlx_mouse.c.

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}
action
Definition MLX42.h:54
mlx_mousefunc func
Definition MLX42_Int.h:123
void * param
Definition MLX42_Int.h:122
Here is the caller graph for this function:

◆ mlx_mouse_hook()

void mlx_mouse_hook ( mlx_t mlx,
mlx_mousefunc  func,
void param 
)

This function sets the mouse callback, which is called when a mouse does any sort of action such as pressing a key.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe mouse callback function.
[in]paramAn additional optional parameter.

Definition at line 54 of file mlx_mouse.c.

55{
58
59 mlx_ctx_t* const mlxctx = mlx->context;
60 mlxctx->mouse_hook.func = func;
61 mlxctx->mouse_hook.param = param;
63}
static void mlx_mouse_cb(GLFWwindow *window, int32_t button, int32_t action, int32_t mods)
Definition mlx_mouse.c:25
Here is the call graph for this function:

◆ mlx_scroll_cb()

static void mlx_scroll_cb ( GLFWwindow window,
double  xoffset,
double  yoffset 
)
static

Definition at line 17 of file mlx_mouse.c.

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}
GLint GLint GLint yoffset
Definition glad.h:2890
GLint GLint xoffset
Definition glad.h:2887
void * param
Definition MLX42_Int.h:116
mlx_scrollfunc func
Definition MLX42_Int.h:117
Here is the caller graph for this function:

◆ mlx_scroll_hook()

void mlx_scroll_hook ( mlx_t mlx,
mlx_scrollfunc  func,
void param 
)

This function sets the scroll callback, which is called when a scrolling device is used, such as a mouse wheel.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe scroll wheel callback function.
[in]paramAn additional optional parameter.

Definition at line 43 of file mlx_mouse.c.

44{
47
48 mlx_ctx_t* const mlxctx = mlx->context;
49 mlxctx->scroll_hook.func = func;
50 mlxctx->scroll_hook.param = param;
52}
static void mlx_scroll_cb(GLFWwindow *window, double xoffset, double yoffset)
Definition mlx_mouse.c:17
Here is the call graph for this function:

◆ mlx_set_mouse_pos()

void mlx_set_mouse_pos ( mlx_t mlx,
int32_t  x,
int32_t  y 
)

Sets the mouse position.

Parameters
[in]mlxThe MLX instance handle.
[in]posThe position.

Definition at line 83 of file mlx_mouse.c.

84{
86
87 glfwSetCursorPos(mlx->window, (double)x, (double)y);
88}