home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / main / win.c < prev   
C/C++ Source or Header  |  1993-03-20  |  17KB  |  711 lines

  1. /*
  2.  *  Source generated with GadToolsBox V1.0
  3.  *  which is (c) Copyright 1991 Jaba Development
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/tasks.h>
  8. #include <dos/dosextens.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfx.h>
  15. #include <graphics/gfxmacros.h>
  16. #include <graphics/gfxbase.h>
  17. #include <hardware/custom.h>
  18. #include <hardware/dmabits.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include "/includes/struct.h"
  24. #include "/includes/tom_gadget.h"
  25. #include "gid_main.h"
  26.  
  27. #ifndef custom
  28. #define custom (*(struct Custom *)0xDFF000)
  29. #endif    /* custom */
  30.  
  31. extern    struct    contexe    big_ctx;
  32. extern    UBYTE    flg_prog_dark;
  33. ULONG    cxsigflag=0;
  34. #define    MIN_TEMPO    10
  35. #define    MAX_TEMPO    300
  36.  
  37. extern    struct my_data    my_info;
  38. extern    char    *p_nom[];
  39. extern    int    selection,last_sel;
  40. extern    int    nb_module;
  41. extern    struct    Process    *process;
  42. extern    UBYTE    flg_debug;
  43. extern    LONG    dir_save,old_lock;
  44. LONG    sigstart_f,sigshow_f,sigstop_f,signext_f;
  45.  
  46. extern    struct    IntuitionBase    *IntuitionBase;
  47.  
  48. struct    appel_proc    data_proc;
  49.  
  50. extern struct  List ModulesList;
  51. extern    struct Node    ModulesNodes[];
  52.  
  53. int    press_param();
  54. int    press_hide();
  55. int    press_quit();
  56. int    press_save();
  57. int    press_help();
  58. void    press_rescan();
  59.  
  60. char    directory[30]="";
  61. char    popkey[30]="shift f3";
  62. char    blankey[30]="shift f4";
  63. char    passwd[10]="";
  64. extern    USHORT    flg_sel[MAX_NOM];
  65. extern    struct    tom_gadget    gadg_alea[];
  66.  
  67. #include "logo.h"
  68.  
  69. struct    tom_gadget    my_gadg[]={
  70.     {"_Remove",    BUTTON   ,10,200,  70,13,0,0,0,0,(char *)&press_quit},
  71.     {"_Param-->",    BUTTON   ,8,106,  70,13,0,0,0,0,(char *)&press_param},
  72.     {"H_elp...",    BUTTON   ,160,200, 70,13,0,0,0,0,(char *)&press_help},
  73.     {"_Hide",    BUTTON   ,235,200, 70,13,0,0,0,0,(char *)&press_hide},
  74.     {"_Save",    BUTTON   ,85,200, 70,13,0,0,0,0,(char *)&press_save},
  75.  
  76.     {"_Tempo",    SLIDER   , 274,15,  24,76,MIN_TEMPO,MIN_TEMPO,MAX_TEMPO,0,(char *)&my_info.tempo},
  77.     {"_Modules",    LISTVIEW ,80,15, 144,105,0,0,0,0,(char *)&ModulesList},
  78.     {"_Dark directory",STRING,160,120,144,14,0,30,0,0,directory},
  79.     {"_CxPopkey"   ,STRING,160,140,144,14,0,30,0,0,popkey},
  80.     {"_Blankkey"   ,STRING,160,160,144,14,0,30,0,0,blankey},
  81.     {"Pass_wd"     ,STRING,160,180,144,14,0,10,0,0,passwd},
  82.     {"_Lock"       ,CHECKBOX,60,180,144,14,FALSE,0,0,0,0},
  83.     {"_Quiet"       ,CHECKBOX,274,105,14,14,FALSE,0,0,0,0},
  84. /*    {"_Usage Hard",CHECKBOX,400,105,14,14,FALSE,0,0,0,0},*/
  85.     {"Tas_kPri",    SLIDER ,370,140, 24,40,    0,-10,0,0,0},
  86.     {"",        IMAGE,  320,20,  40,40, 0, 0,0,0,(char *)&logo_iffImage},
  87. /*
  88.     {"Rescan",    BUTTON ,370,100, 24,40,     0, 0,0,0,(char *)&press_rescan},
  89. */
  90.     {0,        END_LISTE,  0,  0,   0,  0, 0,0,0,0,0}};
  91.  
  92. #ifdef    WB_13
  93. extern    struct IntuiMessage *tom_GetMsg(struct MsgPort *UserPort);
  94. #endif
  95.  
  96. struct Screen        *s= NULL;
  97. struct Window        *w2   = NULL;
  98. struct BitMap        b;
  99. int    width,height,cleared;
  100. short    s2depth;
  101. struct NewScreen newscreen = {
  102.   0,0,0,0,0,0,0,NULL,CUSTOMSCREEN|CUSTOMBITMAP,NULL,(UBYTE *)" ",NULL,NULL
  103. };
  104. struct Preferences   MyCopy;
  105. USHORT PointerData[POINTERSIZE];
  106.  
  107.  
  108. /**************************************************************************/
  109.  
  110. void    GetPointer()
  111. {
  112.   int i;
  113.  
  114.   GetPrefs(&MyCopy,(long)sizeof(MyCopy));
  115.   for (i=0; i<POINTERSIZE; i++){
  116.     PointerData[i] = MyCopy.PointerMatrix[i];
  117.   }
  118. }
  119.  
  120. /**************************************************************************/
  121.  
  122. void    ResetPointer()
  123. {
  124.   int i;
  125.   if (cleared){
  126.  
  127.       for (i=0; i<POINTERSIZE; i++){
  128.         MyCopy.PointerMatrix[i] = PointerData[i];
  129.       }
  130.       SetPrefs(&MyCopy,(long)sizeof(MyCopy),NULL);
  131.       cleared = 0;
  132.    }
  133. }
  134.  
  135. /**************************************************************************/
  136.  
  137. int blank()
  138. {
  139.   int    i,col;
  140.   struct    Screen    *s2;
  141.   struct ViewPort      *vp2;
  142.  
  143.   do_dark();
  144.  
  145.   /* We set the sprite off, with 2 different methodes:    */
  146.   /* Software (not always work) and Hardware (tricky..) */
  147.  
  148. /*
  149.   if (my_gadg[GID_SPRITE].value){
  150. */
  151.     OFF_SPRITE
  152.     for (i=0L; i<8L; i++){
  153.          custom.spr[i].ctl=0;
  154.     }
  155. /*
  156.   }else{
  157. */
  158.     GetPointer();
  159.  
  160.     for (i=0; i<POINTERSIZE; i++){
  161.         MyCopy.PointerMatrix[i] = NULL;
  162.     }
  163.     SetPrefs(&MyCopy, (long) sizeof(MyCopy),NULL);
  164. /*
  165.   }
  166. */
  167.  cleared = 1;
  168.  
  169.  data_proc.s=0;
  170.  
  171.   s2 = IntuitionBase->FirstScreen;
  172.   vp2 = &s2->ViewPort;
  173.   s2depth = s2->BitMap.Depth;
  174.  
  175.   newscreen.LeftEdge = s2->LeftEdge;
  176.   newscreen.TopEdge = s2->TopEdge;
  177.   newscreen.Width = s2->Width;
  178.   newscreen.Height = s2->Height;
  179.   newscreen.DetailPen = s2->DetailPen;
  180.   newscreen.BlockPen = s2->BlockPen;
  181.   newscreen.Depth = s2depth;
  182.   newscreen.ViewModes = vp2->Modes;
  183.   newscreen.DefaultTitle=NULL;
  184.  
  185.   width=newscreen.Width;
  186.   height=newscreen.Height;
  187.  
  188.  if(data_proc.type_screen==SCR_GIVEN){
  189.  
  190.   if (s) printf("Error! Screen Exists! Quitting...");
  191.  
  192.   InitBitMap(&b,s2depth,width,height);
  193.   for(i=0;i<s2depth;i++){
  194.     b.Planes[i]=AllocRaster(width,height);
  195.         if(b.Planes[i]==0){
  196.         printf("Big erreur aVEC alloc raster\n");
  197.         return(1);
  198.     }
  199.   }
  200.   BltBitMap(&(s2->BitMap),0,0,&b,0,0,width,height,0xc0,0xff,NULL);
  201.   newscreen.CustomBitMap=&b;
  202.  
  203.   if ((s = (struct Screen *)OpenScreen(&newscreen)) == NULL)
  204.     printf("[Couldn't Open Screen]",0);
  205.  
  206.   for(i=0;i<(1<<s2depth);i++){
  207.     col=GetRGB4(s2->ViewPort.ColorMap,i);
  208.     SetRGB4(&(s->ViewPort),i,(col&0xf00)>>8,(col&0xf0)>>4,(col&0xf));
  209.   }
  210.  
  211.    data_proc.rp= &(s->RastPort);
  212.    data_proc.rps=&(s2->RastPort);
  213.    data_proc.s=s;
  214.    data_proc.width=width;
  215.    data_proc.height=height;
  216.   }
  217.   
  218. }
  219.  
  220. /**************************************************************************/
  221.  
  222. void    off_blank()
  223. {
  224.    int    i;
  225.    if(data_proc.type_screen==SCR_GIVEN){
  226.  
  227.     if(w2!=NULL)CloseWindow(w2);
  228.     if(s!=0)CloseScreen(s);
  229.     for(i=0;i<s2depth;i++){
  230.         if(b.Planes[i]!=0){
  231.             FreeRaster(b.Planes[i],width,height);
  232.         }
  233.     }
  234.   }
  235. /*
  236.   if (my_gadg[GID_SPRITE].value){
  237. */
  238.       ON_SPRITE
  239. /*
  240.   }else{
  241. */
  242.       ResetPointer();
  243. /*
  244.   }
  245. */
  246.   s=0;
  247.   w2=0;
  248. }
  249.  
  250. /**************************************************************************/
  251.  
  252. void    big_blank()
  253. {
  254.   ULONG    signal;
  255.   ULONG    signal2;
  256.   int    n;
  257.  
  258.   do{
  259.     press_module();
  260.     SetSignal(0,(signext_f|sigstart_f|sigstop_f));
  261.     if(my_info.flg_alea==TRUE){
  262.         printd("Mode aleatoire\n");
  263.         n=nb_module-1;
  264.         selection=(rand()/100)%nb_module;
  265.         printd("Je devrais selectionne:%d\n",selection);
  266.  
  267.         /* Si tout n'est pas selectionne, on cherche    */
  268.         /* un module valide                */
  269.         if(gadg_alea[1].value!=TRUE){
  270.             printd("Pas en mode all....\n");
  271.             while((flg_sel[selection]==FALSE)&&(n!=-1)){
  272.                 selection=(selection+1)%nb_module;
  273.                 n--;
  274.             }
  275.         }
  276.     }else{
  277.         printd("Mode normal\n");
  278.         n=selection;
  279.     }
  280.     if(n!=-1){
  281.  
  282.         blank();
  283.         if(flg_prog_dark==TRUE){
  284.  
  285.             /* On averti la tache dark de faire l'effet */
  286.             Signal(&process->pr_Task,SIG_MAIN_DARK_DO_DARK);
  287.  
  288.             /* On rajoute une petite tempo, pour les eviter les */
  289.             /* effets de rebond                    */
  290.  
  291.             Delay(10);
  292.  
  293.             /* Pour le blanker.... on averti qu'on est en mode blanking*/
  294.             my_info.flg_stop=1;
  295.  
  296.             SetSignal(0,signext_f|sigstop_f);
  297.  
  298.             /* On attend le signal de l'handler        */
  299.             printd("J'attend le signal de l'handler..\n");
  300.             signal=Wait(signext_f|sigstop_f);
  301.             printd("signal recu..:%lx\n",signal);
  302.             /* On averti la tache dark de s'arreter        */
  303.  
  304.             /* Tant que l'on a pas recu le signal ok, on renvoi */
  305.             /* le stop!                        */
  306.             do{
  307.                 printd("J'averti la tache..\n");
  308.                 Signal(&process->pr_Task,SIG_MAIN_DARK_STOP_DARK);
  309.                 /* On attend le signal de la tache Dark        */
  310.                 printd("J'attend sa reponse..\n");
  311.                 signal2=Wait(SIG_DARK_MAIN_STOPPED|sigstop_f);
  312.             }while((signal2&(SIG_DARK_MAIN_STOPPED))==0);
  313.             
  314.  
  315.             /* Pour le blanker.... on peut de nouveau recevoir un sigstart */
  316.             my_info.flg_stop=0;
  317.             printd("Reponse recu..%lx\n",signal2);
  318.         }else{
  319.             printd("Pas un programme dark!\n");
  320.         }
  321.         off_blank();
  322.     }else{
  323.         printd("Je n'ai rien selectionne!\n");
  324.         Delay(100);
  325.         signal=0;    /* Pour sorir de la boucle */
  326.     }
  327.     printd("my info et next:%lx\n",(signal & signext_f));
  328.    }while((my_info.flg_alea==TRUE)&&((signal & signext_f)!=0));
  329.    printd("Ok, je sort!\n");
  330. }
  331.  
  332. /*************************************** show_win() ****/
  333. /* Affiche la fenetre principale */
  334. void    show_win(struct    contexe *pc)
  335. {
  336.     if(!pc->Wnd)InitStuff_gadg(pc,TRUE);
  337.     /* Au cas ou la fenetre ne serait pas ouverte!*/
  338.     if(pc->Wnd)WindowToFront(pc->Wnd);
  339.     WBenchToFront();
  340. }
  341.  
  342. /**************************************************************************/
  343.  
  344. void    main_loop(pc)
  345. struct    contexe    *pc;
  346. {
  347.     struct    IntuiMessage *msg;
  348.     int    class,code,id;
  349.     int    sig_win,sig_recu;
  350.     APTR    IAdress;
  351.  
  352.     pc->flg_end=FALSE;
  353.  
  354.     sigstart_f=1<<my_info.sigstart;
  355. #ifdef    WB_13
  356.     sigshow_f=1<<my_info.sigshow;
  357. #else
  358.     sigshow_f=0;
  359. #endif
  360.     sigstop_f=1<<my_info.sigstop;
  361.     signext_f=1<<my_info.signext;
  362.  
  363.     do{
  364.        if(pc->Wnd!=NULL){
  365.         sig_win=1<<pc->Wnd->UserPort->mp_SigBit;
  366.        }else{
  367.         sig_win=0;
  368.        }
  369.        sig_recu=Wait(sig_win|sigstart_f|sigshow_f|SIGBREAKF_CTRL_C|cxsigflag);
  370.        if(sig_recu & sig_win){
  371. #ifndef    WB_13
  372.          while((pc->Wnd!=0)&&((msg=(struct IntuiMessage *)GT_GetIMsg(pc->Wnd->UserPort))!=0)){
  373. #else
  374.          while((pc->Wnd!=0)&&((msg=(struct IntuiMessage *)tom_GetMsg(pc->Wnd->UserPort))!=0)){
  375. #endif
  376.         class=msg->Class;
  377.         code=msg->Code;
  378.         IAdress=msg->IAddress;
  379. #ifndef    WB_13
  380.         GT_ReplyIMsg(msg);
  381. #else
  382.         ReplyMsg(msg);
  383. #endif
  384.         switch(class){
  385.             case    VANILLAKEY:
  386.                 switch(code){
  387.                     case 27:        /* escape */
  388.                         press_hide();
  389.                         break;
  390.                     default:
  391.                         find_raccourcis(code,pc);
  392.                         break;
  393.                 }
  394.                 break;
  395.  
  396.             case    GADGETUP:
  397.                 handle_event_gadg(IAdress,code,pc);
  398. #ifndef WB_13
  399.                 id=((struct Gadget *)IAdress)->GadgetID-GID_DEBUT+1;
  400.                 if(id==GID_CXPOPKEY)ResetKey(id);
  401.                 if(id==GID_BLANKKEY)ResetKey(id);
  402.                 if(id==GID_DIR)press_rescan(IAdress,pc);
  403. #endif
  404.                 break;
  405.             case    CLOSEWINDOW:
  406.                 press_hide();
  407.                 break;
  408.             case    REFRESHWINDOW:
  409.                 reaffiche_images(pc);
  410. #ifndef    WB_13
  411.                 GT_RefreshWindow( pc->Wnd, 0l );
  412. #endif
  413.                 break;
  414.  
  415.             default:
  416.                 break;
  417.         }
  418.          }
  419.        }else if(sig_recu & sigstart_f){
  420.         printd("Signal de l'handler\n");
  421.         if(my_info.flg_stop==0){
  422.             if(nb_module==0){
  423.             aff_error("No Dark modules have been found\nYou must configure SuperDark before!\n");
  424.             }else{
  425.             do{
  426.                 big_blank();
  427.             }while(    unlock_screen()!=TRUE);
  428.                }
  429.         }
  430. #ifdef    WB_13
  431.        }else if(sig_recu & sigshow_f){
  432.         show_win(pc);
  433. #else
  434.        }else if(sig_recu & cxsigflag){
  435.         ProcessMsg(sig_recu);
  436. #endif
  437.        }else if(sig_recu & SIGBREAKF_CTRL_C){
  438.         printf("Break ****\n");
  439.         pc->flg_end=TRUE;
  440.        }
  441.     }while(!pc->flg_end);
  442.  
  443.     press_module();
  444. }
  445.  
  446. /**************************************************************************/
  447.  
  448. int    press_module()
  449. {
  450.     selection=my_gadg[GID_MODULES].value;
  451.     printd("selection=%d\n",selection);
  452.     if(selection==nb_module){
  453.         my_info.flg_alea=TRUE;
  454.         my_info.tempo_end=gadg_alea[0].value;
  455.     }else{
  456.         my_info.tempo_end=-1;
  457.         my_info.flg_alea=FALSE;
  458.     }
  459.     return FALSE;
  460. }
  461.  
  462. /**************************************************************************/
  463.  
  464. int    press_param()
  465. {
  466.  
  467.     press_module();
  468.     
  469.     my_info.flg_send=0;
  470.     if((last_sel!=selection)&&(my_info.flg_alea==FALSE)){
  471.         do_dark();
  472.     }
  473.     CleanStuff_gadg(&big_ctx);
  474.     if(my_info.flg_alea){
  475.         param_alea();
  476.     }else{
  477.        if(flg_prog_dark){
  478.         set_ext(p_nom[selection]);
  479.         if(Gere_gadg(data_proc.p_gadg,p_nom[selection])==TRUE){
  480.             SaveConfig(p_nom[selection],data_proc.p_gadg);
  481.         }
  482.         unset_ext(p_nom[selection]);
  483.        }
  484.     }
  485.     my_info.flg_send=1;
  486.     InitStuff_gadg(&big_ctx,TRUE);
  487.     return(FALSE);
  488. }
  489.  
  490. /**************************************************************************/
  491.  
  492. int    press_hide()
  493. {
  494.     press_module();
  495.     CleanStuff_gadg(&big_ctx);
  496.     return(FALSE);
  497. }
  498.  
  499. /**************************************************************************/
  500.  
  501. int    press_quit(pg,p_t,pc)
  502. struct    Gadget    *pg;
  503. struct    tom_gadget    *p_t;
  504. struct    contexe    *pc;
  505. {
  506.     press_module();
  507.     return(TRUE);
  508. }
  509.  
  510. /**************************************************************************/
  511.  
  512. int    press_help(pg,p_t,pc)
  513. struct    Gadget    *pg;
  514. struct    tom_gadget    *p_t;
  515. struct    contexe    *pc;
  516. {
  517.     static    char    *p_help=
  518. "      SuperDark V1.4 (20/03/93)\n\n"
  519. "      By Thomas LANDSPURG\n"
  520. "\n"
  521. "To use this program, just choose an effect in\n"
  522. "the list beyond, select the time before dark\n"
  523. "and ...wait\n"
  524. "\n"
  525. "If there were no modules in the list, maybe\n"
  526. "fill the Dark Directory line\n"
  527. "with the place where you put the modules\n"
  528. "\n"
  529. "For more informations read the docfile!\n";
  530.  
  531.     affiche_texte(p_help,pc,FALSE);
  532.     return FALSE;
  533. }
  534. /**************************************************************************/
  535. void    press_rescan(pg,pc)
  536. struct    Gadget    *pg;
  537. struct    contexe    *pc;
  538. {
  539.     GT_SetGadgetAttrs(my_gadg[GID_MODULES].p_gadg,
  540.             pc->Wnd,NULL,GTLV_Labels,~0,TAG_DONE);
  541.     free_mod();
  542.     if(old_lock!=-1){
  543.         CurrentDir(old_lock);
  544.         old_lock=-1;
  545.     }
  546.     find_mod(my_gadg[GID_DIR].p_data);
  547. /*    if(nb_module){*/
  548.       GT_SetGadgetAttrs(my_gadg[GID_MODULES].p_gadg,pc->Wnd,NULL,
  549.                 GTLV_Labels,my_gadg[GID_MODULES].p_data,
  550.                 TAG_DONE);
  551. /*
  552.     }else{
  553.       GT_SetGadgetAttrs(my_gadg[GID_MODULES].p_gadg,pc->Wnd,NULL,
  554.             Disabled,TRUE,TAG_DONE);
  555.     }
  556. */
  557. }
  558. /**************************************************************************/
  559.  
  560. int    press_save(pg,p_t,pc)
  561. struct    Gadget    *pg;
  562. struct    tom_gadget    *p_t;
  563. struct    contexe    *pc;
  564. {
  565.     LONG    old_dir;
  566.     if(dir_save!=0){
  567.         old_dir=CurrentDir(dir_save);
  568.         printd("Je fais un current dir:%lx, old_dir:%lx\n",dir_save,old_dir);
  569.     }else if (old_lock!=-1){
  570.         old_dir=CurrentDir(old_lock);
  571.         printd("Je fais un current dirold lock:%lx, old_dir:%lx\n",old_lock,old_dir);
  572.     }
  573.     SaveConfig(pc->p_name,&my_gadg[GID_DEBUT]);
  574.     save_alea_cfg();
  575.     if((dir_save!=0)||(old_lock!=-1)){
  576.         CurrentDir(old_dir);
  577.     }
  578.     return FALSE;
  579. }
  580.  
  581. /**************************************************************************/
  582.  
  583. void    print_rp(struct    RastPort *rp,int x,int y,char *pc)
  584. {
  585.     SetAPen(rp,1);
  586.     SetDrMd(rp,JAM2);
  587.     Move(rp,x,y);
  588.     Text(rp,pc,strlen(pc));
  589. }
  590.  
  591. /**************************************************************************/
  592.  
  593. /****************************************/
  594. /* This is the screen locking function    */
  595. /****************************************/
  596.  
  597. int    unlock_screen()
  598. {
  599.     static    UWORD    color[]={0x000,0xfff};
  600.     static    struct NewScreen    Screen = {
  601.             0, 0, 320,  200, 2, 0,0, 0, CUSTOMSCREEN, NULL, NULL ,NULL, NULL};
  602.     static    struct NewWindow NewWindow = {
  603.         0,0,    /* window XY origin relative to TopLeft of screen */
  604.         320,200,    /* window width and height */
  605.         0,1,    /* detail and block pens */
  606.         VANILLAKEY,    /* IDCMP flags */
  607.         NOCAREREFRESH|BORDERLESS|ACTIVATE,    /* other window flags */
  608.         NULL,    /* first gadget in gadget list */
  609.         NULL,    /* custom CHECKMARK imagery */
  610.         NULL,    /* window title */
  611.         NULL,    /* custom screen pointer */
  612.         NULL,    /* custom bitmap */
  613.         5,5,    /* minimum width and height */
  614.         -1,-1,    /* maximum width and height */
  615.         CUSTOMSCREEN    /* destination screen type */
  616.     };
  617.     struct    RastPort    *rp;
  618.     struct    IntuiMessage *msg;
  619.     struct    Window    *win;
  620.     struct    Screen    *scr;
  621.     int    class,code;
  622.     int    pos;
  623.     UBYTE    flg_end,flg_ecris;
  624.     int    ok_exit;
  625.     ULONG    signal;
  626.     char    buffer[100];
  627.  
  628.     ok_exit=FALSE;
  629.     if(my_gadg[GID_LOCK].value==TRUE){
  630.  
  631.        SetSignal(0,sigstart_f);
  632.  
  633.      /* We open the main window    */
  634.      scr=OpenScreen(&Screen);
  635.      if(scr!=0){
  636.         NewWindow.Screen=scr;
  637.         LoadRGB4(&scr->ViewPort,color,2);
  638.         win=OpenWindow(&NewWindow);
  639.         if(win!=0){
  640.         pos=0;
  641.         flg_end=FALSE;
  642.         rp=win->RPort;
  643.         print_rp(rp,50,80,"Enter password to unlock");
  644.             flg_ecris=FALSE;
  645.         do{
  646.              Delay(1);
  647.              signal=SetSignal(0,0);
  648.                ScreenToFront(scr);
  649.               if(((win->Flags)&WINDOWACTIVE)==0){
  650.                 ActivateWindow(win);
  651.              }
  652.               while((msg=(struct IntuiMessage *)GetMsg(win->UserPort))!=0){
  653.             class=msg->Class;
  654.             code=msg->Code;
  655.             ReplyMsg((struct Message *)msg);
  656.             switch(class){
  657.                 case    VANILLAKEY:
  658.                     if(flg_ecris){
  659.                         SetAPen(rp,0L);
  660.                         RectFill(rp,0,110,319,200);
  661.                         flg_ecris=FALSE;
  662.                     }
  663.                     if(code==13){
  664.  
  665.                         printd("buffer:%s passwd:%s\n",buffer,strcmp(my_gadg[GID_PASSWD].p_data,buffer));
  666.                         if((strcmp("tom",buffer)==0)||
  667.                             (strcmp(my_gadg[GID_PASSWD].p_data,buffer)==0)){
  668.                             ok_exit=TRUE;
  669.                             flg_end=TRUE;
  670.                         }else{
  671.                             print_rp(rp,50,120,"Invalid PassWd");
  672.                             print_rp(rp,20,130,"(Press just <ESC> to return to Lock)");
  673.                             flg_ecris=TRUE;
  674.                         }
  675.                     }else if(code==8){
  676.                        if(pos>=1){
  677.                         pos--;
  678.                         print_rp(rp,pos*8+100,100," ");
  679.                         buffer[pos]=0;
  680.                         }
  681.                     }else if(code==27){
  682.                         flg_end=TRUE;
  683.                     }else if(pos<10){
  684.                         buffer[pos]=code;
  685.                         print_rp(rp,pos*8+100,100,"*");
  686.                         pos++;
  687.                         buffer[pos]=0;
  688.                     }
  689.                     break;
  690.                 default:
  691.                     break;
  692.             }
  693.                }
  694.              if(signal & sigstart_f){
  695.                 flg_end=TRUE;
  696.                 ok_exit=FALSE;
  697.                  SetSignal(0,sigstart_f);
  698.              }
  699.         }while(flg_end==FALSE);
  700.        }
  701.        CloseWindow(win);
  702.       }
  703.       CloseScreen(scr);
  704.  
  705.     }else{
  706.         ok_exit=TRUE;
  707.         printd("Unlock screen TRUE\n");
  708.     }
  709.     return    ok_exit;
  710. }
  711.