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/creation.c

145 lines
4.3 KiB
C

#include "creation.h"
sfRenderWindow* initialisationFenetre(void)
{
sfVideoMode mode = {WIDTH, HEIGHT, BITSPERPIXEL};
sfRenderWindow *window = sfRenderWindow_create(mode, 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 sous Linux apparemment... Mais l'idée y est ! */
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);
image = NULL;
/* ____________________________________________________________________________________ */
// 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);
}
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);
}
sfVector2f positionCercle = {position.x - rayon, position.y - rayon};
sfCircleShape_setPosition(shape, positionCercle);
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);
sfVector2f positionA = {positionHG.x, positionHG.y};
sfVector2f positionB = {positionHG.x + positionBD.x, positionHG.y};
sfVector2f positionC = {positionHG.x + positionBD.x, positionHG.y + positionBD.y};
sfVector2f positionD = {positionHG.x, positionHG.y + positionBD.y };
sfConvexShape_setPoint(shape, 0, positionA);
sfConvexShape_setPoint(shape, 1, positionB);
sfConvexShape_setPoint(shape, 2, positionC);
sfConvexShape_setPoint(shape, 3, positionD);
sfConvexShape_setFillColor(shape, couleur);
return shape;
}
sfConvexShape* creerDroite(const sfVector2f position1, const sfVector2f position2, const sfColor couleur)
{
sfConvexShape *shape = sfConvexShape_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);
}
sfConvexShape_setPointCount(shape, 4);
sfVector2f positionA = {position1.x + OFFSETFORLINES, position1.y};
sfVector2f positionB = {position1.x, position1.y + OFFSETFORLINES};
sfVector2f positionC = {position2.x + OFFSETFORLINES, position2.y};
sfVector2f positionD = {position2.x, position2.y + OFFSETFORLINES};
sfConvexShape_setPoint(shape, 0, positionA);
sfConvexShape_setPoint(shape, 1, positionB);
sfConvexShape_setPoint(shape, 3, positionC);
sfConvexShape_setPoint(shape, 2, positionD);
sfConvexShape_setFillColor(shape, couleur);
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;
}