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

Go to the source code of this file.

Functions

void mlx_update_matrix (const mlx_t *mlx)
 
static void mlx_resize_callback (GLFWwindow *window, int32_t width, int32_t height)
 
static void mlx_close_callback (GLFWwindow *window)
 
void mlx_close_hook (mlx_t *mlx, mlx_closefunc func, void *param)
 
void mlx_resize_hook (mlx_t *mlx, mlx_resizefunc func, void *param)
 
void mlx_set_icon (mlx_t *mlx, mlx_texture_t *image)
 
void mlx_set_window_pos (mlx_t *mlx, int32_t xpos, int32_t ypos)
 
void mlx_get_window_pos (mlx_t *mlx, int32_t *xpos, int32_t *ypos)
 
void mlx_set_window_size (mlx_t *mlx, int32_t new_width, int32_t new_height)
 
void mlx_set_window_limit (mlx_t *mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h)
 
void mlx_set_window_title (mlx_t *mlx, const char *title)
 

Function Documentation

◆ mlx_close_callback()

static void mlx_close_callback ( GLFWwindow window)
static

Definition at line 53 of file mlx_window.c.

54{
55 const mlx_t* mlx = glfwGetWindowUserPointer(window);
56 const mlx_close_t close_hook = ((mlx_ctx_t*)mlx->context)->close_hook;
57
58 close_hook.func(close_hook.param);
59}
GLuint GLsizei GLsizei * length
Definition glad.h:3372
mlx_closefunc func
Definition MLX42_Int.h:135
void * param
Definition MLX42_Int.h:134
Definition MLX42.h:361
void * context
Definition MLX42.h:363
Here is the caller graph for this function:

◆ mlx_close_hook()

void mlx_close_hook ( mlx_t mlx,
mlx_closefunc  func,
void param 
)

This function sets the close callback, which is called in attempt to close the window device such as a close window widget used in the window bar.

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

Definition at line 63 of file mlx_window.c.

64{
67
69 mlxctx->close_hook.func = func;
70 mlxctx->close_hook.param = param;
72}
#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_close_callback(GLFWwindow *window)
Definition mlx_window.c:53
void * window
Definition MLX42.h:362
Here is the call graph for this function:

◆ mlx_get_window_pos()

void mlx_get_window_pos ( mlx_t mlx,
int32_t xpos,
int32_t ypos 
)

Gets the window's position.

Parameters
[in]mlxThe MLX instance handle.
[out]xposThe x position.
[out]yposThe y position.

Definition at line 106 of file mlx_window.c.

107{
111
113}

◆ mlx_resize_callback()

static void mlx_resize_callback ( GLFWwindow window,
int32_t  width,
int32_t  height 
)
static

Definition at line 44 of file mlx_window.c.

45{
46 const mlx_t* mlx = glfwGetWindowUserPointer(window);
47 const mlx_ctx_t* mlxctx = mlx->context;
48
49 if (mlxctx->resize_hook.func)
50 mlxctx->resize_hook.func(width, height, mlxctx->resize_hook.param);
51}
GLint GLsizei GLsizei height
Definition glad.h:1965
GLint GLsizei width
Definition glad.h:1965
Here is the caller graph for this function:

◆ mlx_resize_hook()

void mlx_resize_hook ( mlx_t mlx,
mlx_resizefunc  func,
void param 
)

This function sets the resize callback, which is called when the window is resized

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

Definition at line 74 of file mlx_window.c.

75{
78
80 mlxctx->resize_hook.func = func;
81 mlxctx->resize_hook.param = param;
83}
static void mlx_resize_callback(GLFWwindow *window, int32_t width, int32_t height)
Definition mlx_window.c:44
Here is the call graph for this function:

◆ mlx_set_icon()

void mlx_set_icon ( mlx_t mlx,
mlx_texture_t image 
)

Lets you set a custom image as the program icon.

NOTE: In MacOS this function does nothing, you should use the bundles icon to set the dock bar icon.

See also
: https://9to5mac.com/2021/11/08/change-mac-icons/
: https://github.com/glfw/glfw/issues/2041
Parameters
[in]mlxThe MLX instance handle.
[in]imageThe image to use as icon.

Definition at line 85 of file mlx_window.c.

86{
89
90 const GLFWimage icon = {
91 .width = image->width,
92 .height = image->height,
93 .pixels = image->pixels
94 };
95
97}
GLenum GLenum GLsizei void * image
Definition glad.h:5132

◆ mlx_set_window_limit()

void mlx_set_window_limit ( mlx_t mlx,
int32_t  min_w,
int32_t  min_h,
int32_t  max_w,
int32_t  max_h 
)

Sets the size limits of the specified window. Will force the window to not be resizable past or below the given values.

Pass -1 for no limit to any of the min/max parameters to ignore that boundary. For instance if you want a min window size but the max window size can be whatever.

Parameters
[in]mlxThe MLX instance handle.
[in]min_wThe min width of the window.
[in]max_wThe max width of the window.
[in]min_hThe min height of the window.
[in]max_hThe max height of the window.

Definition at line 124 of file mlx_window.c.

◆ mlx_set_window_pos()

void mlx_set_window_pos ( mlx_t mlx,
int32_t  xpos,
int32_t  ypos 
)

Sets the window's position.

Do not use this function to move an already visible window unless you have very good reasons for doing so, as it will confuse and annoy the user.

Parameters
[in]mlxThe MLX instance handle.
[in]xposThe x position.
[in]yposThe y position.

Definition at line 99 of file mlx_window.c.

100{
102
104}

◆ mlx_set_window_size()

void mlx_set_window_size ( mlx_t mlx,
int32_t  new_width,
int32_t  new_height 
)

Changes the window size to the newly specified values. Use this to update the window width and height values in the mlx handle.

Parameters
[in]mlxThe MLX instance handle.
[in]new_widthThe new desired width.
[in]new_heightThe new desired height.

Definition at line 115 of file mlx_window.c.

116{
118
122}
int32_t width
Definition MLX42.h:364
int32_t height
Definition MLX42.h:365

◆ mlx_set_window_title()

void mlx_set_window_title ( mlx_t mlx,
const char title 
)

Sets the title of the window.

Parameters
[in]mlxThe MLX instance handle.
[in]titleThe window title.

Definition at line 131 of file mlx_window.c.

132{
135
137}

◆ mlx_update_matrix()

void mlx_update_matrix ( const mlx_t mlx)

Recalculate the view projection matrix, used by images for screen pos Reference: https://bit.ly/3KuHOu1 (Matrix View Projection)

In case the setting to stretch the image is set, we maintain the width and height but not the depth.

Definition at line 21 of file mlx_window.c.

22{
23 const mlx_ctx_t* mlxctx = mlx->context;
24 const float depth = mlxctx->zdepth;
25
26 /**
27 * In case the setting to stretch the image is set, we maintain the width and height but not
28 * the depth.
29 */
30 const float width = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialWidth : mlx->width;
31 const float height = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialHeight : mlx->height;
32
33 const float matrix[16] = {
34 2.f / width, 0, 0, 0,
35 0, 2.f / -(height), 0, 0,
36 0, 0, -2.f / (depth - -depth), 0,
37 -1, -(height / -height),
38 -((depth + -depth) / (depth - -depth)), 1
39 };
40
41 glUniformMatrix4fv(glGetUniformLocation(mlxctx->shaderprogram, "ProjMatrix"), 1, GL_FALSE, matrix);
42}
mlx_settings
Definition MLX42.h:398
@ MLX_STRETCH_IMAGE
Definition MLX42.h:399
#define glGetUniformLocation
Definition glad.h:3401
#define glUniformMatrix4fv
Definition glad.h:3491
GLint GLint GLsizei GLsizei GLsizei depth
Definition glad.h:2966
#define GL_FALSE
Definition glad.h:139
Here is the caller graph for this function: