home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / cdity / colorsaver / src / main.c < prev    next >
C/C++ Source or Header  |  1994-12-12  |  31KB  |  1,034 lines

  1. /****************************************************************************
  2.  *    ColorSaver --- A popup color palette commodity
  3.  *
  4.  *    05 January 1993
  5.  *    Compiled with DICE
  6.  *
  7.  *    Copyright © 1993, 1994 By Dan Fish
  8.  *    All rights reserved.
  9.  *
  10.  *    Permission is granted to freely redistribute this program provided 
  11.  *    the source code and documentation are included in the distribution,
  12.  *    changes are clearly documented, and this copyright notice remains
  13.  *      unchanged.
  14.  *
  15.  ****************************************************************************/
  16.  
  17.  
  18. #include <exec/memory.h>                        /*N*/
  19. #include <clib/macros.h>                        /*N*/
  20. #include <libraries/commodities.h>
  21. #include <intuition/intuition.h>
  22. #include <intuition/intuitionbase.h>
  23. #include <workbench/startup.h>
  24.  
  25. #include <stdlib.h>                             
  26. #include <string.h>                             
  27. #include <stdarg.h>                             
  28. #include <stdio.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/commodities_protos.h>
  32. #include <clib/utility_protos.h>
  33. #include <clib/intuition_protos.h>
  34. #include <clib/alib_protos.h>
  35. #include <clib/gadtools_protos.h>
  36. #include <clib/graphics_protos.h>
  37.  
  38. #include "gadgets.h"               /* GadToolsBox file     */
  39. #include "protos.h"            /* Routine prototypes    */
  40. #include "simplerexx.h"            /* ARexx stuff        */
  41. #include "defs.h"
  42.  
  43. /*-------------------------------------------------------------------------
  44.  * The following strings represent the
  45.  * possible tooltypes of the ColorSaver icon.
  46.  *-------------------------------------------------------------------------*/
  47.  
  48. UBYTE   *CX_PRIORITY        =       "CX_PRIORITY";
  49. UBYTE   *CX_POPUP           =       "CX_POPUP";
  50. UBYTE   *CX_POPKEY          =       "CX_POPKEY";
  51. UBYTE   *CX_QUIT            =       "CX_QUIT";
  52. UBYTE   *CX_HSV         =       "HSV";
  53. UBYTE   *CX_SEL         =       "SELECT";
  54. UBYTE   *CX_PATH            =       "PATH";
  55. UBYTE   *CX_POP_X           =       "POP_X";
  56. UBYTE   *CX_POP_Y           =       "POP_Y";
  57.  
  58. /*-------------------------------------------------------------------------
  59.  * Following are the default ColorSaver
  60.  * settings which can be changed with
  61.  * the command line or the icon tooltypes.
  62.  *-------------------------------------------------------------------------*/
  63.  
  64. #define  CX_DEFPRI           0
  65. #define  CX_DEFSEL           0
  66. #define  CX_DEFPOP_X       175
  67. #define  CX_DEFPOP_Y        50
  68. UBYTE   *CX_DEFPOPKEY       =       "lalt ralt c";
  69. UBYTE   *CX_DEFPOPUP        =       "YES";
  70. UBYTE   *CX_DEFMODE         =       "RGB";
  71. UBYTE   *CX_DEFQUIT         =       "lalt ralt q";
  72. UBYTE   *CX_DEFPATH         =       "SYS:Prefs/Presets";
  73.  
  74. /*-------------------------------------------------------------------------
  75.  * Some Commodity definitions
  76.  *-------------------------------------------------------------------------*/
  77.  
  78. #define  CX_SHOW            1L                      /* show window */
  79. #define  CX_SHUTUP          2L                      /* quit ColorSaver */
  80. #define  CxOn( b )          ActivateCxObj( b, TRUE )
  81. #define  CxOff( b )         ActivateCxObj( b, FALSE );
  82.  
  83. /*-------------------------------------------------------------------------
  84.  * I used this stuff for debugging
  85.  *-------------------------------------------------------------------------*/
  86. #ifdef CS_DEBUG
  87. UBYTE *conwinname   = "CON:10/10/620/180/CS_Debug";
  88. FILE *conwin = NULL;
  89. #endif
  90.  
  91. /*-------------------------------------------------------------------------
  92.  * Miscellaneous program information.
  93.  *-------------------------------------------------------------------------*/
  94.  
  95. #define  CSVersion          "v1.19"
  96. #define  CSName             "ColorSaver"
  97. #define  CSDescr            "Color Palette Tool"
  98. #define  CSCopy             "© 1994, Dan Fish"
  99. #define  CSDate             "(10.12.1994)"
  100. #define  CSTitle            CSName " " CSVersion ", " CSCopy
  101.  
  102. /*-------------------------------------------------------------------------
  103.  * Shell version string.
  104.  *-------------------------------------------------------------------------*/
  105. #define  CSVerString        "$VER:" CSName " "CSVersion " "CSDate"\r\n"
  106. static UBYTE CsVer[]        = {  CSVerString  };
  107.  
  108. /*-------------------------------------------------------------------------
  109.  * The NewBroker structure defining
  110.  * some important information for
  111.  * the commodities.library and Exchange.
  112.  *-------------------------------------------------------------------------*/
  113.  
  114. struct NewBroker             CSNBrok  = {
  115.     NB_VERSION, CSName, CSTitle, CSDescr,
  116.     NBU_NOTIFY | NBU_UNIQUE, COF_SHOW_HIDE, NULL, 0
  117. };
  118.  
  119. /*-------------------------------------------------------------------------
  120.  * DCBack required data. DCBack is a tiny link library
  121.  * written by Jan van den Baard to make it possible to write
  122.  * auto-detachable programs with DICE. DCBack also parses the
  123.  * argument line for you using ReadArgs().
  124.  *-------------------------------------------------------------------------*/
  125.  
  126. UBYTE                       *_procname      = CSName "_" CSVersion;
  127. UBYTE                       *_template      = "PRIORITY/K/N,POPUP/K,POPKEY/K,QUIT/K,POP_X/K/N,POP_Y/K/N,PATH/K,SELECT/K/N,HSV/S";
  128. UBYTE                       *_exthelp       = NULL;
  129. LONG                         _stack         = 4096L;
  130. LONG                         _priority      = NULL;
  131. LONG                         _BackGroundIO  = NULL;
  132.  
  133. /*-------------------------------------------------------------------------
  134.  * ARexx declarations
  135.  *-------------------------------------------------------------------------*/
  136.  
  137. AREXXCONTEXT    RexxStuff;
  138. UBYTE RexxName[64];
  139.  
  140. /*-------------------------------------------------------------------------
  141.  * Required libraries that are not in DICE's
  142.  * auto-init library.
  143.  *-------------------------------------------------------------------------*/
  144.  
  145. struct Library              *CxBase        = NULL;
  146. struct Library              *IconBase      = NULL;
  147. struct Library              *WorkbenchBase = NULL;
  148.  
  149. /*-------------------------------------------------------------------------
  150.  * The following libraries are all auto-init.
  151.  *-------------------------------------------------------------------------*/
  152.  
  153. extern struct IntuitionBase        *IntuitionBase;
  154. extern struct UtilityBase          *UtilityBase;
  155. extern struct GadToolsBase         *GadToolsBase;
  156.  
  157. /*-------------------------------------------------------------------------
  158.  * Some other useful global variables
  159.  *-------------------------------------------------------------------------*/
  160.  
  161. struct MsgPort          *CSComPort  = NULL;    /* commodity port    */
  162. struct MsgPort          *CSIdPort   = NULL;     /* IDCMP port        */
  163. CxObj                   *CSBroker   = NULL;    /* the broker        */
  164. ULONG                    CSMask     = NULL;    /* the port bit-mask     */
  165. ULONG                    CSIdMask   = NULL;     /* IDCMP port bit-mask    */
  166. ULONG                    RexxMask   = NULL;     /* ARexx port bit-mask    */
  167. UBYTE                   *CSTTypes   = NULL;    /* the tooltype array    */
  168. ULONG                   *CSArgs;        /* shell args array    */
  169. struct Screen         *Scr        = NULL;    /* screen we open up on    */
  170. struct WBStartup        *WbMsg      = NULL;     /* workbench message    */
  171. UBYTE                   *CSPopkey;              /* popkey string ptr    */
  172. UBYTE                   *Palette_Dir;           /* default palette path */
  173. UBYTE                    CSIsOpen   = FALSE;    /* window open?     */
  174. UBYTE                    CSPop      = TRUE;     /* open on startup?    */
  175. UBYTE                    CSWTitle[80];          /* window title     */
  176. UWORD                    ColorSaverLeft;    /* left edge of window  */
  177. UWORD                    ColorSaverTop;        /* top edge of window   */
  178. UWORD              RedVal;        /* RGB red value    */
  179. UWORD              GreenVal;        /* RGB green value    */
  180. UWORD              BlueVal;        /* RGB blue value    */
  181. UWORD              HueLevel;        /* HSV hue         */
  182. UWORD              SatLevel;              /* HSV saturation    */
  183. UWORD              ValLevel;              /* HSV value         */
  184. ULONG             NumColors;        /* # of colors in palette   */
  185. SHORT             CurrentColor=0;    /* Currently selected color */
  186. USHORT                  *ResetPal = NULL;    /* Palette w/window first opens */
  187. USHORT                  *SavePal = NULL;           /* Snapshot of current palette*/
  188. UBYTE            ScanFileSpe