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

  1. /* Copyright 1989 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2. #include <stdio.h>
  3. #include "clientimage.h"      /* VID */
  4. #include "couche.h"      /*  CURS2 */
  5. #include "sos.h"    /* SOS .. */
  6. #include "fedor.h"      /* fedchar .. */
  7.  
  8.  
  9. extern nf_mono ;
  10. extern fedchar cartrav ;    /* depuis tr_edit */
  11. extern int Baseliney, Xleft ;
  12. extern int BackColor, CurColor ;
  13.  
  14. void Autom_garb();
  15. void Init_garb();
  16. void CopyCar() ;    
  17. void FontToGarb() ;    /* pour tr_font  */
  18. void afficher_car() ;
  19. static void Rast();
  20.  
  21. int nf_garb ;   /* NUMERO DE LA FENETRE POUBELLE */      
  22. int courant ;   /* pour animation */
  23.  
  24.  
  25.     /*---------- reste du LOCAL */
  26.       
  27. # define MAXCARGARB  8      
  28.  
  29. static int idmraster ;    /* id du popup RASTER */
  30. static char *choixrast[] = {"OR","AND","XOR", 0 } ;
  31.  
  32. static int zgarb,zhelp,zput,zget,zrast,zraz ; /* id des zones crees */
  33.      
  34. #define HGARB 128
  35. #define WGARB 128
  36. #define WHELP 10
  37. #define WGARBMENU 100
  38. #define HGARBITEM (HGARB/4)
  39. #define WFEN (WGARB+WHELP+WGARBMENU)
  40.  
  41. #define XGARB (10 + 100+514+12 + 10 + 2)
  42. #define YGARB (10 + 22 + 2*22+130 + 2 + 22 + 7*23 +2) 
  43.  
  44. static fedchar tabgarb[MAXCARGARB] ;  
  45. static int occupe[MAXCARGARB] ;
  46. static int taborx[MAXCARGARB] ;
  47. static int tabory[MAXCARGARB] ;
  48.  
  49. static int BlackColor ;
  50.  
  51. /************************ INIT_GARB ******************/
  52. void Init_garb () 
  53.  
  54. { int i ;
  55.    
  56.      nf_garb = w_ouvrir(nf_mono, XGARB, YGARB, WFEN, HGARB,
  57.               "XFEDOR : buffer",CURS2,
  58.               EnterZone|ButtonPressed|LeaveZone,WMON) ;
  59.  
  60.     zgarb = w_crzon(nf_garb,0,0,WGARB,HGARB,CURS5);
  61.     zhelp = w_crzon(nf_garb,WGARB,0,WGARB+WHELP,HGARB,CURS2);
  62.     zput  = w_crzon(nf_garb,WGARB+WHELP,0,WFEN,HGARBITEM,CURS2);
  63.     zget  = w_crzon(nf_garb,WGARB+WHELP,HGARBITEM,WFEN,2*HGARBITEM,CURS2);
  64.     zrast = w_crzon(nf_garb,WGARB+WHELP,2*HGARBITEM,WFEN,3*HGARBITEM,CURS2);
  65.     zraz  = w_crzon(nf_garb,WGARB+WHELP,3*HGARBITEM,WFEN,4*HGARBITEM,CURS2);
  66.          
  67.     w_montrer(nf_garb) ;    
  68.  
  69.         /* init du tabgarb de fedchar */
  70.     for (i=0 ; i < MAXCARGARB ; i++)      
  71.           { 
  72.         Rast_Init(&tabgarb[i].image,128,128,1);
  73.         Rast_Off(&tabgarb[i].image,BackColor);
  74.                 occupe[i] = 0 ;
  75.           }
  76.  
  77.     idmraster = MenuCreat(choixrast);
  78.     courant = 0 ;
  79.  
  80.     BlackColor = w_blackpixel() ;
  81. }
  82.  
  83. static Reaffich(fen)
  84. int fen ;
  85. {    char s[2] ;
  86.  
  87.     if (fen == nf_garb) {
  88.          w_cleararea(nf_garb,WGARB,0,WGARB+WHELP,HGARB);    /* help */
  89.      s[1] = '\0' ;
  90.      s[0] = 'S' ;
  91.      w_ecrire(nf_garb,s,WGARB+3,HGARB-40);
  92.      w_ecrire(nf_garb,s,WGARB+3,HGARB-10);
  93.      s[0] = 'O' ;
  94.      w_ecrire(nf_garb,s,WGARB+3,HGARB-25);        /* SOS vertical */
  95.  
  96.          w_line(nf_garb,WGARB,0,WGARB,HGARB,ON); 
  97.          w_line(nf_garb,WGARB+WHELP,0,WGARB+WHELP,WGARB+WHELP,ON); 
  98.          w_line(nf_garb,WGARB+WHELP,0,WFEN,0,ON);     
  99.          w_line(nf_garb,WGARB+WHELP,HGARBITEM,WFEN,HGARBITEM,ON); 
  100.          w_line(nf_garb,WGARB+WHELP,2*HGARBITEM,WFEN,2*HGARBITEM,ON); 
  101.          w_line(nf_garb,WGARB+WHELP,3*HGARBITEM,WFEN,3*HGARBITEM,ON); 
  102.  
  103.      w_centrer(nf_garb,"PUT",WGARB+WHELP,0,WFEN,HGARBITEM);
  104.      w_centrer(nf_garb,"GET",WGARB+WHELP,HGARBITEM,WFEN,2*HGARBITEM);
  105.      w_centrer(nf_garb,"RASTER",WGARB+WHELP,2*HGARBITEM,WFEN,3*HGARBITEM);
  106.      w_centrer(nf_garb,"RAZGARB",WGARB+WHELP,3*HGARBITEM,WFEN,4*HGARBITEM);
  107.               
  108.          afficher_car() ;
  109.     }
  110. }
  111.  
  112.  
  113. /************************* procedure AFFICHER_CAR ***********************/
  114. void afficher_car()
  115. {
  116.     char s[2] ;
  117.     s[0] = (char) (courant + 48);
  118.     s[1] = '\0' ;
  119.     w_ecrire(nf_garb,s,130,10);
  120.     if (occupe[courant])    {  /* raster de memoire dans fenetre donne */
  121.            w_bitblt(nf_garb,tabgarb[courant].image,0,0,WGARB,HGARB,0,0) ;
  122.      }
  123.    else w_gris(nf_garb,0,0,WGARB,HGARB) ;
  124. }
  125.  
  126.  
  127. /***************************** procedure RAZGARB **************************/
  128. /* Procedure faisant une remise a zero de la poubelle */
  129.  
  130. static Razgarb()
  131.  
  132. { register int i ;
  133.  
  134.   if (gd_confirm())
  135.    { for(i = 0 ; i < MAXCARGARB ; i++)
  136.      { if (occupe[i])
  137.        { occupe[i] = 0 ;
  138.          Rast_Off(&tabgarb[i].image, BackColor) ;
  139.        }
  140.      }
  141.      courant = 0 ;
  142.      afficher_car() ;
  143.    }
  144. }
  145.  
  146.  
  147. void CopyCar(c1,c2) 
  148. /* metrique seulement */
  149.     fedcharptr c1,c2 ;
  150. {
  151.     strcpy(c2->name,c1->name) ;
  152.     c2->hincr = c1->hincr ;
  153.     c2->vincr = c1->vincr ;
  154.     c2->hadj = c1->hadj ;
  155.     c2->vadj = c1->vadj ;
  156.     c2->up = c1->up ;
  157.     c2->down = c1->down ;
  158.     c2->hsize = c1->hsize ;
  159. }
  160.  
  161. /***************************** procedure Put *******************************/
  162. /* Met le caractere de travail  dans la poubelle[courant] et le montre */
  163.  
  164. static Put()
  165. {
  166.     if (cartrav.hsize > 0){
  167.     CopyCar(&cartrav,&tabgarb[courant]);
  168.     Rast_Copy(cartrav.image,&tabgarb[courant].image);
  169.     taborx[courant] = Xleft ;
  170.     tabory[courant] = Baseliney + cartrav.up ;
  171.  
  172.         occupe[courant] = 1 ;
  173.         afficher_car() ;
  174.     }
  175. }
  176.  
  177.  
  178. void FontToGarb(fedc)
  179.     fedcharptr fedc ;
  180. {
  181.  
  182.     CopyCar(fedc,&tabgarb[courant]);
  183.         Rast_Off(&tabgarb[courant].image,BackColor) ;
  184.     Rast_Op_1n(fedc->image,&tabgarb[courant].image,
  185.             0,0,0,0,
  186.             fedc->hsize,fedc->down-fedc->up,VIDSTR,BlackColor);
  187.     taborx[courant] = 0 ;
  188.     tabory[courant] = 0 ;
  189.     
  190.         occupe[courant] = 1 ;
  191.         afficher_car() ;
  192. }
  193.  
  194.  
  195. /***************************** procedure RASTER ***************************/
  196. static Raster()
  197. {
  198.      switch(MenuPop(idmraster,choixrast)) {
  199.            case 0: Rast(VIDOR);
  200.                    break;
  201.            case 1: Rast(VIDAND);
  202.                    break;
  203.            case 2: Rast(VIDXOR);
  204.                    break;
  205.            default: return;
  206.      }
  207. }
  208.  
  209. static void Rast(mode)
  210.     int mode ;
  211. {    short x1,y1,x2,y2,w,h ;
  212.  
  213.  
  214.         Dodo();
  215.     x1 = Min(Xleft,taborx[courant]) ;
  216.     x2 = Max(Xleft+cartrav.hsize,taborx[courant]+tabgarb[courant].hsize) ;
  217.     w = x2 - x1 ;
  218.     y1 = Min(Baseliney+cartrav.up,tabory[courant]) ;
  219.     y2 = Max(Baseliney+cartrav.down,tabory[courant]+
  220.         tabgarb[courant].down-tabgarb[courant].up);
  221.     h = y2 - y1 ;
  222.         
  223.     Rast_Op(tabgarb[courant].image,&cartrav.image,
  224.         x1,y1,x1,y1,w,h,mode,BackColor);
  225.  
  226.     if (w > cartrav.hsize) cartrav.hsize = w ;
  227.     if (Xleft > taborx[courant]) 
  228.         Xleft = taborx[courant] ;
  229.     if (Baseliney+cartrav.up > tabory[courant])
  230.        cartrav.up = tabory[courant] - Baseliney ;
  231.     if (Baseliney+cartrav.down < tabory[courant]+
  232.             tabgarb[courant].down-tabgarb[courant].up)
  233.        cartrav.down = tabory[courant]+
  234.         tabgarb[courant].down-tabgarb[courant].up - Baseliney ;
  235.  
  236.     MontrerCarTrav() ;
  237. }
  238.  
  239.  
  240. /*************************** procedure GET *****************************/   
  241. static Get()
  242.    
  243. {
  244.         Dodo();
  245.     CopyCar(&tabgarb[courant],&cartrav) ;
  246.     Rast_Copy(tabgarb[courant].image,&cartrav.image);
  247.     Xleft = taborx[courant] ;
  248.     Baseliney = (tabory[courant] - cartrav.up) ;
  249.     if (Baseliney <0) Baseliney = 0 ;
  250.     MontrerCarTrav();    
  251. }
  252.  
  253.    
  254. static int Inverser_zone(zone)
  255.     int zone;
  256. {
  257.     if (zone==zput) w_inv(nf_garb,WGARB+WHELP+2,2,WFEN-2,HGARBITEM-2);else
  258.     if (zone==zget) w_inv(nf_garb,WGARB+WHELP+2,HGARBITEM+2,WFEN-2,2*HGARBITEM-2);else
  259.     if (zone==zrast) w_inv(nf_garb,WGARB+WHELP+2,2*HGARBITEM+2,WFEN-2,3*HGARBITEM-2);else
  260.     if (zone==zraz) w_inv(nf_garb,WGARB+WHELP+2,3*HGARBITEM+2,WFEN-2,4*HGARBITEM-2);
  261. }
  262.  
  263. static int Traiter_clic(evt)
  264.     myEvent * evt ;
  265. {        
  266.     if (evt->zone==zgarb) {
  267.                switch(evt->click){
  268.                       case 1 : 
  269.               courant -= 1 ;
  270.                           if (courant == -1) {courant = MAXCARGARB-1;}
  271.                           afficher_car() ;
  272.                           break ;
  273.                       case 2 : 
  274.               courant = (courant + 1) % MAXCARGARB ;
  275.                           afficher_car() ;
  276.                           break ;
  277.               default : break ;
  278.                     }                           
  279.     } else
  280.     if (evt->zone==zhelp) Helping(GARB); else
  281.     {
  282.        if (evt->zone==zput) Put(); else
  283.        if (evt->zone==zget) Get();  else
  284.        if (evt->zone==zrast) Raster(); else
  285.        if (evt->zone==zraz) Razgarb();
  286.      };                
  287. }
  288.  
  289. /*********************** procedure AUTOM_GARB ***************************/ 
  290. /* Des que le controleur detecte l'entree de la souris dans la poubelle,
  291.    il appelle cette procedure */
  292.  
  293. void Autom_garb(pev) 
  294.   myEvent * pev ;  
  295. {
  296.     static zonecour = 0 ;
  297.  
  298.   switch (pev->type){
  299.     case Exposure : 
  300.         Reaffich(pev->window) ;
  301.         if (zonecour) Inverser_zone(zonecour);
  302.         break ;
  303.     case EnterZone   : 
  304.         if (pev->zone==zgarb) Afficher_boutons("<--","-->") ; else
  305.               if (pev->zone==zhelp) Afficher_boutons("Help","Help") ;else
  306.                       Afficher_boutons("Select","Select") ;
  307.         Inverser_zone(pev->zone);
  308.         zonecour = pev->zone ;
  309.         break;
  310.     case ButtonPressed :  
  311.         Traiter_clic(pev);
  312.                break ;
  313.         case LeaveZone : 
  314.         Inverser_zone(pev->zone);
  315.         zonecour = 0 ;
  316.                 Afficher_boutons("","") ;
  317.                break ;
  318.     case CloseWindow : break ;                
  319.       }
  320. }
  321.             
  322.