home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 092.lha / ColorFull / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  6.6 KB  |  205 lines

  1. /*~~~~~~~\_______________________________________________________/~~~~~~~~*\
  2. **********<<<<<<<<<<<<<<<<<<<|---={(~!~)}=---|>>>>>>>>>>>>>>>>>>>>**********
  3. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. *    test.c                                                     10/31/87
  5. *
  6. *   This simple program opens an 8 color, HIRES (640*200) screen and a full
  7. * sized window to show the use of the "init_palette()", "palette()" and 
  8. * "get_fname()" routines.
  9. *
  10. *   It will let you modify/load/save color palettes, and is exited by
  11. * selecting "OKAY!" or "CANCEL!" on the color palette.
  12. *
  13. *   See the file: palette.c for source of these routines and also for the
  14. * usage of: get_fname() (also included in this arc file as: getfile.c)
  15. *
  16. *---------------------------------------------------------------------------
  17. *   To use the palette routines in your program, you need only declare two
  18. * external functions... 
  19. *
  20. * extern void init_palette();
  21. * extern void palette();
  22. *
  23. * ...after opening your screen and window, (and a window->UserPort) you call
  24. * init_palette() with a pointer to your window and screen...
  25. *
  26. * init_palette(MyWindow,MyScreen);
  27. *
  28. * ...which sets up certain variables needed and then sets the colors to the
  29. * ones defined in: UBYTE def_colors[] (see: palette.c). Then to open the 
  30. * "Color Palette" window, you call palette() with the same window, screen 
  31. * pointers you used for init_palette()...
  32. * palette(MyWindow,MyScreen);
  33. *
  34. * ...which will the take control of the program until the user is through
  35. * modifying/loading/saving the colors of your screen. (when he/she selects
  36. * "OKAY" or "CANCEL")
  37. *----------------------------------------------------------------------------
  38. *
  39. *   To use the "File Requester" routine you will need to declare an external
  40. * function...
  41. *
  42. * extern UBYTE *get_fname();
  43. *                            
  44. * ...and set up one or more arrays to hold your "probable_file_name[]" and
  45. * one or more to hold your "probable_drive/path_name[]"...
  46. *
  47. * UBYTE color_file_name[] = "MyFile.Color";
  48. * UBYTE def_dir[]         = "SYS:";
  49. *
  50. * ...then to open the "File Requester" (window), you...
  51. *
  52. * get_fname(MyWindow,MyScreen,"Title For Window",color_file_name,def_dir);
  53. *
  54. * ...you can then find the file name in "color_file_name[]". Or you can call
  55. * it by...
  56. *
  57. * fname = get_fname(MyWindow,MyScreen,"Title","file.color","SYS:").
  58. *
  59. * ...using the first method will keep your "color_file_name" and "def_dir" 
  60. * updated for future calls.(See: palette.c for an example.)
  61. *
  62. *----------------------------------------------------------------------------                                           
  63. *
  64. *  These routines now compile using AZTEC 3.4a using 16 bit ints.
  65. * (makefile for MANX also included)
  66. *
  67. *   Any bug reports/suggestions/fixes/etc... would be appreciated.
  68. *   I can be reached at:                 (703) 297-7639
  69. *
  70. * via    E-MAIL-> GEnie: K.Young
  71. *                 CA-AUG: Keith Young
  72. *           Deep Thought: Keith Young
  73. *             COMPUSERVE: 73170,307
  74. *
  75. * via Snail-Mail-> Keith Young
  76. *                  Rt.2 Box 261
  77. *                  Goodview, Va.   (yes, really :-)
  78. *                           24095
  79. *         ______________________________________________________          
  80. \********<<<<<<<<<<<<<<<<<<<|---={(~!~)}=---|>>>>>>>>>>>>>>>>>>>>***********/
  81.  
  82. #include <exec/types.h>
  83. #include <exec/devices.h>
  84. #include <intuition/intuition.h>
  85.  
  86. #include <graphics/gels.h>
  87. #include <graphics/copper.h>
  88. #include <graphics/regions.h>
  89. #include <devices/keymap.h>
  90.  
  91. extern void init_palette(),palette();   /* Color Palette routines */
  92.  
  93. #define DPTH 3L       /* Raster dimensions */
  94. #define WDTH 640L
  95. #define HGHT 200L
  96.  
  97. #define NL 0L
  98.  
  99. /* Font Descriptor   */
  100. struct TextAttr MyFont = {
  101.    (UBYTE *)"topaz.font",
  102.    TOPAZ_EIGHTY,
  103.    FS_NORMAL,
  104.    FPF_ROMFONT
  105.  };
  106.  
  107. /* Used to open a Screen   */
  108. struct NewScreen NewScreen = {
  109.    0,0,WDTH,HGHT,DPTH,         /* Left,Top,Width,Height,Depth    */
  110.    7,5,HIRES,                  /* DetailPen, BlockPen, ViewModes */
  111.    CUSTOMSCREEN,&MyFont,       /* Type, Font  */
  112.    (UBYTE *)"Palette/File Requester Tester by--------> Keith Young",/* Title */
  113.    NL,NL };                    /* Gadgets, BitMap  */
  114.  
  115. /* Used to open a Window   */
  116. struct NewWindow NewWindow = {
  117.    0,0,WDTH,HGHT,              /* LeftEdge,TopEdge,Width,Height */
  118.    7,0,                        /* DetailPen,BlockPen     */
  119.    MOUSEBUTTONS | MOUSEMOVE | MENUVERIFY | MENUPICK | GADGETUP |
  120.       GADGETDOWN | CLOSEWINDOW | ACTIVEWINDOW,
  121.    SMART_REFRESH | REPORTMOUSE | ACTIVATE | BACKDROP | BORDERLESS, /*Flags*/
  122.    NL,NL,NL,                  /* FirstGadget, CheckMark, Title  */
  123.    NL,                        /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  124.    NL,                        /* BitMap    */
  125.    100,60,32767,32767,        /* MinW, MinH, MaxW, MaxH */
  126.    CUSTOMSCREEN };            /* Type   */
  127.  
  128.  
  129. /*******    Variables Initialized by open_stuff()  **********/
  130.  
  131. struct IntuitionBase *IntuitionBase = NL;
  132. struct GfxBase       *GfxBase = NL;
  133. extern UBYTE         *OpenLibrary();
  134. extern struct Screen *OpenScreen();
  135. extern struct Window *OpenWindow();
  136. struct Screen        *p_S;
  137. struct Window        *p_W;
  138.  
  139. /************************************************************
  140. * open_stuff()
  141. *
  142. *     Opens screen and full-sized window for program.
  143. *
  144. *     Initializes handles p_S,p_W
  145. *
  146. *  See also: close_stuff()
  147. *************************************************************/
  148.  
  149. open_stuff()
  150. {
  151.    if ( ! (IntuitionBase = (struct IntuitionBase *)
  152.      OpenLibrary("intuition.library",0L)) ||
  153.       ! (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",0L)) )
  154.          exit(20);
  155.  
  156.    if ( ! (p_S =(struct Screen *)OpenScreen(&NewScreen)) )
  157.      {
  158.       printf("\tCan't Open Screen!\n Call Your Local Dealer and Buy More Mem!\n");
  159.       exit(21);
  160.      }
  161.  
  162.    NewWindow.Screen = p_S;   /* NEED TO SET SCREEN!!! */
  163.  
  164.    if ( ! (p_W =(struct Window *)OpenWindow(&NewWindow)) ) 
  165.      {
  166.       CloseScreen(p_S);
  167.       printf("This is not good.\n");
  168.       exit(22);
  169.      }
  170. }
  171.  
  172. /*************************************************
  173.  * close_stuff()
  174.  *
  175.  *  Cleans up what was allocated by open_stuff()
  176.  *************************************************/
  177.  
  178. void close_stuff()
  179. {
  180.    CloseWindow(p_W);
  181.    CloseScreen(p_S);
  182.    CloseLibrary(GfxBase);
  183.    CloseLibrary(IntuitionBase);
  184. }
  185.  
  186. /*****************************************************************
  187.  * main()
  188.  *
  189.  * open_stuff, initialize_the_palette, call_the_palette_routine,
  190.  * close_stuff and_then_exit. 
  191.  ****************************************************************/
  192.  
  193. void main()
  194. {
  195.  open_stuff();
  196.  init_palette(p_W,p_S);
  197.  palette(p_W,p_S);
  198.  close_stuff();
  199.  exit(1);
  200. }
  201.  
  202. /*** End of Palette/File Requester Tester (test.c) ***/
  203.