From f6736f210a679df6047a2ca5d4f551208fb957f7 Mon Sep 17 00:00:00 2001 From: kbz_8 Date: Wed, 19 Apr 2023 12:36:59 +0200 Subject: [PATCH] adding documentation to mlx.h --- includes/mlx.h | 226 ++++++++++++++++++++++++++++++++++++++- src/core/application.h | 5 +- src/core/application.inl | 10 -- src/core/bridge.cpp | 14 +-- src/platform/inputs.cpp | 5 +- src/platform/inputs.h | 6 +- test/main.c | 4 +- 7 files changed, 229 insertions(+), 41 deletions(-) diff --git a/includes/mlx.h b/includes/mlx.h index e896ee0..fb1aa91 100644 --- a/includes/mlx.h +++ b/includes/mlx.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */ -/* Updated: 2023/04/19 11:35:30 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 12:35:03 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,41 +26,261 @@ typedef enum MLX_WINDOW_EVENT = 4 } mlx_event_type; +/** + * @brief Initializes the MLX internal application + * + * @return (void*) An opaque pointer to the internal MLX application or NULL (0x0) in case of error + */ void* mlx_init(); + +/** + * @brief Creates a new window + * + * @param mlx Internal MLX application + * @param w Width of the window + * @param h Height 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 + */ void* mlx_new_window(void* mlx, int w, int h, const char* title); +/** + * @brief Gives a function to be executed at each loop turn + * + * @param mlx Internal MLX application + * @param f The function + * @param param Param to give to the function passed + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ + int mlx_loop_hook(void* mlx, int (*f)(), void* param); + +/** + * @brief Starts the internal main loop + * + * @param mlx Internal MLX application + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_loop(void* mlx); + +/** + * @brief Ends the internal main loop + * + * @param mlx Internal MLX application + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_loop_end(void* mlx); +/** + * @brief Shows mouse cursor + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_mouse_show(); + +/** + * @brief Hides mouse cursor + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_mouse_hide(); + +/** + * @brief Moves cursor to givent position + * + * @param mlx Internal MLX application + * @param win Internal window from which cursor moves + * @param x X coordinate + * @param y Y coordinate + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_mouse_move(void* mlx, void* win, int x, int y); + +/** + * @brief Get cursor's position + * + * @param mlx Internal MLX application + * @param x X coordinate + * @param y Y coordinate + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_mouse_get_pos(void* mlx, int* x, int* y); + +/** + * @brief Gives a function to be executed on event type + * + * @param mlx Internal MLX application + * @param win Internal window + * @param event Event type (see union on top of this file) + * @param f Function to be executed + * @param param Parameter given to the function + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*f)(), void* param); -int mlx_do_key_autorepeaton(void* mlx); -int mlx_do_key_autorepeatoff(void* mlx); +/** + * @brief Put a pixel in the window + * + * @param mlx Internal MLX application + * @param win Internal window + * @param x X coordinate + * @param y Y coordinate + * @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB) + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_pixel_put(void* mlx, void* win, int x, int y, int color); + +/** + * @brief Create a new empty image + * + * @param mlx Internal MLX application + * @param width Width of the image + * @param height Height of the image + * + * @return (void*) An opaque pointer to the internal image + */ void* mlx_new_image(void* mlx, int width, int height); + +/** + * @brief Get data address of the internal image to modify it + * + * @param mlx Internal MLX application + * @param img Internal image + * @param bits_per_pixel Get bits per pixel information + * @param size_line Get size of a line of the image + * @param endian Get endian of the processor + * + * @return (char*) Return raw address of the image's data + */ char* mlx_get_data_addr(void* mlx, void* img, int* bits_per_pixel, int* size_line, int* endian); + +/** + * @brief Put image to the given window + * + * @param mlx Internal MLX application + * @param win Internal window + * @param img Internal image + * @param x X coordinate + * @param y Y coordinate + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y); + +/** + * @brief Destroys internal image + * + * @param mlx Internal MLX application + * @param img Internal image + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_destroy_image(void* mlx, void* img); + +/** + * @brief Create a new image from a png file + * + * @param mlx Internal MLX application + * @param filename Path to the png file + * @param width Get the width of the image + * @param heigth Get the height of the image + * + * @return (void*) An opaque pointer to the internal image + */ void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height); + +/** + * @brief Create a new image from a jpg file + * + * @param mlx Internal MLX application + * @param filename Path to the jpg file + * @param width Get the width of the image + * @param heigth Get the height of the image + * + * @return (void*) An opaque pointer to the internal image + */ void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height); + +/** + * @brief Create a new image from a bmp file + * + * @param mlx Internal MLX application + * @param filename Path to the bmp file + * @param width Get the width of the image + * @param heigth Get the height of the image + * + * @return (void*) An opaque pointer to the internal image + */ void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height); + +/** + * @brief Put text in given window + * + * @param mlx Internal MLX application + * @param win Internal window + * @param x X coordinate + * @param y Y coordinate + * @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB) + * @param str Text to put + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str); + +/** + * @brief Clears the given window (resets all rendered data) + * + * @param mlx Internal MLX application + * @param win Internal window + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_clear_window(void* mlx, void* win); + +/** + * @brief Destroys internal window + * + * @param mlx Internal MLX application + * @param win Internal window + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_destroy_window(void* mlx, void* win); + +/** + * @brief Destroy internal MLX application + * + * @param mlx Internal MLX application + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_destroy_display(void* mlx); + +/** + * @brief Get screen size + * + * @param mlx Internal MLX application + * @param x Get X size + * @param y Get Y size + * + * @return (int) Always return 0, made this to copy the behaviour of the original MLX + */ int mlx_get_screens_size(void* mlx, int* w, int* h); #ifdef __cplusplus diff --git a/src/core/application.h b/src/core/application.h index e49b51d..ca334bc 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */ -/* Updated: 2023/04/19 11:31:51 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 12:14:07 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,9 +39,6 @@ namespace mlx::core inline void onEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept; - inline void enableAutoRepeat() noexcept; - inline void disableAutoRepeat() noexcept; - inline void getScreenSize(int* w, int* h) noexcept; inline void* newGraphicsSuport(std::size_t w, std::size_t h, std::string title); diff --git a/src/core/application.inl b/src/core/application.inl index c343e7c..b4d74f5 100644 --- a/src/core/application.inl +++ b/src/core/application.inl @@ -32,16 +32,6 @@ namespace mlx::core _in->onEvent(_graphics[*static_cast(win)]->getWindow()->getID(), event, funct_ptr, param); } - void Application::enableAutoRepeat() noexcept - { - _in->enableAutoRepeat(); - } - - void Application::disableAutoRepeat() noexcept - { - _in->disableAutoRepeat(); - } - void Application::getScreenSize(int* w, int* h) noexcept { SDL_DisplayMode DM; diff --git a/src/core/bridge.cpp b/src/core/bridge.cpp index a41511b..32a19b0 100644 --- a/src/core/bridge.cpp +++ b/src/core/bridge.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ -/* Updated: 2023/04/19 11:49:40 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 12:14:02 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,18 +75,6 @@ extern "C" return 0; } - int mlx_do_key_autorepeaton(void* mlx) - { - static_cast(mlx)->enableAutoRepeat(); - return 0; - } - - int mlx_do_key_autorepeatoff(void* mlx) - { - static_cast(mlx)->disableAutoRepeat(); - return 0; - } - void* mlx_new_image(void* mlx, int width, int height) { return static_cast(mlx)->newTexture(width, height); diff --git a/src/platform/inputs.cpp b/src/platform/inputs.cpp index bfb27f6..27e81a2 100644 --- a/src/platform/inputs.cpp +++ b/src/platform/inputs.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */ -/* Updated: 2023/04/12 19:54:20 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 12:14:38 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,9 +26,6 @@ namespace mlx _xRel = 0; _yRel = 0; - if(!_auto_repeat) - std::memset(_keys.data(), 0, SDL_NUM_SCANCODES); - while(SDL_PollEvent(&_event)) { if(_event.type == SDL_MOUSEMOTION) diff --git a/src/platform/inputs.h b/src/platform/inputs.h index af3296b..60c98d1 100644 --- a/src/platform/inputs.h +++ b/src/platform/inputs.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */ -/* Updated: 2023/04/13 10:55:46 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 12:14:43 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,9 +51,6 @@ namespace mlx inline bool is_running() const noexcept { return !_end; } inline constexpr void finish() noexcept { _end = true; } - inline constexpr void enableAutoRepeat() noexcept { _auto_repeat = true; } - inline constexpr void disableAutoRepeat() noexcept { _auto_repeat = false; } - inline void addWindow(std::shared_ptr window) { _windows[window->getID()] = window; @@ -81,6 +78,5 @@ namespace mlx int _yRel = 0; bool _end = false; - bool _auto_repeat = true; }; } diff --git a/test/main.c b/test/main.c index 1684887..500ff16 100644 --- a/test/main.c +++ b/test/main.c @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ -/* Updated: 2023/04/19 11:49:56 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:54:51 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,9 +85,9 @@ int window_hook(int event, t_mlx *param) int main(void) { t_mlx mlx; + void *img; int w; int h; - void *img; mlx.mlx = mlx_init(); mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window");