home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Text / blank.c next >
Encoding:
C/C++ Source or Header  |  1994-10-10  |  3.9 KB  |  193 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 <hardware/custom.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/diskfont_protos.h>
  17. #include <clib/utility_protos.h>
  18. #include <clib/alib_protos.h>
  19.  
  20. #include <string.h>
  21.  
  22. #include "/Garshnelib/Garshnelib_protos.h"
  23. #include "/Garshnelib/Garshnelib_pragmas.h"
  24.  
  25. #include "Text.h"
  26. #include "//defs.h"
  27. #include "/main.h"
  28.  
  29. #define RAND( base, offset ) (( LONG )( RangeRand( base ) + offset ))
  30.  
  31. struct ModulePrefs
  32. {
  33.     LONG Mode;
  34.     LONG Delay;
  35.     LONG Cycle;
  36.     BYTE Text[128];
  37.     BYTE fName[64];
  38.     struct TextAttr Font;
  39. };
  40.  
  41. typedef struct _mPoint
  42. {
  43.     LONG x;
  44.     LONG y;
  45. } mPoint;
  46.  
  47. extern struct ModulePrefs nP;
  48. extern __far struct Custom custom;
  49.  
  50. LONG vals[] = {
  51.     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
  52.     0x0D, 0x0E, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06,
  53.     0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  54.     0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  55.     };
  56.  
  57. LONG Blank( VOID *Prefs )
  58. {
  59.     LONG Wid, Hei, dx = -1, dy = -1, len, numc, count = 0;
  60.     LONG c1 = 0, c2 = 14, c3 = 28, RetVal = OK;
  61.     mPoint new, old, size, min, max;
  62.     struct TextFont *font;
  63.     struct ModulePrefs *tP;
  64.     struct Screen *TextScr;
  65.     struct RastPort *Rast;
  66.     struct ViewPort *View;
  67.     struct Window *Wnd;
  68.     
  69.     if( TextWnd )
  70.         tP = &nP;
  71.     else
  72.         tP = ( struct ModulePrefs * )Prefs;
  73.  
  74.     tP->Font.ta_Name = tP->fName;
  75.     font = OpenDiskFont( &tP->Font );
  76.     if( !font )
  77.         tP->Font.ta_Name = "topaz.font";
  78.     
  79.     TextScr = OpenScreenTags( 0l, SA_DisplayID, tP->Mode, SA_Depth, 1,
  80.                              SA_Quiet, TRUE, SA_Overscan, OSCAN_STANDARD,
  81.                              SA_Font, &( tP->Font ), SA_Behind, TRUE,
  82.                              TAG_DONE );
  83.     if( TextScr )
  84.     {
  85.         Rast = &( TextScr->RastPort );
  86.         View = &( TextScr->ViewPort );
  87.         Wid = TextScr->Width;
  88.         Hei = TextScr->Height;
  89.         
  90.         numc = strlen( tP->Text );
  91.         while(( len = TextLength( Rast, tP->Text, numc )) >= Wid - 5 )
  92.             numc--;
  93.         
  94.         SetRGB4( View, 0, 0L, 0L, 0L );
  95.         switch( tP->Cycle )
  96.         {
  97.         case 0:
  98.             SetRGB4( View, 1, vals[c1], vals[c2], vals[c3] );
  99.             break;
  100.         case 1:
  101.             SetRGB4( View, 1, RAND( 10, 5 ), RAND( 10, 5 ), RAND( 10, 5 ));
  102.             break;
  103.         case 2:
  104.             SetRGB4( View, 1, 15, 15, 15 );
  105.             break;
  106.         case 3:
  107.             setCopperList( Hei, 1, View, &custom );
  108.             break;
  109.         }        
  110.         
  111.         new.x = old.x = ( Wid - len ) / 2;
  112.         new.y = old.y = ( Hei - tP->Font.ta_YSize ) / 2;
  113.         size.x = len + 2;
  114.         size.y = tP->Font.ta_YSize + 2;
  115.         
  116.         min.x = 0;
  117.         min.y = 0;
  118.         max.x = Wid - size.x - 3;
  119.         max.y = Hei - size.y - 3;
  120.         
  121.         SetAPen( Rast, 1 );
  122.         Move( Rast, old.x + 1, old.y + font->tf_Baseline + 1 );
  123.         Text( Rast, tP->Text, numc );
  124.         
  125.         Wnd = BlankMousePointer( TextScr );
  126.         ScreenToFront( TextScr );
  127.         
  128.         while( RetVal == OK )
  129.         {
  130.             WaitTOF();
  131.  
  132.             if(!( count++ % 60 ))
  133.                 ScreenToFront( TextScr );
  134.             
  135.             if( !tP->Cycle && !( count % 10 ))
  136.             {
  137.                 c1 = ++c1 % 42;
  138.                 c2 = ++c2 % 42;
  139.                 c3 = ++c3 % 42;
  140.                 SetRGB4( View, 1, vals[c1], vals[c2], vals[c3] );
  141.             }
  142.             
  143.             if( !tP->Delay || !( count % tP->Delay ))
  144.             {
  145.                 new.x += dx;
  146.                 new.y += dy;
  147.                 
  148.                 if( new.x < min.x )
  149.                 {
  150.                     new.x = min.x;
  151.                     dx = 1;
  152.                 }
  153.                 else if( new.x > max.x )
  154.                 {
  155.                     new.x = max.x;
  156.                     dx = -1;
  157.                 }
  158.                 
  159.                 if( new.y < min.y )
  160.                 {
  161.                     new.y = min.y;
  162.                     dy = 1;
  163.                 }
  164.                 else if( new.y > max.y )
  165.                 {
  166.                     new.y = max.y;
  167.                     dy = -1;
  168.                 }
  169.                 
  170.                 BltBitMapRastPort( Rast->BitMap, old.x, old.y, Rast, new.x,
  171.                                   new.y, size.x, size.y, 0xC0 );
  172.                 
  173.                 old = new;
  174.             }
  175.             RetVal = ContinueBlanking();
  176.         }
  177.         UnblankMousePointer( Wnd );
  178.  
  179.         if( tP->Cycle == 3 )
  180.             clearCopperList( View );
  181.     }
  182.     else
  183.         RetVal = FAILED;
  184.     
  185.     if( TextScr )
  186.         CloseScreen( TextScr );
  187.  
  188.     if( font )
  189.         CloseFont( font );
  190.  
  191.     return RetVal;
  192. }
  193.