cub3d/src/menu/menu.c
2025-05-27 16:32:27 +02:00

69 lines
2.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 14:31:53 by qmennen #+# #+# */
/* Updated: 2025/05/27 15:09:11 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
# include "game_menu.h"
void menu_create(t_game_manager **manager)
{
t_menu *menu;
menu = malloc(sizeof(t_menu));
if (!menu)
return;
menu->background = NULL;
ft_memset(menu->options, 0, sizeof(menu->options));
menu->selector = 0;
menu->selected_option = 0;
(*manager)->menu = menu;
}
void menu_display(t_menu *menu, t_screen *screen)
{
const char *options[NUM_MENU_OPTIONS] = {
"Start Game",
"Exit"
};
int i;
if (menu->selector == 0)
{
menu->selector = mlx_put_string(screen->mlx, ">", screen->width / 2 - 100, 0);
}
i = 0;
while (i < NUM_MENU_OPTIONS)
{
if (i == menu->selected_option && menu->selector)
{
menu->selector->instances[0].y = (screen->height - 100) / 2 + i * 50;
}
if (menu->options[i] == 0)
{
menu->options[i] = mlx_put_string(screen->mlx, options[i],
(screen->width - ft_strlen(options[i]) * 10) / 2,
(screen->height - 100) / 2 + i * 50);
}
i++;
}
}
void menu_free(t_menu *menu, t_screen *screen)
{
if (!menu)
return;
if (menu->options[0])
mlx_delete_image(screen->mlx, menu->options[0]);
if (menu->options[1])
mlx_delete_image(screen->mlx, menu->options[1]);
if (menu->selector)
mlx_delete_image(screen->mlx, menu->selector);
free(menu);
}