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