diff --git a/APL1.1/SAE11_2021/graph_sup.c b/APL1.1/SAE11_2021/graph_sup.c index 96124f2..0c5fc6d 100644 --- a/APL1.1/SAE11_2021/graph_sup.c +++ b/APL1.1/SAE11_2021/graph_sup.c @@ -1,10 +1,43 @@ #include "utils.h" #include #include +#include #include +#include "graph_sup.h" #define FPS 60.0 +button* Buttons; +int BT_Count = 0; + +void clearButtons() { + BT_Count = 0; + Buttons = (button*)realloc(Buttons, sizeof(button) * 1); +} + +void AddButton(int x, int y, int w, int h, char* id) { + button BT = {0, 0, 0, 0}; + BT.x = x; + BT.y = y; + BT.w = w; + BT.h = h; + BT.id = id; + + BT_Count++; + Buttons = (button*) realloc(Buttons, BT_Count * sizeof(button)); + Buttons[BT_Count-1] = BT; +} + +char* GetButton(int x, int y) { + for (int ID = 0; ID < BT_Count; ID++) { + button BT = Buttons[ID]; + if (x >= BT.y && y >= BT.y && x <= BT.x + BT.w && y <= BT.y + BT.h) { + return BT.id; + } + } + return ""; +} + int RegisterInputs(char * screen) { if (ToucheEnAttente() > 0) { int key = Touche(); @@ -18,6 +51,10 @@ int RegisterInputs(char * screen) { } } + if (SourisCliquee()) { + char* BT_ID = GetButton(_X, _Y); + } + return 0; } @@ -31,18 +68,4 @@ int DrawNextFrame() { } return 0; -} - -double a = 0; -void DrawGraphics(char * screen) { - couleur black = CouleurParNom("black"); - couleur white = CouleurParNom("white"); - if (strcmp(screen, "main_menu") == 0) { - a += 1/FPS; - EffacerEcran(white); - ChoisirCouleurDessin(black); - char str[20]; - sprintf(str, "Temps : %f", a); - EcrireTexte(100, 100, str, 2); - } } \ No newline at end of file diff --git a/APL1.1/SAE11_2021/graph_sup.h b/APL1.1/SAE11_2021/graph_sup.h index 6411c77..18d9912 100644 --- a/APL1.1/SAE11_2021/graph_sup.h +++ b/APL1.1/SAE11_2021/graph_sup.h @@ -1,10 +1,26 @@ #ifndef _GRAPH_SUP_H #define _GRAPH_SUP_H +struct Button { + int x; + int y; + int w; + int h; + char* id; + struct Button* next; +}; + +typedef struct Button button; + +extern button* Buttons; +extern int BT_Count; + +void clearButtons(); +char* GetButton(int x, int y); +void AddButton(int x, int y, int w, int h, char* id); + int RegisterInputs(char * screen); int DrawNextFrame(void); -void DrawGraphics(char * screen); - #endif \ No newline at end of file diff --git a/APL1.1/SAE11_2021/lib_taquin/taquin.c b/APL1.1/SAE11_2021/lib_taquin/taquin.c index 3a2cb6b..4669494 100644 --- a/APL1.1/SAE11_2021/lib_taquin/taquin.c +++ b/APL1.1/SAE11_2021/lib_taquin/taquin.c @@ -1,4 +1,5 @@ #include "utils.h" +#include "taquin.h" //Initialise le Taquin, la fonction appelle la création graphique et logique du Taquin. void CreateTaquin(char * filename, int rows, int columns) { diff --git a/APL1.1/SAE11_2021/lib_taquin/taquin_graphique.c b/APL1.1/SAE11_2021/lib_taquin/taquin_graphique.c index e69de29..ad7ab31 100644 --- a/APL1.1/SAE11_2021/lib_taquin/taquin_graphique.c +++ b/APL1.1/SAE11_2021/lib_taquin/taquin_graphique.c @@ -0,0 +1,5 @@ +#include "../graph_sup.h" + +void AnimateTaquin(taquin T) { + +} \ No newline at end of file diff --git a/APL1.1/SAE11_2021/main.c b/APL1.1/SAE11_2021/main.c index aa12107..817dade 100644 --- a/APL1.1/SAE11_2021/main.c +++ b/APL1.1/SAE11_2021/main.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "utils.h" #include "graph_sup.h" @@ -11,12 +13,29 @@ int main(void) { InitialiserGraphique(); CreerFenetre(100, 100, 1200, 700); + + char screen[30] = "taquin"; + while (1) { - if (RegisterInputs("main_menu") == -1) return EXIT_SUCCESS; + if (RegisterInputs(screen) == -1) return EXIT_SUCCESS; - int can_draw = DrawNextFrame(); - if (can_draw == 1) { - DrawGraphics("main_menu"); + if (DrawNextFrame()) { + EffacerEcran(CouleurParNom("white")); + SourisPosition(); + clearButtons(); + double x = (double)Microsecondes() / 100000.0; + AddButton(300+sin(x)*50, 300+cos(x)*50, 100, 100, "owo"); + AddButton(500+cos(x)*50, 500+sin(x)*50, 100, 100, "owo2"); + + for (int i = 0; i < BT_Count; i++) { + button BT = Buttons[i]; + char* ID = GetButton(_X, _Y); + + if (!strcmp(ID, BT.id)) { + ChoisirCouleurDessin(CouleurParNom("red")); + } else ChoisirCouleurDessin(CouleurParNom("black")); + DessinerRectangle(BT.x, BT.y, BT.w, BT.h); + } } } FermerGraphique(); diff --git a/APL1.1/SAE11_2021/utils.c b/APL1.1/SAE11_2021/utils.c index e70e3c4..1476d19 100644 --- a/APL1.1/SAE11_2021/utils.c +++ b/APL1.1/SAE11_2021/utils.c @@ -1,5 +1,5 @@ #include -double lerpf(double a, double b, double t) { +double LerpF(double a, double b, double t) { return a + (b - a) * t; } \ No newline at end of file