home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / commod / sdark14s.lha / blankers / slide_show.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-10  |  14KB  |  634 lines

  1.  /* Fichier slide_show.dark.c                */
  2. /* Module appele par le programme principal    */
  3. /* pour effectuer un effet defini..appele par    */
  4. /* loadseg                    */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <dos/dos.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <graphics/gfx.h>
  12. #include <graphics/gfxbase.h>
  13. #include <graphics/gfxmacros.h>
  14. #include <graphics/rastport.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/display.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/asl_protos.h>
  21.  
  22. #include <rexx/storage.h>
  23. #include <rexx/errors.h>
  24.  
  25. #include <libraries/asl.h>
  26. #include "/includes/struct.h"
  27. #include "/iff/jiff.h"
  28. #include "/includes/tom_gadget.h"
  29.  
  30. struct    FileRequester    *my_req=0;
  31. extern    char    *malloc();
  32. extern    struct    GfxBase    *GfxBase;
  33. char    *name_file="S:Slide_show.cfg";
  34. char    *p_choose="Select file to show...";
  35.  
  36. extern    struct my_data    *p_info;
  37. extern    struct    appel_proc    *p_data_proc;
  38. struct    RastPort    *rp,*rps;
  39. struct    Screen    *s;
  40. extern    char    *hd;
  41.  
  42. struct    Library    *GadToolsBase;
  43. UBYTE    flg_end,flg_modif;
  44.  
  45. USHORT    palette_deb[32],palette_end[32];
  46. extern    USHORT    Palette[];
  47.  
  48. void  put_ea_cmap();
  49.  
  50. char    *p_text_info="This module allow you to make a little slide show\nas a screen blanker\nYou must first select the files you want to see using\nADD (and SHOW to view the selected one)\nThis names wil be saved in a configuration file\nin your s: directory, named\n     s:slide_show.cfg\n\nThomas landspurg...";
  51.  
  52. struct    Gadget    __saveds    *init_gadg();
  53. void    __saveds    press_gadg();
  54. int    __saveds    press_add();
  55. void    __saveds    end_gadg();
  56. int    __saveds    press_del();
  57. int    __saveds    press_show();
  58.  
  59.  
  60. #define    WIDTH    320
  61. #define    HEIGHT    256
  62.  
  63. UWORD    cmap[32];
  64.  
  65. char    buffer2[100];
  66. struct TagItem    ScreenTags[] = {
  67.     SA_Left,          0,
  68.     SA_Top,           0,
  69.     SA_Width,         WIDTH,
  70.     SA_Height,        HEIGHT,
  71.     SA_Depth,         5,
  72.     SA_Type,          CUSTOMSCREEN,
  73.     SA_DisplayID,     PAL_MONITOR_ID,
  74.     TAG_DONE };
  75.  
  76. struct    Library *AslBase=0;
  77.  
  78. struct List ImagesList = {
  79.     (struct Node *)&ImagesList.lh_Tail,
  80.     (struct Node *)0l,
  81.     (struct Node *)&ImagesList.lh_Head,0,0 };
  82.  
  83. #define    MY_MAX_NOM    20
  84. char    *p_nom[MY_MAX_NOM];
  85. char    *p_dir[MY_MAX_NOM];
  86.  
  87. typedef struct my_node{
  88.     struct Node    node;
  89.     int    num;
  90. };
  91. #define    LONG_DSIZE    80
  92. #define    LONG_FSIZE    80
  93.  
  94. static    int    num=0;
  95. static    char    *p_null="non alloue";
  96.  
  97. #define    TAILLE_BUF    100
  98. char    buffer_name[TAILLE_BUF]="";
  99. struct    tom_gadget    my_gadg[]={
  100.     {"_Images",    LISTVIEW, 90, 16, 200,56, 0,0,0,0,(char *)&ImagesList},
  101.     {"^^_Delete^^",    BUTTON , 107, 75, 113,11, 0,0,0,0,(char *)&press_del},
  102.     {"_Add",    BUTTON ,  41, 75,  61,11, 0,0,0,0,(char *)&press_add},
  103.     {"_Show",    BUTTON , 227, 75,  80,11, 0,0,0,0,(char *)&press_show},
  104. #ifdef    TWO_VIEW
  105.     {"_Use_2view",    CHECKBOX, 90, 90,  10,10,FALSE,0,0,0,0},
  106.     {"_2viewName",    STRING,  200, 90,  70,14,0,TAILLE_BUF,0,0,buffer_name},
  107. #endif
  108.     {0,        END_LISTE, 0,  0,   0, 0, 0,0,0,0,            0}};
  109.  
  110. void    my_text(rp,x,y,p_c)
  111. struct    RastPort    *rp;
  112. int    x,y;
  113. char    *p_c;
  114. {
  115.     Move(rp,x,y);
  116.     Text(rp,p_c,strlen(p_c));
  117. }
  118.  
  119. void    rotate()
  120. {
  121.     static    unsigned    int    compt=0;
  122.     unsigned    int    n,i;
  123.  
  124.     n=compt;
  125.     for(i=1;i<32;i++){
  126.         n=n%31;
  127. /*
  128.         SetRGB4(&s->ViewPort,i,ScreenColors[n+1].Red,ScreenColors[n+1].Green,ScreenColors[n+1].Blue);
  129. */
  130.         n++;
  131.     }
  132.     compt++;
  133. }
  134.  
  135. #ifdef    TWO_VIEW
  136. /*************************************************************************/
  137.  
  138. send_msg(buf)
  139. char *buf;
  140. {
  141.     struct    RexxMsg    rx_message;
  142.     struct    MsgPort *rexx_port = NULL;
  143.     struct    MsgPort *reply_port = NULL;
  144.     int    code_ret;
  145.  
  146.    if(mystrlen(buf)!=0){
  147.     code_ret=0;
  148.     Forbid();
  149.     if( (rexx_port=FindPort ("2View.1") ==NULL){
  150.         Permit();
  151.         code_ret=-1;
  152.     }else if((reply_port=(struct MsgPort *)CreatePort ("Reply port", 0L))==NULL){
  153.         Permit();
  154.         code_ret=-1;
  155.     }else{
  156.         rx_message.rm_Args[0]=buf;
  157.         rx_message.rm_Args[1]=NULL;
  158.         rx_message.rm_Args[2]=NULL;
  159.         rx_message.rm_Action=RXCOMM;
  160.         rx_message.rm_Node.mn_ReplyPort=reply_port;
  161.         rx_message.rm_Node.mn_Node.ln_Type=NT_MESSAGE;
  162.  
  163.         PutMsg(rexx_port,&rx_message);
  164.         Permit();
  165.         WaitPort(reply_port);
  166.         DeletePort(reply_port);
  167.         if(rx_message.rm_Result1!=RC_OK)code_ret=-1;
  168.     }
  169.     return(code_ret);
  170.    }
  171. }
  172. #endif
  173.  
  174. /* Ajoute un noeud dans la liste, et retourne le noeau alloue */
  175. /* 0 si pas possbile (deja plein par exemple                */
  176.  
  177. struct    my_node    *add_node(int    pos)
  178. {
  179.     struct my_node *pn;
  180.     struct    Node    *node,*pre;
  181.     int    i;
  182.  
  183.     i=0;
  184.     while((p_nom[i]!=0)&&(i<MY_MAX_NOM)){
  185.         i++;
  186.     }
  187.     if(i<MY_MAX_NOM){
  188.         pn=(struct my_node *)malloc(sizeof(struct my_node));
  189.         node=&pn->node;
  190.  
  191.         node->ln_Pred=0;;
  192.         node->ln_Succ=0;;
  193.         node->ln_Name=p_null;
  194.         node->ln_Type=0;
  195.         pn->num=i;
  196.         if(pos==-1){
  197.             AddTail(&ImagesList,node);
  198.         }else{
  199.             pre=ImagesList.lh_Head;
  200.             for(i=0;i<pos;i++){
  201.                 if(pre!=NULL)pre=pre->ln_Succ;
  202.             }
  203.             Insert(&ImagesList,node,pre);            
  204.         }
  205.  
  206.     }else{
  207.         MyWrite("add_node: liste plein!\n");
  208.         pn=0;
  209.     }
  210.     return(pn);
  211. }
  212.  
  213. /***************************************************** del_node() ********/
  214.  
  215. /*******************************/
  216. /* retire un noeud de la liste */
  217. /*******************************/
  218.  
  219. void    del_node(struct my_node *pn)
  220. {
  221.     p_nom[pn->num]=0;
  222.     if(pn!=0){
  223.         Remove(&pn->node);
  224.         free(pn);
  225.     }
  226. }
  227. /******************************************************* test_iff() *****/
  228. int    test_iff(char *p_name)
  229. {
  230.     BPTR    hd;
  231.     char    buffer[4+4+4];
  232.     int    ret;
  233.  
  234.     ret=FALSE;
  235.     hd=Open(p_name,MODE_OLDFILE);
  236.     if(hd!=NULL){
  237.         Read(hd,buffer,sizeof(buffer));
  238.         if((strncmp(buffer,"FORM",4)==0)&&(strncmp(&buffer[8],"ILBM",4)==0)){
  239.             ret=TRUE;
  240.         }
  241.         Close(hd);
  242.     }
  243.     return ret;
  244. }
  245.  
  246.  
  247. /***********************/
  248. /* Call the IFF loader */
  249. /***********************/
  250.  
  251. struct    Screen    *Charge_Iff(name,old_s)
  252. char    *name;
  253. struct    Screen    *old_s;
  254. {
  255.     struct    ILBM_info    *info;
  256.     struct    RastPort    EcranRastPort;
  257.     struct    Screen    *s;
  258.  
  259.     SPrintF(buffer2,"Charge iff de:%s\n",name);
  260.     MyWrite(buffer2);
  261.  
  262.     InitRastPort(&EcranRastPort);
  263.     if ( (info = read_iff(name,0) ) != NULL){
  264.         ScreenTags[2].ti_Data=(ULONG)info->header.w;
  265.         ScreenTags[3].ti_Data=(ULONG)info->header.h;
  266.         ScreenTags[4].ti_Data=(ULONG)info->header.nPlanes;
  267.          ScreenTags[6].ti_Data=PAL_MONITOR_ID;
  268.         if(info->header.w>320){
  269.         ScreenTags[6].ti_Data|=MODE_640;
  270.         }
  271.         if(info->header.h>256){
  272.         ScreenTags[6].ti_Data|=INTERLACE;
  273.         }
  274.         if(info->header.nPlanes==6){
  275.         ScreenTags[6].ti_Data|=HOLDNMODIFY;
  276.         }
  277. /*
  278.         ScreenTags[6].ti_Data|=info->camg;
  279. */
  280.             if ( ( s = OpenScreenTagList( 0l, ScreenTags ))!=0){
  281.         FreeSprite (0);
  282.         GfxBase->SpriteReserved|=1;
  283.         rp = &(s->RastPort);
  284. /*
  285.  
  286.         SetAPen(rp,0);
  287.         RectFill(rp,0,0,rp->BitMap->BytesPerRow*8,rp->BitMap->Rows);
  288. */
  289.         put_ea_cmap(&info->cmap,32 );
  290.         EcranRastPort.BitMap = &info->bitmap;
  291.         ClipBlit( &EcranRastPort, 0L, 0L,
  292.             rp, 0L, 0L,
  293.             (rp->BitMap->BytesPerRow)*8,
  294.             rp->BitMap->Rows, (long)COPY_MINTERM);
  295.         LoadRGB4(&s->ViewPort,&palette_end,32);
  296.             if(old_s!=0){
  297.             CloseScreen(old_s);
  298.             old_s=0;
  299.             }
  300.         }else{
  301.         s=old_s;
  302.         old_s=0;
  303.         }
  304.         free_planes(&info->bitmap);
  305.     }else{
  306.         s=old_s;
  307.     }
  308.     return(s);
  309. }
  310.  
  311. /************************************************************/
  312. /* Procedure to put the colors of the picture on the screen */
  313. /************************************************************/
  314.  
  315. void put_ea_cmap(cmap, colors)
  316. unsigned char *cmap;
  317. int colors;
  318. {
  319.     int i;
  320.  
  321.     if (colors > MAXCOL)    /*color clipping*/
  322.         colors = MAXCOL;
  323.     for (i=0; i<colors; i++)
  324.     {
  325.         palette_end[i] = 
  326.             ((cmap[0] & 0xf0) << 4) + (cmap[1] & 0xf0) + ((cmap[2] & 0xf0) >> 4);
  327.         cmap += 3;
  328.     }
  329. }
  330.  
  331. void    __saveds    dark()
  332. {
  333.    struct    Screen    *s;
  334.    char    buffer[LONG_DSIZE+LONG_FSIZE];
  335.    int    i,n;
  336.    struct    Node    *node;
  337.    struct    my_node *my_n;
  338.  
  339.    /* Do we use 2view? */
  340. #ifdef    TWO_VIEW
  341.    if(my_gadg[4].value==FALSE){
  342. #endif
  343.     n=0;
  344.     s=0;
  345.     node=ImagesList.lh_Head;
  346.     /* Y a t'il au moins un element dans la liste? */
  347.     if(node!=(struct Node *)&ImagesList.lh_Tail){
  348.         while(tst_end()==FALSE){
  349.             if(node==0){
  350.                 node=ImagesList.lh_Head;
  351.             }
  352.             my_n=(struct my_node *)node;
  353.             n=my_n->num;
  354.             n=n%MY_MAX_NOM;
  355.             if(p_nom[n]!=p_null){
  356.                 sprintf(buffer,"%s%s",p_dir[n],p_nom[n]);
  357.                 s=Charge_Iff(buffer,s);
  358.                 for(i=0;(i<100)&&(tst_end()==FALSE);i++){
  359.                     Delay(1);
  360.                 }
  361.     
  362.             }
  363.             node=node->ln_Succ;
  364.         }
  365.     }
  366.     if(s!=0)CloseScreen(s);
  367. #ifdef    TWO_VIEW
  368.     }else{
  369.     if(my_gadg[5].p_data[0]!=0){
  370.         SPrintF(buffer,"run %s FROM %s SECS 5\n",my_gadg[5].p_data,
  371.                             name_file);
  372.         Execute(buffer,NULL,NULL);
  373.         wait_end();
  374.         send_msg("QUIT");
  375.         }
  376.     }
  377. #endif
  378.  
  379. }
  380.  
  381. struct    Gadget    *get_listview_id(struct    contexe *ctx)
  382. {
  383.     return my_gadg[0].p_gadg;
  384. }
  385. struct    my_node    *get_node(int    num)
  386. {
  387.     int    i;
  388.     struct    Node    *pre;
  389.  
  390.     pre=ImagesList.lh_Head;
  391.  
  392.     for(i=0;i<num;i++){
  393.         if(pre!=NULL)pre=pre->ln_Succ;
  394.     }
  395.  
  396.     return (struct my_node *)pre;
  397. }
  398.  
  399. int    __saveds    press_show(pg,p_t,ctx)
  400. struct    Gadget    *pg;
  401. struct    tom_gadget    *p_t;
  402. struct    contexe    *ctx;
  403. {
  404.     struct    Screen    *s;
  405.     struct    my_node    *my_n;
  406.     char    buffer[LONG_DSIZE+LONG_FSIZE];
  407.  
  408.     my_n=get_node(my_gadg[0].value);
  409.     SPrintF(buffer,"%s%s",p_dir[my_n->num],p_nom[my_n->num]);
  410.     s=Charge_Iff(buffer,0);
  411.     Delay(100);
  412.     if(s!=0)CloseScreen(s);
  413.     return FALSE;
  414. }
  415.  
  416. int    __saveds    press_del(pg,p_t,ctx)
  417. struct    Gadget    *pg;
  418. struct    tom_gadget    *p_t;
  419. struct    contexe    *ctx;
  420. {
  421.     int    num;
  422.     struct    Window    *wnd;
  423.     struct    my_node    *my_n;
  424.     struct    Gadget    *gad;
  425.  
  426.     wnd=ctx->Wnd;
  427.  
  428.     num=my_gadg[0].value;
  429.  
  430.     my_n=get_node(num);
  431.     num=my_n->num;
  432.  
  433.     gad=get_listview_id(ctx);
  434.     GT_SetGadgetAttrs(gad,wnd,NULL,GTLV_Labels,~0,TAG_DONE);
  435.     if(p_nom[num]!=0){
  436.         (char *)free(p_nom[num]);
  437.         (char *)free(p_dir[num]);
  438.         p_nom[num]=0;
  439.         del_node(my_n);
  440.     }
  441.     GT_SetGadgetAttrs(gad,wnd,NULL,GTLV_Labels,&ImagesList,TAG_DONE);
  442.     /* on ne sort pas...*/
  443.     return FALSE;
  444. }
  445.  
  446. int    __saveds    press_add(pg,p_t,ctx)
  447. struct    Gadget    *pg;
  448. struct    tom_gadget    *p_t;
  449. struct    contexe    *ctx;
  450. {
  451.     struct    Window    *wnd;
  452.     int    len_dir;
  453.     int    res;
  454.     struct    Gadget    *gad;
  455.     struct    my_node    *my_node,*node_sel;
  456.  
  457.     char    buffer[LONG_DSIZE+LONG_FSIZE];
  458.  
  459.     /* A t'on pu obtenir le requester? si non, on sort...        */
  460.     if(my_req==0)return -1;
  461.  
  462.     /* Pour un objet de type listview, on met le ptr sur le gadg    */
  463.     gad=get_listview_id(ctx);
  464.     wnd=ctx->Wnd;
  465.  
  466.     /* Je fais une copie du repertoire courant... */
  467.     node_sel=get_node(my_gadg[0].value);
  468.     if((my_req->rf_Dir!=0)&&(p_nom[node_sel->num]!=0)){
  469.         strcpy(my_req->rf_Dir,p_dir[node_sel->num]);
  470.     }
  471.  
  472.  
  473.     /* Ouverture du requester de fichier pour l'utilisateur */
  474. /*
  475.     my_req->rf_Hail=p_choose;
  476. */
  477.     res=(int)RequestFile(my_req);
  478.  
  479.     /* Si l'utilisateur a choisi qq chose, et si il reste de la place */
  480.  
  481.     if((res!=0)&&((my_node=add_node(my_gadg[0].value))!=0)){
  482.         GT_SetGadgetAttrs(gad,wnd,NULL,GTLV_Labels,~0,TAG_DONE);
  483.  
  484.         num=my_node->num;
  485.         p_nom[num]=(char *)malloc(strlen(my_req->rf_File)+1);
  486.         strcpy(p_nom[num],my_req->rf_File);
  487.  
  488.         len_dir=strlen(my_req->rf_Dir);
  489.  
  490.         /* Test si le dernier caractere du rep contient l'antislash */
  491.         if((my_req->rf_Dir[len_dir-1]!='/')&&(my_req->rf_Dir[len_dir-1]!=':')){
  492.             p_dir[num]=(char *)malloc(len_dir+2);
  493.             strcpy(p_dir[num],my_req->rf_Dir);
  494.             p_dir[num][len_dir++]='/';
  495.             p_dir[num][len_dir]=0;
  496.         }else{
  497.             p_dir[num]=(char *)malloc(len_dir+1);
  498.             strcpy(p_dir[num],my_req->rf_Dir);
  499.         }
  500.         my_node->node.ln_Name=p_nom[num];
  501.         sprintf(buffer,"%s%s",p_dir[num],p_nom[num]);
  502.         if(test_iff(buffer)==FALSE){
  503.             MyWrite(buffer);
  504.             MyWrite(" n'est pas un fichier IFF!\n");
  505.             del_node(my_node);
  506.         }
  507.         GT_SetGadgetAttrs(gad,wnd,NULL,    GTLV_Labels,&ImagesList,
  508.                         GTLV_Selected,my_gadg[0].value,
  509.                         TAG_DONE);
  510.     }
  511.     return(FALSE);
  512. }
  513.  
  514.  
  515. load_data()
  516. {
  517.     int i,taille,pos_dir,n;
  518.     UWORD    flg_end;
  519.     char    buffer[100];
  520.     BPTR    slide_hd;
  521.     struct    my_node    *pn;
  522.  
  523.  
  524.     GadToolsBase=(struct Library *)OpenLibrary("gadtools.library",0);
  525.     if(GadToolsBase==0){
  526.         return -1;
  527.     }
  528.     slide_hd=Open(name_file,MODE_OLDFILE);
  529.     flg_end=FALSE;
  530.     if(slide_hd!=0){
  531.         for(i=0;i<MY_MAX_NOM;i++){
  532.             p_nom[i]=0;
  533.             p_dir[i]=0;
  534.         }
  535.         for(i=0;((i<MY_MAX_NOM)&&(flg_end==FALSE));i++){
  536.             n=-1;
  537.             do{
  538.                 n++;
  539.                 if(Read(slide_hd,&buffer[n],1)!=1){
  540.                     flg_end=TRUE;
  541.                 }
  542.             }while((buffer[n]!='\n')&&(flg_end==FALSE));
  543.  
  544.             if(flg_end==FALSE){
  545.                 pn=add_node(-1);
  546.                 if(pn==0){
  547.                     flg_end=TRUE;
  548.                 }
  549.             }
  550.             if(flg_end==FALSE){
  551.                 taille=n;
  552.                 pos_dir=n;
  553.                 while((buffer[n]!='/')&&(buffer[n]!=':')&&(n!=0)){
  554.                     n--;
  555.                 }
  556.                 pos_dir=n+1;
  557.                 if(taille!=pos_dir){
  558.                     p_nom[i]=malloc(taille-pos_dir);
  559.                     strncpy(p_nom[i],&buffer[pos_dir],taille-pos_dir);
  560.                     p_nom[i][taille-pos_dir]=0;
  561.                     pn->node.ln_Name=p_nom[i];
  562.  
  563.                     if(pos_dir!=0){
  564.                         p_dir[i]=malloc(pos_dir);
  565.                         strncpy(p_dir[i],buffer,pos_dir);
  566.                         p_dir[i][pos_dir]=0;
  567.  
  568.                     }else{
  569.                         p_dir[i]=0;
  570.                     }
  571.  
  572.                 }else{
  573.                     p_nom[i]=0;
  574.                 }
  575.             }
  576.         }
  577.         Close(slide_hd);
  578.     }
  579.     AslBase=(struct Library *)OpenLibrary(AslName,0);
  580.     if(AslBase!=0){
  581.         my_req=AllocFileRequest();
  582.     }
  583.     GadToolsBase=(struct Library *)OpenLibrary("gadtools.library",0);
  584.     if(GadToolsBase==0){
  585.         my_req=0;
  586.     }
  587.  
  588. }
  589.  
  590. proc_init()
  591. {
  592.     load_data();
  593.     p_data_proc->code_ret=DARK_WB_20;
  594. }
  595.  
  596. void    proc_end()
  597. {
  598.     BPTR    slide_hd;
  599.     int    i,len;
  600.  
  601.     slide_hd=Open(name_file,MODE_NEWFILE);
  602.     if(slide_hd!=0){
  603.         for(i=0;i<MY_MAX_NOM;i++){
  604.             if(p_nom[i]!=0){
  605.                 len=strlen(p_dir[i]);
  606.                 if(p_dir[i]!=NULL){
  607.                     Write(slide_hd,p_dir[i],len);
  608.                 }
  609.                 if(p_dir[i][len-1]!='/'){
  610.                     Write(slide_hd,"/",1);
  611.                 }
  612.  
  613.                 Write(slide_hd,p_nom[i],strlen(p_nom[i]));
  614.                 Write(slide_hd,"\n",1);
  615.             }
  616.         }
  617.         Close(slide_hd);
  618.     }
  619.     /* Enleve les noeuds..*/
  620.     while(ImagesList.lh_Head!=(struct Node *)&ImagesList.lh_Tail){
  621.         del_node((struct my_node *)ImagesList.lh_Head);
  622.     }
  623.     if(my_req!=0){
  624.         FreeFileRequest(my_req);
  625.     }
  626.     if(AslBase!=0){
  627.         CloseLibrary(AslBase);
  628.     }
  629.     if(GadToolsBase!=0){
  630.         CloseLibrary(GadToolsBase);
  631.     }
  632. }
  633.  
  634.