home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / aswarm / aswarm.c < prev    next >
C/C++ Source or Header  |  1994-06-05  |  8KB  |  279 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "ASwarm.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = "Workbench";
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *ASwarmWnd = NULL;
  31. struct Gadget         *ASwarmGList = NULL;
  32. struct IntuiMessage    ASwarmMsg;
  33. struct Gadget         *ASwarmGadgets[11];
  34. UWORD                  ASwarmLeft = 0;
  35. UWORD                  ASwarmTop = 12;
  36. UWORD                  ASwarmWidth = 285;
  37. UWORD                  ASwarmHeight = 86;
  38. UBYTE                 *ASwarmWdt = (UBYTE *)"Aswarm Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *ASwarmFont = NULL;
  43.  
  44. UBYTE *CY_SPEED0Labels[] = {
  45.     (UBYTE *)"Slooow",
  46.     (UBYTE *)"Sloow",
  47.     (UBYTE *)"Slow",
  48.     (UBYTE *)"Normal",
  49.     (UBYTE *)"Fast",
  50.     (UBYTE *)"Faast",
  51.     (UBYTE *)"Faaast",
  52.     NULL };
  53.  
  54. UBYTE *CY_AIM0Labels[] = {
  55.     (UBYTE *)"Normal",
  56.     (UBYTE *)"Aim Wasp",
  57.     NULL };
  58.  
  59. UBYTE *CY_CYCLE0Labels[] = {
  60.     (UBYTE *)"Normal",
  61.     (UBYTE *)"Cycle",
  62.     NULL };
  63.  
  64. UWORD ASwarmGTypes[] = {
  65.     SLIDER_KIND,
  66.     BUTTON_KIND,
  67.     BUTTON_KIND,
  68.     SLIDER_KIND,
  69.     BUTTON_KIND,
  70.     BUTTON_KIND,
  71.     CYCLE_KIND,
  72.     CYCLE_KIND,
  73.     CYCLE_KIND,
  74.     SLIDER_KIND,
  75.     SLIDER_KIND
  76. };
  77.  
  78. struct NewGadget ASwarmNGad[] = {
  79.     190, 20, 66, 12, (UBYTE *)"_Wasps", NULL, GD_SL_WASPS, PLACETEXT_LEFT, NULL, (APTR)SL_WASPSClicked,
  80.     4, 68, 66, 14, (UBYTE *)"_Save", NULL, GD_BT_SAVE, PLACETEXT_IN, NULL, (APTR)BT_SAVEClicked,
  81.     214, 68, 66, 14, (UBYTE *)"_Cancel", NULL, GD_BT_CANCEL, PLACETEXT_IN, NULL, (APTR)BT_CANCELClicked,
  82.     189, 4, 66, 12, (UBYTE *)"_Bees", NULL, GD_SL_BEES, PLACETEXT_LEFT, NULL, (APTR)SL_BEESClicked,
  83.     74, 68, 66, 14, (UBYTE *)"_Test", NULL, GD_BT_TEST, PLACETEXT_IN, NULL, (APTR)BT_TESTClicked,
  84.     144, 68, 66, 14, (UBYTE *)"_Display", NULL, GD_BT_SCREEN, PLACETEXT_IN, NULL, (APTR)BT_SCREENClicked,
  85.     4, 4, 79, 14, (UBYTE *)"S_peed", NULL, GD_CY_SPEED, PLACETEXT_RIGHT, NULL, (APTR)CY_SPEEDClicked,
  86.     4, 40, 79, 14, (UBYTE *)"_Aim", NULL, GD_CY_AIM, PLACETEXT_RIGHT, NULL, (APTR)CY_AIMClicked,
  87.     4, 22, 79, 14, (UBYTE *)"C_olor", NULL, GD_CY_CYCLE, PLACETEXT_RIGHT, NULL, (APTR)CY_CYCLEClicked,
  88.     190, 52, 66, 12, (UBYTE *)"Wasp Acce_l", NULL, GD_SL_WASPACC, PLACETEXT_LEFT, NULL, (APTR)SL_WASPACCClicked,
  89.     190, 36, 66, 12, (UBYTE *)"B_ee Accel", NULL, GD_SL_BEEACC, PLACETEXT_LEFT, NULL, (APTR)SL_BEEACCClicked
  90. };
  91.  
  92. ULONG ASwarmGTags[] = {
  93.     (GTSL_Min), 1, (GTSL_Max), 10, (GTSL_Level), 3, (GTSL_MaxLevelLen), 6, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  94.     (GT_Underscore), '_', (TAG_DONE),
  95.     (GT_Underscore), '_', (TAG_DONE),
  96.     (GTSL_Min), 1, (GTSL_Max), 50, (GTSL_Level), 16, (GTSL_MaxLevelLen), 5, (GTSL_LevelFormat), (ULONG)"%2ld0", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  97.     (GT_Underscore), '_', (TAG_DONE),
  98.     (GT_Underscore), '_', (TAG_DONE),
  99.     (GTCY_Labels), (ULONG)&CY_SPEED0Labels[ 0 ], (GTCY_Active), 3, (GT_Underscore), '_', (TAG_DONE),
  100.     (GTCY_Labels), (ULONG)&CY_AIM0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  101.     (GTCY_Labels), (ULONG)&CY_CYCLE0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  102.     (GTSL_Min), 1, (GTSL_Level), 3, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  103.     (GTSL_Min), 1, (GTSL_Level), 5, (GTSL_MaxLevelLen), 5, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE)
  104. };
  105.  
  106. static UWORD ComputeX( UWORD value )
  107. {
  108.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  109. }
  110.  
  111. static UWORD ComputeY( UWORD value )
  112. {
  113.     return(( UWORD )((( FontY * value ) + 4 ) / 9 ));
  114. }
  115.  
  116. static void ComputeFont( UWORD width, UWORD height )
  117. {
  118.     Forbid();
  119.     Font = &Attr;
  120.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  121.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  122.     FontX = GfxBase->DefaultFont->tf_XSize;
  123.     Permit();
  124.  
  125.     OffX = Scr->WBorLeft;
  126.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  127.  
  128.     if ( width && height ) {
  129.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  130.             goto UseTopaz;
  131.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  132.             goto UseTopaz;
  133.     }
  134.     return;
  135.  
  136. UseTopaz:
  137.     Font->ta_Name = (STRPTR)"topaz.font";
  138.     FontX = FontY = Font->ta_YSize = 8;
  139. }
  140.  
  141. int SetupScreen( void )
  142. {
  143.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  144.         return( 1L );
  145.  
  146.     ComputeFont( 0, 0 );
  147.  
  148.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  149.         return( 2L );
  150.  
  151.     return( 0L );
  152. }
  153.  
  154. void CloseDownScreen( void )
  155. {
  156.     if ( VisualInfo ) {
  157.         FreeVisualInfo( VisualInfo );
  158.         VisualInfo = NULL;
  159.     }
  160.  
  161.     if ( Scr        ) {
  162.         UnlockPubScreen( NULL, Scr );
  163.         Scr = NULL;
  164.     }
  165. }
  166.  
  167. int HandleASwarmIDCMP( void )
  168. {
  169.     struct IntuiMessage    *m;
  170.     int            (*func)();
  171.     BOOL            running = TRUE;
  172.  
  173.     while( m = GT_GetIMsg( ASwarmWnd->UserPort )) {
  174.  
  175.         CopyMem(( char * )m, ( char * )&ASwarmMsg, (long)sizeof( struct IntuiMessage ));
  176.  
  177.         GT_ReplyIMsg( m );
  178.  
  179.         switch ( ASwarmMsg.Class ) {
  180.  
  181.             case    IDCMP_REFRESHWINDOW:
  182.                 GT_BeginRefresh( ASwarmWnd );
  183.                 GT_EndRefresh( ASwarmWnd, TRUE );
  184.                 break;
  185.  
  186.             case    IDCMP_VANILLAKEY:
  187.                 running = ASwarmVanillaKey();
  188.                 break;
  189.  
  190.             case    IDCMP_GADGETUP:
  191.             case    IDCMP_GADGETDOWN:
  192.                 func = ( void * )(( struct Gadget * )ASwarmMsg.IAddress )->UserData;
  193.                 running = func();
  194.                 break;
  195.         }
  196.     }
  197.     return( running );
  198. }
  199.  
  200. int OpenASwarmWindow( void )
  201. {
  202.     struct NewGadget    ng;
  203.     struct Gadget    *g;
  204.     UWORD        lc, tc;
  205.     UWORD        wleft = ASwarmLeft, wtop = ASwarmTop, ww, wh;
  206.  
  207.     ComputeFont( ASwarmWidth, ASwarmHeight );
  208.  
  209.     ww = ComputeX( ASwarmWidth );
  210.     wh = ComputeY( ASwarmHeight );
  211.  
  212.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  213.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  214.  
  215.     if ( ! ( ASwarmFont = OpenDiskFont( Font )))
  216.         return( 5L );
  217.  
  218.     if ( ! ( g = CreateContext( &ASwarmGList )))
  219.         return( 1L );
  220.  
  221.     for( lc = 0, tc = 0; lc < ASwarm_CNT; lc++ ) {
  222.  
  223.         CopyMem((char * )&ASwarmNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  224.  
  225.         ng.ng_VisualInfo = VisualInfo;
  226.         ng.ng_TextAttr   = Font;
  227.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  228.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  229.         ng.ng_Width      = ComputeX( ng.ng_Width );
  230.         ng.ng_Height     = ComputeY( ng.ng_Height);
  231.  
  232.         ASwarmGadgets[ lc ] = g = CreateGadgetA((ULONG)ASwarmGTypes[ lc ], g, &ng, ( struct TagItem * )&ASwarmGTags[ tc ] );
  233.  
  234.         while( ASwarmGTags[ tc ] ) tc += 2;
  235.         tc++;
  236.  
  237.         if ( NOT g )
  238.             return( 2L );
  239.     }
  240.  
  241.     if ( ! ( ASwarmWnd = OpenWindowTags( NULL,
  242.                 WA_Left,    wleft,
  243.                 WA_Top,        wtop,
  244.                 WA_Width,    ww + OffX + Scr->WBorRight,
  245.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  246.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|CYCLEIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  247.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  248.                 WA_Gadgets,    ASwarmGList,
  249.                 WA_Title,    ASwarmWdt,
  250.                 WA_ScreenTitle,    "Aswarm Prefs",
  251.                 WA_AutoAdjust,    TRUE,
  252.                 WA_PubScreenFallBack,    TRUE,
  253.                 TAG_DONE )))
  254.     return( 4L );
  255.  
  256.     GT_RefreshWindow( ASwarmWnd, NULL );
  257.  
  258.     return( 0L );
  259. }
  260.  
  261. void CloseASwarmWindow( void )
  262. {
  263.     if ( ASwarmWnd        ) {
  264.         CloseWindow( ASwarmWnd );
  265.         ASwarmWnd = NULL;
  266.     }
  267.  
  268.     if ( ASwarmGList      ) {
  269.         FreeGadgets( ASwarmGList );
  270.         ASwarmGList = NULL;
  271.     }
  272.  
  273.     if ( ASwarmFont ) {
  274.         CloseFont( ASwarmFont );
  275.         ASwarmFont = NULL;
  276.     }
  277. }
  278.  
  279.