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

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <dos/dos.h>
  5.  
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8. #include <intuition/gadgetclass.h>
  9. #include <libraries/gadtools.h>
  10. #include <libraries/asl.h>
  11. #include <graphics/text.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/gadtools_protos.h>
  17. #include <clib/asl_protos.h>
  18.  
  19. #include "/Garshnelib/Garshnelib_protos.h"
  20. #include "/Garshnelib/Garshnelib_pragmas.h"
  21.  
  22. #include <string.h>
  23.  
  24. #include "Clock.h"
  25. #include "Clock_rev.h"
  26. #include "//defs.h"
  27. #include "/main.h"
  28.  
  29. struct ModulePrefs {
  30.     LONG Mode;
  31.     LONG Delay;
  32.     LONG Cycle;
  33.     LONG Secs;
  34.     LONG Military;
  35.     struct TextAttr Font;
  36.     BYTE fName[64];
  37. };
  38.  
  39. struct ModulePrefs nP;
  40. VOID *OldPrefs = 0L;
  41. STATIC const UBYTE VersTag[] = VERSTAG;
  42.  
  43. int BT_SAVEClicked( VOID )
  44. {
  45.     if( OldPrefs )
  46.     {
  47.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  48.         SavePrefs( OldPrefs );
  49.         OldPrefs = 0L;
  50.     }
  51.     
  52.     return QUIT;
  53. }
  54.  
  55. int BT_TESTClicked( VOID )
  56. {
  57.     MessageServer( BM_SENDBLANK );
  58.     
  59.     return OK;
  60. }
  61.  
  62. int BT_SCREENClicked( VOID )
  63. {
  64.     ScreenModeRequest( ClockWnd, &nP.Mode, 0L );
  65.     
  66.     return OK;
  67. }
  68.  
  69. int BT_CANCELClicked( VOID )
  70. {
  71.     OldPrefs = 0L;
  72.     
  73.     return QUIT;
  74. }
  75.  
  76. int SL_DELAYClicked( VOID )
  77. {
  78.     nP.Delay = ClockMsg.Code;
  79.     
  80.     return OK;
  81. }
  82.  
  83. int CY_MILClicked( VOID )
  84. {
  85.     nP.Military = ClockMsg.Code;
  86.     
  87.     return OK;
  88. }
  89.  
  90. int CY_CYCLEClicked( VOID )
  91. {
  92.     nP.Cycle = ClockMsg.Code;
  93.     
  94.     return OK;
  95. }
  96.  
  97. int CY_SECSClicked( VOID )
  98. {
  99.     nP.Secs = ClockMsg.Code;
  100.     
  101.     return OK;
  102. }
  103.  
  104. int BT_FONTClicked( VOID )
  105. {
  106.     struct FontRequester *fReq;
  107.     struct Library *AslBase;
  108.     
  109.     AslBase = OpenLibrary( "asl.library", 37L );
  110.  
  111.     if( !AslBase )
  112.         return OK;
  113.     
  114.     fReq = ( struct FontRequester * )AllocAslRequestTags( ASL_FontRequest, ASL_FontName,
  115.                                                          ( LONG )nP.fName, ASL_FontHeight,
  116.                                                          nP.Font.ta_YSize, ASL_MaxHeight, 100,
  117.                                                          TAG_DONE );
  118.     if( fReq )
  119.     {
  120.         if( AslRequestTags( fReq, ASLFO_Window, ClockWnd, ASLFO_SleepWindow, TRUE, ASLFO_TitleText,
  121.                            ( LONG )"Please choose a font...", 0L ))
  122.         {
  123.             CopyMem( fReq->fo_Attr.ta_Name, nP.fName, 31 );
  124.             nP.Font.ta_YSize = fReq->fo_Attr.ta_YSize;
  125.         }
  126.         FreeAslRequest( fReq );
  127.     }
  128.  
  129.     CloseLibrary( AslBase );
  130.     
  131.     return OK;
  132. }
  133.  
  134. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( ClockGadgets[Gad], ClockWnd, 0L, Tag, Val, TAG_END )
  135.  
  136. int ClockVanillaKey( VOID )
  137. {
  138.     switch( ClockMsg.Code ) {
  139.     case 's':
  140.         return BT_SAVEClicked();
  141.     case 't':
  142.         return BT_TESTClicked();
  143.     case 'd':
  144.         return BT_SCREENClicked();
  145.     case 'c':
  146.         return QUIT;
  147.     case 'f':
  148.         return BT_FONTClicked();
  149.     case 'p':
  150.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Inc( nP.Delay, 1, 120 ));
  151.         return OK;
  152.     case 'S':
  153.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Dec( nP.Delay, 1, 0 ));
  154.         return OK;
  155.     default:
  156.         return OK;
  157.     }
  158. }
  159.  
  160. #define ComputeX( x ) ((( FontX * x ) + 4 ) / 8 )
  161. #define ComputeY( x ) ((( FontY * x ) + 4 ) / 8 )
  162.  
  163. VOID DoPrefs( LONG command, VOID *Prefs )
  164. {
  165.     switch( command )
  166.     {
  167.     case STARTUP:
  168.         OldPrefs = Prefs;
  169.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  170.         if( !SetupScreen())
  171.         {
  172.             ClockLeft = ( Scr->Width - ComputeX( ClockWidth ))/2 - Scr->WBorRight;
  173.             ClockTop = ( Scr->Height - ComputeY( ClockHeight ) - Font->ta_YSize )/2 - Scr->WBorBottom;
  174.             if( !OpenClockWindow())
  175.             {
  176.                 BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, nP.Delay );
  177.                 BL_SetGadgetAttrs( GD_CY_MIL, GTCY_Active, nP.Military );
  178.                 BL_SetGadgetAttrs( GD_CY_CYCLE, GTCY_Active, nP.Cycle );
  179.                 BL_SetGadgetAttrs( GD_CY_SECS, GTCY_Active, nP.Secs );
  180.             }
  181.             CloseDownScreen();
  182.         }
  183.         break;
  184.     case IDCMP:
  185.         if( HandleClockIDCMP() != QUIT )
  186.             break;
  187.     case KILL:
  188.         CloseClockWindow();
  189.         break;
  190.     }
  191. }
  192.  
  193. LONG WndSignal( VOID )
  194. {
  195.     return ClockWnd ? 1L << ClockWnd->UserPort->mp_SigBit : 0L;
  196. }
  197.  
  198. VOID FillDefaults( VOID *Prefs )
  199. {
  200.     struct ModulePrefs *NewPrefs = ( struct ModulePrefs * )Prefs;
  201.     
  202.     NewPrefs->Mode = getTopScreenMode();
  203.     NewPrefs->Delay = 60L;
  204.     NewPrefs->Cycle = 0L;
  205.     NewPrefs->Secs = 0L;
  206.     NewPrefs->Military = 0L;
  207.     NewPrefs->Font.ta_YSize = 11;
  208.     NewPrefs->Font.ta_Style = FS_NORMAL;
  209.     NewPrefs->Font.ta_Flags = FPB_ROMFONT;
  210.     strcpy( NewPrefs->fName, "topaz.font" );
  211. }
  212.