254 lines
7.7 KiB
C
254 lines
7.7 KiB
C
#include "affichage.h"
|
|
|
|
|
|
void displayBackgroundSprite(sfRenderWindow *const window, const sfSprite *const sprite)
|
|
{
|
|
sfRenderWindow_clear(window, COULEUR_GRIS);
|
|
sfRenderWindow_drawSprite(window, sprite, NULL);
|
|
sfRenderWindow_display(window);
|
|
}
|
|
|
|
|
|
void resetTextureAndSpriteFromOriginal(sfRenderTexture *const renderTexture, sfSprite **renderSprite, sfTexture *const originalTexture)
|
|
{
|
|
sfRenderTexture_clear(renderTexture, COULEUR_GRIS);
|
|
|
|
freeSprite(renderSprite);
|
|
*renderSprite = loadSpriteFromTexture((sfVector2f){0.0, 0.0}, originalTexture);
|
|
sfRenderTexture_drawSprite(renderTexture, *renderSprite, NULL);
|
|
}
|
|
|
|
|
|
void dessinerPoint(sfRenderTexture *const renderTexture, sfVector2f points, sfCircleShape **ptrCercle, sfColor couleur)
|
|
{
|
|
sfCircleShape *cercle = creerCercle((sfVector2f){points.x, points.y}, CIRCLERADIUS, couleur);
|
|
sfRenderTexture_drawCircleShape(renderTexture, cercle, NULL);
|
|
|
|
// On sauvegarde l'adresse des cercles pour pouvoir les libérer dans le futur !
|
|
*ptrCercle = cercle;
|
|
}
|
|
|
|
|
|
void dessinerAgglo(sfRenderTexture *const renderTexture, Agglomerat *agglos, sfCircleShape **ptrCercle, uint32_t nbPointAgglosMin, const Carte *const carte, const sfColor couleur)
|
|
{
|
|
float facteur = 1;
|
|
if (carte->echelle > 120000)
|
|
{
|
|
facteur = 0.7;
|
|
}
|
|
if (carte->echelle > 220000)
|
|
{
|
|
facteur = 0.5;
|
|
}
|
|
if (carte->echelle > 500000)
|
|
{
|
|
facteur = 0.3;
|
|
}
|
|
|
|
sfCircleShape *cercle = NULL;
|
|
|
|
if(agglos->nbPts <= nbPointAgglosMin * 1.5)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPts <= nbPointAgglosMin * 2)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 1.5, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 1.5;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPts <= nbPointAgglosMin * 2.5)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 2, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 2;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPts <= nbPointAgglosMin * 3)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 2.5, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 2.5;
|
|
}
|
|
|
|
else
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 3, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sfRenderTexture_drawCircleShape(renderTexture, cercle, NULL);
|
|
*ptrCercle = cercle;
|
|
}
|
|
|
|
|
|
void dessinerAggloGlobal(sfRenderTexture *const renderTexture, AgglomeratGlobal *agglos, sfCircleShape **ptrCercle, uint32_t nbPointAgglosMin, const Carte *const carte, const sfColor couleur)
|
|
{
|
|
float facteur = 1;
|
|
if (carte->echelle > 120000)
|
|
{
|
|
facteur = 0.7;
|
|
}
|
|
if (carte->echelle > 220000)
|
|
{
|
|
facteur = 0.5;
|
|
}
|
|
if (carte->echelle > 500000)
|
|
{
|
|
facteur = 0.3;
|
|
}
|
|
|
|
sfCircleShape *cercle = NULL;
|
|
|
|
if(agglos->nbPtsGlobal <= nbPointAgglosMin * 1.5)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPtsGlobal <= nbPointAgglosMin * 2)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 1.5, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 1.5;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPtsGlobal <= nbPointAgglosMin * 2.5)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 2, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 2;
|
|
}
|
|
|
|
else
|
|
{
|
|
if(agglos->nbPtsGlobal <= nbPointAgglosMin * 3)
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 2.5, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 2.5;
|
|
}
|
|
|
|
else
|
|
{
|
|
cercle = creerCercle((sfVector2f){agglos->moyConv.x, agglos->moyConv.y}, facteur * CIRCLERADIUSAGGLO * 3, couleur);
|
|
agglos->tailleCercle = facteur * CIRCLERADIUSAGGLO * 3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sfRenderTexture_drawCircleShape(renderTexture, cercle, NULL);
|
|
*ptrCercle = cercle;
|
|
}
|
|
|
|
|
|
void afficherCarte(sfRenderTexture *const renderTexture, sfTexture **mapTexture, sfSprite **mapSprite, const char *const cheminFichier)
|
|
{
|
|
*mapTexture = loadTextureFromFile(cheminFichier);
|
|
*mapSprite = loadSpriteFromTexture((sfVector2f){0, 0}, *mapTexture);
|
|
|
|
sfSprite_scale(*mapSprite, (sfVector2f){WIDTH / (float)(MAPSIZE * MAPSCALE), HEIGHT / (float)(MAPSIZE * MAPSCALE)});
|
|
|
|
sfRenderTexture_clear(renderTexture, COULEUR_GRIS);
|
|
sfRenderTexture_drawSprite(renderTexture, *mapSprite, NULL);
|
|
sfRenderTexture_display(renderTexture);
|
|
}
|
|
|
|
|
|
void afficherLoading(sfRenderWindow *const window, sfRenderTexture *renderTexture, sfSprite **renderSprite)
|
|
{
|
|
sfTexture *const texture = loadTextureFromFile(IMAGELOADINGPATH);
|
|
|
|
const sfVector2f scale = {(WIDTH + MENUWIDTH) / (float)sfTexture_getSize(texture).x, HEIGHT / (float)sfTexture_getSize(texture).y};
|
|
const sfVector2f positionSprite = {((WIDTH + MENUWIDTH) / 2.0) - (sfTexture_getSize(texture).x / 2.0 * scale.x), (HEIGHT / 2) - (sfTexture_getSize(texture).y / 2.0 * scale.y)};
|
|
|
|
sfSprite *const sprite = loadSpriteFromTexture(positionSprite, texture);
|
|
sfSprite_setScale(sprite, scale);
|
|
|
|
sfRenderTexture_drawSprite(renderTexture, sprite, NULL);
|
|
sfRenderTexture_display(renderTexture);
|
|
|
|
freeSprite(renderSprite);
|
|
*renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
sfRenderWindow_drawSprite(window, *renderSprite, NULL);
|
|
|
|
sfRenderWindow_display(window);
|
|
|
|
sfTexture_destroy(texture);
|
|
sfSprite_destroy(sprite);
|
|
}
|
|
|
|
|
|
void afficherSablier(sfRenderWindow *const window, sfRenderTexture *renderTexture, sfSprite **renderSprite)
|
|
{
|
|
sfTexture *const texture = loadTextureFromFile(IMAGEHOURGLASSPATH);
|
|
|
|
const double ratio = 5 / 100.0;
|
|
|
|
const sfVector2f scale = {(WIDTH / (float)sfTexture_getSize(texture).x) * ratio, (HEIGHT / (float)sfTexture_getSize(texture).y) * ratio};
|
|
const sfVector2f positionSprite = {WIDTH * (1 - ratio) - (sfTexture_getSize(texture).x / 2.0 * scale.x), HEIGHT * ratio - (sfTexture_getSize(texture).y / 2.0 * scale.y)};
|
|
|
|
sfSprite *const sprite = loadSpriteFromTexture(positionSprite, texture);
|
|
sfSprite_setScale(sprite, scale);
|
|
|
|
sfRenderTexture_drawSprite(renderTexture, sprite, NULL);
|
|
sfRenderTexture_display(renderTexture);
|
|
|
|
*renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
sfRenderWindow_drawSprite(window, *renderSprite, NULL);
|
|
|
|
sfRenderWindow_display(window);
|
|
|
|
sfTexture_destroy(texture);
|
|
sfSprite_destroy(sprite);
|
|
}
|
|
|
|
|
|
void dessinerMenu(sfRenderTexture *const renderTexture, const Menu *const menu)
|
|
{
|
|
for(uint8_t i = 0; i <= menu->sommetTableau; i++)
|
|
{
|
|
sfRenderTexture_drawSprite(menu->renderTextureMenu, menu->liste[i]->spriteButton, NULL);
|
|
}
|
|
|
|
sfSprite *menuSprite = loadSpriteFromRenderTexture(menu->renderTextureMenu);
|
|
sfSprite_setPosition(menuSprite, (sfVector2f){WIDTH, 0});
|
|
|
|
sfRenderTexture_drawSprite(renderTexture, menuSprite, NULL);
|
|
}
|
|
|
|
|
|
Bouton* ajouterBoutonAccueil(const Tool outil, const char *const icone, const sfVector2f *const position, bool lowButt)
|
|
{
|
|
sfVector2f scale;
|
|
if(lowButt)
|
|
{
|
|
scale = (sfVector2f){0.15, 0.15};
|
|
}
|
|
else
|
|
{
|
|
scale = (sfVector2f){0.5, 0.5};
|
|
}
|
|
|
|
Bouton *bouton = loadButtonMenu(outil, "", icone);
|
|
|
|
bouton->spriteButton = loadSpriteFromTexture(*position, bouton->textureButton);
|
|
sfSprite_setScale(bouton->spriteButton, scale);
|
|
|
|
bouton->zone = (Rectangle){*position, {(sfTexture_getSize(bouton->textureButton).x * scale.x + position->x), (sfTexture_getSize(bouton->textureButton).y * scale.y + position->y)}};
|
|
|
|
return bouton;
|
|
}
|
|
|