mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
added show and hide cursor support, fixing technological debt from original mlx, fixed missaligned comments in mlx.h
This commit is contained in:
@@ -97,6 +97,9 @@ And you can enjoy your project
|
|||||||
### 📦 Compile mode
|
### 📦 Compile mode
|
||||||
By default the mlx is built in release mode but you can switch to debug by using `make DEBUG=true`.
|
By default the mlx is built in release mode but you can switch to debug by using `make DEBUG=true`.
|
||||||
|
|
||||||
|
### 🦺 Safety
|
||||||
|
MacroLibX has a strong safety support, mainly by checking every pointer that you pass to it. But this safety has a cost that can be avoided by enabling `DISABLE_ALL_SAFETIES=true` before compiling but don't be afraid to recieve segmentation faults from the mlx.
|
||||||
|
|
||||||
### 🛠️ Set the toolchain
|
### 🛠️ Set the toolchain
|
||||||
If you want to use `GCC` to build the mlx you can use `make TOOLCHAIN=gcc`
|
If you want to use `GCC` to build the mlx you can use `make TOOLCHAIN=gcc`
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ Just as the Makfile build system, you can configure how xmake should build the M
|
|||||||
### 📦 Compile mode
|
### 📦 Compile mode
|
||||||
You can configure xmake to build the mlx in debug mode or in release mode (release mode is enabled by default). To do so you can use `xmake config --mode=debug` or `xmake config --mode=release`.
|
You can configure xmake to build the mlx in debug mode or in release mode (release mode is enabled by default). To do so you can use `xmake config --mode=debug` or `xmake config --mode=release`.
|
||||||
|
|
||||||
|
### 🦺 Safety
|
||||||
|
MacroLibX has a strong safety support, mainly by checking every pointer that you pass to it. But this safety has a cost that can be avoided by enabling `xmake config --disable_all_safeties=y` before compiling but don't be afraid to recieve segmentation faults from the mlx.
|
||||||
|
|
||||||
### 🛠️ Set the toolchain
|
### 🛠️ Set the toolchain
|
||||||
To change the compilation toolchain you can use `xmake config --toolchain=[gcc|clang|...]`
|
To change the compilation toolchain you can use `xmake config --toolchain=[gcc|clang|...]`
|
||||||
|
|
||||||
|
|||||||
322
includes/mlx.h
322
includes/mlx.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <contact@kbz8.me> +#+ +:+ +#+ */
|
/* By: maldavid <contact@kbz8.me> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/10/22 11:56:44 by maldavid ### ########.fr */
|
/* Updated: 2024/10/31 15:15:24 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -34,281 +34,281 @@ typedef enum
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the MLX internal application
|
* @brief Initializes the MLX internal application
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal MLX application or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal MLX application or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_init();
|
MLX_API void* mlx_init();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new window
|
* @brief Creates a new window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param w Width of the window
|
* @param w Width of the window
|
||||||
* @param h Height of the window
|
* @param h Height of the window
|
||||||
* @param title Title of the window
|
* @param title Title of the window
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal MLX window or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal MLX window or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new window
|
* @brief Creates a new window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window to move
|
* @param win Internal window to move
|
||||||
* @param x New x position
|
* @param x New x position
|
||||||
* @param y New y position
|
* @param y New y position
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MLX_API void mlx_set_window_position(void *mlx, void *win, int x, int y);
|
MLX_API void mlx_set_window_position(void *mlx, void *win, int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gives a function to be executed at each loop turn
|
* @brief Gives a function to be executed at each loop turn
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param f The function
|
* @param f The function
|
||||||
* @param param Param to give to the function passed
|
* @param param Param to give to the function passed
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
MLX_API void mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Starts the internal main loop
|
* @brief Starts the internal main loop
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_loop(void* mlx);
|
MLX_API void mlx_loop(void* mlx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Ends the internal main loop
|
* @brief Ends the internal main loop
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_loop_end(void* mlx);
|
MLX_API void mlx_loop_end(void* mlx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Shows mouse cursor
|
* @brief Shows mouse cursor
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_mouse_show();
|
MLX_API void mlx_mouse_show();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Hides mouse cursor
|
* @brief Hides mouse cursor
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_mouse_hide();
|
MLX_API void mlx_mouse_hide();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Moves cursor to givent position
|
* @brief Moves cursor to givent position
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window from which cursor moves
|
* @param win Internal window from which cursor moves
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_mouse_move(void* mlx, void* win, int x, int y);
|
MLX_API void mlx_mouse_move(void* mlx, void* win, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get cursor's position
|
* @brief Get cursor's position
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param x Get x coordinate
|
* @param x Get x coordinate
|
||||||
* @param y Get y coordinate
|
* @param y Get y coordinate
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_mouse_get_pos(void* mlx, int* x, int* y);
|
MLX_API void mlx_mouse_get_pos(void* mlx, int* x, int* y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gives a function to be executed on event type
|
* @brief Gives a function to be executed on event type
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param event Event type (see union on top of this file)
|
* @param event Event type (see union on top of this file)
|
||||||
* @param f Function to be executed
|
* @param f Function to be executed
|
||||||
* @param param Parameter given to the function
|
* @param param Parameter given to the function
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*f)(int, void*), void* param);
|
MLX_API void mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*f)(int, void*), void* param);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Put a pixel in the window
|
* @brief Put a pixel in the window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
||||||
*
|
*
|
||||||
* Note : If your're reading pixel colors from an image, don't forget to shift them
|
* Note : If your're reading pixel colors from an image, don't forget to shift them
|
||||||
* one byte to the right as image pixels are encoded as 0xRRGGBBAA and pixel put takes 0xAARRGGBB.
|
* one byte to the right as image pixels are encoded as 0xRRGGBBAA and pixel put takes 0xAARRGGBB.
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
|
MLX_API void mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new empty image
|
* @brief Create a new empty image
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param width Width of the image
|
* @param width Width of the image
|
||||||
* @param height Height of the image
|
* @param height Height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_new_image(void* mlx, int width, int height);
|
MLX_API void* mlx_new_image(void* mlx, int width, int height);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get image pixel data
|
* @brief Get image pixel data
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param img Internal image
|
* @param img Internal image
|
||||||
* @param x X coordinate in the image
|
* @param x X coordinate in the image
|
||||||
* @param y Y coordinate in the image
|
* @param y Y coordinate in the image
|
||||||
*
|
*
|
||||||
* @return (int) Return the pixel data
|
* @return (int) Return the pixel data
|
||||||
*
|
*
|
||||||
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
||||||
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
||||||
* ```
|
* ```
|
||||||
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
||||||
* ~ cd MacroLibX
|
* ~ cd MacroLibX
|
||||||
* ~ make IMAGES_OPTIMIZED=false
|
* ~ make IMAGES_OPTIMIZED=false
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
|
MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set image pixel data
|
* @brief Set image pixel data
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param img Internal image
|
* @param img Internal image
|
||||||
* @param x X coordinate in the image
|
* @param x X coordinate in the image
|
||||||
* @param y Y coordinate in the image
|
* @param y Y coordinate in the image
|
||||||
* @param color Color of the pixel to set
|
* @param color Color of the pixel to set
|
||||||
*
|
*
|
||||||
* @return (void)
|
* @return (void)
|
||||||
*
|
*
|
||||||
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
||||||
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
||||||
* ```
|
* ```
|
||||||
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
||||||
* ~ cd MacroLibX
|
* ~ cd MacroLibX
|
||||||
* ~ make IMAGES_OPTIMIZED=false
|
* ~ make IMAGES_OPTIMIZED=false
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Put image to the given window
|
* @brief Put image to the given window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param img Internal image
|
* @param img Internal image
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);
|
MLX_API void mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys internal image
|
* @brief Destroys internal image
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param img Internal image
|
* @param img Internal image
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_destroy_image(void* mlx, void* img);
|
MLX_API void mlx_destroy_image(void* mlx, void* img);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new image from a png file
|
* @brief Create a new image from a png file
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param filename Path to the png file
|
* @param filename Path to the png file
|
||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new image from a jpg file
|
* @brief Create a new image from a jpg file
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param filename Path to the jpg file
|
* @param filename Path to the jpg file
|
||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
MLX_API void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new image from a bmp file
|
* @brief Create a new image from a bmp file
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param filename Path to the bmp file
|
* @param filename Path to the bmp file
|
||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
MLX_API void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height);
|
MLX_API void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Put text in given window
|
* @brief Put text in given window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
||||||
* @param str Text to put
|
* @param str Text to put
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str);
|
MLX_API void mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads a font to be used by `mlx_string_put`
|
* @brief Loads a font to be used by `mlx_string_put`
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
||||||
*
|
*
|
||||||
* @return (void)
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
@@ -316,12 +316,12 @@ MLX_API void mlx_set_font(void* mlx, char* filepath);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads a font to be used by `mlx_string_put` and scales it
|
* @brief Loads a font to be used by `mlx_string_put` and scales it
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
||||||
* @param scale Scale to apply to the font
|
* @param scale Scale to apply to the font
|
||||||
*
|
*
|
||||||
* @return (void)
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
@@ -329,58 +329,58 @@ MLX_API void mlx_set_font_scale(void* mlx, char* filepath, float scale);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clears the given window (resets all rendered data)
|
* @brief Clears the given window (resets all rendered data)
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_clear_window(void* mlx, void* win);
|
MLX_API void mlx_clear_window(void* mlx, void* win);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys internal window
|
* @brief Destroys internal window
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_destroy_window(void* mlx, void* win);
|
MLX_API void mlx_destroy_window(void* mlx, void* win);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy internal MLX application
|
* @brief Destroy internal MLX application
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_destroy_display(void* mlx);
|
MLX_API void mlx_destroy_display(void* mlx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the size of the screen the given window is on
|
* @brief Get the size of the screen the given window is on
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param w Get width size
|
* @param w Get width size
|
||||||
* @param h Get height size
|
* @param h Get height size
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_get_screens_size(void* mlx, void* win, int* w, int* h);
|
MLX_API void mlx_get_screens_size(void* mlx, void* win, int* w, int* h);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Caps the FPS
|
* @brief Caps the FPS
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param fps The FPS cap
|
* @param fps The FPS cap
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0
|
* @return (void)
|
||||||
*/
|
*/
|
||||||
MLX_API int mlx_set_fps_goal(void* mlx, int fps);
|
MLX_API void mlx_set_fps_goal(void* mlx, int fps);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace mlx
|
|||||||
CHECK_WINDOW_PTR(win);
|
CHECK_WINDOW_PTR(win);
|
||||||
if(str == nullptr)
|
if(str == nullptr)
|
||||||
{
|
{
|
||||||
Error("wrong text (NULL)");
|
Error("invalid text (NULL)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(std::strlen(str) == 0)
|
if(std::strlen(str) == 0)
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ namespace mlx
|
|||||||
void GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept;
|
void GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept;
|
||||||
void SetWindowPosition(Handle window, int x, int y) const noexcept;
|
void SetWindowPosition(Handle window, int x, int y) const noexcept;
|
||||||
|
|
||||||
|
static void HideCursor() noexcept;
|
||||||
|
static void ShowCursor() noexcept;
|
||||||
|
|
||||||
std::int32_t GetX() const noexcept;
|
std::int32_t GetX() const noexcept;
|
||||||
std::int32_t GetY() const noexcept;
|
std::int32_t GetY() const noexcept;
|
||||||
std::int32_t GetXRel() const noexcept;
|
std::int32_t GetXRel() const noexcept;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <PreCompiled.h>
|
#include <PreCompiled.h>
|
||||||
|
|
||||||
#include <Core/Application.h>
|
#include <Core/Application.h>
|
||||||
|
#include <Core/SDLManager.h>
|
||||||
#include <Renderer/RenderCore.h>
|
#include <Renderer/RenderCore.h>
|
||||||
#include <mlx.h>
|
#include <mlx.h>
|
||||||
#include <Core/Memory.h>
|
#include <Core/Memory.h>
|
||||||
@@ -54,52 +55,46 @@ extern "C"
|
|||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->LoopHook(f, param);
|
static_cast<mlx::Application*>(mlx)->LoopHook(f, param);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_loop(void* mlx)
|
void mlx_loop(void* mlx)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->Run();
|
static_cast<mlx::Application*>(mlx)->Run();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_loop_end(void* mlx)
|
void mlx_loop_end(void* mlx)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->LoopEnd();
|
static_cast<mlx::Application*>(mlx)->LoopEnd();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_mouse_show()
|
void mlx_mouse_show()
|
||||||
{
|
{
|
||||||
return 0;
|
mlx::SDLManager::ShowCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_mouse_hide()
|
void mlx_mouse_hide()
|
||||||
{
|
{
|
||||||
return 0;
|
mlx::SDLManager::HideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_mouse_move(void* mlx, void* win, int x, int y)
|
void mlx_mouse_move(void* mlx, void* win, int x, int y)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->MouseMove(win, x, y);
|
static_cast<mlx::Application*>(mlx)->MouseMove(win, x, y);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_mouse_get_pos(void* mlx, int* x, int* y)
|
void mlx_mouse_get_pos(void* mlx, int* x, int* y)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->GetMousePos(x, y);
|
static_cast<mlx::Application*>(mlx)->GetMousePos(x, y);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*funct_ptr)(int, void*), void* param)
|
void mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*funct_ptr)(int, void*), void* param)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->OnEvent(win, static_cast<int>(event), funct_ptr, param);
|
static_cast<mlx::Application*>(mlx)->OnEvent(win, static_cast<int>(event), funct_ptr, param);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* mlx_new_image(void* mlx, int width, int height)
|
void* mlx_new_image(void* mlx, int width, int height)
|
||||||
@@ -136,18 +131,16 @@ extern "C"
|
|||||||
static_cast<mlx::Application*>(mlx)->SetTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
static_cast<mlx::Application*>(mlx)->SetTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
|
void mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y);
|
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_destroy_image(void* mlx, void* img)
|
void mlx_destroy_image(void* mlx, void* img)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->DestroyTexture(img);
|
static_cast<mlx::Application*>(mlx)->DestroyTexture(img);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
|
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
|
||||||
@@ -201,7 +194,7 @@ extern "C"
|
|||||||
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
|
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
|
void mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
unsigned char color_bits[4];
|
unsigned char color_bits[4];
|
||||||
@@ -210,10 +203,9 @@ extern "C"
|
|||||||
color_bits[2] = (color & 0x000000FF);
|
color_bits[2] = (color & 0x000000FF);
|
||||||
color_bits[3] = (color & 0xFF000000) >> 24;
|
color_bits[3] = (color & 0xFF000000) >> 24;
|
||||||
static_cast<mlx::Application*>(mlx)->PixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
static_cast<mlx::Application*>(mlx)->PixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
|
void mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
unsigned char color_bits[4];
|
unsigned char color_bits[4];
|
||||||
@@ -222,7 +214,6 @@ extern "C"
|
|||||||
color_bits[2] = (color & 0x000000FF);
|
color_bits[2] = (color & 0x000000FF);
|
||||||
color_bits[3] = (color & 0xFF000000) >> 24;
|
color_bits[3] = (color & 0xFF000000) >> 24;
|
||||||
static_cast<mlx::Application*>(mlx)->StringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
|
static_cast<mlx::Application*>(mlx)->StringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mlx_set_font(void* mlx, char* filepath)
|
void mlx_set_font(void* mlx, char* filepath)
|
||||||
@@ -262,49 +253,39 @@ extern "C"
|
|||||||
static_cast<mlx::Application*>(mlx)->LoadFont(file, scale);
|
static_cast<mlx::Application*>(mlx)->LoadFont(file, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_clear_window(void* mlx, void* win)
|
void mlx_clear_window(void* mlx, void* win)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->ClearGraphicsSupport(win);
|
static_cast<mlx::Application*>(mlx)->ClearGraphicsSupport(win);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_destroy_window(void* mlx, void* win)
|
void mlx_destroy_window(void* mlx, void* win)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->DestroyGraphicsSupport(win);
|
static_cast<mlx::Application*>(mlx)->DestroyGraphicsSupport(win);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_destroy_display(void* mlx)
|
void mlx_destroy_display(void* mlx)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
delete static_cast<mlx::Application*>(mlx);
|
delete static_cast<mlx::Application*>(mlx);
|
||||||
__mlx_ptr = nullptr;
|
__mlx_ptr = nullptr;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_get_screens_size(void* mlx, void* win, int* w, int* h)
|
void mlx_get_screens_size(void* mlx, void* win, int* w, int* h)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
static_cast<mlx::Application*>(mlx)->GetScreenSize(win, w, h);
|
static_cast<mlx::Application*>(mlx)->GetScreenSize(win, w, h);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_set_fps_goal(void* mlx, int fps)
|
void mlx_set_fps_goal(void* mlx, int fps)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
if(fps < 0)
|
if(fps < 0)
|
||||||
{
|
|
||||||
mlx::Error("You cannot set a negative FPS cap (nice try)");
|
mlx::Error("You cannot set a negative FPS cap (nice try)");
|
||||||
return 0;
|
else if(fps == 0)
|
||||||
}
|
|
||||||
if(fps == 0)
|
|
||||||
{
|
|
||||||
mlx::Error("You cannot set a FPS cap to 0 (nice try)");
|
mlx::Error("You cannot set a FPS cap to 0 (nice try)");
|
||||||
return 0;
|
else
|
||||||
}
|
static_cast<mlx::Application*>(mlx)->SetFPSCap(static_cast<std::uint32_t>(fps));
|
||||||
static_cast<mlx::Application*>(mlx)->SetFPSCap(static_cast<std::uint32_t>(fps));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,16 @@ namespace mlx
|
|||||||
SDL_SetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
SDL_SetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLManager::HideCursor() noexcept
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDLManager::ShowCursor() noexcept
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
std::int32_t SDLManager::GetX() const noexcept
|
std::int32_t SDLManager::GetX() const noexcept
|
||||||
{
|
{
|
||||||
int dummy;
|
int dummy;
|
||||||
|
|||||||
Reference in New Issue
Block a user