home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / xfedor.zip / XFree86 / src / xfedor / ed_line.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 "couche.h"    /* myEvent */
  4. #include "style.h"    /* NORMAL .. */
  5.  
  6. static Carline(xorig,yorig,xfin,yfin)
  7.     int xorig,yorig,xfin,yfin ;
  8.  
  9. {
  10.      register short e,s1,s2,dx,dy;
  11.      int x,y ;
  12.      int inter,i;
  13.  
  14.      if ((xorig == xfin)&&(yorig == yfin))    
  15.         { Adjpoint(xorig,yorig);
  16.           return;
  17.         }  
  18.      x = xorig;
  19.      y = yorig;
  20.      if ((dx = (xfin - xorig)) <0)
  21.          {s1 = -1;
  22.           dx = -dx;
  23.          }
  24.          else
  25.          {if ((xfin - xorig) >0)
  26.              { s1 = 1;}
  27.              else
  28.              { s1 = 0;}
  29.          }
  30.      if ((dy = (yfin - yorig)) <0)
  31.          {s2 = -1;
  32.           dy = -dy;
  33.          }
  34.          else
  35.          {if ((yfin -yorig) >0)
  36.              { s2 = 1;}
  37.              else
  38.              { s2 = 0;}
  39.          }
  40.     /* on va echanger dx & dy suivant la pente */
  41.     if ( dy > dx)
  42.       { i = dx;
  43.         dx = dy;
  44.         dy = i;
  45.         inter = 1 ;
  46.       }
  47.       else
  48.       { inter = 0;}
  49.  
  50.     /* erreur initiale */
  51.     e = 2*dy - dx;
  52.     for (i = 1; i<=dx; i+=1)
  53.        {
  54.         Adjpoint(x,y);
  55.         while (e >= 0)
  56.            {
  57.             if (inter)
  58.                { x += s1;}
  59.                else
  60.                { y += s2;}
  61.             e -= 2*dx;
  62.            } /* end while */
  63.         if (inter)
  64.              { y += s2;}
  65.              else
  66.              { x += s1;}
  67.         e += 2*dy;
  68.        } /* end for */
  69.           /* ON AFFICHE LE DERNIER POINT */  
  70.      Adjpoint(x,y);
  71.      Aff_all() ;
  72.      CarFen();
  73. }      
  74.  
  75.  
  76. Autom_line (pev)
  77.     myEvent * pev ; 
  78. {   static int x,y ;
  79.     
  80.     switch (pev->type) {
  81.     case EnterZone : Afficher_boutons("ORIGIN","ORIGIN");
  82.              x = -1 ;
  83.              break ;
  84.     case ButtonPressed : if (x == -1 ) {
  85.                 Afficher_boutons("ENDLINE","ENDLINE");
  86.                     x = pev->x ; 
  87.                     y = pev->y ; 
  88.                      stylesouris(LIGNE,x,y);
  89.                  }
  90.                  break ;
  91.     case ButtonReleased : stylesouris(NORMAL,0,0);
  92.                   Afficher_boutons("ORIGIN","ORIGIN");
  93.                   if (x != -1) {
  94.                 Dodo();
  95.                 Carline(convert(x),
  96.                     convert(y),
  97.                     convert(pev->x),
  98.                     convert(pev->y));
  99.                   }
  100.                   x = -1 ;
  101.                   break ;
  102.     case MoveMouse : break ;                
  103.     case CloseWindow : break ;                
  104.     case LeaveZone : stylesouris(NORMAL,0,0);
  105.                  Afficher_numview(-1,-1) ; /* restaure le gris */
  106.              Afficher_boutons("","");
  107.              break ;
  108.     }
  109.