home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / interference / interference.c < prev    next >
C/C++ Source or Header  |  1994-08-28  |  7KB  |  240 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 "Interference.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *InterferenceWnd = NULL;
  31. struct Gadget         *InterferenceGList = NULL;
  32. struct IntuiMessage    InterferenceMsg;
  33. struct Gadget         *InterferenceGadgets[5];
  34. UWORD                  InterferenceLeft = 0;
  35. UWORD                  InterferenceTop = 12;
  36. UWORD                  InterferenceWidth = 220;
  37. UWORD                  InterferenceHeight = 36;
  38. UBYTE                 *InterferenceWdt = (UBYTE *)"Interference Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *InterferenceFont = NULL;
  43.  
  44. UWORD InterferenceGTypes[] = {
  45.     BUTTON_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     BUTTON_KIND,
  49.     SLIDER_KIND
  50. };
  51.  
  52. struct NewGadget InterferenceNGad[] = {
  53.     4, 19, 50, 14, (UBYTE *)"_Save", NULL, GD_BT_SAVE, PLACETEXT_IN, NULL, (APTR)BT_SAVEClicked,
  54.     166, 19, 50, 14, (UBYTE *)"_Cancel", NULL, GD_BT_CANCEL, PLACETEXT_IN, NULL, (APTR)BT_CANCELClicked,
  55.     58, 19, 50, 14, (UBYTE *)"_Test", NULL, GD_BT_TEST, PLACETEXT_IN, NULL, (APTR)BT_TESTClicked,
  56.     112, 19, 50, 14, (UBYTE *)"_Display", NULL, GD_BT_SCREEN, PLACETEXT_IN, NULL, (APTR)BT_SCREENClicked,
  57.     99, 3, 97, 12, (UBYTE *)"Extend _Palette", NULL, GD_SL_EXTPAL, PLACETEXT_LEFT, NULL, (APTR)SL_EXTPALClicked
  58. };
  59.  
  60. ULONG InterferenceGTags[] = {
  61.     (GT_Underscore), '_', (TAG_DONE),
  62.     (GT_Underscore), '_', (TAG_DONE),
  63.     (GT_Underscore), '_', (TAG_DONE),
  64.     (GT_Underscore), '_', (TAG_DONE),
  65.     (GTSL_Max), 4, (GTSL_Level), 2, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%2ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (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 HandleInterferenceIDCMP( void )
  130. {
  131.     struct IntuiMessage    *m;
  132.     int            (*func)();
  133.     BOOL            running = TRUE;
  134.  
  135.     while( m = GT_GetIMsg( InterferenceWnd->UserPort )) {
  136.  
  137.         CopyMem(( char * )m, ( char * )&InterferenceMsg, (long)sizeof( struct IntuiMessage ));
  138.  
  139.         GT_ReplyIMsg( m );
  140.  
  141.         switch ( InterferenceMsg.Class ) {
  142.  
  143.             case    IDCMP_REFRESHWINDOW:
  144.                 GT_BeginRefresh( InterferenceWnd );
  145.                 GT_EndRefresh( InterferenceWnd, TRUE );
  146.                 break;
  147.  
  148.             case    IDCMP_VANILLAKEY:
  149.                 running = InterferenceVanillaKey();
  150.                 break;
  151.  
  152.             case    IDCMP_GADGETUP:
  153.             case    IDCMP_GADGETDOWN:
  154.                 func = ( void * )(( struct Gadget * )InterferenceMsg.IAddress )->UserData;
  155.                 running = func();
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenInterferenceWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD        lc, tc;
  167.     UWORD        wleft = InterferenceLeft, wtop = InterferenceTop, ww, wh;
  168.  
  169.     ComputeFont( InterferenceWidth, InterferenceHeight );
  170.  
  171.     ww = ComputeX( InterferenceWidth );
  172.     wh = ComputeY( InterferenceHeight );
  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 ( ! ( InterferenceFont = OpenDiskFont( Font )))
  178.         return( 5L );
  179.  
  180.     if ( ! ( g = CreateContext( &InterferenceGList )))
  181.         return( 1L );
  182.  
  183.     for( lc = 0, tc = 0; lc < Interference_CNT; lc++ ) {
  184.  
  185.         CopyMem((char * )&InterferenceNGad[ 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.         InterferenceGadgets[ lc ] = g = CreateGadgetA((ULONG)InterferenceGTypes[ lc ], g, &ng, ( struct TagItem * )&InterferenceGTags[ tc ] );
  195.  
  196.         while( InterferenceGTags[ tc ] ) tc += 2;
  197.         tc++;
  198.  
  199.         if ( NOT g )
  200.             return( 2L );
  201.     }
  202.  
  203.     if ( ! ( InterferenceWnd = 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,    BUTTONIDCMP|SLIDERIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  209.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  210.                 WA_Gadgets,    InterferenceGList,
  211.                 WA_Title,    InterferenceWdt,
  212.                 WA_ScreenTitle,    "Interference Prefs",
  213.                 WA_PubScreen,    Scr,
  214.                 TAG_DONE )))
  215.     return( 4L );
  216.  
  217.     GT_RefreshWindow( InterferenceWnd, NULL );
  218.  
  219.     return( 0L );
  220. }
  221.  
  222. void CloseInterferenceWindow( void )
  223. {
  224.     if ( InterferenceWnd        ) {
  225.         CloseWindow( InterferenceWnd );
  226.         InterferenceWnd = NULL;
  227.     }
  228.  
  229.     if ( InterferenceGList      ) {
  230.         FreeGadgets( InterferenceGList );
  231.         InterferenceGList = NULL;
  232.     }
  233.  
  234.     if ( InterferenceFont ) {
  235.         CloseFont( InterferenceFont );
  236.         InterferenceFont = NULL;
  237.     }
  238. }
  239.  
  240.