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

  1. /* Copyright 1989 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2. #include <stdio.h>
  3. #include "math.h"               /* ceil , sqrt */
  4. #include "couche.h"         /* myEvent */
  5.  
  6. extern root ;
  7. extern BackColor, CurColor ;
  8.  
  9. void Init_colormap() ;
  10. void Autom_colormap() ;
  11.  
  12. int nf_colormap ;   /* NUMERO DE LA FENETRE COLORMAP */      
  13.  
  14.  
  15.     /*---------- reste du LOCAL */
  16.  
  17. #define XCMAP  200
  18. #define YCMAP  200
  19.  
  20. int wcell ;         /* cote d'une cellule couleur */
  21. int ncell ;         /* nombre de cellule par ligne si fenetre carre */
  22. int xcell ;         /* nombre de cellule par ligne */
  23. int ycell ;         /* nombre de cellule par colonne */
  24. int Wcmap, Hcmap ;  /* dimension de la fenetre */
  25. int ncolors ;       /* nombre de couleurs disponibles au max */
  26.  
  27. void Init_colormap()
  28. {
  29.      ncolors = w_ncolor() ;         /* entree max dans la colormap */
  30.  
  31.      /* on fait une fenetre carre si il y a moins de 16 couleurs, 
  32.     sinon on la fait rectangulaire verticale */
  33.      wcell = (ncolors>16)?16:32 ;
  34.      ncell = (int)ceil(sqrt((double)ncolors)) ;
  35.      xcell = (ncolors>16)?ncell/2:ncell ;
  36.      ycell = (ncolors>16)?ncell*2:ncell ;
  37.      Wcmap = xcell*(wcell+2); 
  38.      Hcmap = ycell*(wcell+2); 
  39.        
  40.      nf_colormap = w_ouvrir(root,XCMAP,YCMAP,2+Wcmap,2+Hcmap,
  41.               "XFEDOR : Colormap Window",
  42.               CURS2,
  43.               EnterWindow|LeaveWindow|ButtonPressed,WMON) ;
  44. }
  45.  
  46.  
  47. static Reaffich(fen)
  48. int fen ;
  49.   int i, j ;
  50.  
  51.   if (fen == nf_colormap)  {
  52.     for (i=0 ; i < xcell ; i++)
  53.       for (j=0 ; j < ycell ; j++)
  54.     w_color(nf_colormap,2+i*(wcell+2),2+j*(wcell+2),
  55.         2+i*(wcell+2)+wcell,2+j*(wcell+2)+wcell,
  56.         ((i*xcell+j)>ncolors)?BackColor:(i*xcell+j));
  57.     /* cad que l'on met du BackColor la ou ya des trous */
  58.   }
  59. }
  60.  
  61.  
  62. static int Traiter_clic(evt)
  63.     myEvent * evt ;
  64. {        
  65.   int i, j ;
  66.  
  67.   if (evt->click == 2) 
  68.     {
  69.       w_cacher(nf_colormap) ;
  70.       return ;
  71.     } else {
  72.       i = (evt->x - 2)/(wcell + 2) ; if (i < 0) i = 0 ;
  73.       j = (evt->y - 2)/(wcell + 2) ; if (j < 0) j = 0 ;
  74.       CurColor = ((i*xcell+j)>ncolors)?BackColor:(i*xcell+j) ;
  75.       Afficher_colors() ;  /* sur fenetre tr_edit */
  76.     }
  77. }
  78.  
  79.  
  80. void Autom_colormap(pev)
  81.     myEvent * pev ;
  82. {
  83.  
  84.      switch (pev->type){
  85.     case EnterWindow   : 
  86.                 Afficher_boutons("Select","Quit") ;
  87.         break;   
  88.     case Exposure :
  89.         Reaffich(pev->window) ;
  90.         break ;
  91.      case ButtonPressed :  
  92.         Traiter_clic(pev);
  93.                break ;
  94.         case LeaveWindow : 
  95.         Afficher_boutons("","") ; 
  96.         break ;
  97.     case CloseWindow :
  98.             w_cacher(nf_colormap) ;
  99.         break ;
  100.       }        
  101. }
  102.  
  103.  
  104.  
  105.