home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / player / ahi / developer / examples / harddiskrecord / gui.c next >
Encoding:
C/C++ Source or Header  |  1996-07-17  |  12.7 KB  |  435 lines

  1. /*********************************************/
  2. /*                                           */
  3. /*       Designer (C) Ian OConnor 1994       */
  4. /*                                           */
  5. /*      Designer Produced C include file     */
  6. /*                                           */
  7. /*********************************************/
  8.  
  9. #include <exec/types.h>
  10. #include <libraries/locale.h>
  11. #include <exec/memory.h>
  12. #include <dos/dosextens.h>
  13. #include <intuition/screens.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/gadtools.h>
  17. #include <diskfont/diskfont.h>
  18. #include <utility/utility.h>
  19. #include <graphics/gfxbase.h>
  20. #include <workbench/workbench.h>
  21. #include <graphics/scale.h>
  22. #include <clib/locale_protos.h>
  23. #include <clib/exec_protos.h>
  24. #include <clib/wb_protos.h>
  25. #include <clib/intuition_protos.h>
  26. #include <clib/gadtools_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/utility_protos.h>
  29. #include <string.h>
  30. #include <clib/diskfont_protos.h>
  31.  
  32. #include "GUI.extras.h"
  33. #include "GUI.h"
  34.  
  35.  
  36. ULONG BevelTags[] = 
  37.     {
  38.     (GTBB_Recessed), TRUE,
  39.     (GT_VisualInfo), 0,
  40.     (TAG_DONE)
  41.     };
  42. UBYTE Win0FirstScaleTexts = 0;
  43.  
  44. UBYTE Win0TextsLocalized = 0;
  45.  
  46. struct IntuiText Win0Texts[] =
  47.     {
  48.     1, 3, JAM1, 230, 101, NULL, (UBYTE *)Win0Texts1, NULL
  49.     };
  50.  
  51. struct Window *Win0 = NULL;
  52. APTR Win0VisualInfo;
  53. APTR Win0DrawInfo;
  54. struct Gadget *Win0GList;
  55. struct Gadget *Win0Gadgets[15];
  56. UBYTE Win0FirstRun = 0;
  57.  
  58. STRPTR Win0_formatLabels[] =
  59. {
  60.     (STRPTR)Win0_formatString0,
  61.     (STRPTR)Win0_formatString1,
  62.     NULL
  63. };
  64.  
  65. ULONG Win0GadgetTags[] =
  66.     {
  67.     (GTLV_ShowSelected), 0,
  68.     (GT_Underscore), '_',
  69.     (GTLV_Selected), 0,
  70.     (TAG_END),
  71.     (GTLV_ShowSelected), 0,
  72.     (GT_Underscore), '_',
  73.     (GTLV_Selected), 0,
  74.     (TAG_END),
  75.     (GTSL_LevelFormat), 0,
  76.     (GTSL_MaxLevelLen), 64,
  77.     (GTSL_LevelPlace), 2,
  78.     (GA_Immediate), TRUE,
  79.     (GA_RelVerify), TRUE,
  80.     (GT_Underscore), '_',
  81.     (TAG_END),
  82.     (GT_Underscore), '_',
  83.     (TAG_END),
  84.     (GTTX_CopyText), TRUE,
  85.     (GT_TagBase+74), 0,  /* Justification in V39 */
  86.     (TAG_END),
  87.     (GTTX_CopyText), TRUE,
  88.     (GT_TagBase+74), 0,  /* Justification in V39 */
  89.     (TAG_END),
  90.     (GTSL_Min), 100,
  91.     (GTSL_Max), 100,
  92.     (GTSL_Level), 100,
  93.     (GTSL_LevelFormat), 0,
  94.     (GTSL_MaxLevelLen), 64,
  95.     (GTSL_LevelPlace), 2,
  96.     (GA_Immediate), TRUE,
  97.     (GA_RelVerify), TRUE,
  98.     (GT_Underscore), '_',
  99.     (TAG_END),
  100.     (GTIN_MaxChars), 4,
  101.     (GT_Underscore), '_',
  102.     (TAG_END),
  103.     (GTNM_Border), TRUE,
  104.     (GT_TagBase+74), 0,  /* Justification in V39 */
  105.     (GT_TagBase+75), 0,  /* String Formatting */
  106.     (TAG_END),
  107.     (GTST_String), (ULONG)"NewSample.AIFC",
  108.     (GTST_MaxChars), 1024,
  109.     (GT_Underscore), '_',
  110.     (TAG_END),
  111.     (GT_Underscore), '_',
  112.     (TAG_END),
  113.     (GT_Underscore), '_',
  114.     (TAG_END),
  115.     (GT_Underscore), '_',
  116.     (TAG_END),
  117.     (GTNM_Border), TRUE,
  118.     (GT_TagBase+74), 0,  /* Justification in V39 */
  119.     (TAG_END),
  120.     (GT_Underscore), '_',
  121.     (GTCY_Active), 1,
  122.     (GTCY_Labels), (ULONG)&Win0_formatLabels[0],
  123.     (TAG_END),
  124.     };
  125.  
  126. UWORD Win0GadgetTypes[] =
  127.     {
  128.     LISTVIEW_KIND,
  129.     LISTVIEW_KIND,
  130.     SLIDER_KIND,
  131.     BUTTON_KIND,
  132.     TEXT_KIND,
  133.     TEXT_KIND,
  134.     SLIDER_KIND,
  135.     INTEGER_KIND,
  136.     NUMBER_KIND,
  137.     STRING_KIND,
  138.     BUTTON_KIND,
  139.     BUTTON_KIND,
  140.     BUTTON_KIND,
  141.     NUMBER_KIND,
  142.     CYCLE_KIND,
  143.     };
  144.  
  145. struct NewGadget Win0NewGadgets[] =
  146.     {
  147.     16, 24, 140, 28, (UBYTE*)Win0_srclistString, NULL, Win0_srclist, 4, NULL,  (APTR)&Win0GadgetTags[0],
  148.     163, 24, 140, 28, (UBYTE*)Win0_dstlistString, NULL, Win0_dstlist, 4, NULL,  (APTR)&Win0GadgetTags[7],
  149.     163, 54, 93, 14, (UBYTE*)Win0_volsliderString, NULL, Win0_volslider, 1, NULL,  (APTR)&Win0GadgetTags[14],
  150.     312, 54, 267, 14, (UBYTE*)Win0_ambuttonString, NULL, Win0_ambutton, 16, NULL,  (APTR)&Win0GadgetTags[27],
  151.     317, 26, 258, 12, (UBYTE*)Win0_amtext1String, NULL, Win0_amtext1, 4, NULL,  (APTR)&Win0GadgetTags[30],
  152.     317, 38, 258, 12, (UBYTE*)Win0_amtext2String, NULL, Win0_amtext2, 1, NULL,  (APTR)&Win0GadgetTags[35],
  153.     163, 70, 93, 14, (UBYTE*)Win0_gainsliderString, NULL, Win0_gainslider, 1, NULL,  (APTR)&Win0GadgetTags[40],
  154.     163, 98, 61, 14, (UBYTE*)Win0_durationString, NULL, Win0_duration, 1, NULL,  (APTR)&Win0GadgetTags[59],
  155.     163, 114, 141, 14, (UBYTE*)Win0_lengthString, NULL, Win0_length, 1, NULL,  (APTR)&Win0GadgetTags[64],
  156.     163, 130, 416, 14, (UBYTE*)Win0_filenameString, NULL, Win0_filename, 1, NULL,  (APTR)&Win0GadgetTags[71],
  157.     16, 130, 141, 14, (UBYTE*)Win0_fnbuttonString, NULL, Win0_fnbutton, 16, NULL,  (APTR)&Win0GadgetTags[78],
  158.     312, 98, 267, 14, (UBYTE*)Win0_createString, NULL, Win0_create, 16, NULL,  (APTR)&Win0GadgetTags[81],
  159.     312, 114, 267, 14, (UBYTE*)Win0_beginString, NULL, Win0_begin, 16, NULL,  (APTR)&Win0GadgetTags[84],
  160.     401, 146, 70, 14, (UBYTE*)Win0_secleftString, NULL, Win0_secleft, 2, NULL,  (APTR)&Win0GadgetTags[87],
  161.     163, 146, 230, 14, (UBYTE*)Win0_formatString, NULL, Win0_format, 1, NULL,  (APTR)&Win0GadgetTags[92],
  162.     };
  163.  
  164. struct Library *AslBase = NULL;
  165. struct Library *DiskfontBase = NULL;
  166. struct Library *GadToolsBase = NULL;
  167. struct GfxBase *GfxBase = NULL;
  168. struct IntuitionBase *IntuitionBase = NULL;
  169. struct Library *UtilityBase = NULL;
  170. struct LocaleBase *LocaleBase = NULL;
  171. struct Catalog *HardDiskRecord_Catalog = NULL;
  172. STRPTR HardDiskRecord_BuiltInLanguage = (STRPTR)"english";
  173. LONG HardDiskRecord_Version = 0;
  174.  
  175. STRPTR HardDiskRecord_Strings[] =
  176. {
  177.   (STRPTR)"Please select an audio mode!",
  178.   (STRPTR)"File has not been prepared yet!",
  179.   (STRPTR)"OK",
  180.   (STRPTR)"Can't allocate audio hardware.",
  181.   (STRPTR)"Unknown error.",
  182.   (STRPTR)"Finished!",
  183.   (STRPTR)"(seconds)",
  184.   (STRPTR)"IFF-AIFF",
  185.   (STRPTR)"IFF-AIFC (Not compr.)",
  186.   (STRPTR)"%ld %%",
  187.   (STRPTR)"%ld %%",
  188.   (STRPTR)"%ld kB",
  189.   (STRPTR)"Source",
  190.   (STRPTR)"Loopback dest.",
  191.   (STRPTR)"Loopback volume",
  192.   (STRPTR)"Select audio mode...",
  193.   (STRPTR)"",
  194.   (STRPTR)"",
  195.   (STRPTR)"Input gain",
  196.   (STRPTR)"Sample duration",
  197.   (STRPTR)"Sample length",
  198.   (STRPTR)"",
  199.   (STRPTR)"File name...",
  200.   (STRPTR)"Prepare sample file",
  201.   (STRPTR)"Begin recording",
  202.   (STRPTR)"seconds left",
  203.   (STRPTR)"File format",
  204.   (STRPTR)"AHI Hard disk record example",
  205.   (STRPTR)"HardDiskRecord",
  206. };
  207.  
  208. void RendWindowWin0( struct Window *Win, void *vi )
  209. {
  210. int loop;
  211. UWORD offx,offy;
  212. ULONG scalex,scaley;
  213. scalex = 65535*Win->WScreen->RastPort.Font->tf_XSize/8;
  214. scaley = 65535*Win->WScreen->RastPort.Font->tf_YSize/8;
  215. offx = Win->BorderLeft;
  216. offy = Win->BorderTop;
  217. if (Win != NULL) 
  218.     {
  219.     BevelTags[3] = (ULONG)vi;
  220.     DrawBevelBoxA( Win->RPort, 8*scalex/65535+offx,4*scaley/65535+offy,579*scalex/65535,85*scaley/65535, (struct TagItem *)(&BevelTags[0]));
  221.     DrawBevelBoxA( Win->RPort, 8*scalex/65535+offx,93*scaley/65535+offy,579*scalex/65535,72*scaley/65535, (struct TagItem *)(&BevelTags[0]));
  222.     DrawBevelBoxA( Win->RPort, 312*scalex/65535+offx,24*scaley/65535+offy,267*scalex/65535,28*scaley/65535, (struct TagItem *)(&BevelTags[0]));
  223.     for( loop=0; loop<1; loop++)
  224.         {
  225.         if (Win0Texts[loop].ITextFont==NULL)
  226.             Win0Texts[loop].ITextFont=Win->WScreen->Font;
  227.         if (Win0FirstScaleTexts==0)
  228.             {
  229.             Win0Texts[loop].LeftEdge = Win0Texts[loop].LeftEdge*scalex/65535;
  230.             Win0Texts[loop].TopEdge = Win0Texts[loop].TopEdge*scaley/65535;
  231.             }
  232.         }
  233.     Win0FirstScaleTexts = 1;
  234.     if (Win0TextsLocalized == 0)
  235.         {
  236.         Win0TextsLocalized = 1;
  237.         for( loop=0; loop<1; loop++)
  238.             Win0Texts[loop].IText = GetString((LONG)Win0Texts[loop].IText);
  239.         }
  240.     PrintIText( Win->RPort, Win0Texts, offx, offy);
  241.     }
  242. }
  243.  
  244. int OpenWindowWin0( STRPTR ScrName)
  245. {
  246. struct Screen *Scr;
  247. UWORD offx, offy;
  248. UWORD loop;
  249. struct NewGadget newgad;
  250. struct Gadget *Gad;
  251. struct Gadget *Gad2;
  252. APTR Cla;
  253. ULONG scalex,scaley;
  254. if (Win0FirstRun == 0)
  255.     {
  256.     Win0FirstRun = 1;
  257.     for ( loop=0; loop<2; loop++)
  258.         Win0_formatLabels[loop] = GetString((LONG)Win0_formatLabels[loop]);
  259.     Win0GadgetTags[15] = (ULONG)GetString(Win0_volsliderLevelFormat);
  260.     Win0GadgetTags[47] = (ULONG)GetString(Win0_gainsliderLevelFormat);
  261.     Win0GadgetTags[69] = (ULONG)GetString(Win0_lengthStringFormat);
  262.     }
  263. if (Win0 == NULL)
  264.     {
  265.     Scr = LockPubScreen(ScrName);
  266.     if (NULL == Scr)
  267.     Scr = LockPubScreen(NULL);
  268.     if (NULL != Scr)
  269.         {
  270.         offx = Scr->WBorLeft;
  271.         offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  272.         scalex = 65535*Scr->RastPort.Font->tf_XSize/8;
  273.         scaley = 65535*Scr->RastPort.Font->tf_YSize/8;
  274.         if (NULL != ( Win0VisualInfo = GetVisualInfoA( Scr, NULL)))
  275.             {
  276.             if (NULL != ( Win0DrawInfo = GetScreenDrawInfo( Scr)))
  277.                 {
  278.                 Win0GList = NULL;
  279.                 Gad = CreateContext( &Win0GList);
  280.                 for ( loop=0 ; loop<15 ; loop++ )
  281.                     if (Win0GadgetTypes[loop] != 198)
  282.                         {
  283.                         CopyMem((char * )&Win0NewGadgets[loop], ( char * )&newgad, (long)sizeof( struct NewGadget ));
  284.                         newgad.ng_VisualInfo = Win0VisualInfo;
  285.                         newgad.ng_LeftEdge = newgad.ng_LeftEdge*scalex/65535;
  286.                         newgad.ng_TopEdge = newgad.ng_TopEdge*scaley/65535;
  287.                         if (Win0GadgetTypes[loop] != GENERIC_KIND)
  288.                             {
  289.                             newgad.ng_Width = newgad.ng_Width*scalex/65535;
  290.                             newgad.ng_Height = newgad.ng_Height*scaley/65535;
  291.                             };
  292.                         newgad.ng_TextAttr = Scr->Font;
  293.                         newgad.ng_LeftEdge += offx;
  294.                         newgad.ng_TopEdge += offy;
  295.                         if ( newgad.ng_GadgetText != (UBYTE *)~0)
  296.                             newgad.ng_GadgetText = GetString((LONG)newgad.ng_GadgetText);
  297.                         else
  298.                             newgad.ng_GadgetText = (UBYTE *)0;
  299.                         Win0Gadgets[ loop ] = NULL;
  300.                         Win0Gadgets[ newgad.ng_GadgetID - Win0FirstID ] = Gad = CreateGadgetA( Win0GadgetTypes[loop], Gad, &newgad, (struct TagItem *) newgad.ng_UserData );
  301.                         }
  302.                 for ( loop=0 ; loop<15 ; loop++ )
  303.                     if (Win0GadgetTypes[loop] == 198)
  304.                         {
  305.                         Win0Gadgets[ loop ] = NULL;
  306.                         Cla = NULL;
  307.                         if (Gad)
  308.                             Win0Gadgets[ loop ] = Gad2 = (struct Gadget *) NewObjectA( (struct IClass *)Cla, Win0NewGadgets[ loop ].ng_GadgetText, (struct TagItem *)Win0NewGadgets[ loop ].ng_UserData );
  309.                         }
  310.                 if (Gad != NULL)
  311.                     {
  312.                     if (NULL != (Win0 = OpenWindowTags( NULL, (WA_Left), 7,
  313.                                     (WA_Top), 18,
  314.                                     (WA_InnerWidth), 595*scalex/65535,
  315.                                     (WA_InnerHeight), 169*scaley/65535,
  316.                                     (WA_Title), (LONG)GetString(Win0Title),
  317.                                     (WA_ScreenTitle), (LONG)GetString(Win0ScreenTitle),
  318.                                     (WA_MinWidth), 10,
  319.                                     (WA_MinHeight), 2,
  320.                                     (WA_MaxWidth), 1200,
  321.                                     (WA_MaxHeight), 1200,
  322.                                     (WA_DragBar), TRUE,
  323.                                     (WA_DepthGadget), TRUE,
  324.                                     (WA_CloseGadget), TRUE,
  325.                                     (WA_Activate), TRUE,
  326.                                     (WA_Dummy+0x30), TRUE,
  327.                                     (WA_SmartRefresh), TRUE,
  328.                                     (WA_AutoAdjust), TRUE,
  329.                                     (WA_Gadgets), Win0GList,
  330.                                     (WA_PubScreen) , (LONG)Scr,
  331.                                     (WA_IDCMP),6292092,
  332.                                     (TAG_END))))
  333.                         {
  334.                         RendWindowWin0(Win0, Win0VisualInfo );
  335.                         GT_RefreshWindow( Win0, NULL);
  336.                         RefreshGList( Win0GList, Win0, NULL, ~0);
  337.                         UnlockPubScreen( NULL, Scr);
  338.                         return( 0L );
  339.                         }
  340.                     }
  341.                 FreeGadgets( Win0GList);
  342.                 FreeScreenDrawInfo( Scr, (struct DrawInfo *) Win0DrawInfo );
  343.                 }
  344.             FreeVisualInfo( Win0VisualInfo );
  345.             }
  346.         UnlockPubScreen( NULL, Scr);
  347.         }
  348.     }
  349. else
  350.     {
  351.     WindowToFront(Win0);
  352.     ActivateWindow(Win0);
  353.     return( 0L );
  354.     }
  355. return( 1L );
  356. }
  357.  
  358. void CloseWindowWin0( void )
  359. {
  360. if (Win0 != NULL)
  361.     {
  362.     FreeScreenDrawInfo( Win0->WScreen, (struct DrawInfo *) Win0DrawInfo );
  363.     Win0DrawInfo = NULL;
  364.     CloseWindow( Win0);
  365.     Win0 = NULL;
  366.     FreeVisualInfo( Win0VisualInfo);
  367.     FreeGadgets( Win0GList);
  368.     }
  369. }
  370.  
  371. int OpenLibs( void )
  372. {
  373. LocaleBase = (struct LocaleBase * )OpenLibrary((UBYTE *)"locale.library", 38);
  374. if ( NULL != (AslBase = OpenLibrary((UBYTE *)"asl.library" , 37)))
  375.     if ( NULL != (DiskfontBase = OpenLibrary((UBYTE *)"diskfont.library" , 36)))
  376.         if ( NULL != (GadToolsBase = OpenLibrary((UBYTE *)"gadtools.library" , 37)))
  377.             if ( NULL != (GfxBase = (struct GfxBase * )OpenLibrary((UBYTE *)"graphics.library" , 37)))
  378.                 if ( NULL != (IntuitionBase = (struct IntuitionBase * )OpenLibrary((UBYTE *)"intuition.library" , 37)))
  379.                     if ( NULL != (UtilityBase = OpenLibrary((UBYTE *)"utility.library" , 37)))
  380.                         return( 0L );
  381. CloseLibs();
  382. return( 1L );
  383. }
  384.  
  385. void CloseLibs( void )
  386. {
  387. if (NULL != AslBase )
  388.     CloseLibrary( AslBase );
  389. if (NULL != DiskfontBase )
  390.     CloseLibrary( DiskfontBase );
  391. if (NULL != GadToolsBase )
  392.     CloseLibrary( GadToolsBase );
  393. if (NULL != GfxBase )
  394.     CloseLibrary( ( struct Library * )GfxBase );
  395. if (NULL != IntuitionBase )
  396.     CloseLibrary( ( struct Library * )IntuitionBase );
  397. if (NULL != UtilityBase )
  398.     CloseLibrary( UtilityBase );
  399. if (NULL != LocaleBase )
  400.     CloseLibrary( ( struct Library * )LocaleBase );
  401. }
  402.  
  403. STRPTR GetString(LONG strnum)
  404. {
  405.     if (HardDiskRecord_Catalog == NULL)
  406.         return(HardDiskRecord_Strings[strnum]);
  407.     return(GetCatalogStr(HardDiskRecord_Catalog, strnum, HardDiskRecord_Strings[strnum]));
  408. }
  409.  
  410. void CloseHardDiskRecordCatalog(void)
  411. {
  412.     if (LocaleBase != NULL)
  413.         CloseCatalog(HardDiskRecord_Catalog);
  414.     HardDiskRecord_Catalog = NULL;
  415. }
  416.  
  417. void OpenHardDiskRecordCatalog(struct Locale *loc, STRPTR language)
  418. {
  419.     LONG tag, tagarg;
  420.     if (language == NULL)
  421.         tag=TAG_IGNORE;
  422.     else
  423.         {
  424.         tag = OC_Language;
  425.         tagarg = (LONG)language;
  426.         }
  427.     if (LocaleBase != NULL  &&  HardDiskRecord_Catalog == NULL)
  428.         HardDiskRecord_Catalog = OpenCatalog(loc, (STRPTR) "HardDiskRecord.catalog",
  429.                                             OC_BuiltInLanguage, HardDiskRecord_BuiltInLanguage,
  430.                                             tag, tagarg,
  431.                                             OC_Version, HardDiskRecord_Version,
  432.                                             TAG_DONE);
  433. }
  434.  
  435.