home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / clock / blank.c next >
C/C++ Source or Header  |  1994-10-09  |  5KB  |  247 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <utility/date.h>
  11. #include <hardware/custom.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/diskfont_protos.h>
  18. #include <clib/utility_protos.h>
  19. #include <clib/alib_protos.h>
  20.  
  21. #include "/Garshnelib/Garshnelib_protos.h"
  22. #include "/Garshnelib/Garshnelib_pragmas.h"
  23.  
  24. #include <string.h>
  25.  
  26. #include "Clock.h"
  27. #include "//defs.h"
  28. #include "/main.h"
  29.  
  30. extern __far struct Custom custom;
  31.  
  32. struct ModulePrefs
  33. {
  34.     LONG Mode;
  35.     LONG Delay;
  36.     LONG Cycle;
  37.     LONG Secs;
  38.     LONG Military;
  39.     struct TextAttr Font;
  40.     BYTE fName[64];
  41. };
  42.  
  43. extern struct ModulePrefs nP;
  44. LONG Hour[] = {12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11};
  45.  
  46. LONG getTime( BYTE *time, struct ModulePrefs *nP )
  47. {
  48.     struct DateStamp Stamp;
  49.     struct ClockData Data;
  50.     LONG pos = 0, hour;
  51.     
  52.     DateStamp( &Stamp );
  53.     Amiga2Date((( Stamp.ds_Days * 1440 ) + Stamp.ds_Minute ) * 60 +
  54.                Stamp.ds_Tick/TICKS_PER_SECOND, &Data );
  55.     
  56.     if( !nP->Military )
  57.         hour = Hour[Data.hour];
  58.     else
  59.         hour = Data.hour;
  60.  
  61.     if( hour > 9 )
  62.         time[pos++] = ( BYTE )( hour / 10 ) + '0';
  63.     time[pos++] = ( BYTE )( hour % 10 ) + '0';
  64.  
  65.     time[pos++] = ':';
  66.  
  67.     time[pos++] = ( BYTE )( Data.min / 10 ) + '0';
  68.     time[pos++] = ( BYTE )( Data.min % 10 ) + '0';
  69.  
  70.     if( nP->Secs )
  71.     {
  72.         time[pos++] = ':';
  73.         time[pos++] = ( BYTE )( Data.sec / 10 ) + '0';
  74.         time[pos++] = ( BYTE )( Data.sec % 10 ) + '0';
  75.     }
  76.  
  77.     if( !nP->Military )
  78.     {
  79.         if( Data.hour > 11 )
  80.             time[pos++] = 'p';
  81.         else
  82.             time[pos++] = 'a';
  83.         time[pos++] = 'm';
  84.     }
  85.  
  86.     time[pos] = '\0';
  87.     
  88.     return ( LONG )strlen( time );
  89. }
  90.  
  91. LONG Diff( BYTE *One, BYTE *Two )
  92. {
  93.     while( *One && *Two )
  94.         if( *One++ != *Two++ )
  95.             return TRUE;
  96.  
  97.     return *One != *Two;
  98. }
  99.  
  100. LONG Blank( VOID *Prefs )
  101. {
  102.     struct TextFont *font;
  103.     struct ModulePrefs *bP;
  104.     struct Screen *Scr;
  105.     struct Window *Wnd;
  106.     struct RastPort *RP;
  107.     struct ViewPort *VP;
  108.     LONG vals[] = {
  109.         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10,
  110.         9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  111.     BYTE scrClock[32], oldClock[32];
  112.     LONG ScrToFrontCnt=0, c1 = 0, c2 = 14, c3 = 28, delay, fonty, RetVal = OK;
  113.     LONG x, y, Wid, Hei, len, nlen, numc, base, count = 0, dx = -1, dy = -1;
  114.     
  115.     if( ClockWnd )
  116.         bP = &nP;
  117.     else
  118.         bP = ( struct ModulePrefs * )Prefs;
  119.     
  120.     delay = bP->Delay;
  121.     
  122.     bP->Font.ta_Name = bP->fName;
  123.     font = OpenDiskFont(&( bP->Font ));
  124.     if( !font )
  125.     {
  126.         strcpy( bP->fName, "topaz.font" );
  127.         font = OpenDiskFont(&( bP->Font ));
  128.     }
  129.     base = font->tf_Baseline;
  130.     fonty = bP->Font.ta_YSize;
  131.     
  132.     Scr = OpenScreenTags( 0l, SA_DisplayID, bP->Mode, SA_Depth, 1, SA_Quiet,
  133.                          TRUE, SA_Behind, TRUE, SA_Overscan, OSCAN_STANDARD,
  134.                          SA_Font, &( bP->Font ), TAG_DONE );
  135.     if( Scr )
  136.     {
  137.         Wid = Scr->Width;
  138.         Hei = Scr->Height;
  139.         RP = &( Scr->RastPort );
  140.         VP = &( Scr->ViewPort );
  141.         
  142.         SetRGB4( VP, 0, 0L, 0L, 0L );
  143.         switch( bP->Cycle )
  144.         {
  145.         case 0:
  146.             SetRGB4( VP, 1, vals[c1], vals[c2], vals[c3] );
  147.             break;
  148.         case 1:
  149.             SetRGB4( VP, 1, ( ULONG )RangeRand( 15 ) + 1,
  150.                     ( ULONG )RangeRand( 15 ) + 1,
  151.                     ( ULONG )RangeRand( 15 ) + 1 );
  152.             break;
  153.         case 2:
  154.             SetRGB4( VP, 1, 15, 15, 15 );
  155.             break;
  156.         case 3:
  157.             setCopperList( Hei, 1, VP, &custom );
  158.             break;
  159.         }
  160.         
  161.         numc = getTime( scrClock, bP );
  162.         while(( len = TextLength( RP, scrClock, numc )) >= Wid )
  163.             numc--;
  164.         
  165.         x = ( Wid - len ) / 2;
  166.         y = ( Hei - fonty ) / 2;
  167.         
  168.         SetAPen( RP, 1 );
  169.         Move( RP, x, y + base );
  170.         Text( RP, scrClock, numc );
  171.         
  172.         Wnd = BlankMousePointer( Scr );
  173.         ScreenToFront( Scr );
  174.         
  175.         while( RetVal == OK )
  176.         {
  177.             WaitTOF();
  178.  
  179.             if(!( ScrToFrontCnt++ % ( 20 * bP->Secs ? 1 : 6 )))
  180.             {
  181.                 numc = getTime( scrClock, bP );
  182.                 while(( nlen = TextLength( RP, scrClock, numc )) + x > Wid )
  183.                     numc--;
  184.                 if( Diff( oldClock, scrClock ))
  185.                 {
  186.                     Move( RP, x, y + base );
  187.                     Text( RP, scrClock, numc );
  188.                     
  189.                     if( nlen < len )
  190.                     {
  191.                         SetAPen( RP, 0 );
  192.                         RectFill( RP, x + nlen, y - 2, x + len + 2,
  193.                                  y + fonty + 2 );
  194.                         SetAPen( RP, 1 );
  195.                     }
  196.                     len = nlen;
  197.                     strcpy( oldClock, scrClock );
  198.                 }
  199.             }
  200.             
  201.             if(!( ScrToFrontCnt % 60 ))
  202.                 ScreenToFront( Scr );
  203.  
  204.             if( !delay || !( ++count % delay ))
  205.             {
  206.                 ScrollRaster( RP, dx, dy, x-2, y-2, x+len+2, y+fonty+2 );
  207.                 x -= dx;
  208.                 y -= dy;
  209.                 if( x < 3 )
  210.                     dx = -1;
  211.                 else
  212.                     if( x > Wid-len-3 )
  213.                         dx = 1;
  214.                 if( y < 3 )
  215.                     dy = -1;
  216.                 else
  217.                     if( y > Hei-fonty-3 )
  218.                         dy = 1;
  219.             }
  220.  
  221.             if( !bP->Cycle )
  222.             {
  223.                 if(!( count % 10 ))
  224.                 {
  225.                     c1 = ++c1 % 42;
  226.                     c2 = ++c2 % 42;
  227.                     c3 = ++c3 % 42;
  228.                     SetRGB4( VP, 1, vals[c1], vals[c2], vals[c3] );
  229.                 }
  230.             }
  231.  
  232.             RetVal = ContinueBlanking();
  233.         }
  234.         if( bP->Cycle == 3 )
  235.             clearCopperList( VP );
  236.         UnblankMousePointer( Wnd );
  237.         CloseScreen( Scr );
  238.     }
  239.     else
  240.         RetVal = FAILED;
  241.     
  242.     if( font )
  243.         CloseFont( font );
  244.     
  245.     return RetVal;
  246. }
  247.