78 lines
2.6 KiB
C
78 lines
2.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* utils.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */
|
|
/* Updated: 2024/10/31 17:15:31 by mc ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef UTILS_H
|
|
# define UTILS_H
|
|
|
|
# include "include.h"
|
|
|
|
typedef uint32_t u_int32_t;
|
|
|
|
typedef struct s_point_double
|
|
{
|
|
double x;
|
|
double y;
|
|
} t_point_double;
|
|
|
|
typedef struct s_point_int
|
|
{
|
|
int x;
|
|
int y;
|
|
} t_point_int;
|
|
|
|
// TODO Must the transparency be 0 or 255?
|
|
/// @brief Represents an TRGB color in 0xTTRRGGBB format.
|
|
typedef __u32 t_color;
|
|
|
|
/// @brief Convert a color from each color value to a t_color.
|
|
///
|
|
/// @param red Level of red from 0 to 255.
|
|
/// @param green Level of green from 0 to 255.
|
|
/// @param blue Level of blue from 0 to 255.
|
|
/// @return The result.
|
|
t_color color_from_rgb(int red, int green, int blue);
|
|
|
|
/// @brief Write an error message on stderr.
|
|
///
|
|
/// @param str... All the strings to write. The last parameter MUST BE NULL.
|
|
void write_err(const char *str, ...);
|
|
|
|
/// @brief Call the function in loop.
|
|
/// If not enough time passed since the last call, returns without doing
|
|
/// anything.
|
|
///
|
|
/// @param f Function to call in loop.
|
|
void timedloop(void (*f)(void));
|
|
|
|
/// @brief Get an address to the image data, but only if
|
|
/// bpp == 32 and endian == 0.
|
|
///
|
|
/// @param img_ptr mlx image to use.
|
|
/// @return Address to the data, or NULL if error.
|
|
u_int32_t *get_data_addr(void *img_ptr);
|
|
|
|
void vector_from_rotation(t_point_double *vec, double angle, double norm);
|
|
|
|
/// @brief Size of buffer used in read_all_text().
|
|
# define READ_ALL_TEXT_BUFFER_SIZE 1000
|
|
|
|
/// @brief Read all the text of the given file.
|
|
///
|
|
/// If the last line isn't ended by a '\\n', add one.
|
|
///
|
|
/// If error, returns NULL and set errno accordingly.
|
|
///
|
|
/// @param fd File descriptor of the file.
|
|
/// @return Alloc'd string of the file content. NULL if error.
|
|
char *read_all_text(int fd);
|
|
|
|
#endif
|