home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Goats / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-04  |  3.7 KB  |  191 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 <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 "/Garshnelib/Garshnelib_protos.h"
  16. #include "/Garshnelib/Garshnelib_pragmas.h"
  17.  
  18. #include "Goats.h"
  19. #include "Goats_rev.h"
  20. #include "/main.h"
  21. #include "//defs.h"
  22.  
  23. struct ModulePrefs {
  24.     LONG Mode;
  25.     LONG Delay;
  26.     LONG Herders;
  27.     LONG Goats;
  28.     LONG Reproduction;
  29.     LONG Screen;
  30. };
  31.  
  32. struct ModulePrefs nP;
  33. VOID *OldPrefs = 0L;
  34. STATIC const UBYTE VersTag[] = VERSTAG;
  35.  
  36. int BT_SAVEClicked( VOID )
  37. {
  38.     if( OldPrefs )
  39.     {
  40.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  41.         SavePrefs( OldPrefs );
  42.         OldPrefs = 0L;
  43.     }
  44.     
  45.     return QUIT;
  46. }
  47.  
  48. int BT_TESTClicked( VOID )
  49. {
  50.     MessageServer( BM_SENDBLANK );
  51.  
  52.     return OK;
  53. }
  54.  
  55. int BT_SCREENClicked( VOID )
  56. {
  57.     ScreenModeRequest( GoatsWnd, &nP.Mode, 0L );
  58.     
  59.     return OK;
  60. }
  61.  
  62. int BT_CANCELClicked( VOID )
  63. {
  64.     OldPrefs = 0L;
  65.     
  66.     return QUIT;
  67. }
  68.  
  69. int SL_DELAYClicked( VOID )
  70. {
  71.     nP.Delay = GoatsMsg.Code;
  72.  
  73.     return OK;
  74. }
  75.  
  76. int SL_HERDERSClicked( VOID )
  77. {
  78.     nP.Herders = GoatsMsg.Code;
  79.  
  80.     return OK;
  81. }
  82.  
  83. int SL_GOATSClicked( VOID )
  84. {
  85.     nP.Goats = GoatsMsg.Code;
  86.  
  87.     return OK;
  88. }
  89.  
  90. int SL_REPRODUCTIONClicked( VOID )
  91. {
  92.     nP.Reproduction = GoatsMsg.Code;
  93.  
  94.     return OK;
  95. }
  96.  
  97. int CB_SCREENClicked( VOID )
  98. {
  99.     nP.Screen = GoatsMsg.Code;
  100.  
  101.     return OK;
  102. }
  103.  
  104. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( GoatsGadgets[Gad], GoatsWnd, 0L, Tag, Val, TAG_END )
  105.  
  106. int GoatsVanillaKey( VOID )
  107. {
  108.     switch( GoatsMsg.Code ) {
  109.     case 's':
  110.         return BT_SAVEClicked();
  111.     case 't':
  112.         return BT_TESTClicked();
  113.     case 'd':
  114.         return BT_SCREENClicked();
  115.     case 'c':
  116.         return QUIT;
  117.     case 'l':
  118.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Inc( nP.Delay, 1, 120 ));
  119.         return OK;
  120.     case 'L':
  121.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Dec( nP.Delay, 1, 0 ));
  122.         return OK;
  123.     case 'h':
  124.         BL_SetGadgetAttrs( GD_SL_HERDERS, GTSL_Level, Inc( nP.Herders, 1, 999 ));
  125.         return OK;
  126.     case 'H':
  127.         BL_SetGadgetAttrs( GD_SL_HERDERS, GTSL_Level, Dec( nP.Herders, 1, 5 ));
  128.         return OK;
  129.     case 'g':
  130.         BL_SetGadgetAttrs( GD_SL_GOATS, GTSL_Level, Inc( nP.Goats, 1, 99 ));
  131.         return OK;
  132.     case 'G':
  133.         BL_SetGadgetAttrs( GD_SL_GOATS, GTSL_Level, Dec( nP.Goats, 1, 1 ));
  134.         return OK;
  135.     case 'r':
  136.         BL_SetGadgetAttrs( GD_SL_REPRODUCTION, GTSL_Level, Inc( nP.Reproduction, 1, 99 ));
  137.         return OK;
  138.     case 'R':
  139.         BL_SetGadgetAttrs( GD_SL_REPRODUCTION, GTSL_Level, Dec( nP.Reproduction, 1, 1 ));
  140.         return OK;
  141.     default:
  142.         return OK;
  143.     }
  144. }
  145.  
  146. VOID DoPrefs( LONG command, VOID *Prefs )
  147. {
  148.     switch( command )
  149.     {
  150.     case STARTUP:
  151.         OldPrefs = Prefs;
  152.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  153.         if( !SetupScreen())
  154.         {
  155.             GoatsLeft = ( Scr->Width - ComputeX( GoatsWidth ))/2 - Scr->WBorRight;
  156.             GoatsTop = ( Scr->Height - ComputeY( GoatsHeight ) - Font->ta_YSize )/2 -
  157.                 Scr->WBorBottom;
  158.             if( !OpenGoatsWindow())
  159.             {
  160.                 BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, nP.Delay );
  161.                 BL_SetGadgetAttrs( GD_SL_HERDERS, GTSL_Level, nP.Herders );
  162.                 BL_SetGadgetAttrs( GD_SL_GOATS, GTSL_Level, nP.Goats );
  163.                 BL_SetGadgetAttrs( GD_SL_REPRODUCTION, GTSL_Level, nP.Reproduction );
  164.                 BL_SetGadgetAttrs( GD_CB_SCREEN, GTSL_Level, nP.Screen );
  165.             }
  166.             CloseDownScreen();
  167.         }
  168.         break;
  169.     case IDCMP:
  170.         if( HandleGoatsIDCMP() != QUIT )
  171.             break;
  172.     case KILL:
  173.         CloseGoatsWindow();
  174.         break;
  175.     }
  176. }
  177.  
  178. LONG WndSignal( VOID )
  179. {
  180.     return GoatsWnd ? 1L << GoatsWnd->UserPort->mp_SigBit : 0L;
  181. }
  182.  
  183. VOID FillDefaults( VOID *Prefs )
  184. {
  185.     struct ModulePrefs mPO = { 0L, 0L, 40L, 60L, 2L, 0L };
  186.  
  187.     mPO.Mode = getTopScreenMode();
  188.     
  189.     CopyMem( &mPO, Prefs, sizeof( struct ModulePrefs ));
  190. }
  191.