home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / xfedor.zip / XFree86 / src / xfedor / ed_cercle.c < prev    next >
C/C++ Source or Header  |  1999-03-02  |  2KB  |  110 lines

  1. /* Copyright 1989 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2. #include <stdio.h>
  3. #include <math.h>        /* sqrt */
  4. #include "couche.h"        /* myEvent */
  5. #include "style.h"        /* NORMAL .. */
  6.  
  7. static CirclePoint(x,y,dx,dy)
  8.     int x,y,dx,dy ;
  9. {
  10.      Adjpoint(x + dx, y + dy);  
  11.     Adjpoint(x - dx, y - dy);  
  12.     Adjpoint(x - dy, y + dx);  
  13.     Adjpoint(x + dy, y - dx);  
  14. }
  15.  
  16. static CircleLine(x1,x2,y)
  17.     int x1,x2,y;
  18. {
  19.     register int i ;
  20.     
  21.     for (i= x1 ; i<= x2 ; i++) Adjpoint(i,y);
  22.  
  23. }
  24.  
  25. static CarCercle(x, y, r, click)
  26.     int             x, y, r;
  27.     int             click;
  28. {
  29.     register int E,px,py,oldpx ;
  30.  
  31.     px  =  r ;
  32.     py = 1 ;
  33.     E = 0 ;
  34.     if (click == 1) {    /* contour */
  35.     CirclePoint(x,y,r,0);
  36.     while (px > py) {
  37.         CirclePoint(x,y,px,py);
  38.           CirclePoint(x,y,py,px);
  39.           py++ ;
  40.           if ( E <= 0 ) E += (py << 1) + 1 ; 
  41.             else { px -- ; E += (py - px + 1) << 1 ;}
  42.     }
  43.     if (px == py) CirclePoint(x,y,px,py);
  44.     } else {         /* plein */
  45.     CircleLine(x-r,x+r,y);
  46.     oldpx = 0 ;
  47.     while (px > py) {
  48.         CircleLine(x-px,x+px,y+py);
  49.         CircleLine(x-px,x+px,y-py);
  50.         if (px != oldpx) {
  51.             CircleLine(x-py,x+py,y+px);
  52.             CircleLine(x-py,x+py,y-px);
  53.             oldpx = px ;
  54.         }
  55.           py++ ;
  56.           if ( E <= 0 ) E += (py << 1) + 1 ; 
  57.             else { px -- ; E += (py - px + 1) << 1 ;}
  58.     }
  59.     if (px == py) {
  60.         CircleLine(x-px,x+px,y+py);
  61.         CircleLine(x-px,x+px,y-py);
  62.     }
  63.     }
  64.     Aff_all() ;
  65.     CarFen() ;
  66. }
  67.  
  68.  
  69. Autom_cercle(pev)
  70.     myEvent *        pev;
  71. {
  72.     static int      x, y;
  73.  
  74.     switch (pev->type) {
  75.     case EnterZone:
  76.         Afficher_boutons("OUTSIDE", "FILLED");
  77.         x = -1;
  78.         break;
  79.     case ButtonPressed:
  80.         if (x == -1) {
  81.             Afficher_boutons("RADIUS", "RADIUS");
  82.             x = pev->x;
  83.             y = pev->y;
  84.             stylesouris(LIGNE, x, y);
  85.         }
  86.         break;
  87.     case ButtonReleased:
  88.         stylesouris(NORMAL, 0, 0);
  89.         Afficher_boutons("OUTSIDE", "FILLED");
  90.         if (x != -1) {
  91.             int             r;
  92.             Dodo();
  93.             r = (int) sqrt((double)
  94.                        ((x - pev->x) * (x - pev->x) +
  95.                     (y - pev->y) * (y - pev->y)));
  96.             CarCercle(convert(x), convert(y),convert(r), pev->click);
  97.         }
  98.         x = -1;
  99.         break;
  100.     case MoveMouse:
  101.         break;
  102.     case CloseWindow : break ;                
  103.     case LeaveZone:
  104.         stylesouris(NORMAL, 0, 0);
  105.         Afficher_numview(-1, -1);    /* restaure le gris */
  106.         Afficher_boutons("", "");
  107.         break;
  108.     }
  109. }
  110.