b3ba261664
Intègre le basculement des modes PBP vers le GLOBAL Diminue le nombre d'icônes max' du menu
545 lines
16 KiB
C
545 lines
16 KiB
C
#include "waiting.h"
|
|
|
|
|
|
void waitingForEvent(sfRenderWindow *const window, sfEvent *const event, const sfSprite *const sprite)
|
|
{
|
|
while(sfRenderWindow_waitEvent(window, event))
|
|
{
|
|
if(event->type == sfEvtClosed || (event->type == sfEvtKeyPressed && event->key.code == sfKeyEscape))
|
|
{
|
|
sfRenderWindow_close(window);
|
|
sfRenderWindow_destroy(window);
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
else if(event->type == sfEvtResized)
|
|
{
|
|
displayBackgroundSprite(window, sprite);
|
|
}
|
|
|
|
else if(event->type == sfEvtKeyPressed || event->type == sfEvtMouseButtonPressed)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Rectangle waitingOnMapEvent(sfRenderWindow *const window, sfEvent *const event, sfRenderTexture *renderTexture, sfSprite *renderSprite, const Carte *const carte, const uint32_t nbPointsAffiches, Point ** ptsAffiches, sfCircleShape *tabPointeursCercles[nbPointsAffiches], const uint32_t nbAgglos, sfCircleShape *tabPointeursCerclesAgglos[nbAgglos], Agglomerat *agglos, uint32_t nbPoints, Point *tabPoint, char **tabDatesConverties, const sfFont *const font, Action *const action, const Mode mode, Menu *const menu, Tool *const currentTool)
|
|
{
|
|
sfTexture *originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
|
|
// Un booléen qui se souviendra de la présence (ou de l'absence) du curseur sur la fenêtre !
|
|
bool inWindow = true;
|
|
|
|
/* 'nbPointsAffiches' est la valeur impossible signifiant qu'aucun point n'est affiché */
|
|
uint32_t pointAffiche = nbPointsAffiches;
|
|
/* 'nbPointsAffiches' est la valeur impossible signifiant qu'aucun agglomérat n'est sélectionné */
|
|
uint32_t aggloSelectionne = nbAgglos;
|
|
|
|
Bouton *boutonActuel = NULL;
|
|
|
|
while(sfRenderWindow_waitEvent(window, event))
|
|
{
|
|
if(event->type == sfEvtClosed || sfKeyboard_isKeyPressed(sfKeyEscape))
|
|
{
|
|
sfRenderWindow_close(window);
|
|
sfRenderWindow_destroy(window);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
else if(event->type == sfEvtResized)
|
|
{
|
|
displayBackgroundSprite(window, renderSprite);
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseEntered)
|
|
{
|
|
inWindow = true;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseLeft)
|
|
{
|
|
inWindow = false;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseMoved)
|
|
{
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
|
|
bool needToRefreshDisplay = false;
|
|
|
|
if(event->mouseMove.x >= WIDTH)
|
|
{
|
|
boutonActuel = afficherDescriptionBouton(event, menu, renderTexture, &renderSprite);
|
|
if(boutonActuel != NULL)
|
|
{
|
|
needToRefreshDisplay = true;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
pointAffiche = afficherDateSelectionnerPoint(event, renderTexture, &renderSprite, nbPointsAffiches, ptsAffiches, tabPointeursCercles, tabPoint,tabDatesConverties, font);
|
|
aggloSelectionne = selectionnerAgglomerats(event, nbAgglos, tabPointeursCerclesAgglos, agglos);
|
|
}
|
|
|
|
if(needToRefreshDisplay || pointAffiche != nbPoints || aggloSelectionne != nbAgglos)
|
|
{
|
|
displayBackgroundSprite(window, renderSprite);
|
|
}
|
|
}
|
|
|
|
else if(event->type == sfEvtKeyPressed)
|
|
{
|
|
if(sfKeyboard_isKeyPressed(sfKeyS) && (mode == MODE_PREVIEW || mode == MODE_PREVIEW_SUGG))
|
|
{
|
|
suppressionAndVerbosity(window, renderSprite, tabPoint, nbPoints, agglos, nbAgglos, mode);
|
|
}
|
|
|
|
else if(sfKeyboard_isKeyPressed(sfKeyBack))
|
|
{
|
|
*action = ACTION_QUIT;
|
|
break;
|
|
}
|
|
|
|
else if(sfKeyboard_isKeyPressed(sfKeySpace))
|
|
{
|
|
*action = ACTION_CHANGE_MAP_TYPE;
|
|
break;
|
|
}
|
|
|
|
else if(sfKeyboard_isKeyPressed(sfKeyV))
|
|
{
|
|
*action = ACTION_CHANGE_VISUALISATION;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Il n'est pas possible d'utiliser `sfMouse_isButtonPressed(sfMouseXButton2)` ici...
|
|
--> cf. https://github.com/SFML/SFML/blob/fae3b65f0567f87fa9925cd42d28df15eb69e79c/src/SFML/Window/Unix/InputImpl.cpp#L237 */
|
|
else if((event->type == sfEvtMouseButtonPressed && event->mouseButton.button == sfMouseXButton2) || sfKeyboard_isKeyPressed(sfKeyN))
|
|
{
|
|
*action = ACTION_ZOOM_NEXT;
|
|
break;
|
|
}
|
|
|
|
/* Il n'est pas possible d'utiliser `sfMouse_isButtonPressed(sfMouseXButton1)` ici...
|
|
--> cf. https://github.com/SFML/SFML/blob/fae3b65f0567f87fa9925cd42d28df15eb69e79c/src/SFML/Window/Unix/InputImpl.cpp#L238 */
|
|
else if((event->type == sfEvtMouseButtonPressed && event->mouseButton.button == sfMouseXButton1) || sfKeyboard_isKeyPressed(sfKeyP))
|
|
{
|
|
*action = ACTION_ZOOM_PREV;
|
|
break;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseButtonPressed && inWindow)
|
|
{
|
|
if(event->mouseButton.x > MAPSIZE)
|
|
{
|
|
// Dans quasiment tous les cas, il faudra sortir de la boucle englobante...
|
|
bool needToBreakTheWhile = true;
|
|
|
|
switch(whichTool(event, menu))
|
|
{
|
|
case TOOL_EXIT:
|
|
if(questionBox(window, renderSprite, "Êtes-vous vraiment sûr de vouloir quitter le logiciel ?"))
|
|
{
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
needToBreakTheWhile = false;
|
|
}
|
|
break;
|
|
|
|
case TOOL_BACKTOHOME:
|
|
if(questionBox(window, renderSprite, "Êtes-vous vraiment sûr de vouloir quitter cette vue ?"))
|
|
{
|
|
*action = ACTION_QUIT;
|
|
}
|
|
else
|
|
{
|
|
needToBreakTheWhile = false;
|
|
}
|
|
break;
|
|
|
|
case TOOL_CHANGEMAP:
|
|
*action = ACTION_CHANGE_MAP_TYPE;
|
|
break;
|
|
|
|
case TOOL_CENTERPOSITION:
|
|
*action = ACTION_CENTERPOSITION;
|
|
break;
|
|
|
|
case TOOL_ZOOMZONE:
|
|
needToBreakTheWhile = false;
|
|
*currentTool = (*currentTool == TOOL_ZOOMZONE) ? NO_TOOL : TOOL_ZOOMZONE;
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
sfRenderTexture_drawSprite(renderTexture, renderSprite, NULL);
|
|
updateAndDrawMenu(renderTexture, menu, mode, true, true, *currentTool);
|
|
freeSprite(&renderSprite);
|
|
renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
sfTexture_destroy(originalTexture);
|
|
originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
displayBackgroundSprite(window, renderSprite);
|
|
break;
|
|
|
|
case TOOL_ZOOMPREV:
|
|
*action = ACTION_ZOOM_PREV;
|
|
break;
|
|
|
|
case TOOL_ZOOMNEXT:
|
|
*action = ACTION_ZOOM_NEXT;
|
|
break;
|
|
|
|
case TOOL_SELECTPOINTS:
|
|
needToBreakTheWhile = false;
|
|
*currentTool = (*currentTool == TOOL_SELECTPOINTS) ? NO_TOOL : TOOL_SELECTPOINTS;
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
sfRenderTexture_drawSprite(renderTexture, renderSprite, NULL);
|
|
updateAndDrawMenu(renderTexture, menu, mode, true, true, *currentTool);
|
|
freeSprite(&renderSprite);
|
|
renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
displayBackgroundSprite(window, renderSprite);
|
|
sfTexture_destroy(originalTexture);
|
|
originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
break;
|
|
|
|
case TOOL_DESELECTPOINTS:
|
|
needToBreakTheWhile = false;
|
|
*currentTool = (*currentTool == TOOL_DESELECTPOINTS) ? NO_TOOL : TOOL_DESELECTPOINTS;
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
sfRenderTexture_drawSprite(renderTexture, renderSprite, NULL);
|
|
updateAndDrawMenu(renderTexture, menu, mode, true, true, *currentTool);
|
|
freeSprite(&renderSprite);
|
|
renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
displayBackgroundSprite(window, renderSprite);
|
|
sfTexture_destroy(originalTexture);
|
|
originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
break;
|
|
|
|
case TOOL_PREVIEW:
|
|
*action = ACTION_CHANGE_VISUALISATION;
|
|
break;
|
|
|
|
case TOOL_SAVE:
|
|
needToBreakTheWhile = false;
|
|
if(mode == MODE_PREVIEW || mode == MODE_PREVIEW_SUGG)
|
|
{
|
|
suppressionAndVerbosity(window, renderSprite, tabPoint, nbPoints, agglos, nbAgglos, mode);
|
|
}
|
|
break;
|
|
|
|
case TOOL_REPEAT:
|
|
*action = ACTION_REPEAT;
|
|
break;
|
|
|
|
case TOOL_TOGGLEAGGLO:
|
|
*action = ACTION_TOGGLEAGGLO;
|
|
break;
|
|
|
|
case TOOL_TOGGLEROUTE:
|
|
*action = ACTION_TOGGLEROUTE;
|
|
break;
|
|
|
|
case NO_TOOL:
|
|
default:
|
|
needToBreakTheWhile = false;
|
|
break;
|
|
}
|
|
|
|
if(needToBreakTheWhile)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if(*currentTool == TOOL_ZOOMZONE && *action == ACTION_ZOOMABLE)
|
|
{
|
|
Rectangle carre = selectionRectangle(window, event, renderSprite, true);
|
|
|
|
// Si l'utilisateur a réellement sélectionné une zone...
|
|
if(carre.positionHG.x != 0.0 && carre.positionHG.y != 0.0 && carre.positionBD.x != 0.0 && carre.positionBD.y != 0.0)
|
|
{
|
|
*action = ACTION_ZOOM_ZONE;
|
|
sfTexture_destroy(originalTexture);
|
|
freeSprite(&renderSprite);
|
|
return carre;
|
|
}
|
|
}
|
|
else if(*currentTool == TOOL_SELECTPOINTS)
|
|
{
|
|
controleSelectionSuppression(window, event, renderSprite, ptsAffiches, nbPointsAffiches, pointAffiche, agglos, nbAgglos, aggloSelectionne, tabPointeursCercles, tabPointeursCerclesAgglos, true);
|
|
*action = ACTION_REFRESH;
|
|
break;
|
|
}
|
|
else if(*currentTool == TOOL_DESELECTPOINTS && mode != MODE_PREVIEW && mode != MODE_PREVIEW_SUGG)
|
|
{
|
|
controleSelectionSuppression(window, event, renderSprite, ptsAffiches, nbPointsAffiches, pointAffiche, agglos, nbAgglos, aggloSelectionne, tabPointeursCercles, tabPointeursCerclesAgglos, false);
|
|
*action = ACTION_REFRESH;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseWheelMoved && event->mouseWheel.x < WIDTH)
|
|
{
|
|
int delta = event->mouseWheel.delta;
|
|
|
|
if(delta > 0 && carte->zoom < ZOOMAX)
|
|
{
|
|
*action = ACTION_ZOOM_IN;
|
|
break;
|
|
}
|
|
|
|
else if(delta < 0 && carte->zoom > ZOOMIN)
|
|
{
|
|
*action = ACTION_ZOOM_OUT;
|
|
break;
|
|
}
|
|
|
|
else
|
|
{
|
|
/* `delta = 0` est une possibilité ? */
|
|
}
|
|
}
|
|
}
|
|
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
displayBackgroundSprite(window, renderSprite);
|
|
|
|
sfTexture_destroy(originalTexture);
|
|
freeSprite(&renderSprite);
|
|
|
|
// On retourne un Rectangle nul, mais c'est la valeur de `action` qui importe le plus ici.
|
|
return (Rectangle){{0.0, 0.0}, {0.0, 0.0}};
|
|
}
|
|
|
|
|
|
Rectangle waitingOnMapEventAgglo(sfRenderWindow *const window, sfEvent *const event, sfRenderTexture *const renderTexture, sfSprite *renderSprite, const Carte *const carte, const uint32_t tailleGlobalMultiFile, const AgglomeratGlobal globalMultiFile[tailleGlobalMultiFile], sfCircleShape **tabPointeursCerclesAgglos, const sfFont *const font, Action *const action, Menu *const menu, Tool *const currentTool)
|
|
{
|
|
sfTexture *originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
|
|
// Un booléen qui se souviendra de la présence (ou de l'absence) du curseur sur la fenêtre !
|
|
bool inWindow = true;
|
|
|
|
Bouton *boutonActuel = NULL;
|
|
bool adresseActuelle = false;
|
|
|
|
while(sfRenderWindow_waitEvent(window, event))
|
|
{
|
|
if(event->type == sfEvtClosed || sfKeyboard_isKeyPressed(sfKeyEscape))
|
|
{
|
|
sfRenderWindow_close(window);
|
|
sfRenderWindow_destroy(window);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
else if(event->type == sfEvtResized)
|
|
{
|
|
displayBackgroundSprite(window, renderSprite);
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseEntered)
|
|
{
|
|
inWindow = true;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseLeft)
|
|
{
|
|
inWindow = false;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseMoved)
|
|
{
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
|
|
bool needToRefreshDisplay = false;
|
|
|
|
if(event->mouseMove.x >= WIDTH)
|
|
{
|
|
boutonActuel = afficherDescriptionBouton(event, menu, renderTexture, &renderSprite);
|
|
if(boutonActuel != NULL)
|
|
{
|
|
needToRefreshDisplay = true;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if(boutonActuel != NULL || adresseActuelle)
|
|
{
|
|
needToRefreshDisplay = true;
|
|
}
|
|
|
|
adresseActuelle = afficherAdresseAgglomerats(event, renderTexture, &renderSprite, tailleGlobalMultiFile, globalMultiFile, tabPointeursCerclesAgglos, font);
|
|
|
|
if(!needToRefreshDisplay)
|
|
{
|
|
needToRefreshDisplay = adresseActuelle;
|
|
}
|
|
}
|
|
|
|
if(needToRefreshDisplay)
|
|
{
|
|
displayBackgroundSprite(window, renderSprite);
|
|
}
|
|
}
|
|
|
|
else if(event->type == sfEvtKeyPressed)
|
|
{
|
|
if(sfKeyboard_isKeyPressed(sfKeyBack))
|
|
{
|
|
*action = ACTION_QUIT;
|
|
break;
|
|
}
|
|
|
|
else if(sfKeyboard_isKeyPressed(sfKeySpace))
|
|
{
|
|
*action = ACTION_CHANGE_MAP_TYPE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Il n'est pas possible d'utiliser `sfMouse_isButtonPressed(sfMouseXButton2)` ici...
|
|
--> cf. https://github.com/SFML/SFML/blob/fae3b65f0567f87fa9925cd42d28df15eb69e79c/src/SFML/Window/Unix/InputImpl.cpp#L237 */
|
|
else if((event->type == sfEvtMouseButtonPressed && event->mouseButton.button == sfMouseXButton2) || sfKeyboard_isKeyPressed(sfKeyN))
|
|
{
|
|
*action = ACTION_ZOOM_NEXT;
|
|
break;
|
|
}
|
|
|
|
/* Il n'est pas possible d'utiliser `sfMouse_isButtonPressed(sfMouseXButton1)` ici...
|
|
--> cf. https://github.com/SFML/SFML/blob/fae3b65f0567f87fa9925cd42d28df15eb69e79c/src/SFML/Window/Unix/InputImpl.cpp#L238 */
|
|
else if((event->type == sfEvtMouseButtonPressed && event->mouseButton.button == sfMouseXButton1) || sfKeyboard_isKeyPressed(sfKeyP))
|
|
{
|
|
*action = ACTION_ZOOM_PREV;
|
|
break;
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseButtonPressed && inWindow)
|
|
{
|
|
if(event->mouseButton.x > MAPSIZE)
|
|
{
|
|
// Dans quasiment tous les cas, il faudra sortir de la boucle englobante...
|
|
bool needToBreakTheWhile = true;
|
|
|
|
switch(whichTool(event, menu))
|
|
{
|
|
case TOOL_EXIT:
|
|
if(questionBox(window, renderSprite, "Êtes-vous vraiment sûr de vouloir quitter le logiciel ?"))
|
|
{
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
needToBreakTheWhile = false;
|
|
}
|
|
break;
|
|
|
|
case TOOL_BACKTOHOME:
|
|
if(questionBox(window, renderSprite, "Êtes-vous vraiment sûr de vouloir quitter cette vue ?"))
|
|
{
|
|
*action = ACTION_QUIT;
|
|
}
|
|
else
|
|
{
|
|
needToBreakTheWhile = false;
|
|
}
|
|
break;
|
|
|
|
case TOOL_CHANGEMAP:
|
|
*action = ACTION_CHANGE_MAP_TYPE;
|
|
break;
|
|
|
|
case TOOL_CENTERPOSITION:
|
|
*action = ACTION_CENTERPOSITION;
|
|
break;
|
|
|
|
case TOOL_ZOOMZONE:
|
|
needToBreakTheWhile = false;
|
|
*currentTool = (*currentTool == TOOL_ZOOMZONE) ? NO_TOOL : TOOL_ZOOMZONE;
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
sfRenderTexture_drawSprite(renderTexture, renderSprite, NULL);
|
|
updateAndDrawMenu(renderTexture, menu, MODE_MULTI_FILES, false, false, *currentTool);
|
|
freeSprite(&renderSprite);
|
|
renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
sfTexture_destroy(originalTexture);
|
|
originalTexture = sfTexture_copy(sfRenderTexture_getTexture(renderTexture));
|
|
displayBackgroundSprite(window, renderSprite);
|
|
break;
|
|
|
|
case TOOL_ZOOMPREV:
|
|
*action = ACTION_ZOOM_PREV;
|
|
break;
|
|
|
|
case TOOL_ZOOMNEXT:
|
|
*action = ACTION_ZOOM_NEXT;
|
|
break;
|
|
|
|
case NO_TOOL:
|
|
default:
|
|
needToBreakTheWhile = false;
|
|
break;
|
|
}
|
|
|
|
if(needToBreakTheWhile)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if(*currentTool == TOOL_ZOOMZONE && *action == ACTION_ZOOMABLE)
|
|
{
|
|
Rectangle carre = selectionRectangle(window, event, renderSprite, true);
|
|
|
|
// Si l'utilisateur a réellement sélectionné une zone...
|
|
if(carre.positionHG.x != 0.0 && carre.positionHG.y != 0.0 && carre.positionBD.x != 0.0 && carre.positionBD.y != 0.0)
|
|
{
|
|
*action = ACTION_ZOOM_ZONE;
|
|
sfTexture_destroy(originalTexture);
|
|
freeSprite(&renderSprite);
|
|
return carre;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if(event->type == sfEvtMouseWheelMoved && event->mouseWheel.x < WIDTH)
|
|
{
|
|
int delta = event->mouseWheel.delta;
|
|
|
|
if(delta > 0 && carte->zoom < ZOOMAX)
|
|
{
|
|
*action = ACTION_ZOOM_IN;
|
|
break;
|
|
}
|
|
|
|
else if(delta < 0 && carte->zoom > ZOOMIN)
|
|
{
|
|
*action = ACTION_ZOOM_OUT;
|
|
break;
|
|
}
|
|
|
|
else
|
|
{
|
|
/* `delta = 0` est une possibilité ? */
|
|
}
|
|
}
|
|
}
|
|
|
|
resetTextureAndSpriteFromOriginal(renderTexture, &renderSprite, originalTexture);
|
|
displayBackgroundSprite(window, renderSprite);
|
|
|
|
sfTexture_destroy(originalTexture);
|
|
freeSprite(&renderSprite);
|
|
|
|
// On retourne un Rectangle nul, mais c'est la valeur de `action` qui importe le plus ici.
|
|
return (Rectangle){{0.0, 0.0}, {0.0, 0.0}};
|
|
} |