home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / worms / prefs.c < prev    next >
C/C++ Source or Header  |  1994-09-07  |  3KB  |  157 lines

  1. /*
  2.  *    Copyright (c) 1993 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 <libraries/gadtools.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/gadtools_protos.h>
  14.  
  15. #include "Worms.h"
  16. #include "Worms_rev.h"
  17. #include "/main.h"
  18. #include "//defs.h"
  19.  
  20. struct ModulePrefs
  21. {
  22.     LONG Number;
  23.     LONG Length;
  24.     LONG FadePct;
  25.     LONG TopScr;
  26. };
  27.  
  28. struct ModulePrefs nP;
  29. VOID *OldPrefs = 0L;
  30. STATIC const UBYTE VersTag[] = VERSTAG;
  31.  
  32. int BT_SAVEClicked( VOID )
  33. {
  34.     if( OldPrefs )
  35.     {
  36.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  37.         SavePrefs( OldPrefs );
  38.         OldPrefs = 0L;
  39.     }
  40.     
  41.     return QUIT;
  42. }
  43.  
  44. int BT_TESTClicked( VOID )
  45. {
  46.     MessageServer( BM_SENDBLANK );
  47.  
  48.     return OK;
  49. }
  50.  
  51. int BT_CANCELClicked( VOID )
  52. {
  53.     OldPrefs = 0L;
  54.     
  55.     return QUIT;
  56. }
  57.  
  58. int SL_NUMBERClicked( VOID )
  59. {
  60.     nP.Number = WormsMsg.Code;
  61.  
  62.     return OK;
  63. }
  64.  
  65. int SL_LENGTHClicked( VOID )
  66. {
  67.     nP.Length = WormsMsg.Code;
  68.  
  69.     return OK;
  70. }
  71.  
  72. int SL_FADEClicked( VOID )
  73. {
  74.     nP.FadePct = WormsMsg.Code;
  75.  
  76.     return OK;
  77. }
  78.  
  79. int CY_TOPSCRClicked( VOID )
  80. {
  81.     nP.TopScr = WormsMsg.Code;
  82.  
  83.     return OK;
  84. }
  85.  
  86. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( WormsGadgets[Gad], WormsWnd, 0L, Tag, Val, TAG_END )
  87.  
  88. int WormsVanillaKey( VOID )
  89. {
  90.     switch( WormsMsg.Code ) {
  91.     case 's':
  92.         return BT_SAVEClicked();
  93.     case 't':
  94.         return BT_TESTClicked();
  95.     case 'c':
  96.         return QUIT;
  97.     case 'w':
  98.         BL_SetGadgetAttrs( GD_SL_NUMBER, GTSL_Level, Inc( nP.Number, 1, 50 ));
  99.         return OK;
  100.     case 'W':
  101.         BL_SetGadgetAttrs( GD_SL_NUMBER, GTSL_Level, Dec( nP.Number, 1, 1 ));
  102.         return OK;
  103.     case 'f':
  104.         BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, Inc( nP.FadePct, 1, 99 ));
  105.         return OK;
  106.     case 'F':
  107.         BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, Dec( nP.FadePct, 1, 0 ));
  108.         return OK;
  109.     default:
  110.         return OK;
  111.     }
  112. }
  113.  
  114. VOID DoPrefs( LONG command, VOID *Prefs )
  115. {
  116.     switch( command )
  117.     {
  118.     case STARTUP:
  119.         OldPrefs = Prefs;
  120.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  121.         if( !SetupScreen())
  122.         {
  123.             WormsLeft = ( Scr->Width - ComputeX( WormsWidth ))/2 -
  124.                 Scr->WBorRight;
  125.             WormsTop = ( Scr->Height - ComputeY( WormsHeight ) -
  126.                         Font->ta_YSize )/2 - Scr->WBorBottom;
  127.             if( !OpenWormsWindow())
  128.             {
  129.                 BL_SetGadgetAttrs( GD_SL_NUMBER, GTSL_Level, nP.Number );
  130.                 BL_SetGadgetAttrs( GD_SL_LENGTH, GTSL_Level, nP.Length );
  131.                 BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, nP.FadePct );
  132.                 BL_SetGadgetAttrs( GD_CY_TOPSCR, GTCY_Active, nP.TopScr );
  133.             }
  134.             CloseDownScreen();
  135.         }
  136.         break;
  137.     case IDCMP:
  138.         if( HandleWormsIDCMP() != QUIT )
  139.             break;
  140.     case KILL:
  141.         CloseWormsWindow();
  142.         break;
  143.     }
  144. }
  145.  
  146. LONG WndSignal( VOID )
  147. {
  148.     return WormsWnd ? 1L << WormsWnd->UserPort->mp_SigBit : 0L;
  149. }
  150.  
  151. VOID FillDefaults( VOID *Prefs )
  152. {
  153.     struct ModulePrefs mPO = { 10L, 10L, 10L, 0L };
  154.  
  155.     CopyMem( &mPO, Prefs, sizeof( struct ModulePrefs ));
  156. }
  157.