home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / iffconverter / gadgets.c < prev    next >
C/C++ Source or Header  |  1997-01-07  |  3KB  |  111 lines

  1. /*
  2. **     $VER: Gadgets.c V0.01 (14-06-95)
  3. **
  4. **     Author:  Gerben Venekamp
  5. **     Updates: 14-06-96  Version 0.01      Initial module
  6. **
  7. **  Gadgets.c contains all the necessary functions to control your
  8. **  gadgets. Gadgets.c needs the file Gadgets.h for the defenitions
  9. **  of your gadgets.
  10. **
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <proto/gadtools.h>
  16.  
  17. #include "IFFConverter.h"
  18. #include "Gadgets.h"
  19.  
  20.  
  21. // Define variables
  22. struct Gadget *FirstGadget = NULL;
  23.  
  24. UWORD FileMode   = FM_Single;
  25. UWORD RenderMode = RM_Interleave;
  26.  
  27. // Define protos
  28. void  GetGadgetStatus(ULONG, ULONG, ...);
  29. void  InitGadgets(void);
  30. void  UpdateGadgets(ULONG Commands, ...);
  31.  
  32. /*
  33. **  InitGadgets()
  34. **
  35. **     Is were your Gadgets are initialized. For this function to work,
  36. **     you need to include 'Gadgets.h'!!!
  37. **
  38. **  pre:  None.
  39. **  post: None.
  40. */
  41. void InitGadgets()
  42. {
  43.    UWORD i;
  44.    ULONG Kind;
  45.    struct Gadget * PreviousGadget;
  46.    struct NewGadget *GadgetToAdd;
  47.    APTR GadgetTags;
  48.    APTR register _VisualInfo = VisualInfo;
  49.    APTR register ConverterFont;
  50.  
  51.    if(SystemFont)
  52.       ConverterFont = &System_8;
  53.    else
  54.       ConverterFont = NULL;
  55.       
  56.    if( PreviousGadget = CreateContext(&FirstGadget) )
  57.    {
  58.       for (i=0; i<GD_Sentinal; i++)
  59.       {
  60.          Kind = PanelGadgets[i].MyGadgetType;
  61.          GadgetToAdd                       = &(PanelGadgets[i].mng);
  62.          GadgetTags                        = PanelGadgets[i].MyGadgetTags;
  63.          PanelGadgets[i].mng.ng_VisualInfo = _VisualInfo;
  64.          PanelGadgets[i].mng.ng_TextAttr   = ConverterFont;
  65.  
  66.          if(!( GadgetIAddress[i] = PreviousGadget = CreateGadgetA(Kind, PreviousGadget, GadgetToAdd, GadgetTags) ))
  67.             ErrorHandler( IFFerror_GadCreate, (APTR)i );
  68.       }
  69.    }
  70.    else
  71.       ErrorHandler( IFFerror_GadCreate, (APTR)-1 );
  72. }
  73.  
  74.  
  75. /*
  76. **  GetGadgetStatus(GadID, Commands)
  77. **
  78. **     Gets the status of a gadget. Status checking is controled through
  79. **     'Commands'.
  80. **
  81. **  pre:  GadID - ID of gadget to check its status.
  82. **        Commands - TagList of commands of what to check.
  83. **  post: None.
  84. **
  85. */
  86. void GetGadgetStatus(ULONG GadID, ULONG Commands, ...)
  87. {
  88.    GT_GetGadgetAttrsA(GadgetIAddress[GadID], PanelWindow, NULL, (struct TagItem *)&Commands);
  89. }
  90.  
  91.  
  92. /*
  93. **  UpdateGadgets(Commands)
  94. **
  95. **     Updates gadgets. You can change an inactive gadget into an active
  96. **     gadget and visa versa. It's also possible to change a gadget
  97. **     alltogether.
  98. **
  99. **  pre:  Commands -> Tag List of commands to change the gadget.
  100. **                    First  Tag: GadgetID,
  101. **                    Second Tag: Pointer to a tag list of attributes.
  102. **  post: None.
  103. */
  104. void UpdateGadgets(ULONG Commands, ...)
  105. {
  106.    ULONG *WhatCommands = &Commands;
  107.    
  108.    while (*WhatCommands != TAG_DONE)
  109.       GT_SetGadgetAttrsA( (struct Gadget *) GadgetIAddress[*WhatCommands++], PanelWindow, NULL, (struct TagItem *)*WhatCommands++);
  110. }
  111.