1f1aa8283a
Ajout & fix' Doxygen des constantes
183 lines
5.3 KiB
C
183 lines
5.3 KiB
C
#include "creation.h"
|
|
|
|
|
|
sfRenderWindow* initialisationFenetre(void)
|
|
{
|
|
sfRenderWindow *window = sfRenderWindow_create((sfVideoMode){WIDTH + MENUWIDTH, HEIGHT, BITSPERPIXEL}, WINDOWNAME, sfDefaultStyle, NULL);
|
|
|
|
if(window == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création de la fenêtre.\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
/* La partie ci-dessous ne fonctionne pas avec tous les Window Managers malheureusement... */
|
|
sfImage *image = sfImage_createFromFile(WINDOWICONPATH);
|
|
|
|
if(image == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de l'ouverture du fichier icône: \"%s\".\n", WINDOWICONPATH);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfRenderWindow_setIcon(window, sfImage_getSize(image).x, sfImage_getSize(image).y, sfImage_getPixelsPtr(image));
|
|
sfImage_destroy(image);
|
|
/* ________________________________________________________________________________________ */
|
|
|
|
// Le programme tournera avec un nombre de FPS limité, afin de contenir l'utilisation CPU...
|
|
sfRenderWindow_setFramerateLimit(window, FRAMERATELIMITSLEEP);
|
|
|
|
// On empêche la répétition des touches dans le futur...
|
|
sfRenderWindow_setKeyRepeatEnabled(window, false);
|
|
|
|
return window;
|
|
}
|
|
|
|
|
|
sfRenderTexture* initialisationRenderTexture(const uint16_t width, const uint16_t height)
|
|
{
|
|
sfRenderTexture *renderTexture = sfRenderTexture_create(width, height, sfFalse);
|
|
|
|
if(renderTexture == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création d'une nouvelle texture de rendu..\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfRenderTexture_setSmooth(renderTexture, true);
|
|
|
|
return renderTexture;
|
|
}
|
|
|
|
|
|
sfCircleShape* creerCercle(const sfVector2f position, const float rayon, const sfColor couleur)
|
|
{
|
|
sfCircleShape *shape = sfCircleShape_create();
|
|
|
|
if(shape == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création du cercle de centre (%f, %f) et de rayon %f.\n", position.x, position.y, rayon);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfCircleShape_setPosition(shape, (sfVector2f){position.x - rayon, position.y - rayon});
|
|
sfCircleShape_setRadius(shape, rayon);
|
|
sfCircleShape_setFillColor(shape, couleur);
|
|
|
|
return shape;
|
|
}
|
|
|
|
|
|
sfConvexShape* creerRectangle(const sfVector2f positionHG, const sfVector2f positionBD, const sfColor couleur)
|
|
{
|
|
sfConvexShape *shape = sfConvexShape_create();
|
|
|
|
if(shape == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création du rectangle de point HAUT GAUCHE (%f, %f), et de point BAS DROIT (%f,%f).\n", positionHG.x, positionHG.y, positionBD.x, positionBD.y);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfConvexShape_setPointCount(shape, 4);
|
|
|
|
sfConvexShape_setPoint(shape, 0, (sfVector2f){positionHG.x, positionHG.y});
|
|
sfConvexShape_setPoint(shape, 1, (sfVector2f){positionBD.x, positionHG.y});
|
|
sfConvexShape_setPoint(shape, 2, (sfVector2f){positionBD.x, positionBD.y});
|
|
sfConvexShape_setPoint(shape, 3, (sfVector2f){positionHG.x, positionBD.y});
|
|
|
|
sfConvexShape_setFillColor(shape, couleur);
|
|
|
|
return shape;
|
|
}
|
|
|
|
|
|
sfVertexArray* creerDroite(const sfVector2f position1, const sfVector2f position2, const sfColor couleur)
|
|
{
|
|
sfVertexArray *shape = sfVertexArray_create();
|
|
|
|
if(shape == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création de la droite de (%f, %f) à (%f, %f)\n", position1.x, position1.y, position2.x, position2.y);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfVertexArray_setPrimitiveType(shape, sfLines);
|
|
|
|
sfVertexArray_append(shape, (sfVertex){position1, couleur, (sfVector2f){0.0, 0.0}});
|
|
sfVertexArray_append(shape, (sfVertex){position2, couleur, (sfVector2f){0.0, 0.0}});
|
|
|
|
return shape;
|
|
}
|
|
|
|
|
|
sfText* creerTexte(const sfVector2f position, const char *const chaine, const sfFont *const font, const uint16_t taille, const sfColor couleur)
|
|
{
|
|
sfText *text = sfText_create();
|
|
|
|
if(text == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création du texte: \"%s\".\n", chaine);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfText_setPosition(text, position);
|
|
sfText_setString(text, chaine);
|
|
sfText_setFont(text, font);
|
|
sfText_setCharacterSize(text, taille);
|
|
sfText_setColor(text, couleur);
|
|
|
|
return text;
|
|
}
|
|
|
|
|
|
|
|
sfVertexArray* creerDroiteFromRoute(Route route, uint8_t numRoute, Mode mode)
|
|
{
|
|
sfVertexArray *ligneRoute = sfVertexArray_create();
|
|
|
|
if(ligneRoute == NULL)
|
|
{
|
|
fprintf(stderr, "Erreur lors de la création de la route d\'indice %u.", numRoute);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
sfVertexArray_setPrimitiveType(ligneRoute, sfLinesStrip);
|
|
|
|
for(uint32_t i = 0; i < route.nbPts; i++)
|
|
{
|
|
if(route.chemin[i]->aSupprimer)
|
|
{
|
|
if(mode != MODE_PREVIEW && mode != MODE_PREVIEW_SUGG)
|
|
{
|
|
sfVertexArray_append(ligneRoute, (sfVertex){route.chemin[i]->posConv, COULEUR_POINT_SUPPRIME, route.chemin[i]->posConv});
|
|
}
|
|
else
|
|
{
|
|
sfVertexArray_append(ligneRoute, (sfVertex){route.chemin[i]->posConv, COULEUR_INVISIBLE, route.chemin[i]->posConv});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Route* r = (Route*)route.chemin[i]->ptOnStructure;
|
|
if(!(route.chemin[i]->type == AGGLOMERAT))
|
|
{
|
|
if((r->ptAgglo[0] != NULL && r->ptAgglo[0]->aSupprimer) || (r->ptAgglo[1] != NULL && r->ptAgglo[1]->aSupprimer))
|
|
{
|
|
if(mode != MODE_PREVIEW_SUGG)
|
|
sfVertexArray_append(ligneRoute, (sfVertex){route.chemin[i]->posConv, COULEUR_POINT_SUGGERE, route.chemin[i]->posConv});
|
|
}
|
|
else
|
|
{
|
|
sfVertexArray_append(ligneRoute, (sfVertex){route.chemin[i]->posConv, COULEUR_POINT, route.chemin[i]->posConv});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sfVertexArray_append(ligneRoute, (sfVertex){route.chemin[i]->posConv, COULEUR_POINT, route.chemin[i]->posConv});
|
|
}
|
|
}
|
|
}
|
|
|
|
return ligneRoute;
|
|
}
|