home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / puzzle / prefs.c < prev    next >
C/C++ Source or Header  |  1994-10-04  |  4KB  |  195 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 "Puzzle.h"
  16. #include "Puzzle_rev.h"
  17. #include "/main.h"
  18. #include "//defs.h"
  19.  
  20. struct ModulePrefs
  21. {
  22.     LONG Horiz;
  23.     LONG Vert;
  24.     LONG Divisions;
  25.     LONG Delay;
  26.     LONG FadePct;
  27.     LONG TopScr;
  28. };
  29.  
  30. struct ModulePrefs nP;
  31. VOID *OldPrefs = 0L;
  32. STATIC const UBYTE VersTag[] = VERSTAG;
  33.  
  34. int BT_SAVEClicked( VOID )
  35. {
  36.     if( OldPrefs )
  37.     {
  38.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  39.         SavePrefs( OldPrefs );
  40.         OldPrefs = 0L;
  41.     }
  42.     
  43.     return QUIT;
  44. }
  45.  
  46. int BT_TESTClicked( VOID )
  47. {
  48.     MessageServer( BM_SENDBLANK );
  49.  
  50.     return OK;
  51. }
  52.  
  53. int BT_CANCELClicked( VOID )
  54. {
  55.     OldPrefs = 0L;
  56.     
  57.     return QUIT;
  58. }
  59.  
  60. int SL_HORIZClicked( VOID )
  61. {
  62.     nP.Horiz = PuzzleMsg.Code;
  63.  
  64.     return OK;
  65. }
  66.  
  67. int SL_VERTClicked( VOID )
  68. {
  69.     nP.Vert = PuzzleMsg.Code;
  70.  
  71.     return OK;
  72. }
  73.  
  74. int SL_DIVISIONSClicked( VOID )
  75. {
  76.     nP.Divisions = PuzzleMsg.Code;
  77.  
  78.     return OK;
  79. }
  80.  
  81. int SL_DELAYClicked( VOID )
  82. {
  83.     nP.Delay = PuzzleMsg.Code;
  84.  
  85.     return OK;
  86. }
  87.  
  88. int SL_FADEClicked( VOID )
  89. {
  90.     nP.FadePct = PuzzleMsg.Code;
  91.  
  92.     return OK;
  93. }
  94.  
  95. int CY_TOPSCRClicked( VOID )
  96. {
  97.     nP.TopScr = PuzzleMsg.Code;
  98.  
  99.     return OK;
  100. }
  101.  
  102. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( PuzzleGadgets[Gad], PuzzleWnd, 0L, Tag, Val, TAG_END )
  103.  
  104. int PuzzleVanillaKey( VOID )
  105. {
  106.     switch( PuzzleMsg.Code ) {
  107.     case 's':
  108.         return BT_SAVEClicked();
  109.     case 't':
  110.         return BT_TESTClicked();
  111.     case 'c':
  112.         return QUIT;
  113.     case 'h':
  114.         BL_SetGadgetAttrs( GD_SL_HORIZ, GTSL_Level, Inc( nP.Horiz, 1, 14 ));
  115.         return OK;
  116.     case 'H':
  117.         BL_SetGadgetAttrs( GD_SL_HORIZ, GTSL_Level, Dec( nP.Horiz, 1, 2 ));
  118.         return OK;
  119.     case 'v':
  120.         BL_SetGadgetAttrs( GD_SL_VERT, GTSL_Level, Inc( nP.Vert, 1, 10 ));
  121.         return OK;
  122.     case 'V':
  123.         BL_SetGadgetAttrs( GD_SL_VERT, GTSL_Level, Dec( nP.Vert, 1, 2 ));
  124.         return OK;
  125.     case 'd':
  126.         BL_SetGadgetAttrs( GD_SL_DIVISIONS, GTSL_Level,
  127.                           Inc( nP.Divisions, 1, 10 ));
  128.         return OK;
  129.     case 'D':
  130.         BL_SetGadgetAttrs( GD_SL_DIVISIONS, GTSL_Level,
  131.                           Dec( nP.Divisions, 1, 2 ));
  132.         return OK;
  133.     case 'l':
  134.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Inc( nP.Delay, 1, 20 ));
  135.         return OK;
  136.     case 'L':
  137.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Dec( nP.Delay, 1, 0 ));
  138.         return OK;
  139.     case 'f':
  140.         BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, Inc( nP.FadePct, 1, 99 ));
  141.         return OK;
  142.     case 'F':
  143.         BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, Dec( nP.FadePct, 1, 0 ));
  144.         return OK;
  145.     default:
  146.         return OK;
  147.     }
  148. }
  149.  
  150. VOID DoPrefs( LONG command, VOID *Prefs )
  151. {
  152.     switch( command )
  153.     {
  154.     case STARTUP:
  155.         OldPrefs = Prefs;
  156.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  157.         if( !SetupScreen())
  158.         {
  159.             PuzzleLeft = ( Scr->Width - ComputeX( PuzzleWidth ))/2 -
  160.                 Scr->WBorRight;
  161.             PuzzleTop = ( Scr->Height - ComputeY( PuzzleHeight ) -
  162.                          Font->ta_YSize )/2 - Scr->WBorBottom;
  163.             if( !OpenPuzzleWindow())
  164.             {
  165.                 BL_SetGadgetAttrs( GD_SL_HORIZ, GTSL_Level, nP.Horiz );
  166.                 BL_SetGadgetAttrs( GD_SL_VERT, GTSL_Level, nP.Vert );
  167.                 BL_SetGadgetAttrs( GD_SL_DIVISIONS, GTSL_Level, nP.Divisions );
  168.                 BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, nP.Delay );
  169.                 BL_SetGadgetAttrs( GD_SL_FADE, GTSL_Level, nP.FadePct );
  170.                 BL_SetGadgetAttrs( GD_CY_TOPSCR, GTCY_Active, nP.TopScr );
  171.             }
  172.             CloseDownScreen();
  173.         }
  174.         break;
  175.     case IDCMP:
  176.         if( HandlePuzzleIDCMP() != QUIT )
  177.             break;
  178.     case KILL:
  179.         ClosePuzzleWindow();
  180.         break;
  181.     }
  182. }
  183.  
  184. LONG WndSignal( VOID )
  185. {
  186.     return PuzzleWnd ? 1L << PuzzleWnd->UserPort->mp_SigBit : 0L;
  187. }
  188.  
  189. VOID FillDefaults( VOID *Prefs )
  190. {
  191.     struct ModulePrefs mPO = { 7L, 5L, 5L, 5L, 10L, 0L };
  192.  
  193.     CopyMem( &mPO, Prefs, sizeof( struct ModulePrefs ));
  194. }
  195.