Geoffrey Frogeye
82a60fccf9
Passage en v1.0.0 finale (il faut bien, à un moment...). * Traitement image & commandes * Ajout de la fonction teinte * Ajout de la fonction saturation * Ajout de la fonction luminosité * Utilitaires * Ajout de conversions RVB→TSL & TSL→RVB pour les fonctions teinte, saturation et luminosité * L'image par défaut est désormais générée à partir de teinte et luminosité * Affichage de la fenêtre * La taille de l'écran est récupérable * L'échelle est désormais variable et est calculée selon les dimensions de l'écran
110 lines
3.1 KiB
C++
110 lines
3.1 KiB
C++
#include <SDL/SDL.h>
|
|
#include <string>
|
|
|
|
int fenetreDimensionX; // Stocke les dimensions X de la fenêtre
|
|
int fenetreDimensionY; // Stocke les dimensions Y de la fenêtre
|
|
int ecranX = 1024;
|
|
int ecranY = 1080;
|
|
bool fenetreOuverte = false;
|
|
SDL_Surface *fenetreEcran;
|
|
SDL_Surface *fenetreImage;
|
|
|
|
|
|
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
|
|
int nbOctetsParPixel = surface->format->BytesPerPixel;
|
|
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
|
|
|
|
switch (nbOctetsParPixel) {
|
|
case 1:
|
|
*p = pixel;
|
|
break;
|
|
|
|
case 2:
|
|
*(Uint16 *)p = pixel;
|
|
break;
|
|
|
|
case 3:
|
|
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
|
|
p[0] = (pixel >> 16) & 0xff;
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
p[2] = pixel & 0xff;
|
|
} else {
|
|
p[0] = pixel & 0xff;
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
p[2] = (pixel >> 16) & 0xff;
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
*(Uint32 *)p = pixel;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void s_nomFenetre(std::string nom) { // Change le nom de la fenêtre
|
|
SDL_WM_SetCaption(nom.c_str(), NULL);
|
|
}
|
|
|
|
void pointFenetre(int x, int y, int r, int v, int b) {
|
|
// std::cout << "(" << x << ";" << y << ") = (" << r << ";" << v << ";" << b << ")" << std::endl; // DEBUG
|
|
Uint32 pixel;
|
|
Uint8 u_r, u_v, u_b, u_a;
|
|
u_r = (r > 255 ? 0xff : (Uint8) r);
|
|
u_v = (v > 255 ? 0xff : (Uint8) v);
|
|
u_b = (b > 255 ? 0xff : (Uint8) b);
|
|
u_a = 0xff;
|
|
pixel = SDL_MapRGBA(fenetreImage->format, u_r, u_v, u_b, u_a);
|
|
definirPixel(fenetreImage, x, y, pixel);
|
|
}
|
|
|
|
void afficherFenetre() {
|
|
SDL_Rect position;
|
|
position.x = 0;
|
|
position.y = 0;
|
|
SDL_UnlockSurface(fenetreImage);
|
|
SDL_BlitSurface(fenetreImage, NULL, fenetreEcran, &position);
|
|
SDL_Flip(fenetreEcran);
|
|
SDL_LockSurface(fenetreImage);
|
|
}
|
|
|
|
void attendreFenetre() {
|
|
SDL_Event evenement;
|
|
|
|
do {
|
|
SDL_WaitEvent(&evenement);
|
|
} while (evenement.type != SDL_QUIT &&
|
|
evenement.type != SDL_KEYDOWN); //|| evenement.type != SDL_KEYDOWN);
|
|
}
|
|
|
|
void fermerFenetre() {
|
|
SDL_UnlockSurface(fenetreImage);
|
|
SDL_FreeSurface(fenetreImage);
|
|
SDL_Quit();
|
|
fenetreOuverte = false;
|
|
}
|
|
|
|
|
|
void ouvrirFenetre(int dimensionX, int dimensionY,
|
|
std::string nom) { // Crée une fenêtre
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
fenetreDimensionX = dimensionX;
|
|
fenetreDimensionY = dimensionY;
|
|
fenetreEcran = SDL_SetVideoMode(fenetreDimensionX, fenetreDimensionY, 32,
|
|
SDL_HWSURFACE);
|
|
fenetreImage = SDL_CreateRGBSurface(SDL_HWSURFACE, fenetreDimensionX,
|
|
fenetreDimensionY, 32, 0, 0, 0, 0);
|
|
SDL_FillRect(fenetreImage, NULL, SDL_MapRGB(fenetreEcran->format, 0, 0, 0));
|
|
s_nomFenetre(nom);
|
|
SDL_LockSurface(fenetreImage);
|
|
fenetreOuverte = true;
|
|
}
|
|
|
|
void actualiserDimensionsEcran() {
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
const SDL_VideoInfo *info = SDL_GetVideoInfo();
|
|
ecranX = info->current_w;
|
|
ecranY = info->current_h;
|
|
SDL_Quit();
|
|
}
|