home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff257.lzh / ColorReq / ColorTest.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  10KB  |  299 lines

  1. /* C example application:
  2.  
  3. cc +p ShowPic.c
  4. as -cd FileInterface.asm
  5. as -cd IlbmInterface.asm
  6. ln -o ShowPic ShowPic.o FileInterface.o IlbmInterface.o ColorInterface.o -lc32
  7.  
  8.  This program presents the dissidents FileIO requester upon being run. This
  9.  is a filename selection requester based upon R.J. Mical's ProSuite code.
  10.  The user can select the name of an ilbm picture file and click on OK. This
  11.  program will then load the picture into a window using the dissidents ilbm
  12.  library. This library is used in loading or saving IFF files and is based
  13.  upon the Electronic Arts code. If the user clicks the mouse button, then
  14.  the picture will disappear and the FileIO requester will be presented
  15.  once again. When the user wishes to exit, he should select the FileIO's
  16.  Cancel gadget. If the user presses any key while a picture is being
  17.  displayed, the dissidents ColorTool window will appear. This is a library
  18.  that allows adjusting the colors of any viewport via a color requester
  19.  pallete. These 3 libraries and approprite doc files are all available on
  20.  Fred Fish discs. The requester and ilbm libraries are public domain. The
  21.  color.library is copyrighted by dissidents, but can be freely distributed.
  22.  */
  23.  
  24. #include "math.h"
  25. #include "functions.h"    /* Manx C declarations */
  26. #include "intuition/intuition.h"
  27.  
  28. #include "exec/tasks.h"
  29. #include "exec/types.h"
  30. #include "exec/memory.h"
  31. #include "graphics/gfxbase.h"
  32. #include "graphics/rastport.h"
  33. #include "graphics/gfx.h"
  34. #include "graphics/view.h"
  35. #include "graphics/text.h"
  36. #include "intuition/intuitionbase.h"
  37.  
  38.  /* These INCLUDE files come with the ilbm and requester libs */
  39. #include "ILBM_Lib.h"
  40. #include "FileIO.h"
  41.  
  42. /*-------------------------------defines---------------------------------*/
  43.  
  44. #define INTUITION_REV 33L
  45. #define GRAPHICS_REV  33L
  46.  
  47. struct IntuitionBase *IntuitionBase=0L;
  48. struct GfxBase       *GfxBase=0L;
  49. struct Window        *back_wind=0L;
  50. struct Screen        *main_scrn=0L;
  51.  
  52.  /* Data for the Dissidents Requester library */
  53. struct RequesterBase *RequesterBase=0L;
  54. struct FileIO        *myFileIO=0L;
  55.  
  56.  /* Data for the Dissidents ILBM library */
  57. struct ILBMBase      *ILBMBase=0L;
  58. struct ILBMFrame     myILBMFrame;
  59.  
  60.  /* Data for the color requester lib */
  61. struct ColorBase     *ColorBase=0L;
  62.  
  63. USHORT def_color_table[32]={0x000,0x009,0x480,0x660,0x840,\
  64.                      0xa00,0x804,0x706,0x608,0x60a,0x40a,\
  65.                      0x06a,0x088,0x0a6,0x700,0x070,0x0,\
  66.                      0x800,0x555,0x0a0,0x0a4,0x0a6,0x0a8,0x0aa,\
  67.                      0x0ac,0x0ae,0x0b0,0x0b2,0x0b4,0x0b6,0x0b8,0x0ba};
  68.  
  69. BYTE DoColor();
  70.  
  71. struct TextAttr my_font_attr={(UBYTE *)"topaz.font",TOPAZ_EIGHTY,\
  72.                          FS_NORMAL, FPF_ROMFONT};
  73.  
  74.  
  75. VOID open_all(), damp_mop();
  76.  
  77. /*------------------------------start of main()----------------------------*/
  78.  
  79. main( argc, argv )
  80. LONG argc;
  81. UBYTE *argv[];
  82. {
  83.    UBYTE Filename[260];
  84.    UBYTE *string;
  85.    IFFP  Result;
  86.    struct IntuiMessage *message;
  87.    UBYTE flag;
  88.    BYTE  error;
  89.  
  90.    open_all();
  91.  
  92.  /* The FileIO is for the file requester lib. See Fish Disc #203 for the
  93.     documentation and examples */
  94.    myFileIO->X = 6;
  95.    myFileIO->Y = 11;
  96.    myFileIO->DrawMode = JAM2;
  97.    myFileIO->PenA = 0;
  98.    myFileIO->PenB = 1;
  99.    myFileIO->Buffer = &Filename[0];
  100.  
  101.    /* Get the filename to load */
  102.  
  103.    while( (string = DoFileIOWindow(myFileIO, 0L)) == &Filename[0] )
  104.    {
  105.       /* If user was positive and fileio opened ok, load the Filename */
  106.  
  107.  
  108.  /* We can open our own window/screen and load pictures there by setting
  109.     the ILBMFrame's iWindow and iScreen fields to this address. Any pic
  110.     that is larger than our window/screen dimensions will be scaled to
  111.     fit. Also, any picture intended for a different view mode than our
  112.     screen (or with more colors) may come out "weird". The main advantage
  113.     of loading into an open window is that we are certain what dimensions
  114.     the screen/window will be. If you had a program which loaded a company
  115.     logo in an IFF ILBM FORM when it started, you would certainly make sure
  116.     that the ILBM file was the proper dimensions for your opened screen.
  117.     In a dissidents product, SpeakerSim, there is a feature for loading in
  118.     an ILBM beneath the speaker plot graph. Since the mouse coordinates
  119.     figure prominantly in obtaining info from the user, it would have been
  120.     too much overhead to tailor all functions to work in both HIRES, LORES,
  121.     and INTERLACE simultaneously. So, there are several "versions" of
  122.     SpeakerSim, each one's graphing routines optimized for the dimensions
  123.     of the main screen. Since the ILBM is meant to be a low-key, background
  124.     beneath the speaker plot, the picture is scaled to fit. Obviously, its
  125.     best to load an ILBM that fits that version of SpeakerSim, but the em-
  126.     phasis is on the graphing, not the background. This is an example of why
  127.     you might load into an existing window.
  128.     Otherwise, we could have the lib open an appropriately sized
  129.     backdrop window/screen by setting iWindow and iScreen to 0. In this
  130.     case, the lib will place the addresses in the ILBMFrame fields. We
  131.     could then do a ModifyIDCMP after the load. Eventually, we'll have
  132.     to CloseWindow and CloseScreen. With this method, the image is never
  133.     scaled (currently the lib doesn't allow for overscan images) as long
  134.     the pic's BMHD w=pageWidth and h=pageHeight, and the image is a standard
  135.     amiga screen dimension. Unfortunately, you won't know whether you have
  136.     a HAM, LORES, HIRES, etc until after the load.
  137.  
  138.     We are going to let the ilbm lib open the window for us. See Fred Fish
  139.     disk for the ilbm.library and the docs */
  140.  
  141.       myILBMFrame.iScreen = 0;
  142.       myILBMFrame.iWindow = 0;
  143.       myILBMFrame.iUserFlags = 3;     /* no pointer, and hidden title bar */
  144.  
  145.       Result = LoadIFFToWindow( &Filename[0], &myILBMFrame );
  146.  
  147.       main_scrn = myILBMFrame.iScreen;
  148.       back_wind = myILBMFrame.iWindow;
  149.  
  150.       if( !Result )
  151.       {
  152.          /* Successful picture load. Now wait for user to click buttons or
  153.          rawkey */
  154.          ModifyIDCMP(back_wind, RAWKEY|MOUSEBUTTONS);
  155.  
  156.          flag=1;  /* to indicate when to close up the window and get next pic
  157.                 */
  158.  
  159.          while( back_wind )
  160.          {
  161.  
  162.             while( message=(struct IntuiMessage *)GetMsg(back_wind->UserPort) )
  163.             {
  164.                ULONG  class = message->Class;
  165.                USHORT code = message->Code;
  166.                APTR   address = message->IAddress;
  167.                USHORT qualifier = message->Qualifier;
  168.  
  169.                ReplyMsg( message );
  170.                switch( class )
  171.                {
  172.                 case MOUSEBUTTONS:
  173.                   if( code == SELECTDOWN )
  174.                      flag = 0;
  175.                   break;
  176.  
  177.                 case RAWKEY:
  178.                      /* If we pass a NULL instead of our def color table, the
  179.                         default gadget will do nothing */
  180.                      error = DoColor( &def_color_table[0], main_scrn );
  181.                      if (error<0)  printf("Error in opening ColorTool\n");
  182.                   break;
  183.                }
  184.                break;
  185.             }
  186.  
  187.             if( !flag )
  188.             {
  189.               /* drain the IDCMP and close back_wind and screen */
  190.                 while( message=(struct IntuiMessage *)GetMsg(back_wind->UserPort))
  191.                    ReplyMsg(message);
  192.                 CloseWindow( back_wind );
  193.                 back_wind=0;
  194.  
  195.                 CloseScreen( main_scrn );
  196.                 main_scrn=0;
  197.             }
  198.             else  /* Wait for msg from user */
  199.             {
  200.                WaitPort( back_wind->UserPort );
  201.             }
  202.  
  203.          }  /* end of while() */
  204.  
  205.       }
  206.       else
  207.       {
  208.          /* Get the IFFP error message and display it */
  209.          printf( "%s", GetIFFPMsg( Result ));
  210.          if( back_wind )
  211.          {
  212.              CloseWindow( back_wind );
  213.              back_wind=0;
  214.          }
  215.  
  216.          if( main_scrn )
  217.          {
  218.              CloseScreen( main_scrn );
  219.              main_scrn=0;
  220.          }
  221.       }
  222.    }
  223.  
  224.    if (!string)    printf("Error in opening FileIO requester\n");
  225.    if (string==-1) printf("User aborted FileIO\n");
  226.    damp_mop();
  227.  
  228. }          /* end of main() */
  229.  
  230.  
  231. /*------opens Intuition, graphics, requester, color, and ilbm libs--------*/
  232.  
  233. VOID open_all()
  234. {
  235.  
  236.  if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library", INTUITION_REV)))
  237.     damp_mop();
  238.  
  239.  if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library", GRAPHICS_REV)))
  240.     damp_mop();
  241.  
  242.  if(!(RequesterBase=(struct RequesterBase *)OpenLibrary("requester.library", 0L)))
  243.    {
  244.     printf("Need the dissidents requester.library on boot disk\n");
  245.     damp_mop();
  246.    }
  247.  
  248.  if(!(ILBMBase=(struct ILBMBase *)OpenLibrary("ilbm.library", 0L)))
  249.    {
  250.     printf("Need the dissidents ilbm.library on boot disk\n");
  251.     damp_mop();
  252.    }
  253.  
  254.    if (!(ColorBase = (struct ColorBase *)OpenLibrary("color.library", 0L)))
  255.    {
  256.     printf("Need the dissidents color.library on boot disk\n");
  257.     damp_mop();
  258.    }
  259.  
  260.  /* The FileIO is for the file requester lib. See Fish Disc #203 for the
  261.     documentation and examples */
  262.    if(!(myFileIO = GetFileIO()))
  263.    {
  264.     printf("Can't get a fileio structure\n");
  265.     damp_mop();
  266.    }
  267.  
  268. }
  269.  
  270.  
  271. /*---------------closes windows, screen, libs---------------*/
  272.  
  273. VOID damp_mop()
  274. {
  275.  struct IntuiMessage *mes;
  276.  
  277.  if( RequesterBase )
  278.  {
  279.  ReleaseFileIO( myFileIO ); /* ReleaseFileIO checks for myFileIO==NULL */
  280.  }
  281.  
  282.  if(back_wind)
  283.  {                /* drain the IDCMP */
  284.    while( mes=(struct IntuiMessage *)GetMsg(back_wind->UserPort))
  285.      ReplyMsg(mes);
  286.    CloseWindow( back_wind );
  287.  }
  288.  
  289.  if( main_scrn )     CloseScreen( main_scrn );
  290.  if( ColorBase )     CloseLibrary( ColorBase );
  291.  if( ILBMBase )      CloseLibrary( ILBMBase );
  292.  if( RequesterBase ) CloseLibrary( RequesterBase );
  293.  if( GfxBase )       CloseLibrary( GfxBase );
  294.  if( IntuitionBase ) CloseLibrary( IntuitionBase );
  295.  
  296.  exit(FALSE);
  297.  
  298. }
  299.