APL/APL1.1/SAE11_2021/menu.c

102 lines
3.6 KiB
C
Raw Normal View History

2021-12-09 11:26:52 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <string.h>
#include "taquin.h"
#include "graph_sup.h"
void UpdateSelection(char* selection, int param) {
2021-12-10 18:57:48 +01:00
int MenuHeight = HEIGHT - 120, i;
2021-12-09 11:26:52 +01:00
if (selection == "lines") {
2021-12-12 18:07:25 +01:00
char str[30];
for (i = 3; i <= 8; i++) {
sprintf(str, "./images/assets/sel_%d.png", i);
ChargerImage(str, 1001, 88 + 81 * (i-3), 0, 0, 61, 61);
}
ChargerImage("./images/assets/sel_halo.png", 1001, 88 + 81 * (param-3), 0, 0, 61, 61);
2021-12-09 11:26:52 +01:00
} else if (selection == "columns") {
2021-12-12 18:07:25 +01:00
char str[30];
for (i = 3; i <= 8; i++) {
sprintf(str, "./images/assets/sel_%d.png", i);
ChargerImage(str, 737, 88 + 81 * (i-3), 0, 0, 61, 61);
}
ChargerImage("./images/assets/sel_halo.png", 737, 88 + 81 * (param-3), 0, 0, 61, 61);
2021-12-10 18:57:48 +01:00
} else if (selection == "image"){
2021-12-12 18:07:25 +01:00
ChargerImage("./images/assets/img_sel.png", 0, MenuHeight/3 * param, 0, 0, 603, 198);
2021-12-09 11:26:52 +01:00
}
};
int DrawMenu() {
ClearButtons();
2021-12-10 18:57:48 +01:00
EffacerEcran(GetColor(255, 255, 255));
2021-12-09 11:26:52 +01:00
int MenuHeight = HEIGHT - 120;
int Lines = 3, Columns = 3, i;
2021-12-12 18:07:25 +01:00
int X_image = 0, Y_image = 0;
2021-12-09 11:26:52 +01:00
char filename[100];
char str[3];
for (i = 0; i <= 5; i++) {
2021-12-12 18:07:25 +01:00
AddButton(737, 88 + 81 * i, 61, 61, 10 + i); //Colonnes
AddButton(1001, 88 + 81 * i, 61, 61, 20 + i); //Lignes
2021-12-09 11:26:52 +01:00
}
2021-12-12 18:07:25 +01:00
ChargerImage("./images/assets/menu_background.png", 0, 0, 0, 0, WIDTH, HEIGHT);
AddButton(WIDTH/4 * 3 - 100, HEIGHT - 100, 200, 80, 1); //Lancer le Taquin
AddButton(WIDTH/4 - 100, HEIGHT -100, 200, 80, 2); //Quitter
2021-12-09 11:26:52 +01:00
UpdateSelection("lines", Lines);
UpdateSelection("columns", Columns);
2021-12-12 18:07:25 +01:00
AddButton(0, 0, WIDTH/2, MenuHeight/3, 3); //Luna
AddButton(0, MenuHeight/3, WIDTH/2, MenuHeight/3, 4); //Zanitsu
AddButton(0, MenuHeight/3 *2, WIDTH/2, MenuHeight/3, 5); //Bonsaï
2021-12-09 11:26:52 +01:00
while (1) {
if (DrawNextFrame()) {
if (SourisCliquee()) {
int BT_ID = GetButton(_X, _Y);
if (BT_ID >= 10 && BT_ID <= 15) {
Columns = BT_ID - 7;
UpdateSelection("columns", Columns);
} else if (BT_ID >= 20 && BT_ID <= 25) {
Lines = BT_ID - 17;
UpdateSelection("lines", Lines);
2021-12-12 18:07:25 +01:00
} else if (BT_ID >= 3 && BT_ID <= 5){
ChargerImage("./images/assets/menu_background.png", 0, 0, 0, 0, WIDTH, HEIGHT);
UpdateSelection("lines", Lines);
UpdateSelection("columns", Columns);
2021-12-10 18:57:48 +01:00
UpdateSelection("image", BT_ID - 3);
2021-12-12 18:07:25 +01:00
if (BT_ID == 3){
X_image = 500;
Y_image = 445;
strcpy(filename, "./images/luna.png");
} else if (BT_ID == 4){
X_image = 450;
Y_image = 311;
strcpy(filename, "./images/zenitsu.png");
} else if (BT_ID == 5){
X_image = 400;
Y_image = 400;
strcpy(filename, "./images/bonsai.png");
}
} else {
if (BT_ID == 1 && X_image != 0) {
2021-12-09 11:26:52 +01:00
ClearButtons();
EffacerEcran(GetColor(255, 255, 255));
2021-12-10 18:57:48 +01:00
CreateTaquin(filename, X_image, Y_image, Lines, Columns);
2021-12-12 18:07:25 +01:00
return 1;
2021-12-10 18:57:48 +01:00
} else if (BT_ID == 2) {
2021-12-12 18:07:25 +01:00
return 0;
}
2021-12-09 11:26:52 +01:00
}
}
}
}
return 0;
2021-12-10 18:57:48 +01:00
}