This repository has been archived on 2023-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
GINPA/Vue/vue.c

203 lines
6.5 KiB
C

#include "vue.h"
void boucleGraphique(void)
{
// Création de la fenêtre
sfRenderWindow *window = initialisationFenetre();
// Écran d'accueil !
splashScreen(window);
// Menu !
//handleMenu(window);
controlePoints(window, "Donnees/geoloc-logs.txt");
// La destruction de la fenêtre est déplacée dans les corps des fonctions ad hoc.
}
void splashScreen(sfRenderWindow *window)
{
sfRenderTexture *renderTexture = initialisationRenderTexture(sfRenderWindow_getSize(window).x, sfRenderWindow_getSize(window).y);
// Fond gris
sfRenderTexture_clear(renderTexture, (sfColor){158, 158, 158, 255});
// Image du projet
sfTexture *texture = loadTextureFromFile(PROJECTIMAGEPATH);
const sfVector2f scale = {0.25, 0.25};
const sfVector2f positionSprite = {(WIDTH / 8.0) - (sfTexture_getSize(texture).x / 2.0 * scale.x), (HEIGHT * (3 / 8.0)) - (sfTexture_getSize(texture).y / 2.0 * scale.y)};
sfSprite *sprite = loadSpriteFromTexture(positionSprite, texture);
sfSprite_setScale(sprite, scale);
sfRenderTexture_drawSprite(renderTexture, sprite, NULL);
// GINPA
// GINPA Is Not A Position Analyst
sfFont *italicFont = loadFont(ITALICFONTPATH);
sfFont *boldFont = loadFont(BOLDFONTPATH);
sfText *title = creerTexte((sfVector2f){WIDTH / 2.0, HEIGHT * (3 / 8.0)}, PROJECTNAME, boldFont, 50, sfBlack);
sfRenderTexture_drawText(renderTexture, title, NULL);
sfText *description = creerTexte((sfVector2f){WIDTH / 3.0, HEIGHT / 2.0}, PROJECTDESC, italicFont, 30, sfBlack);
sfRenderTexture_drawText(renderTexture, description, NULL);
sfRenderTexture_display(renderTexture);
sfSprite *renderSprite = loadSpriteFromRenderTexture(renderTexture);
displayBackgroundSprite(window, renderSprite);
sfEvent event;
waitingForEvent(window, &event, renderSprite, true);
scrollUpDisplay(window, renderSprite);
sfTexture_destroy(texture);
texture = NULL;
sfSprite_destroy(sprite);
sprite = NULL;
sfFont_destroy(boldFont);
boldFont = NULL;
sfFont_destroy(italicFont);
italicFont = NULL;
sfText_destroy(title);
title = NULL;
sfText_destroy(description);
description = NULL;
sfRenderTexture_destroy(renderTexture);
renderTexture = NULL;
sfSprite_destroy(renderSprite);
renderSprite = NULL;
}
void handleMenu(sfRenderWindow *const window)
{
sfRenderTexture *renderTexture = initialisationRenderTexture(sfRenderWindow_getSize(window).x, sfRenderWindow_getSize(window).y);
sfRenderTexture_clear(renderTexture, sfWhite);
sfFont* font = loadFont(REGULARFONTPATH);
sfFont* fontIt = loadFont(ITALICFONTPATH);
sfText* monTexte1 = creerTexte((sfVector2f){50.f, 100.f}, "Tapez 'A' pour tracer un cercle", font, 30, sfBlack);
sfRenderTexture_drawText(renderTexture,monTexte1,NULL);
sfText* monTexte2 = creerTexte((sfVector2f){50.f, 200.f}, "Tapez 'Z' pour tracer un rectangle", font, 30, sfBlack);
sfRenderTexture_drawText(renderTexture,monTexte2,NULL);
sfText* monTexte3 = creerTexte((sfVector2f){50.f, 300.f}, "Vous pouvez a tout moment revenir au menu en appuyant sur la touche espace de votre clavier", fontIt, 10, sfBlack);
sfRenderTexture_drawText(renderTexture,monTexte3,NULL);
sfRenderTexture_display(renderTexture);
sfSprite *renderSprite = loadSpriteFromRenderTexture(renderTexture);
displayBackgroundSprite(window, renderSprite);
sfEvent event;
while(sfRenderWindow_isOpen(window))
{
waitingForEvent(window, &event, renderSprite, true);
if(event.type == sfEvtKeyPressed)
{
sfRenderWindow_setFramerateLimit(window, FRAMERATELIMITPOWER);
if(event.key.code == sfKeyA || event.key.code == sfKeyNumpad1)
{
// Tant que l'on appuie pas sur espace (ou escape), on peut tracer
while(!(event.type == sfEvtKeyPressed && event.key.code == sfKeySpace))
{
//On affiche ici un fond blanc pour tracer un cercle
clearDisplayBackground(window, renderTexture, &renderSprite);
waitingForEvent(window, &event, renderSprite, true);
if(event.type == sfEvtMouseButtonPressed)
{
Cercle cercleSelectionne = selectionCercle(window, &event, renderSprite);
fprintf(stdout, "L'utilisateur à sélectionné un cercle de centre (%f, %f) et de rayon %f.\n", cercleSelectionne.centre.x, cercleSelectionne.centre.y, cercleSelectionne.rayon);
displayBackgroundSprite(window, renderSprite);
}
}
}
else if(event.key.code == sfKeyZ || event.key.code == sfKeyNumpad2)
{
// Tant que l'on appuie pas sur espace (ou escape), on peut tracer
while(!(event.type == sfEvtKeyPressed && event.key.code == sfKeySpace))
{
// On affiche ici un fond blanc pour tracer un rectangle
clearDisplayBackground(window, renderTexture, &renderSprite);
waitingForEvent(window, &event, renderSprite, true);
if(event.type == sfEvtMouseButtonPressed)
{
Rectangle rectangleSelectionne = selectionRectangle(window, &event, renderSprite);
fprintf(stdout, "L'utilisateur à sélectionné un rectangle de positionHG (%f, %f) et de positionBD (%f, %f).\n", rectangleSelectionne.positionHG.x, rectangleSelectionne.positionHG.y, rectangleSelectionne.positionBD.x, rectangleSelectionne.positionBD.y);
displayBackgroundSprite(window, renderSprite);
}
}
}
sfRenderWindow_setFramerateLimit(window, FRAMERATELIMITSLEEP);
}
// Si on appuye sur ESPACE, on retourne au menu
sfRenderTexture_clear(renderTexture, sfWhite);
sfRenderTexture_drawText(renderTexture, monTexte1, NULL);
sfRenderTexture_drawText(renderTexture, monTexte2, NULL);
sfRenderTexture_drawText(renderTexture, monTexte3, NULL);
sfRenderTexture_display(renderTexture);
renderSprite = loadSpriteFromRenderTexture(renderTexture);
displayBackgroundSprite(window, renderSprite);
}
sfSprite_destroy(renderSprite);
renderSprite = NULL;
sfFont_destroy(font);
font = NULL;
sfText_destroy(monTexte1);
monTexte1 = NULL;
sfText_destroy(monTexte2);
monTexte2 = NULL;
sfText_destroy(monTexte3);
monTexte3 = NULL;
sfRenderTexture_destroy(renderTexture);
renderTexture = NULL;
}
void waitingForEvent(sfRenderWindow *const window, sfEvent *const event, const sfSprite *const sprite, const bool exitAfterClose)
{
while(sfRenderWindow_waitEvent(window, event))
{
if(event->type == sfEvtClosed || (event->type == sfEvtKeyPressed && event->key.code == sfKeyEscape))
{
sfRenderWindow_close(window);
sfRenderWindow_destroy(window);
if(exitAfterClose)
{
exit(EXIT_SUCCESS);
}
else
{
return;
}
}
else if(event->type == sfEvtResized)
{
displayBackgroundSprite(window, sprite);
}
else if(event->type == sfEvtKeyPressed || event->type == sfEvtMouseButtonPressed)
{
break;
}
}
}