Fin v2 bientot fini

This commit is contained in:
lecointre
2025-12-06 19:44:44 +01:00
parent 9ad4e56bd8
commit 512523b53d
21 changed files with 290 additions and 51 deletions
+50 -5
View File
@@ -1,3 +1,7 @@
/* src/menu_view.c
* Implémentation complète de l'interface de configuration (Menu)
*/
#include "menu_view.h"
#include "defs.h"
#include <graph.h>
@@ -5,30 +9,37 @@
#include <stdlib.h>
#include <string.h>
/* Constantes de positionnement */
#define IMG_PREVIEW_SIZE 150
#define IMG_START_X 50
#define IMG_START_X 250
#define IMG_START_Y 150
#define IMG_SPACING 200
#define BUTTON_SIZE 30
#define DIM_START_Y 350
/* Variables globales de la bibliothèque IUT pour la souris */
extern int _X;
extern int _Y;
/* --- PROTOTYPES DES UTILITAIRES PRIVÉS --- */
static int is_in_rect(int x_click, int y_click, int rx, int ry, int rw, int rh);
static void draw_button(int x, int y, const char *text, couleur C_BG);
static void draw_text_centered(int x, int y, int w, int h, const char *text, int size);
/* --- IMPLÉMENTATION DES FONCTIONS PUBLIQUES (API du Menu) --- */
/* Initialise l'état du menu */
void menu_init(menu_state_t *state)
{
state->selected_image = 0;
state->selected_image = 0; /* Image 1 sélectionnée par défaut */
/* Ces constantes sont maintenant trouvées dans menu_view.h */
state->rows = MIN_DIMENSION;
state->cols = MIN_DIMENSION;
state->ready_to_play = 0;
}
/* Dessine l'écran de configuration du menu */
void menu_render(const menu_state_t *state)
{
int i;
@@ -40,22 +51,35 @@ void menu_render(const menu_state_t *state)
char buffer[50];
char path_buffer[30];
const char *path_fixed = "assets/spiderman.jpg"; /* FIXE LE CHEMIN */
EffacerEcran(C_FOND);
ChoisirCouleurDessin(C_TEXTE);
/* 1. Titre et Section Image */
EcrireTexte(IMG_START_X, 50, "CONFIGURATION DU JEU TAQUIN", 2);
EcrireTexte(IMG_START_X, 100, "1. Choisir l'image :", 1);
/* BOUCLE : Affichage des 3 aperçus */
for (i = 0; i < NUM_IMAGES; i++) {
int x = IMG_START_X + i * IMG_SPACING;
int y = IMG_START_Y;
strcpy(path_buffer, path_fixed);
/* Définition du chemin */
if (i == 0) {
strcpy(path_buffer, "assets/spiderman.jpg");
} else if (i == 1) {
strcpy(path_buffer, "assets/capy.jpg");
} else {
strcpy(path_buffer, "assets/iut.jpg");
}
ChargerImage(path_buffer, x, y, 0, 0, IMG_PREVIEW_SIZE, IMG_PREVIEW_SIZE);
/* Affiche l'image */
ChargerImage(path_buffer,
x, y,
0, 0,
IMG_PREVIEW_SIZE, IMG_PREVIEW_SIZE);
/* Encadrement si sélectionné */
if (state->selected_image == i) {
ChoisirCouleurDessin(C_SELECTION);
DessinerRectangle(x - 5, y - 5, IMG_PREVIEW_SIZE + 10, IMG_PREVIEW_SIZE + 10);
@@ -63,27 +87,33 @@ void menu_render(const menu_state_t *state)
}
ChoisirCouleurDessin(C_TEXTE);
/* 2. Section Dimensions */
int dim_section_x = IMG_START_X;
int button_l_offset = 180;
int button_c_offset = 400;
EcrireTexte(dim_section_x, DIM_START_Y, "2. Choisir les dimensions (3x3 a 8x8) :", 1);
/* Affichage de la taille LIGNES */
EcrireTexte(dim_section_x, DIM_START_Y + 40, "Lignes :", 0);
sprintf(buffer, "%d", state->rows);
EcrireTexte(dim_section_x + 100, DIM_START_Y + 40, buffer, 0);
/* Affichage de la taille COLONNES */
EcrireTexte(dim_section_x + 250, DIM_START_Y + 40, "Colonnes :", 0);
sprintf(buffer, "%d", state->cols);
EcrireTexte(dim_section_x + 350, DIM_START_Y + 40, buffer, 0);
/* Boutons de contrôle LIGNES */
draw_button(dim_section_x + button_l_offset, DIM_START_Y + 30, "+", C_BOUTON);
draw_button(dim_section_x + button_l_offset + 40, DIM_START_Y + 30, "-", C_BOUTON);
/* Boutons de contrôle COLONNES */
draw_button(dim_section_x + button_c_offset, DIM_START_Y + 30, "+", C_BOUTON);
draw_button(dim_section_x + button_c_offset + 40, DIM_START_Y + 30, "-", C_BOUTON);
/* 3. Bouton DÉMARRER LA PARTIE */
ChoisirCouleurDessin(C_START);
RemplirRectangle(300, 500, 200, 50);
ChoisirCouleurDessin(CouleurParNom("white"));
@@ -91,6 +121,7 @@ void menu_render(const menu_state_t *state)
}
/* Gère l'interaction après un clic de souris */
void menu_handle_mouse_click(menu_state_t *state)
{
int i;
@@ -101,6 +132,7 @@ void menu_handle_mouse_click(menu_state_t *state)
int button_l_offset = 180;
int button_c_offset = 400;
/* 1. Clic sur les images */
for (i = 0; i < NUM_IMAGES; i++) {
int x_img = IMG_START_X + i * IMG_SPACING;
int y_img = IMG_START_Y;
@@ -111,28 +143,35 @@ void menu_handle_mouse_click(menu_state_t *state)
}
}
/* 2. Clic sur les boutons de Lignes (+/-) */
/* + Lignes */
if (is_in_rect(x_click, y_click, dim_section_x + button_l_offset, DIM_START_Y + 30, btn_size, btn_size)) {
if (state->rows < MAX_DIMENSION) state->rows++;
return;
}
/* - Lignes */
if (is_in_rect(x_click, y_click, dim_section_x + button_l_offset + 40, DIM_START_Y + 30, btn_size, btn_size)) {
if (state->rows > MIN_DIMENSION) state->rows--;
return;
}
/* 3. Clic sur les boutons de Colonnes (+/-) */
/* + Colonnes */
if (is_in_rect(x_click, y_click, dim_section_x + button_c_offset, DIM_START_Y + 30, btn_size, btn_size)) {
if (state->cols < MAX_DIMENSION) state->cols++;
return;
}
/* - Colonnes */
if (is_in_rect(x_click, y_click, dim_section_x + button_c_offset + 40, DIM_START_Y + 30, btn_size, btn_size)) {
if (state->cols > MIN_DIMENSION) state->cols--;
return;
}
/* 4. Clic sur DÉMARRER */
if (is_in_rect(x_click, y_click, 300, 500, 200, 50)) {
state->ready_to_play = 1;
return;
@@ -140,6 +179,7 @@ void menu_handle_mouse_click(menu_state_t *state)
}
/* Gère l'interaction clavier */
void menu_handle_key(menu_state_t *state)
{
if (ToucheEnAttente()) {
@@ -166,12 +206,15 @@ void menu_handle_key(menu_state_t *state)
}
}
/* --- IMPLÉMENTATION DES UTILITAIRES PRIVÉS --- */
/* Vérifie si (x_click, y_click) est dans le rectangle */
static int is_in_rect(int x_click, int y_click, int rx, int ry, int rw, int rh)
{
return (x_click >= rx && x_click <= rx + rw && y_click >= ry && y_click <= ry + rh);
}
/* Dessine un bouton rectangulaire rempli avec du texte centré */
static void draw_button(int x, int y, const char *text, couleur C_BG)
{
ChoisirCouleurDessin(C_BG);
@@ -180,10 +223,12 @@ static void draw_button(int x, int y, const char *text, couleur C_BG)
draw_text_centered(x, y, BUTTON_SIZE, BUTTON_SIZE, (char*)text, 1);
}
/* Centre le texte dans une zone (x, y, w, h) */
static void draw_text_centered(int x, int y, int w, int h, const char *text, int size)
{
int text_w = TailleChaineEcran((char*)text, size);
int text_h_sup = TailleSupPolice(size);
/* Calcul de la position de départ pour centrer le texte */
int draw_x = x + (w - text_w) / 2;
int draw_y = y + (h + text_h_sup) / 2;