123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "Point.h"
- Point::Point(int rayon,Uint32 couleur)
- :m_rayon(rayon)
- {
- m_pixel = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 16, 0, 0, 0, 0);
- SDL_FillRect(m_pixel,NULL,couleur);
- if (!m_pixel)
- {
- std::cout << "Impossible de créer la surface dans l'objet Point " << SDL_GetError() << std::endl;
- }
- }///Constructeur standard
- Point::Point(int rayon,Uint32 couleur,int transparence)
- :m_rayon(rayon)
- {
- m_pixel = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 16, 0, 0, 0, 0);
- SDL_FillRect(m_pixel,NULL,couleur);
- if (!m_pixel)
- {
- std::cout << "Impossible de créer la surface dans l'objet Point " << SDL_GetError() << std::endl;
- }
- }///Constructeur +transparence
- Point::~Point()
- {
- SDL_FreeSurface(m_pixel);
- m_pixel=0;
- std::cout << "Destruction du point effective. " << std::endl;
- }///Destructeur
- int Point::getRayon()
- {
- return m_rayon;
- }///getRayon
- void Point::afficherPoint(SDL_Surface *screen,int const x, int const y)
- {
- int distance(0);
- SDL_Rect position;
- for (int i(x-m_rayon); i<=x+m_rayon; i++)
- {
- for (int j(y-m_rayon); j<=y+m_rayon; j++)
- {
- distance = pow(i-x,2)+pow(j-y,2);
- if (distance <= pow(m_rayon,2))
- {
- position.x=i;
- position.y=j;
- SDL_BlitSurface(m_pixel, 0, screen, &position);
- }//test blit
- }//for j
- }//for i
- }///afficherPoint
- SDL_Surface* createPoint(int rayon,Uint32 couleur)
- {
- return createCircle(rayon,couleur,0);
- }///createPoint
- SDL_Surface* createCircle(int rayOut,Uint32 couleur,int rayIn)
- {
- // [1] Création des composants
- int diametre(rayOut*2);
- SDL_Surface* point = SDL_CreateRGBSurface(SDL_HWSURFACE, diametre, diametre, 16, 0, 0, 0, 0);
- SDL_Surface* pixel = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 16, 0, 0, 0, 0);
- SDL_FillRect(pixel,NULL,couleur);
- int distance(0);
- int ext(rayOut*rayOut);
- int ins(rayIn*rayIn);
- SDL_Rect pos={0,0,0,0};
- int x;
- int y;
- // [2] Traçage du cercle
- for (x=-rayOut; x<rayOut; x++)
- {
- for (y=-rayOut; y<rayOut; y++)
- {
- distance = y*y+x*x;
- if (distance <= ext && distance >= ins)
- {
- pos.x=x+rayOut;
- pos.y=y+rayOut;
- SDL_BlitSurface(pixel, 0, point, &pos);
- }//test blit
- }//for j
- }//for i
- // [3] Traitement transparence
- SDL_SetColorKey(point,SDL_SRCCOLORKEY,SDL_MapRGB(point->format,0,0,0));
- // [4] Renvoi
- SDL_FreeSurface(pixel);
- return point;
- }///createCircle
|