part: add headers for all mlx

This commit is contained in:
Zy 2024-10-04 21:34:29 +02:00
parent d606305241
commit c7d0dba4fd
11 changed files with 574 additions and 0 deletions

3
.gitignore vendored
View file

@ -42,3 +42,6 @@ output/
# Debug files # Debug files
*.dSYM/ *.dSYM/
# VSCode
/.vscode/

1
TODO Normal file
View file

@ -0,0 +1 @@
TODO move mlx .c and .h files in its own directory

45
include/mlx.h Normal file
View file

@ -0,0 +1,45 @@
/**
* mlx.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file and all /include/mlx_*.h files from the root of the
* repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* This header file includes all the mlx_* functions.
* These are all the functions that already exist in the original MinilibX.
*
* Functions that start with '_' aren't yet implemented.
* TODO Implement _*() functions.
*/
#ifndef MLX_H
# define MLX_H
# include "mlx3ds_3dskey.h"
# include "mlx3ds_typealiases.h"
# include "mlx_init.h"
# include "mlx_window.h"
# include "mlx_put.h"
# include "mlx_image.h"
# include "mlx_hook.h"
# include "mlx_unknown.h"
#endif

95
include/mlx3ds_3dskey.h Normal file
View file

@ -0,0 +1,95 @@
/**
* mlx3ds_3dskey.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* Enum of all the keys of the 3ds.
*
* These are the same constants defined in hid.h from devkitPro,
* but with documentation that basically repeat what the name
* of the constants already say.
*/
#ifndef MLX3DS_3DSKEY_H
# define MLX3DS_3DSKEY_H
# define BIT(n) 1U << n
/// @brief Represents a key of the 3DS.
typedef enum e_3dskey
{
/* BUTTONS */
/// @brief A button
KEY_A = BIT(0),
/// @brief B button
KEY_B = BIT(1),
/// @brief X button
KEY_X = BIT(10),
/// @brief Y button
KEY_Y = BIT(11),
/// @brief Select button
KEY_SELECT = BIT(2),
/// @brief Start button
KEY_START = BIT(3),
/// @brief R button
KEY_R = BIT(8),
/// @brief L button
KEY_L = BIT(9),
/* DIRECTIONS */
/// @brief D-Pad Right
KEY_DRIGHT = BIT(4),
/// @brief D-Pad Left
KEY_DLEFT = BIT(5),
/// @brief D-Pad Up
KEY_DUP = BIT(6),
/// @brief D-Pad Down
KEY_DDOWN = BIT(7),
/// @brief C-Pad Right
KEY_CPAD_RIGHT= BIT(28),
/// @brief C-Pad Left
KEY_CPAD_LEFT = BIT(29),
/// @brief C-Pad Up
KEY_CPAD_UP = BIT(30),
/// @brief C-Pad Down
KEY_CPAD_DOWN = BIT(31),
/* TOUCH */
// ??? unsure what KEY_TOUCH is... TODO
KEY_TOUCH = BIT(20),
/* New 3DS */
/// @brief C-Stick Right (only for New 3DS)
KEY_CSTICK_RIGHT = BIT(24),
/// @brief C-Stick Left (only for New 3DS)
KEY_CSTICK_LEFT = BIT(25),
/// @brief C-Stick Up (only for New 3DS)
KEY_CSTICK_UP = BIT(26),
/// @brief C-Stick Down (only for New 3DS)
KEY_CSTICK_DOWN = BIT(27),
/// @brief ZL button (only for New 3DS)
KEY_ZL = BIT(14),
/// @brief ZR button (only for New 3DS)
KEY_ZR = BIT(15),
// TODO implement catch-all directions?
/*
// ???
KEY_UP = KEY_DUP | KEY_CPAD_UP, ///< D-Pad Up or Circle Pad Up
// ???
KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN, ///< D-Pad Down or Circle Pad Down
// ???
KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT, ///< D-Pad Left or Circle Pad Left
// ???
KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT, ///< D-Pad Right or Circle PadRight
*/
} t_3dskey;
#endif

View file

@ -0,0 +1,24 @@
/**
* mlx3ds_typealiases.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* Define different type aliases for the different void* values used with
* the mlx_ functions.
*/
#ifndef MLX3DS_TYPEALIASES_H
# define MLX3DS_TYPEALIASES_H
/// @brief An mlx connection identifier returned by mlx_init().
typedef void *t_mlx;
/// @brief Reference to a window.
typedef void *t_win;
/// @brief Reference to an image in memory.
typedef void *t_image;
#endif

93
include/mlx_hook.h Normal file
View file

@ -0,0 +1,93 @@
/**
* mlx_hook.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* Functions to manage window events.
*/
#ifndef MLX_HOOK_H
# define MLX_HOOK_H
# include "mlx3ds_typealiases.h"
# include "mlx3ds_3dskey.h"
/// @brief Doesn't do anything, the 3DS doesn't have a mouse.
///
/// @param win_ptr Unused.
/// @param funct_ptr Unused
/// @param param Unused.
/// @return Unused.
int _mlx_mouse_hook(t_win win_ptr, int (*funct_ptr)(), void *param);
/// @brief Assign a function to a key event. When a key is pressed, the function
/// will be called.
///
/// @param win_ptr Window to affect.
/// @param funct_ptr Function to call when the event occurs. `keycode` is the
/// key pressed (note that they are obviously different than
/// the keyboard ones, see 'mlx3ds_3ds_key.h')).
/// (TODO what was the name of the key constants use with mlx?)
/// `param` is set as the address given to mlx_key_hook().
/// The return value is unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int _mlx_key_hook(t_win win_ptr,
int (*funct_ptr)(t_3dskey keycode, void *param), void *param);
/// @brief Assign a function which will be called when the window should be
/// redrawn.
/// TODO is mlx_expose_hook() needed for the 3DS?
///
/// @param win_ptr Window to affect.
/// @param funct_ptr Function to call when the event occurs. `param` is set as
/// the address given to mlx_key_hook(). The return value is
/// unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int _mlx_expose_hook(t_win win_ptr,
int (*funct_ptr)(void *param), void *param);
/// @brief Assign a function which will be called in loop non-stop.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param funct_ptr Function to call when the event occurs. `param` is set as
/// the address given to mlx_key_hook(). The return value is
/// unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int _mlx_loop_hook(t_mlx mlx_ptr,
int (*funct_ptr)(void *param), void *param);
/// @brief Loop indefinitely and wait for events to occurs to call the
/// corresponding functions.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @return This function never returns.
int _mlx_loop(void *mlx_ptr);
// ???
int _mlx_loop_end(void *mlx_ptr);
// god
int _mlx_hook(t_mlx win_ptr, int x_event, int x_mask,
int (*funct)(), void *param);
#endif

84
include/mlx_image.h Normal file
View file

@ -0,0 +1,84 @@
/**
* mlx_image.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* Functions to import, create, modify and display images.
*/
#ifndef MLX_IMAGE_H
# define MLX_IMAGE_H
# include "mlx3ds_typealiases.h"
/// @brief Create an image in memory.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param width Desired width of the image.
/// @param height Desired height of the image.
/// @return A reference to the image. NULL if failed.
t_image _mlx_new_image(void *mlx_ptr, int width, int height);
/// @brief Get an address containing all the pixel values of the image. The user
/// can then modify the image using this pointer directly.
///
/// @param img_ptr Image to use.
/// @param bits_per_pixel Will be filled with the number of bits used for each
/// pixel. Will always be 24.
/// @param size_line Will be filled with the number of bytes used to store
/// a line of the image, aka 3 * width.
/// @param endian Will be filled with the endianness of all color values.
/// 1 for big endian, 0 for little endian. Will always be 1.
/// @return Address to the data of the image.
/// Use `data[y * size_line + x * 3]` to get the first color value (red)
/// of a specific pixel.
char *_mlx_get_data_addr(t_image img_ptr, int *bits_per_pixel,
int *size_line, int *endian);
/// @brief Draw an image on the window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param img_ptr Image to use.
/// @param x x position of the image to draw.
/// @param y y position of the image to draw.
/// @return Unused.
int _mlx_put_image_to_window(t_mlx mlx_ptr, t_win win_ptr, t_image img_ptr,
int x, int y);
// ???
t_image _mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
int *width, int *height);
// ???
t_image _mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
int *width, int *height);
/// @brief Destroy an image.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param img_ptr Image to destroy.
/// @return Unused.
int _mlx_destroy_image(t_mlx mlx_ptr, t_image img_ptr);
#endif

40
include/mlx_init.h Normal file
View file

@ -0,0 +1,40 @@
/**
* mlx_init.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* Function which initialize everything for the mlx3ds.
*/
#ifndef MLX_INIT_H
# define MLX_INIT_H
# include "mlx3ds_typealiases.h"
/// @brief Call this function before anything else.
///
/// @return The mlx connection identifier to use for all other functions.
/// NULL if failed.
t_mlx _mlx_init(void); // TODO should call this before REALLY anything else?
#endif

60
include/mlx_put.h Normal file
View file

@ -0,0 +1,60 @@
/**
* mlx_put.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* Functions to draw specific things on the window.
*
* Note that mlx_put_image_to_window() is in mlx_image.h
*/
#ifndef MLX_PUT_H
# define MLX_PUT_H
# include "mlx3ds_typealiases.h"
/// @brief Draws a pixel on the window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param x x position of the pixel to set.
/// @param y y position of the pixel to set.
/// @param color Color to use in 0x00RRGGBB format.
/// @return Unused.
int _mlx_pixel_put(t_mlx mlx_ptr, t_win win_ptr, int x, int y, int color);
/// @brief Print text on the window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param x x position of the text to draw.
/// @param y y position of the text to draw.
/// @param color Color to use in 0x00RRGGBB format.
/// @return Unused.
int _mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
char *string);
// ???
void _mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
#endif

69
include/mlx_unknown.h Normal file
View file

@ -0,0 +1,69 @@
/**
* mlx_unknown.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* Here lies
* all the functions
* that i
* have no idea
* what they does
* so that
* i can't
* yet
* organize
* but
* i shall
* someday
* allow
* myself
* TODO it (organize the unknown functions)
*/
#ifndef MLX_UNKNOWN_H
# define MLX_UNKNOWN_H
# include "mlx3ds_typealiases.h"
// ???
int _mlx_get_color_value(void *mlx_ptr, int color);
// ???
int _mlx_destroy_display(t_mlx mlx_ptr);
// ???
int _mlx_do_sync(t_mlx mlx_ptr);
// ???
int _mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
// ???
int _mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y);
// ???
int _mlx_mouse_hide(void *mlx_ptr, void *win_ptr);
// ???
int _mlx_mouse_show(void *mlx_ptr, void *win_ptr);
// ???
int _mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
// ???
int _mlx_do_key_autorepeatoff(t_mlx mlx_ptr);
// ???
int _mlx_do_key_autorepeaton(t_mlx mlx_ptr);
#endif

60
include/mlx_window.h Normal file
View file

@ -0,0 +1,60 @@
/**
* mlx_window.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image.
*/
/**
* Functions to manage windows.
*/
#ifndef MLX_WINDOW_H
# define MLX_WINDOW_H
# include "mlx3ds_typealiases.h"
/// @brief Create a window. It isn't really a window but a way to draw on the
/// top screen of the 3DS. Only one window can be opened at a time.
///
/// @param mlx_ptr The mlx connection identifier returned by mlx_init().
/// @param size_x Width of the window.
/// Maximum 400 to be able to adapt to the top screen of the 3DS.
/// @param size_y Height of the window.
/// Maximum 240 to be able to adapt to the top screen of the 3DS.
/// @param title The title of the window. Unused in the 3DS.
/// @return A reference to the window. NULL if failed.
t_win _mlx_new_window(t_mlx mlx_ptr, int size_x, int size_y, char *title);
/// @brief Clear the window in black.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @return Unused.
int _mlx_clear_window(t_mlx mlx_ptr, t_win win_ptr);
/// @brief Destroy a window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to destroy.
/// @return Unused.
int _mlx_destroy_window(t_mlx mlx_ptr, t_win win_ptr);
#endif