home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / main / win_alea.c < prev    next >
C/C++ Source or Header  |  1993-03-04  |  5KB  |  221 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    File win_alea.c                            */
  4. /*                                    */
  5. /************************************************************************/
  6. /* Open the window for the random modules                */
  7. /************************************************************************/
  8.  
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/displayinfo.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/gadtools_protos.h>
  17. #include <dos/dos.h>
  18. #include "/includes/struct.h"
  19. #include "/includes/tom_gadget.h"
  20.  
  21. extern    struct my_data    my_info;
  22. extern    struct    appel_proc    data_proc;
  23. #define    MIN_DUREE    10
  24. #define    MAX_DUREE    999
  25. extern    int    nb_module;
  26. extern    char    *p_nom[];
  27. extern    int    selection,last_sel;
  28. extern    struct my_data    my_info;
  29. extern    LONG    dir_save;
  30. extern    BPTR    old_lock;
  31.  
  32. extern    char    *p_name;
  33.  
  34. struct    Node ModulesNodes_alea[MAX_NOM];
  35. USHORT    flg_sel[MAX_NOM];
  36. char    *p_nom_alea[MAX_NOM];
  37. #define    MAX_LONG    20
  38.  
  39. struct    Gadget    *init_gadg();
  40. void         press_gadg();
  41. void         end_gadg();
  42.  
  43. struct List ModulesListAlea = {
  44.     ( struct Node * )&ModulesListAlea.lh_Tail,
  45.     ( struct Node * )0l,
  46.     ( struct Node * )&ModulesListAlea.lh_Head,0,0 };
  47.  
  48. static    struct    own_init    my_init={&init_gadg,&press_gadg,&end_gadg};
  49. char    *texte_alea="     Alea\n\n    V1.0\n\nSelect ALL if you want to have a\nseleection of all the modules, or\nunselect ALL and choose some modules\nin the list at the left.\n";
  50.  
  51. struct    tom_gadget    gadg_alea[]={
  52.         {"_Duree",    SLIDER   , 68, 78, 187,11,MIN_DUREE,MIN_DUREE,MAX_DUREE,0,(char *)&my_info.tempo_end},
  53.         {"_All",    CHECKBOX ,320, 37,  10,10,TRUE,0,0,0,0},
  54. #ifndef    WB_13
  55.         {"Selection",    OWN_GADGET ,85,16, 193,55,10,0,0,0,(char *)&my_init},
  56. #endif
  57. #ifdef    WB_13
  58.         {"Selection",    LISTVIEW   ,82,16, 193,55,10,0,0,0,(char *)&ModulesListAlea},
  59. #endif
  60.         {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}};
  61.  
  62.  
  63. /*****************************************************************************/
  64.  
  65. create_list()
  66. {
  67.     int i;
  68.     char *p_chaines;
  69.  
  70.     p_chaines=(char *)malloc(nb_module*MAX_LONG);
  71.     for(i=0;i<nb_module;i++){
  72.         p_nom_alea[i]=p_chaines+i*MAX_LONG;
  73.  
  74.         strcpy(p_nom_alea[i]+1,p_nom[i]);
  75.         if(flg_sel[i]==FALSE){
  76.             *p_nom_alea[i]=' ';
  77.         }else{
  78.             *p_nom_alea[i]='>';
  79.         }
  80.         ModulesNodes_alea[i].ln_Name=p_nom_alea[i];
  81.         ModulesNodes_alea[i].ln_Type=0;
  82.         AddTail(&ModulesListAlea,&ModulesNodes_alea[i]);
  83.     }
  84. }
  85.  
  86. /*****************************************************************************/
  87.  
  88. struct    Gadget    *init_gadg(p_gadg,g ,p_ng)
  89. struct    tom_gadget    *p_gadg;
  90. struct    Gadget    *g;
  91. struct NewGadget     *p_ng;
  92. {
  93.     create_list();
  94.  
  95.     g = CreateGadget( LISTVIEW_KIND, g, p_ng,
  96.         GTLV_Labels, &ModulesListAlea, TAG_DONE );
  97.     return(g);
  98. }
  99.  
  100.  
  101. /*****************************************************************************/
  102.  
  103. void    end_gadg()
  104. {
  105.     free(p_nom_alea[0]);
  106. }
  107.  
  108.  
  109. /*****************************************************************************/
  110.  
  111. void    press_gadg(pg,code,wnd)
  112. struct    Gadget    *pg;
  113. int    code;
  114. struct    Window    *wnd;
  115.  
  116. {
  117.     if(flg_sel[code]==FALSE){
  118.         flg_sel[code]=TRUE;
  119.         *p_nom_alea[code]='>';
  120.     }else{
  121.         flg_sel[code]=FALSE;
  122.         *p_nom_alea[code]=' ';
  123.     }
  124. #ifndef    WB_13
  125.     GT_RefreshWindow( wnd, 0l );
  126. #endif
  127. }
  128.  
  129. /*****************************************************************************/
  130.  
  131. void param_alea()
  132. {
  133.     LONG    old_dir;
  134.  
  135.     data_proc.p_texte=texte_alea;
  136. #ifdef    WB_13
  137.     create_list();
  138. #endif
  139.     Gere_gadg(gadg_alea,"Alea");
  140.     old_dir=0;
  141.     if(dir_save!=0){
  142.         old_dir=CurrentDir(dir_save);
  143.     }else if(old_lock!=-1){
  144.         old_dir=CurrentDir(old_lock);
  145.     }
  146.     SaveConfig(p_name,gadg_alea);
  147.     if(old_dir!=0){
  148.         CurrentDir(old_dir);
  149.     }
  150. #ifdef    WB_13
  151.     end_gadg();
  152. #endif
  153. }
  154.  
  155. /*****************************************************************************/
  156.  
  157. /************************************************/
  158. /* Load the configuration of the random modules */
  159. /* this configuration is saved in a file in the */
  160. /* s: directory, an ASCII file...        */
  161. /************************************************/
  162.  
  163. void    load_alea_cfg()
  164. {
  165.     UWORD    flg_end;
  166.     char    buffer[100];
  167.     BPTR    alea_hd;
  168.     int    i;
  169.  
  170.     alea_hd=Open(NAME_FILE_ALEA,MODE_OLDFILE);
  171.     flg_end=FALSE;
  172.  
  173.     for(i=0;i<nb_module;i++){
  174.         flg_sel[i]=FALSE;
  175.     }
  176.  
  177.     if(alea_hd!=0){
  178.         while(flg_end==FALSE){
  179.             /* Lecture d'une ligne */
  180.             i=-1;
  181.             do{
  182.                 i++;
  183.                 if(Read(alea_hd,&buffer[i],1)!=1){
  184.                     flg_end=TRUE;
  185.                 }
  186.             }while((buffer[i]!='\n')&&(flg_end==FALSE));
  187.             buffer[i]=0;
  188.  
  189.             /* Recherche si l'element existe */
  190.             if(flg_end==FALSE){
  191.                 for(i=0;i<nb_module;i++){
  192.                     if(strcmp(buffer,p_nom[i])==0){
  193.                         flg_sel[i]=TRUE;
  194.                     }
  195.                 }
  196.             }
  197.         }
  198.         Close(alea_hd);
  199.     }
  200. }
  201.  
  202. /*****************************************************************************/
  203.  
  204. void    save_alea_cfg()
  205. {
  206.     BPTR    alea_hd;
  207.     int    i,len;
  208.  
  209.     alea_hd=Open(NAME_FILE_ALEA,MODE_NEWFILE);
  210.     if(alea_hd!=0){
  211.         for(i=0;i<nb_module;i++){
  212.             if(flg_sel[i]==TRUE){
  213.                 len=strlen(p_nom[i]);
  214.                 Write(alea_hd,p_nom[i],len);
  215.                 Write(alea_hd,"\n",1);
  216.             }
  217.         }
  218.         Close(alea_hd);
  219.     }
  220. }
  221.