b3ba261664
Intègre le basculement des modes PBP vers le GLOBAL Diminue le nombre d'icônes max' du menu
197 lines
7.8 KiB
C
197 lines
7.8 KiB
C
#include "menu.h"
|
|
|
|
|
|
void initialiserMenu(Menu *const menu)
|
|
{
|
|
menu->sommetTableau = -1;
|
|
|
|
for(uint8_t i = 0; i < MAXBUTTONSMENU; i++)
|
|
{
|
|
menu->liste[i] = NULL;
|
|
}
|
|
|
|
menu->renderTextureMenu = initialisationRenderTexture(MENUWIDTH, MENUHEIGHT);
|
|
sfRenderTexture_clear(menu->renderTextureMenu, COULEUR_GRIS);
|
|
}
|
|
|
|
|
|
void detruireBouton(Bouton *const bouton)
|
|
{
|
|
sfSprite_destroy(bouton->spriteButton);
|
|
sfTexture_destroy(bouton->textureButton);
|
|
}
|
|
|
|
|
|
void detruireMenu(Menu *const menu)
|
|
{
|
|
for(uint8_t i = 0; i <= menu->sommetTableau; i++)
|
|
{
|
|
detruireBouton(menu->liste[i]);
|
|
|
|
free(menu->liste[i]);
|
|
menu->liste[i] = NULL;
|
|
}
|
|
|
|
menu->sommetTableau = -1;
|
|
|
|
sfRenderTexture_destroy(menu->renderTextureMenu);
|
|
menu->renderTextureMenu = NULL;
|
|
}
|
|
|
|
|
|
Tool whichTool(const sfEvent *const event, const Menu *const menu)
|
|
{
|
|
for(uint8_t i = 0; i <= menu->sommetTableau; i++)
|
|
{
|
|
if(mouseIsInRect((sfVector2f){event->mouseButton.x, event->mouseButton.y}, menu->liste[i]->zone))
|
|
{
|
|
return menu->liste[i]->outil;
|
|
}
|
|
}
|
|
|
|
return NO_TOOL;
|
|
}
|
|
|
|
|
|
void ajouterEntreeMenu(Menu *const menu, Bouton *const bouton)
|
|
{
|
|
if(menu->sommetTableau < MAXBUTTONSMENU - 1)
|
|
{
|
|
menu->liste[++menu->sommetTableau] = bouton;
|
|
|
|
const uint16_t ordonneeDernierBoutonActuel = (menu->sommetTableau - 1 < 0 ? 0 : menu->liste[menu->sommetTableau - 1]->zone.positionBD.y);
|
|
|
|
menu->liste[menu->sommetTableau]->zone = (Rectangle){{WIDTH, ordonneeDernierBoutonActuel + BUTTONGAP}, {WIDTH + MENUWIDTH, ordonneeDernierBoutonActuel + BUTTONGAP + RATIOMENU}};
|
|
|
|
sfSprite_setPosition(menu->liste[menu->sommetTableau]->spriteButton, (sfVector2f){0.0, ordonneeDernierBoutonActuel + BUTTONGAP});
|
|
sfRenderTexture_drawSprite(menu->renderTextureMenu, menu->liste[menu->sommetTableau]->spriteButton, NULL);
|
|
|
|
sfRenderTexture_display(menu->renderTextureMenu);
|
|
}
|
|
|
|
else
|
|
{
|
|
fprintf(stderr, "Nombre maximal de boutons dans le menu atteint ! Sale développeur va :D\n");
|
|
exit(0xDEAD);
|
|
}
|
|
}
|
|
|
|
|
|
Bouton* afficherDescriptionBouton(const sfEvent *const event, const Menu *const menu, sfRenderTexture *renderTexture, sfSprite **renderSprite)
|
|
{
|
|
for(uint8_t i = 0; i <= menu->sommetTableau; i++)
|
|
{
|
|
if(mouseIsInRect((sfVector2f){event->mouseMove.x, event->mouseMove.y}, menu->liste[i]->zone))
|
|
{
|
|
sfFont *font = loadFontFromFile(BOLDFONTPATH);
|
|
|
|
sfConvexShape *rectangle = creerRectangle((sfVector2f){WIDTH - BUTTONAMESIZE * 9, menu->liste[i]->zone.positionHG.y}, (sfVector2f){WIDTH, menu->liste[i]->zone.positionHG.y + RATIOMENU}, COULEUR_GRIS_TRANSPARENT);
|
|
sfRenderTexture_drawConvexShape(renderTexture, rectangle, NULL);
|
|
|
|
sfText *texte = creerTexte((sfVector2f){WIDTH - BUTTONAMESIZE * 8, menu->liste[i]->zone.positionHG.y + RATIOMENU / 2.0 - 8}, menu->liste[i]->nom, font, 12, sfBlack);
|
|
sfRenderTexture_drawText(renderTexture, texte, NULL);
|
|
|
|
sfRenderTexture_display(renderTexture);
|
|
|
|
freeSprite(renderSprite);
|
|
*renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
|
|
sfFont_destroy(font);
|
|
sfText_destroy(texte);
|
|
sfConvexShape_destroy(rectangle);
|
|
|
|
return menu->liste[i];
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
void chargerMenuAffichageLog(Menu *const menu, const Mode mode, const bool displayEnded, const bool displayPaused, const Tool currentTool)
|
|
{
|
|
if(mode != MODE_MULTI_FILES)
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_EXIT, "QUITTER ", "Vue/Ressources/Icones/exit.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_BACKTOHOME, "MENU ", "Vue/Ressources/Icones/home.png"));
|
|
|
|
if(displayEnded)
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMPREV, "VUE PRECEDENTE ", "Vue/Ressources/Icones/back.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMNEXT, "VUE SUIVANTE ", "Vue/Ressources/Icones/next.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMZONE, "ZOOMER ZONE ", (currentTool == TOOL_ZOOMZONE ? "Vue/Ressources/Icones/zoom-in_selected.png" : "Vue/Ressources/Icones/zoom-in.png")));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_CHANGEMAP, "CHANGER FOND ", "Vue/Ressources/Icones/layers.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_SELECTPOINTS, "SELECTIONNE ZONE", (currentTool == TOOL_SELECTPOINTS ? "Vue/Ressources/Icones/flag_selected.png" : "Vue/Ressources/Icones/flag.png")));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_DESELECTPOINTS, "DESELECT. ZONE ", (currentTool == TOOL_DESELECTPOINTS ? "Vue/Ressources/Icones/flag_barre_selected.png" : "Vue/Ressources/Icones/flag_barre.png")));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_PREVIEW, "PREVISUALISATION", (mode == MODE_GLOBAL ? "Vue/Ressources/Icones/hide_mode1.png" : (mode == MODE_PREVIEW ? "Vue/Ressources/Icones/hide_mode2.png" : "Vue/Ressources/Icones/hide_mode3.png"))));
|
|
if(mode == MODE_GLOBAL)
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_SAVE, "SAUVEGARDER ", "Vue/Ressources/Icones/download_disabled.png"));
|
|
else
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_SAVE, "SAUVEGARDER ", "Vue/Ressources/Icones/download_enabled.png"));
|
|
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_CENTERPOSITION, "RECENTRER ", "Vue/Ressources/Icones/target.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_TOGGLEAGGLO, "AGGLOMERATS ", "Vue/Ressources/Icones/push-pin.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_TOGGLEROUTE, "ROUTES ", "Vue/Ressources/Icones/road-perspective-of-curves.png"));
|
|
}
|
|
|
|
else
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_GLOBAL, "PASSER EN GLOBAL", "Vue/Ressources/Icones/worldwide.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ERASE, "EFFACE AFFICHAGE", "Vue/Ressources/Icones/eraser.png"));
|
|
|
|
if(mode == MODE_PBP_AUTOMATIC)
|
|
{
|
|
if(displayPaused)
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_RESUME, "REPRENDRE ", "Vue/Ressources/Icones/play.png"));
|
|
}
|
|
|
|
else
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_PAUSE, "PAUSE ", "Vue/Ressources/Icones/pause.png"));
|
|
}
|
|
}
|
|
|
|
else if(mode == MODE_PBP_MANUAL)
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_CONTINUE, "POINT SUIVANT ", "Vue/Ressources/Icones/fast-forward.png"));
|
|
}
|
|
}
|
|
|
|
if(mode != MODE_GLOBAL && mode != MODE_PREVIEW && mode != MODE_PREVIEW_SUGG)
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_REPEAT, "RESET AFFICHAGE ", "Vue/Ressources/Icones/repeat.png"));
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_EXIT, "QUITTER ", "Vue/Ressources/Icones/exit.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_BACKTOHOME, "MENU ", "Vue/Ressources/Icones/home.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMPREV, "VUE PRECEDENTE ", "Vue/Ressources/Icones/back.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMNEXT, "VUE SUIVANTE ", "Vue/Ressources/Icones/next.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_ZOOMZONE, "ZOOMER ZONE ", (currentTool == TOOL_ZOOMZONE ? "Vue/Ressources/Icones/zoom-in_selected.png" : "Vue/Ressources/Icones/zoom-in.png")));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_CHANGEMAP, "CHANGER FOND ", "Vue/Ressources/Icones/layers.png"));
|
|
ajouterEntreeMenu(menu, loadButtonMenu(TOOL_CENTERPOSITION, "RECENTRER ", "Vue/Ressources/Icones/target.png"));
|
|
}
|
|
}
|
|
|
|
|
|
void updateAndDrawMenu(sfRenderTexture *const renderTexture, Menu *const menu, const Mode mode, const bool displayEnded, const bool displayPaused, const Tool currentTool)
|
|
{
|
|
detruireMenu(menu);
|
|
initialiserMenu(menu);
|
|
chargerMenuAffichageLog(menu, mode, displayEnded, displayPaused, currentTool);
|
|
|
|
/* Méthode dégueu': Il faut "effacer" les anciens boutons avant de remettre les nouveaux... */
|
|
sfConvexShape *temp = creerRectangle((sfVector2f){WIDTH, 0.0}, (sfVector2f){WIDTH + MENUWIDTH, MENUHEIGHT}, COULEUR_GRIS);
|
|
sfRenderTexture_drawConvexShape(renderTexture, temp, NULL);
|
|
/* ________________________________________________________________________________________ */
|
|
|
|
dessinerMenu(renderTexture, menu);
|
|
|
|
/* Suite de la méthode dégueu' */
|
|
sfConvexShape_destroy(temp);
|
|
/* ___________________________ */
|
|
}
|