home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / disks / tools / hdsleep / source / gadtools.c < prev    next >
C/C++ Source or Header  |  1996-08-09  |  7KB  |  283 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Thom/Union
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/classes.h>
  12. #include <intuition/classusr.h>
  13. #include <intuition/imageclass.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <libraries/gadtools.h>
  16. #include <graphics/displayinfo.h>
  17. #include <graphics/gfxbase.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/gadtools_protos.h>
  21. #include <clib/graphics_protos.h>
  22. #include <clib/utility_protos.h>
  23. #include <string.h>
  24. #include "gadtools.h"
  25.  
  26. struct Screen         *Scr = NULL;
  27. UBYTE                 *PubScreenName = NULL;
  28. APTR                   VisualInfo = NULL;
  29. struct Window         *MainWnd = NULL;
  30. struct Gadget         *MainGList = NULL;
  31. struct Menu           *MainMenus = NULL;
  32. struct Gadget         *MainGadgets[5];
  33. UWORD                  MainLeft = 202;
  34. UWORD                  MainTop = 72;
  35. UWORD                  MainWidth = 268;
  36. UWORD                  MainHeight = 72;
  37. UBYTE                 *MainWdt = (UBYTE *)"HDSleep v1.3";
  38. struct TextAttr       *Font, Attr;
  39. UWORD                  FontX, FontY;
  40. UWORD                  OffX, OffY;
  41.  
  42. struct IntuiText MainIText[] = {
  43.     1, 0, JAM2,133, 8, NULL, (UBYTE *)" Time To Go ", NULL };
  44.  
  45. #define Main_TNUM 1
  46.  
  47. struct NewMenu MainNewMenu[] = {
  48.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  49.     NM_ITEM, (STRPTR)"Sleep", (STRPTR)"S", 0, 0L, NULL,
  50.     NM_ITEM, (STRPTR)"Abort", (STRPTR)"A", 0, 0L, NULL,
  51.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  52.     NM_ITEM, (STRPTR)"About", (STRPTR)"B", 0, 0L, NULL,
  53.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  54.     NM_ITEM, (STRPTR)"Hide", (STRPTR)"H", 0, 0L, NULL,
  55.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  56.     NM_END, NULL, NULL, 0, 0L, NULL };
  57.  
  58. UWORD MainGTypes[] = {
  59.     NUMBER_KIND,
  60.     BUTTON_KIND,
  61.     BUTTON_KIND,
  62.     NUMBER_KIND,
  63.     BUTTON_KIND
  64. };
  65.  
  66. struct NewGadget MainNGad[] = {
  67.     147, 14, 45, 14, (UBYTE *)"Master:", NULL, GD_MASTEROFF, PLACETEXT_LEFT, NULL, NULL,
  68.     11, 51, 79, 15, (UBYTE *)"_Sleep", NULL, GD_SLEEP, PLACETEXT_IN, NULL, NULL,
  69.     94, 51, 79, 15, (UBYTE *)"_Abort", NULL, GD_ABORT, PLACETEXT_IN, NULL, NULL,
  70.     147, 27, 45, 14, (UBYTE *)"Slave:", NULL, GD_SLAVEOFF, PLACETEXT_LEFT, NULL, NULL,
  71.     177, 51, 79, 15, (UBYTE *)"_Quit", NULL, GD_QUIT, PLACETEXT_IN, NULL, NULL
  72. };
  73.  
  74. ULONG MainGTags[] = {
  75.     (TAG_DONE),
  76.     (GT_Underscore), '_', (TAG_DONE),
  77.     (GT_Underscore), '_', (TAG_DONE),
  78.     (TAG_DONE),
  79.     (GT_Underscore), '_', (TAG_DONE)
  80. };
  81.  
  82. static UWORD ComputeX( UWORD value )
  83. {
  84.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  85. }
  86.  
  87. static UWORD ComputeY( UWORD value )
  88. {
  89.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  90. }
  91.  
  92. static void ComputeFont( UWORD width, UWORD height )
  93. {
  94.     Font = &Attr;
  95.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  96.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  97.     FontX = Scr->RastPort.Font->tf_XSize;
  98.  
  99.     OffX = Scr->WBorLeft;
  100.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  101.  
  102.     if ( width && height ) {
  103.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  104.             goto UseTopaz;
  105.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  106.             goto UseTopaz;
  107.     }
  108.     return;
  109.  
  110. UseTopaz:
  111.     Font->ta_Name = (STRPTR)"topaz.font";
  112.     FontX = FontY = Font->ta_YSize = 8;
  113. }
  114.  
  115. struct Screen *OldScr=NULL;
  116.  
  117. int SetupScreen( void )
  118. {
  119.     ULONG ibaselock;
  120.  
  121.     ibaselock=LockIBase(0);
  122.     OldScr = IntuitionBase->FirstScreen;
  123.     UnlockIBase(ibaselock);
  124.  
  125.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  126.         return( 1L );
  127.  
  128.     ComputeFont( 0, 0 );
  129.  
  130.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  131.         return( 2L );
  132.  
  133.     return( 0L );
  134. }
  135.  
  136. void CloseDownScreen( void )
  137. {
  138.     ULONG ibaselock;
  139.     struct Screen *ScrList;
  140.  
  141.     ibaselock=LockIBase(0);
  142.     ScrList = IntuitionBase->FirstScreen;
  143.     while(ScrList)
  144.     {
  145.         if(ScrList==OldScr)
  146.         {
  147.             UnlockIBase(ibaselock);
  148.             ScreenToFront(OldScr);
  149.             OldScr=NULL;
  150.             goto skipit;
  151.         }
  152.         ScrList=ScrList->NextScreen;
  153.     }
  154.     UnlockIBase(ibaselock);
  155.  
  156. skipit:
  157.  
  158.     if ( VisualInfo ) {
  159.         FreeVisualInfo( VisualInfo );
  160.         VisualInfo = NULL;
  161.     }
  162.  
  163.     if ( Scr        ) {
  164.         UnlockPubScreen( NULL, Scr );
  165.         Scr = NULL;
  166.     }
  167. }
  168.  
  169. void MainRender( void )
  170. {
  171.     struct IntuiText    it;
  172.     UWORD            cnt;
  173.  
  174.     ComputeFont( MainWidth, MainHeight );
  175.  
  176.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 11 ),
  177.                     OffY + ComputeY( 7 ),
  178.                     ComputeX( 245 ),
  179.                     ComputeY( 40 ),
  180.                     GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  181.  
  182.     for ( cnt = 0; cnt < Main_TNUM; cnt++ ) {
  183.         CopyMem(( char * )&MainIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  184.         it.ITextFont = Font;
  185.         it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
  186.         it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
  187.         PrintIText( MainWnd->RPort, &it, 0, 0 );
  188.     }
  189. }
  190.  
  191. int OpenMainWindow( void )
  192. {
  193.     struct NewGadget    ng;
  194.     struct Gadget    *g;
  195.     struct DrawInfo *DRI;
  196.     UWORD        lc, tc;
  197.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  198.     ULONG Pen;
  199.  
  200.     ComputeFont( MainWidth, MainHeight );
  201.  
  202.     ww = ComputeX( MainWidth );
  203.     wh = ComputeY( MainHeight );
  204.  
  205.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  206.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  207.  
  208.     if ( ! ( g = CreateContext( &MainGList )))
  209.         return( 1L );
  210.  
  211.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  212.  
  213.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  214.  
  215.         ng.ng_VisualInfo = VisualInfo;
  216.         ng.ng_TextAttr   = Font;
  217.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  218.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  219.         ng.ng_Width      = ComputeX( ng.ng_Width );
  220.         ng.ng_Height     = ComputeY( ng.ng_Height);
  221.  
  222.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  223.  
  224.         while( MainGTags[ tc ] ) tc += 2;
  225.         tc++;
  226.  
  227.         if ( NOT g )
  228.             return( 2L );
  229.     }
  230.  
  231.     if(DRI=GetScreenDrawInfo(Scr))
  232.     {
  233.         Pen=DRI->dri_Pens[BARDETAILPEN];
  234.         FreeScreenDrawInfo(Scr,DRI);
  235.     }
  236.     else Pen=1;
  237.  
  238.     if ( ! ( MainMenus = CreateMenus( MainNewMenu, GTMN_NewLookMenus, TRUE, GTMN_FrontPen, Pen, TAG_DONE )))
  239.         return( 3L );
  240.  
  241.     LayoutMenus( MainMenus, VisualInfo, TAG_DONE );
  242.  
  243.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  244.                 WA_Left,    wleft,
  245.                 WA_Top,        wtop,
  246.                 WA_Width,    ww + OffX + Scr->WBorRight,
  247.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  248.                 WA_IDCMP,    NUMBERIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  249.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  250.                 WA_Gadgets,    MainGList,
  251.                 WA_Title,    MainWdt,
  252.                 WA_ScreenTitle,    "HDSleep v1.3 - by Tomasz Muszynski (Thom/Union)",
  253.                 WA_PubScreen,    Scr,
  254.                 TAG_DONE )))
  255.     return( 4L );
  256.  
  257.     SetMenuStrip( MainWnd, MainMenus );
  258.     GT_RefreshWindow( MainWnd, NULL );
  259.  
  260.     MainRender();
  261.  
  262.     return( 0L );
  263. }
  264.  
  265. void CloseMainWindow( void )
  266. {
  267.     if ( MainMenus      ) {
  268.         ClearMenuStrip( MainWnd );
  269.         FreeMenus( MainMenus );
  270.         MainMenus = NULL;    }
  271.  
  272.     if ( MainWnd        ) {
  273.         CloseWindow( MainWnd );
  274.         MainWnd = NULL;
  275.     }
  276.  
  277.     if ( MainGList      ) {
  278.         FreeGadgets( MainGList );
  279.         MainGList = NULL;
  280.     }
  281. }
  282.  
  283.