Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file Draw_Circle.c
  3.   \author Mario Palomo <mpalomo@ihman.com>
  4.   \author Jose M. de la Huerga Fernández
  5.   \author Pepe González Mora
  6.   \date 05-2002
  7.  
  8.   This library is free software; you can redistribute it and/or
  9.   modify it under the terms of the GNU Library General Public
  10.   License as published by the Free Software Foundation; either
  11.   version 2 of the License, or (at your option) any later version.
  12.  
  13.   This library is distributed in the hope that it will be useful,
  14.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.   Library General Public License for more details.
  17.  
  18.   You should have received a copy of the GNU Library General Public
  19.   License along with this library; if not, write to the Free Foundation,
  20.   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22.  
  23. #define SDL_DRAW_PUTPIXEL_BPP(A, B, C)  \
  24. *(##A##(##B##(Uint8*)super->pixels + (y0+y)*super->pitch +               \
  25.                                           (x0+x)*SDL_DRAW_BPP)) = ##C##; \
  26. *(##A##(##B##(Uint8*)super->pixels + (y0-y)*super->pitch +               \
  27.                                           (x0+x)*SDL_DRAW_BPP)) = ##C##; \
  28. *(##A##(##B##(Uint8*)super->pixels + (y0+y)*super->pitch +               \
  29.                                           (x0-x)*SDL_DRAW_BPP)) = ##C##; \
  30. *(##A##(##B##(Uint8*)super->pixels + (y0-y)*super->pitch +               \
  31.                                           (x0-x)*SDL_DRAW_BPP)) = ##C##; \
  32. *(##A##(##B##(Uint8*)super->pixels + (y0+x)*super->pitch +               \
  33.                                           (x0+y)*SDL_DRAW_BPP)) = ##C##; \
  34. *(##A##(##B##(Uint8*)super->pixels + (y0-x)*super->pitch +               \
  35.                                           (x0+y)*SDL_DRAW_BPP)) = ##C##; \
  36. *(##A##(##B##(Uint8*)super->pixels + (y0+x)*super->pitch +               \
  37.                                           (x0-y)*SDL_DRAW_BPP)) = ##C##; \
  38. *(##A##(##B##(Uint8*)super->pixels + (y0-x)*super->pitch +               \
  39.                                           (x0-y)*SDL_DRAW_BPP)) = ##C##;
  40.  
  41. #if SDL_DRAW_BPP == 1
  42. #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP(0+,0+,color)
  43.  
  44. #elif SDL_DRAW_BPP == 2
  45. #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint16*),0+,color)
  46.  
  47. #elif SDL_DRAW_BPP == 3
  48. #define SDL_DRAW_PUTPIXEL \
  49.   SDL_DRAW_PUTPIXEL_BPP(0+,1+,colorbyte1)   \
  50.   if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {  \
  51.     SDL_DRAW_PUTPIXEL_BPP(0+,0+,colorbyte2)   \
  52.     SDL_DRAW_PUTPIXEL_BPP(0+,2+,colorbyte0) \
  53.   }else{                                  \
  54.     SDL_DRAW_PUTPIXEL_BPP(0+,0+,colorbyte0)   \
  55.     SDL_DRAW_PUTPIXEL_BPP(0+,2+,colorbyte2) \
  56.   }
  57.  
  58. #elif SDL_DRAW_BPP == 4
  59. #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint32*),0+,color)
  60.  
  61. #endif /*SDL_DRAW_BPP*/
  62.  
  63.  
  64. void SDL_DRAWFUNCTION(SDL_Surface *super,
  65.                       Sint16 x0, Sint16 y0, Uint16 r,
  66.                       Uint32 color)
  67. {
  68. #if SDL_DRAW_BPP == 3
  69.   Uint8 colorbyte0 = (Uint8) (color & 0xff);
  70.   Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff);
  71.   Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff);
  72. #endif
  73.  
  74.   Sint16 x = 0;
  75.   Sint16 y = r-1;     /*radius zero == draw nothing*/
  76.   Sint16 d = 3 - 2*r;
  77.   Sint16 diagonalInc = 10 - 4*r;
  78.   Sint16 rightInc = 6;
  79.  
  80.   while (x <= y) {
  81.  
  82.     SDL_DRAW_PUTPIXEL
  83.  
  84.     if (d >=  0) {
  85.       d += diagonalInc;
  86.       diagonalInc += 8;
  87.       y -= 1;
  88.     } else {
  89.       d += rightInc;
  90.       diagonalInc += 4;
  91.     }
  92.     rightInc += 4;
  93.     x += 1;
  94.   }
  95.  
  96. }/*Draw_Circle*/
  97.  
  98.  
  99. #undef SDL_DRAW_PUTPIXEL
  100. #undef SDL_DRAW_PUTPIXEL_BPP
  101.  
  102.