home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / plasma / plasma.c < prev    next >
C/C++ Source or Header  |  1994-08-28  |  6KB  |  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 "Plasma.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *PlasmaWnd = NULL;
  31. struct Gadget         *PlasmaGList = NULL;
  32. struct IntuiMessage    PlasmaMsg;
  33. struct Gadget         *PlasmaGadgets[6];
  34. UWORD                  PlasmaLeft = 0;
  35. UWORD                  PlasmaTop = 12;
  36. UWORD                  PlasmaWidth = 236;
  37. UWORD                  PlasmaHeight = 54;
  38. UBYTE                 *PlasmaWdt = (UBYTE *)"Plasma Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *PlasmaFont = NULL;
  43.  
  44. UBYTE *CY_DIMEN0Labels[] = {
  45.     (UBYTE *)"Width",
  46.     (UBYTE *)"Height",
  47.     NULL };
  48.  
  49. UWORD PlasmaGTypes[] = {
  50.     BUTTON_KIND,
  51.     BUTTON_KIND,
  52.     BUTTON_KIND,
  53.     CYCLE_KIND,
  54.     BUTTON_KIND,
  55.     SLIDER_KIND
  56. };
  57.  
  58. struct NewGadget PlasmaNGad[] = {
  59.     4, 37, 54, 14, (UBYTE *)"_Save", NULL, GD_BT_SAVE, PLACETEXT_IN, NULL, (APTR)BT_SAVEClicked,
  60.     178, 37, 54, 14, (UBYTE *)"_Cancel", NULL, GD_BT_CANCEL, PLACETEXT_IN, NULL, (APTR)BT_CANCELClicked,
  61.     62, 37, 54, 14, (UBYTE *)"_Test", NULL, GD_BT_TEST, PLACETEXT_IN, NULL, (APTR)BT_TESTClicked,
  62.     123, 4, 109, 14, (UBYTE *)"_Limiting Dimension", NULL, GD_CY_DIMEN, PLACETEXT_LEFT, NULL, (APTR)CY_DIMENClicked,
  63.     120, 37, 54, 14, (UBYTE *)"_Display", NULL, GD_BT_SCREEN, PLACETEXT_IN, NULL, (APTR)BT_SCREENClicked,
  64.     99, 22, 113, 11, (UBYTE *)"Extend _Palette", NULL, GD_SL_EXTPAL, PLACETEXT_LEFT, NULL, (APTR)SL_EXTPALClicked
  65. };
  66.  
  67. ULONG PlasmaGTags[] = {
  68.     (GT_Underscore), '_', (TAG_DONE),
  69.     (GT_Underscore), '_', (TAG_DONE),
  70.     (GT_Underscore), '_', (TAG_DONE),
  71.     (GTCY_Labels), (ULONG)&CY_DIMEN0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  72.     (GT_Underscore), '_', (TAG_DONE),
  73.     (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)
  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 HandlePlasmaIDCMP( void )
  138. {
  139.     struct IntuiMessage    *m;
  140.     int            (*func)();
  141.     BOOL            running = TRUE;
  142.  
  143.     while( m = GT_GetIMsg( PlasmaWnd->UserPort )) {
  144.  
  145.         CopyMem(( char * )m, ( char * )&PlasmaMsg, (long)sizeof( struct IntuiMessage ));
  146.  
  147.         GT_ReplyIMsg( m );
  148.  
  149.         switch ( PlasmaMsg.Class ) {
  150.  
  151.             case    IDCMP_REFRESHWINDOW:
  152.                 GT_BeginRefresh( PlasmaWnd );
  153.                 GT_EndRefresh( PlasmaWnd, TRUE );
  154.                 break;
  155.  
  156.             case    IDCMP_VANILLAKEY:
  157.                 running = PlasmaVanillaKey();
  158.                 break;
  159.  
  160.             case    IDCMP_GADGETUP:
  161.             case    IDCMP_GADGETDOWN:
  162.                 func = ( void * )(( struct Gadget * )PlasmaMsg.IAddress )->UserData;
  163.                 running = func();
  164.                 break;
  165.         }
  166.     }
  167.     return( running );
  168. }
  169.  
  170. int OpenPlasmaWindow( void )
  171. {
  172.     struct NewGadget    ng;
  173.     struct Gadget    *g;
  174.     UWORD        lc, tc;
  175.     UWORD        wleft = PlasmaLeft, wtop = PlasmaTop, ww, wh;
  176.  
  177.     ComputeFont( PlasmaWidth, PlasmaHeight );
  178.  
  179.     ww = ComputeX( PlasmaWidth );
  180.     wh = ComputeY( PlasmaHeight );
  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 ( ! ( PlasmaFont = OpenDiskFont( Font )))
  186.         return( 5L );
  187.  
  188.     if ( ! ( g = CreateContext( &PlasmaGList )))
  189.         return( 1L );
  190.  
  191.     for( lc = 0, tc = 0; lc < Plasma_CNT; lc++ ) {
  192.  
  193.         CopyMem((char * )&PlasmaNGad[ 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.         PlasmaGadgets[ lc ] = g = CreateGadgetA((ULONG)PlasmaGTypes[ lc ], g, &ng, ( struct TagItem * )&PlasmaGTags[ tc ] );
  203.  
  204.         while( PlasmaGTags[ tc ] ) tc += 2;
  205.         tc++;
  206.  
  207.         if ( NOT g )
  208.             return( 2L );
  209.     }
  210.  
  211.     if ( ! ( PlasmaWnd = 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,    BUTTONIDCMP|CYCLEIDCMP|SLIDERIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  217.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  218.                 WA_Gadgets,    PlasmaGList,
  219.                 WA_Title,    PlasmaWdt,
  220.                 WA_ScreenTitle,    "Plasma Prefs",
  221.                 WA_PubScreen,    Scr,
  222.                 TAG_DONE )))
  223.     return( 4L );
  224.  
  225.     GT_RefreshWindow( PlasmaWnd, NULL );
  226.  
  227.     return( 0L );
  228. }
  229.  
  230. void ClosePlasmaWindow( void )
  231. {
  232.     if ( PlasmaWnd        ) {
  233.         CloseWindow( PlasmaWnd );
  234.         PlasmaWnd = NULL;
  235.     }
  236.  
  237.     if ( PlasmaGList      ) {
  238.         FreeGadgets( PlasmaGList );
  239.         PlasmaGList = NULL;
  240.     }
  241.  
  242.     if ( PlasmaFont ) {
  243.         CloseFont( PlasmaFont );
  244.         PlasmaFont = NULL;
  245.     }
  246. }
  247.  
  248.