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