home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / species / species.c < prev    next >
C/C++ Source or Header  |  1994-07-02  |  6KB  |  242 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 "Species.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *SpeciesWnd = NULL;
  31. struct Gadget         *SpeciesGList = NULL;
  32. struct IntuiMessage    SpeciesMsg;
  33. struct Gadget         *SpeciesGadgets[5];
  34. UWORD                  SpeciesLeft = 0;
  35. UWORD                  SpeciesTop = 12;
  36. UWORD                  SpeciesWidth = 227;
  37. UWORD                  SpeciesHeight = 36;
  38. UBYTE                 *SpeciesWdt = (UBYTE *)"Species Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *SpeciesFont = NULL;
  43.  
  44. UWORD SpeciesGTypes[] = {
  45.     SLIDER_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     BUTTON_KIND,
  49.     BUTTON_KIND
  50. };
  51.  
  52. struct NewGadget SpeciesNGad[] = {
  53.     47, 4, 150, 11, (UBYTE *)"S_ize", NULL, GD_SL_SIZE, PLACETEXT_LEFT, NULL, (APTR)SL_SIZEClicked,
  54.     4, 19, 52, 14, (UBYTE *)"_Save", NULL, GD_BT_SAVE, PLACETEXT_IN, NULL, (APTR)BT_SAVEClicked,
  55.     172, 19, 52, 14, (UBYTE *)"_Cancel", NULL, GD_BT_CANCEL, PLACETEXT_IN, NULL, (APTR)BT_CANCELClicked,
  56.     60, 19, 52, 14, (UBYTE *)"_Test", NULL, GD_BT_TEST, PLACETEXT_IN, NULL, (APTR)BT_TESTClicked,
  57.     116, 19, 52, 14, (UBYTE *)"_Display", NULL, GD_BT_SCREEN, PLACETEXT_IN, NULL, (APTR)BT_SCREENClicked
  58. };
  59.  
  60. ULONG SpeciesGTags[] = {
  61.     (GTSL_Min), 3, (GTSL_Max), 10, (GTSL_Level), 6, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%2ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  62.     (GT_Underscore), '_', (TAG_DONE),
  63.     (GT_Underscore), '_', (TAG_DONE),
  64.     (GT_Underscore), '_', (TAG_DONE),
  65.     (GT_Underscore), '_', (TAG_DONE)
  66. };
  67.  
  68. static UWORD ComputeX( UWORD value )
  69. {
  70.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  71. }
  72.  
  73. static UWORD ComputeY( UWORD value )
  74. {
  75.     return(( UWORD )((( FontY * value ) + 4 ) / 9 ));
  76. }
  77.  
  78. static void ComputeFont( UWORD width, UWORD height )
  79. {
  80.     Forbid();
  81.     Font = &Attr;
  82.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  83.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  84.     FontX = GfxBase->DefaultFont->tf_XSize;
  85.     Permit();
  86.  
  87.     OffX = Scr->WBorLeft;
  88.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  89.  
  90.     if ( width && height ) {
  91.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  92.             goto UseTopaz;
  93.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  94.             goto UseTopaz;
  95.     }
  96.     return;
  97.  
  98. UseTopaz:
  99.     Font->ta_Name = (STRPTR)"topaz.font";
  100.     FontX = FontY = Font->ta_YSize = 8;
  101. }
  102.  
  103. int SetupScreen( void )
  104. {
  105.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  106.         return( 1L );
  107.  
  108.     ComputeFont( 0, 0 );
  109.  
  110.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  111.         return( 2L );
  112.  
  113.     return( 0L );
  114. }
  115.  
  116. void CloseDownScreen( void )
  117. {
  118.     if ( VisualInfo ) {
  119.         FreeVisualInfo( VisualInfo );
  120.         VisualInfo = NULL;
  121.     }
  122.  
  123.     if ( Scr        ) {
  124.         UnlockPubScreen( NULL, Scr );
  125.         Scr = NULL;
  126.     }
  127. }
  128.  
  129. int HandleSpeciesIDCMP( void )
  130. {
  131.     struct IntuiMessage    *m;
  132.     int            (*func)();
  133.     BOOL            running = TRUE;
  134.  
  135.     while( m = GT_GetIMsg( SpeciesWnd->UserPort )) {
  136.  
  137.         CopyMem(( char * )m, ( char * )&SpeciesMsg, (long)sizeof( struct IntuiMessage ));
  138.  
  139.         GT_ReplyIMsg( m );
  140.  
  141.         switch ( SpeciesMsg.Class ) {
  142.  
  143.             case    IDCMP_REFRESHWINDOW:
  144.                 GT_BeginRefresh( SpeciesWnd );
  145.                 GT_EndRefresh( SpeciesWnd, TRUE );
  146.                 break;
  147.  
  148.             case    IDCMP_VANILLAKEY:
  149.                 running = SpeciesVanillaKey();
  150.                 break;
  151.  
  152.             case    IDCMP_GADGETUP:
  153.             case    IDCMP_GADGETDOWN:
  154.                 func = ( void * )(( struct Gadget * )SpeciesMsg.IAddress )->UserData;
  155.                 running = func();
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenSpeciesWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD        lc, tc;
  167.     UWORD        wleft = SpeciesLeft, wtop = SpeciesTop, ww, wh;
  168.  
  169.     ComputeFont( SpeciesWidth, SpeciesHeight );
  170.  
  171.     ww = ComputeX( SpeciesWidth );
  172.     wh = ComputeY( SpeciesHeight );
  173.  
  174.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  175.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  176.  
  177.     if ( ! ( SpeciesFont = OpenDiskFont( Font )))
  178.         return( 5L );
  179.  
  180.     if ( ! ( g = CreateContext( &SpeciesGList )))
  181.         return( 1L );
  182.  
  183.     for( lc = 0, tc = 0; lc < Species_CNT; lc++ ) {
  184.  
  185.         CopyMem((char * )&SpeciesNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  186.  
  187.         ng.ng_VisualInfo = VisualInfo;
  188.         ng.ng_TextAttr   = Font;
  189.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  190.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  191.         ng.ng_Width      = ComputeX( ng.ng_Width );
  192.         ng.ng_Height     = ComputeY( ng.ng_Height);
  193.  
  194.         SpeciesGadgets[ lc ] = g = CreateGadgetA((ULONG)SpeciesGTypes[ lc ], g, &ng, ( struct TagItem * )&SpeciesGTags[ tc ] );
  195.  
  196.         while( SpeciesGTags[ tc ] ) tc += 2;
  197.         tc++;
  198.  
  199.         if ( NOT g )
  200.             return( 2L );
  201.     }
  202.  
  203.     if ( ! ( SpeciesWnd = OpenWindowTags( NULL,
  204.                 WA_Left,    wleft,
  205.                 WA_Top,        wtop,
  206.                 WA_Width,    ww + OffX + Scr->WBorRight,
  207.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  208.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  209.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  210.                 WA_Gadgets,    SpeciesGList,
  211.                 WA_Title,    SpeciesWdt,
  212.                 WA_ScreenTitle,    "Species Prefs",
  213.                 WA_PubScreen,    Scr,
  214.                 WA_AutoAdjust,    TRUE,
  215.                 WA_PubScreenFallBack,    TRUE,
  216.                 TAG_DONE )))
  217.     return( 4L );
  218.  
  219.     GT_RefreshWindow( SpeciesWnd, NULL );
  220.  
  221.     return( 0L );
  222. }
  223.  
  224. void CloseSpeciesWindow( void )
  225. {
  226.     if ( SpeciesWnd        ) {
  227.         CloseWindow( SpeciesWnd );
  228.         SpeciesWnd = NULL;
  229.     }
  230.  
  231.     if ( SpeciesGList      ) {
  232.         FreeGadgets( SpeciesGList );
  233.         SpeciesGList = NULL;
  234.     }
  235.  
  236.     if ( SpeciesFont ) {
  237.         CloseFont( SpeciesFont );
  238.         SpeciesFont = NULL;
  239.     }
  240. }
  241.  
  242.