2023-01-06 13:37:36 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* asset.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
2023-01-16 12:38:47 -05:00
|
|
|
/* Updated: 2023/01/16 18:27:18 by cchauvet ### ########.fr */
|
2023-01-06 13:37:36 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "solong.h"
|
|
|
|
|
2023-01-13 10:10:11 -05:00
|
|
|
static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
|
|
|
|
{
|
|
|
|
t_square square;
|
|
|
|
char *name;
|
|
|
|
int dimmension;
|
|
|
|
void *img;
|
|
|
|
|
|
|
|
square.color = color;
|
|
|
|
square.size = case_size;
|
|
|
|
name = ft_xpm_gen_file(square);
|
|
|
|
if (name == NULL)
|
|
|
|
return (NULL);
|
|
|
|
img = mlx_xpm_file_to_image(data->mlx,
|
|
|
|
name, &dimmension, &dimmension);
|
|
|
|
free(name);
|
|
|
|
return (img);
|
|
|
|
}
|
|
|
|
|
2023-01-11 13:10:28 -05:00
|
|
|
int ft_gen_assets(t_data *data)
|
2023-01-06 13:37:36 -05:00
|
|
|
{
|
|
|
|
char **colors;
|
2023-01-08 12:03:40 -05:00
|
|
|
size_t i;
|
2023-01-06 13:37:36 -05:00
|
|
|
|
|
|
|
colors = ft_split(COLORS, '|');
|
2023-01-08 12:03:40 -05:00
|
|
|
if (colors == NULL)
|
2023-01-06 13:37:36 -05:00
|
|
|
return (1);
|
2023-01-08 12:03:40 -05:00
|
|
|
i = 0;
|
2023-01-11 13:10:28 -05:00
|
|
|
while (i < NB_COLORS)
|
2023-01-06 13:37:36 -05:00
|
|
|
{
|
2023-01-13 10:10:11 -05:00
|
|
|
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
|
|
|
|
if (data->assets[i] == NULL)
|
|
|
|
return (1);
|
2023-01-08 12:03:40 -05:00
|
|
|
i++;
|
2023-01-06 13:37:36 -05:00
|
|
|
}
|
2023-01-16 12:38:47 -05:00
|
|
|
data->assets[NB_COLORS] = ft_gen_asset(colors[i],
|
|
|
|
WINDOW_SIZE, data);
|
|
|
|
if (data->assets[NB_COLORS] == NULL)
|
|
|
|
return (1);
|
2023-01-08 12:03:40 -05:00
|
|
|
ft_freer_tab_ultimate(1, colors);
|
2023-01-06 13:37:36 -05:00
|
|
|
return (0);
|
|
|
|
}
|