Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*!
  2.   \file Draw_FillRound.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. #if SDL_DRAW_BPP == 1
  24. #define SDL_DRAW_PUTPIXEL \
  25.   memset(p0, color, X2center - Xcenter + 2*corner+1);                      \
  26.   memset(p1, color, X2center - Xcenter + 2*corner+1);                      \
  27.   p0 = ((Uint8*)super->pixels+(Y2center+corner)*super->pitch+(Xcenter-x)); \
  28.   p1 = ((Uint8*)super->pixels+(Ycenter-corner)*super->pitch +(Xcenter-x)); \
  29.   memset(p0, color, X2center - Xcenter + 2*x+1);                           \
  30.   memset(p1, color, X2center - Xcenter + 2*x+1);
  31.  
  32. #elif SDL_DRAW_BPP == 2
  33. #define SDL_DRAW_PUTPIXEL \
  34.   i = X2center - Xcenter + 2*corner+1;                    \
  35.   switch( i % 4 ) {                                       \
  36.     do{                                                   \
  37.       case 0: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  38.               p0+=2; p1+=2;                               \
  39.       case 3: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  40.               p0+=2; p1+=2;                               \
  41.       case 2: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  42.               p0+=2; p1+=2;                               \
  43.       case 1: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  44.               p0+=2; p1+=2;                               \
  45.     }while( (i-=4) > 0 );                                 \
  46.   }                                                       \
  47.   p0 = ((Uint8*)super->pixels+(Y2center+corner)*super->pitch+(Xcenter-x)*2); \
  48.   p1 = ((Uint8*)super->pixels+(Ycenter-corner)*super->pitch +(Xcenter-x)*2); \
  49.   i = X2center - Xcenter + 2*x+1;                         \
  50.   switch( i % 4 ) {                                       \
  51.     do{                                                   \
  52.       case 0: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  53.               p0+=2; p1+=2;                               \
  54.       case 3: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  55.               p0+=2; p1+=2;                               \
  56.       case 2: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  57.               p0+=2; p1+=2;                               \
  58.       case 1: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \
  59.               p0+=2; p1+=2;                               \
  60.     }while( (i-=4) > 0 );                                 \
  61.   }
  62.  
  63. #elif SDL_DRAW_BPP == 3
  64. #define SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  65.     if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
  66.       p0[0] = colorbyte2;                   \
  67.       p0[1] = colorbyte1;                   \
  68.       p0[2] = colorbyte0;                   \
  69.       p1[0] = colorbyte2;                   \
  70.       p1[1] = colorbyte1;                   \
  71.       p1[2] = colorbyte0;                   \
  72.     } else {                                \
  73.       p0[0] = colorbyte0;                   \
  74.       p0[1] = colorbyte1;                   \
  75.       p0[2] = colorbyte2;                   \
  76.       p1[0] = colorbyte0;                   \
  77.       p1[1] = colorbyte1;                   \
  78.       p1[2] = colorbyte2;                   \
  79.     }
  80.  
  81. #define SDL_DRAW_PUTPIXEL \
  82.   i = X2center - Xcenter + 2*corner+1;    \
  83.   switch( i % 4 ) {                       \
  84.     do{                                   \
  85.       case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  86.               p0+=3; p1+=3;               \
  87.       case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  88.               p0+=3; p1+=3;               \
  89.       case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  90.               p0+=3; p1+=3;               \
  91.       case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  92.               p0+=3; p1+=3;               \
  93.     }while( (i-=4) > 0 );                 \
  94.   }                                       \
  95.   p0 = ((Uint8*)super->pixels+(Y2center+corner)*super->pitch+(Xcenter-x)*3); \
  96.   p1 = ((Uint8*)super->pixels+(Ycenter-corner)*super->pitch +(Xcenter-x)*3); \
  97.   i = X2center - Xcenter + 2*x+1;         \
  98.   switch( i % 4 ) {                       \
  99.     do{                                   \
  100.       case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  101.               p0+=3; p1+=3;               \
  102.       case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  103.               p0+=3; p1+=3;               \
  104.       case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  105.               p0+=3; p1+=3;               \
  106.       case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX \
  107.               p0+=3; p1+=3;               \
  108.     }while( (i-=4) > 0 );                 \
  109.   }
  110.  
  111.  
  112. #elif SDL_DRAW_BPP == 4
  113.  
  114. #ifdef __linux__
  115. #define SDL_DRAW_WMEMSET_START \
  116. if (sizeof(wchar_t) == sizeof(Uint32)) { \
  117.   wmemset((wchar_t*)p0, color, X2center - Xcenter + 2*corner+1); \
  118.   wmemset((wchar_t*)p1, color, X2center - Xcenter + 2*corner+1); \
  119.   p0 = ((Uint8*)super->pixels+(Y2center+corner)*super->pitch+(Xcenter-x)*4); \
  120.   p1 = ((Uint8*)super->pixels+(Ycenter-corner)*super->pitch +(Xcenter-x)*4); \
  121.   wmemset((wchar_t*)p0, color, X2center - Xcenter + 2*x+1); \
  122.   wmemset((wchar_t*)p1, color, X2center - Xcenter + 2*x+1); \
  123. } else {
  124. #define SDL_DRAW_WMEMSET_END }
  125. #else
  126. #define SDL_DRAW_WMEMSET_START
  127. #define SDL_DRAW_WMEMSET_END
  128. #endif
  129.  
  130. #define SDL_DRAW_PUTPIXEL \
  131. SDL_DRAW_WMEMSET_START                                    \
  132.   i = X2center - Xcenter + 2*corner+1;                    \
  133.   switch( i % 4 ) {                                       \
  134.     do{                                                   \
  135.       case 0: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  136.               p0+=4; p1+=4;                               \
  137.       case 3: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  138.               p0+=4; p1+=4;                               \
  139.       case 2: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  140.               p0+=4; p1+=4;                               \
  141.       case 1: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  142.               p0+=4; p1+=4;                               \
  143.     }while( (i-=4) > 0 );                                 \
  144.   }                                                       \
  145.   p0 = ((Uint8*)super->pixels+(Y2center+corner)*super->pitch+(Xcenter-x)*4); \
  146.   p1 = ((Uint8*)super->pixels+(Ycenter-corner)*super->pitch +(Xcenter-x)*4); \
  147.   i = X2center - Xcenter + 2*x+1;                         \
  148.   switch( i % 4 ) {                                       \
  149.     do{                                                   \
  150.       case 0: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  151.               p0+=4; p1+=4;                               \
  152.       case 3: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  153.               p0+=4; p1+=4;                               \
  154.       case 2: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  155.               p0+=4; p1+=4;                               \
  156.       case 1: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \
  157.               p0+=4; p1+=4;                               \
  158.     }while( (i-=4) > 0 );                                 \
  159.   }                                                       \
  160. SDL_DRAW_WMEMSET_END
  161.  
  162. #endif /*SDL_DRAW_BPP*/
  163.  
  164.  
  165. void SDL_DRAWFUNCTION(SDL_Surface *super,
  166.                       Sint16 x0,Sint16 y0, Uint16 w,Uint16 h,
  167.                       Uint16 corner, Uint32 color)
  168. {
  169. #if SDL_DRAW_BPP == 3
  170.   Uint8 colorbyte0 = (Uint8) (color & 0xff);
  171.   Uint8 colorbyte1 = (Uint8) ((color >> 8)  & 0xff);
  172.   Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff);
  173. #endif
  174.  
  175.   register Uint8 *p0;
  176.   register Uint8 *p1;
  177. #if SDL_DRAW_BPP != 1
  178.   register Sint16 i;
  179. #endif
  180.   Sint16 dx, dy;
  181.  
  182.   Sint16 Xcenter, Ycenter, X2center, Y2center;
  183.  
  184.   Sint16 x = 0;
  185.   Sint16 rightInc = 6;
  186.   Sint16 d, diagonalInc;
  187.  
  188.   SDL_Rect r;
  189.  
  190.  
  191.   if (w==0 || h==0)  return;
  192.  
  193.   /*TODO: We can do better :-)*/
  194.   if (corner!=0) {
  195.     d = w<h ? w : h;
  196.     --corner;
  197.     if (corner!=0 && corner+2 >= d ) {
  198.       if (corner+2 == d)  --corner;
  199.       else corner = 0;
  200.     }
  201.   }
  202.  
  203.   d = 3 - (corner<<1);
  204.   diagonalInc = 10 - (corner<<2);
  205.  
  206.   /*Rectangles*/
  207.   dx = w - (corner<<1);
  208.   Xcenter = x0+corner;
  209.   dy = h - (corner<<1);
  210.   Ycenter = y0+corner;
  211.  
  212.   /*Centers*/
  213.   X2center=Xcenter+dx-1;
  214.   Y2center=Ycenter+dy-1;
  215.  
  216.   r.x = x0; r.y = Ycenter;
  217.   r.w = w; r.h = dy;
  218.   SDL_FillRect(super, &r, color);
  219.  
  220.   while (x < corner) {
  221.  
  222.     p0 = ((Uint8*)super->pixels+(Ycenter-x)*super->pitch +
  223.                                        (Xcenter-corner)*SDL_DRAW_BPP);
  224.     p1 = ((Uint8*)super->pixels+(Y2center+x)*super->pitch +
  225.                                         (Xcenter-corner)*SDL_DRAW_BPP);
  226.  
  227.     SDL_DRAW_PUTPIXEL
  228.  
  229.     if (d >= 0) {
  230.       d += diagonalInc;
  231.       diagonalInc += 8;
  232.       --corner;
  233.     } else {
  234.       d += rightInc;
  235.       diagonalInc += 4;
  236.     }
  237.     rightInc += 4;
  238.     ++x;
  239.   }/*while*/
  240.  
  241. }/*Draw_FillRound*/
  242.  
  243.  
  244. #undef SDL_DRAW_PUTPIXEL
  245.  
  246. #undef SDL_DRAW_WMEMSET_START
  247. #undef SDL_DRAW_WMEMSET_END
  248.  
  249.