retourner.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "retourner.h"
  2. SDL_Surface* retournement(SDL_Surface* originale, int nbQuarts)
  3. {
  4. //Création de la seconde surface
  5. SDL_Surface* pivot(0);
  6. if (nbQuarts%2)
  7. pivot=SDL_CreateRGBSurface(SDL_HWSURFACE,originale->h,originale->w,32,0,0,0,0);
  8. else
  9. pivot=SDL_CreateRGBSurface(SDL_HWSURFACE,originale->w,originale->h,32,0,0,0,0);
  10. //Photocopie quart de tour
  11. SDL_Rect fromPos={0,0,1,1};
  12. SDL_Rect toPos={0,0,0,0};
  13. for (fromPos.x = 0; fromPos.x < originale->w; fromPos.x++)
  14. for (fromPos.y = 0; fromPos.y < originale->h; fromPos.y++)
  15. {
  16. if (nbQuarts%4 == 0)
  17. {
  18. toPos.x=fromPos.x;
  19. toPos.y=fromPos.y;
  20. }
  21. if (nbQuarts%4 == 1)
  22. {
  23. toPos.x=originale->h-fromPos.y;
  24. toPos.y=fromPos.x;
  25. }
  26. if (nbQuarts%4 == 2)
  27. {
  28. toPos.x=originale->w-fromPos.x;
  29. toPos.y=originale->h-fromPos.y;
  30. }
  31. if (nbQuarts%4 == 3)
  32. {
  33. toPos.x=fromPos.y;
  34. toPos.y=originale->w-fromPos.x;
  35. }
  36. SDL_BlitSurface(originale,&fromPos,pivot,&toPos);
  37. }
  38. return pivot;
  39. }