home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / time.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  11KB  |  500 lines

  1.   /* Fichier clock.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/memory.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <graphics/gfx.h>
  11. #include <graphics/gfxbase.h>
  12. #include <dos/dos.h>
  13. #include <graphics/gfxmacros.h>
  14. #include <graphics/rastport.h>
  15. #include <graphics/displayinfo.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/diskfont_protos.h>
  21.  
  22. #include "/includes/struct.h"
  23. #include "/includes/tom_gadget.h"
  24.  
  25. struct Library        *DiskfontBase;
  26. extern  struct  GfxBase *GfxBase;
  27.  
  28. #define    VOID_ARG    void    __regargs
  29.  
  30. char    *p_text_info="   ClockV1.1\n\nChoose on of the three kind of clocks:\n\n- A digital (bad looking at the moment)\n- Aiguilles (also bad looking!)\n- Moderne: A little bit better\n\n      February 1993\n      By Thomas LANDSPURG";
  31.  
  32. WORD    areabuffer[25];
  33. struct    AreaInfo    myarea;
  34. struct    TmpRas    tmpras;
  35.  
  36. struct    RastPort    *rp;
  37. struct    Screen        *s;
  38. struct    TextAttr myta;
  39.  
  40. #define    WIDTH    640
  41. #define    HEIGHT    256
  42.  
  43. UWORD  ScreenColors[] = {
  44.     0x000,
  45.     0xFFF,
  46.     0xFE2,
  47.     0x68B,
  48.     0xF90,
  49.     0x0F0,
  50.     0x00F,
  51.     0xF0F,
  52.     0x000 };
  53.  
  54. struct NewScreen Screen= {
  55.      0, 0, WIDTH, HEIGHT, 3,0,1,HIRES,CUSTOMSCREEN,NULL,NULL,NULL,NULL};
  56.  
  57. #define    RAYON    80
  58. #define    CENTRE_X (RAYON+20)*2
  59. #define    CENTRE_Y (RAYON+20)
  60.  
  61. #define    TAILLE_N    ((RAYON+20)*2)
  62.  
  63. struct NewWindow    Window = {
  64.     WIDTH/2-(RAYON+20)*2,
  65.     HEIGHT/2-(RAYON+20),
  66.     (RAYON+20)*4,
  67.     (RAYON+20)*2,0,1,
  68.     IDCMP_GADGETDOWN|IDCMP_GADGETUP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_INTUITICKS,
  69. /*    WFLG_SMART_REFRESH|WFLG_ACTIVATE,*/
  70.     WFLG_SMART_REFRESH|WFLG_ACTIVATE|BORDERLESS,
  71.     0l,0,0,0,0,5,5,-1,-1,CUSTOMSCREEN};
  72.  
  73. UBYTE         *TypeLabels[] = {
  74.     "Digital",
  75.     "Normal",
  76.     "Modern",
  77.     0l };
  78.  
  79. struct    TextAttr myta={"topaz                    ",0,0,0};
  80. struct    tom_gadget    my_gadg[]={
  81.     {"Type",    MX,    167,14,17,40,0, 0,0,0,(char *)TypeLabels},
  82.     {"_seconds",    CHECKBOX,160, 46, 10,10,0,0,0,0,0},
  83.     {"_Fonts",    FONT,    160, 66, 80,12,0,         0,0,0,(char *)&myta},
  84.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}};
  85.  
  86. static    short    int    cos[360]={
  87. 256,255,255,255,255,255,254,254,
  88. 253,252,252,251,250,249,248,247,
  89. 246,244,243,242,240,238,237,235,
  90. 233,232,230,228,226,223,221,219,
  91. 217,214,212,209,207,204,201,198,
  92. 196,193,190,187,184,181,177,174,
  93. 171,167,164,161,157,154,150,146,
  94. 143,139,135,131,127,124,120,116,
  95. 112,108,104,100,95,91,87,83,
  96. 79,74,70,66,61,57,53,48,
  97. 44,40,35,31,26,22,17,13,
  98. 8,4,0,-4,-8,-13,-17,-22,
  99. -26,-31,-35,-40,-44,-48,-53,-57,
  100. -61,-66,-70,-74,-79,-83,-87,-91,
  101. -95,-100,-104,-108,-112,-116,-120,-124,
  102. -128,-131,-135,-139,-143,-146,-150,-154,
  103. -157,-161,-164,-167,-171,-174,-177,-181,
  104. -184,-187,-190,-193,-196,-198,-201,-204,
  105. -207,-209,-212,-214,-217,-219,-221,-223,
  106. -226,-228,-230,-232,-233,-235,-237,-238,
  107. -240,-242,-243,-244,-246,-247,-248,-249,
  108. -250,-251,-252,-252,-253,-254,-254,-255,
  109. -255,-255,-255,-255,-256,-255,-255,-255,
  110. -255,-255,-254,-254,-253,-252,-252,-251,
  111. -250,-249,-248,-247,-246,-244,-243,-242,
  112. -240,-238,-237,-235,-233,-232,-230,-228,
  113. -226,-223,-221,-219,-217,-214,-212,-209,
  114. -207,-204,-201,-198,-196,-193,-190,-187,
  115. -184,-181,-177,-174,-171,-167,-164,-161,
  116. -157,-154,-150,-146,-143,-139,-135,-131,
  117. -127,-124,-120,-116,-112,-108,-104,-100,
  118. -95,-91,-87,-83,-79,-74,-70,-66,
  119. -61,-57,-53,-48,-44,-40,-35,-31,
  120. -26,-22,-17,-13,-8,-4,0,4,
  121. 8,13,17,22,26,31,35,40,
  122. 44,48,53,57,61,66,70,74,
  123. 79,83,87,91,95,100,104,108,
  124. 112,116,120,124,128,131,135,139,
  125. 143,146,150,154,157,161,164,167,
  126. 171,174,177,181,184,187,190,193,
  127. 196,198,201,204,207,209,212,214,
  128. 217,219,221,223,226,228,230,232,
  129. 233,235,237,238,240,242,243,244,
  130. 246,247,248,249,250,251,252,252,
  131. 253,254,254,255,255,255,255,255
  132. };
  133. static    short    int    centre_x,centre_y,old_x,old_y,rayon;
  134. static    int    old_min,old_hour,old_sec;
  135.  
  136. VOID_ARG    aff_line(struct    RastPort    *rp,
  137.         short    int    cx,
  138.         short    int    cy,
  139.         short    int    sx,
  140.         short    int    sy,
  141.         USHORT        angle)
  142. {
  143.     short    int    x,y;
  144.     unsigned    short    int    angle_sin;
  145.     angle=angle%360;
  146.     angle_sin=(angle+360-90)%360;
  147.     x=sx*cos[angle]-sy*cos[angle_sin];
  148.     y=sy*cos[angle]+sx*cos[angle_sin];
  149.     Draw(rp,cx+2*x/256,cy-y/256);
  150.  
  151. }
  152.  
  153. VOID_ARG    aff_aguille(struct    RastPort    *rp,
  154.         short    int    size,
  155.         USHORT        angle)
  156. {
  157.     short        int    d;
  158.     unsigned    short    int    ang;
  159.  
  160.     ang=(360-angle)%360;
  161.     d=size/10;
  162.     Move(rp,centre_x,centre_y);
  163.     aff_line(rp,centre_x,centre_y,-d,size-d,ang);
  164.     aff_line(rp,centre_x,centre_y,0,size,ang);
  165.     aff_line(rp,centre_x,centre_y,d,size-d,ang);
  166.     Draw(rp,centre_x,centre_y);
  167. }
  168.  
  169. VOID_ARG    aff_aguille_sec(struct    RastPort    *rp,
  170.         short    int    size,
  171.         USHORT        angle)
  172. {
  173.     short        int    d;
  174.     unsigned    short    int    ang;
  175.  
  176.     ang=(360-angle)%360;
  177.     d=size/10;
  178.     Move(rp,centre_x,centre_y);
  179.     aff_line(rp,centre_x,centre_y,0,size,ang);
  180.     Move(rp,centre_x,centre_y);
  181.     ang=(ang+180)%360;
  182.     aff_line(rp,centre_x,centre_y,0,size/10,ang);
  183. }
  184.  
  185. VOID_ARG    aff_aguille_pleine(struct    RastPort    *rp,
  186.             short    int    size,
  187.             short    int    div,
  188.             USHORT        angle)
  189. {
  190.     short    int    x1,y1,x2,y2;
  191.  
  192.     x1=size*cos[(angle+360-90)%360];
  193.     y1=size*cos[(angle+360-180)%360];
  194.     x2=(x1)/div;
  195.     y2=(y1)/div;
  196.     x1>>=8;
  197.     y1>>=8;
  198.     x2>>=8;
  199.     y2>>=8;
  200.  
  201.     AreaMove(rp,centre_x+2*y2,centre_y-x2);
  202. /*    AreaDraw(rp,centre_x+2*(y2+x1),centre_y-x2+y1);*/
  203. /*    AreaDraw(rp,centre_x+2*(-y2+x1),centre_y+x2+y1);*/
  204.  
  205.     AreaDraw(rp,centre_x+2*x1,centre_y+y1);
  206.  
  207.     AreaDraw(rp,centre_x-2*y2,centre_y+x2);
  208.     AreaEnd(rp);
  209. }
  210.  
  211. VOID_ARG    aff_time(struct    Window    *win)
  212. {
  213.    struct    RastPort    *rp;
  214.    int    seconds,minutes,hours;
  215.    char        buffer[40];
  216.    struct    DateStamp    now;
  217.  
  218.    DateStamp(&now) ;
  219.  
  220.    seconds=(int)(now.ds_Tick/TICKS_PER_SECOND);
  221.  
  222.  
  223.    if(seconds!=old_sec){
  224.  
  225.     rp=win->RPort;
  226.     minutes = now.ds_Minute % 60 ;
  227.     hours = now.ds_Minute / 10 ;    /* Je divise par 6 tt a l'heure */
  228.  
  229.     SPrintF(buffer,"Time:%02ld:%02ld:%02ld",hours/6,minutes,seconds);
  230.  
  231.     switch(my_gadg[0].value){
  232.         case 0:
  233.         Move(rp,10,win->Height-10);
  234.         Text(rp,buffer,4+3*3);
  235.         old_sec=seconds;
  236.         break;
  237.         case 1:
  238.         SetDrMd(rp,JAM2);
  239.  
  240.         if( ( (old_sec!=seconds)&&(my_gadg[1].value!=FALSE))||
  241.             ( (old_min!=minutes)&&(my_gadg[1].value==FALSE))){
  242.  
  243.             SetDrMd(rp,COMPLEMENT);
  244.             SetAPen(rp,2);
  245.  
  246.             if(my_gadg[1].value){
  247.                 if(old_sec!=-1){
  248.                     aff_aguille_sec(rp,rayon-10,360*old_sec/60);
  249.                 }
  250.                 aff_aguille_sec(rp,rayon-10,360*seconds/60);
  251.                 old_sec=seconds;    
  252.             }
  253.  
  254.             if(minutes!=old_min){
  255.                 SetAPen(rp,3);
  256.                 if(old_min!=-1){
  257.                     aff_aguille(rp,rayon-10,360*old_min/60);
  258.                 }
  259.                 old_min=minutes;
  260.                 aff_aguille(rp,rayon-10,360*old_min/60);
  261.             }
  262.  
  263.             if(hours!=old_hour){
  264.                 SetAPen(rp,2);
  265.                 if(old_hour!=-1){
  266.                     aff_aguille(rp,rayon-30,(360*old_hour/(12*6))%360);
  267.                 }
  268.                 old_hour=hours;
  269.                 aff_aguille(rp,rayon-30,(360*old_hour/(12*6))%360);
  270.             }
  271.         }
  272.  
  273.         break;
  274.         case 2:
  275.  
  276.         SetAPen(rp,3);
  277.         SetDrMd(rp,JAM2);
  278.  
  279.         if( ( (old_sec!=seconds)&&(my_gadg[1].value!=FALSE))||
  280.             ( (old_min!=minutes)&&(my_gadg[1].value==FALSE))){
  281.  
  282.             SetAPen(rp,1);
  283.             if((old_hour!=-1)&&(old_hour!=hours)){
  284.                 aff_aguille_pleine(rp,rayon-30,5,(360*old_hour/(12*6))%360);
  285.             }
  286.             if((old_min!=-1)&&(old_min!=minutes)){
  287.                 aff_aguille_pleine(rp,rayon-15,8,360*old_min/60);
  288.             }
  289.             if(old_sec!=-1){
  290.                 aff_aguille_pleine(rp,rayon-10,20,360*old_sec/60);
  291.             }
  292.  
  293.             old_hour=hours;
  294.             SetAPen(rp,6);
  295.             aff_aguille_pleine(rp,rayon-30,5,(360*old_hour/(12*6))%360);
  296.  
  297.             old_min=minutes;
  298.             SetAPen(rp,7);
  299.             aff_aguille_pleine(rp,rayon-15,8,360*old_min/60);
  300.  
  301.             if(my_gadg[1].value!=FALSE){
  302.                 SetAPen(rp,5);
  303.                 aff_aguille_pleine(rp,rayon-10,20,360*seconds/60);
  304.                 old_sec=seconds;
  305.             }
  306.  
  307.         }
  308.  
  309.         break;
  310.     }
  311.    }
  312. }
  313.  
  314.  
  315. VOID_ARG    init_clock(struct    Window    *win)
  316. {
  317.     short    int    i,x,y;
  318.         struct TextFont *myfont;
  319.     SHORT    len,h;
  320.     char    debug2[100];
  321.     centre_x=win->Width/2;
  322.     centre_y=win->Height/2;
  323.     centre_x=CENTRE_X;
  324.     centre_y=CENTRE_Y;
  325.     rayon=RAYON;
  326.     old_x=0;
  327.     old_y=0;
  328.     old_min=-1;
  329.     old_hour=-1;
  330.     old_sec=-1;
  331.  
  332.     switch(my_gadg[0].value){
  333.         case 0:
  334.         if(DiskfontBase&&(myta.ta_Name!=0)){
  335.                     if (myfont = OpenDiskFont(&myta))
  336.                     {
  337.                         SetFont(rp, myfont);
  338.                             SetSoftStyle(rp,   myta.ta_Style ^ myfont->tf_Style,
  339.                                       (FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC));
  340.             }
  341.         }
  342.         if(myta.ta_Name!=0){
  343.             h=myta.ta_YSize;
  344.         }else{
  345.             h=8;
  346.         }
  347.         h+=10;
  348.         len=TextLength(rp,"Time:00:00:00",13);
  349.         len+=20;
  350.         SizeWindow(win,-(win->Width-len),-(win->Height-h));
  351.         break;
  352.         case 1:
  353.         SetAPen(win->RPort,3);
  354.         SetDrMd(win->RPort,JAM2);
  355.         SetAPen(win->RPort,4);
  356.         for(i=0;i<12*3;i++){
  357.             x=(rayon+10)*cos[(i*(360/12))%360];
  358.             y=(rayon+10)*cos[(i*(360/12)+90)%360];
  359.             Move(win->RPort,centre_x+2*x/256,centre_y+y/256);
  360.             x=(x*9)/10;
  361.             y=(y*9)/10;
  362.             Draw(win->RPort,centre_x+2*x/256,centre_y+y/256);
  363.         }
  364.         break;
  365.         case 2:
  366.         SetDrMd(win->RPort,JAM2);
  367.         SetAPen(win->RPort,3);
  368.         AreaMove(win->RPort,centre_x,centre_y);
  369.         AreaEllipse(win->RPort,centre_x,centre_y,(rayon+10)*2,rayon+10);
  370.         DrawEllipse(win->RPort,centre_x,centre_y,(rayon+10)*2,rayon+10);
  371.         AreaEnd(win->RPort);
  372.  
  373.         SetAPen(win->RPort,1);
  374.         AreaMove(win->RPort,centre_x,centre_y);
  375.         AreaEllipse(win->RPort,centre_x,centre_y,(rayon-10)*2,rayon-10);
  376.         AreaEnd(win->RPort);
  377.         DrawEllipse(win->RPort,centre_x,centre_y,(rayon-10)*2,rayon-10);
  378.         break;
  379.     }
  380. }
  381.  
  382. void    dark()
  383. {
  384.    struct    IntuiMessage    *msg;
  385.    ULONG        class,depth;
  386.    struct    Window    *w_time;
  387.    UWORD    px,py,tx,ty;
  388.    static    UWORD    sx=1;
  389.    static    UWORD    sy=1;
  390.    static    UWORD    oldpy=0;
  391.    static    UWORD    oldpx=0;
  392.  
  393. /*
  394.    switch(my_gadg[0].value){
  395.     case 0:
  396.     case 1:
  397.         depth=2;
  398.         break;
  399.     case 2:
  400.         depth=3;
  401.         break;
  402.    }
  403.    Screen.Depth=depth;
  404. */
  405.  
  406.    if (( s = OpenScreen(&Screen ))!=NULL){
  407.  
  408.     rp = &(s->RastPort);
  409.  
  410.     SetRast(rp,0);
  411.     Window.Screen=s;
  412.     Window.Width=TAILLE_N*2;
  413.     Window.Height=TAILLE_N;
  414.     LoadRGB4(&s->ViewPort,ScreenColors,1<<3);
  415.  
  416.     if (  w_time = OpenWindow(&Window )){
  417.         FreeSprite (0);
  418.         GfxBase->SpriteReserved|=1;
  419.         rp=w_time->RPort;
  420. /*
  421.         RefreshWindow( w_time, 0l );
  422. */
  423.         InitArea(&myarea,areabuffer,10);
  424.         rp->AreaInfo=&myarea;
  425.         rp->TmpRas=(struct TmpRas *)InitTmpRas(&tmpras,AllocRaster(WIDTH,HEIGHT),RASSIZE(WIDTH,HEIGHT));
  426.     
  427.         init_clock(w_time);
  428.  
  429.         px=w_time->LeftEdge<<3;
  430.         py=w_time->TopEdge<<3;
  431.         sx=1;
  432.  
  433.         while(tst_end()==FALSE){
  434.             WaitPort(w_time->UserPort);
  435.             while((msg=(struct IntuiMessage *)GetMsg(w_time->UserPort))!=0){
  436.                 class=msg->Class;
  437.                 ReplyMsg((struct Message *)msg);
  438.                 switch(class){
  439.                     case    INTUITICKS:
  440.                         aff_time(w_time);
  441.  
  442.                         px+=sx;
  443.                         py+=sy;
  444.                         tx=px>>3;
  445.                         ty=py>>3;
  446.                         if(px<0){
  447.                             px=0;
  448.                             sx=-sx;
  449.                         }
  450.                         if(py<0){
  451.                             py=0;
  452.                             sy=-sy;
  453.                         }
  454.                         if(tx+w_time->Width>=s->Width){
  455.                             px-=sx;
  456.                             sx=-sx;
  457.                         }
  458.                         if(ty+w_time->Height>=s->Height){
  459.                             py-=sy;
  460.                             sy=-sy;
  461.                         }
  462.                         if((oldpx!=tx)||(oldpy!=ty)){
  463. /*                            MoveWindow(w_time,tx-oldpx,ty-oldpy);*/
  464.                             oldpx=tx;
  465.                             oldpy=ty;
  466.                         }
  467.  
  468.                         break;
  469.  
  470.                     case    REFRESHWINDOW:
  471. /*                        RefreshWindow( w_time, 0l );
  472. */
  473.                         init_clock(w_time);
  474.                         break;
  475.                     default:
  476.                         break;
  477.                 }
  478.             }
  479.         }
  480.     }
  481.     if ( w_time)CloseWindow( w_time );
  482.     FreeRaster(tmpras.RasPtr,WIDTH,HEIGHT);
  483.     CloseScreen(s);
  484.    }
  485. }
  486.  
  487. void    proc_init()
  488. {
  489.         DiskfontBase = OpenLibrary("diskfont.library", 37L);
  490. }
  491.  
  492. void    proc_save()
  493. {
  494. }
  495. void    proc_end()
  496. {
  497.     if(DiskfontBase)CloseLibrary(DiskfontBase);
  498. }
  499.  
  500.