home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / appkit / color.h < prev    next >
Text File  |  1992-02-03  |  6KB  |  154 lines

  1. /*
  2.         color.h
  3.         Application Kit, Release 2.0
  4.         Copyright (c) 1988, 1989, 1990, NeXT, Inc.  All rights reserved. 
  5. */
  6.  
  7. #import <stddef.h>
  8. #import <objc/typedstream.h>
  9.  
  10. /*
  11.  * NXColor structure for passing colors around in the Application Kit.
  12.  * Do not access structure elements directly; the values stored in the 
  13.  * various fields are likely to change between releases.
  14.  */ 
  15. typedef struct _NXColor {
  16.     unsigned short colorField[6];
  17.     const char *str;
  18. } NXColor;
  19.  
  20. /*
  21.  * Basic functions to create new NXColor values.  All values are in the
  22.  * range 0..1 (inclusive), following the PostScript model. (The only 
  23.  * exception is an alpha value of NX_NOALPHA, described below.)
  24.  *
  25.  *   RGB = red, green, blue
  26.  *   HSB = hue, saturation, brightness
  27.  *   CMYK = cyan, magenta, yellow, black
  28.  *   A = alpha
  29.  */
  30. extern NXColor NXConvertRGBAToColor (float, float, float, float);
  31. extern NXColor NXConvertHSBAToColor (float, float, float, float);
  32. extern NXColor NXConvertCMYKAToColor (float, float, float, float, float);
  33. extern NXColor NXConvertGrayAlphaToColor (float, float);
  34.  
  35. /* 
  36.  * Basic functions to extract color components from NXColors.  If you don't
  37.  * want the alpha value, pass NULL and the value won't be returned. 
  38.  */ 
  39. extern void NXConvertColorToRGBA (NXColor, float *, float *, float *, float *);
  40. extern void NXConvertColorToHSBA (NXColor, float *, float *, float *, float *);
  41. extern void NXConvertColorToCMYKA (NXColor, float *, float *, float *, float *, float *);
  42. extern void NXConvertColorToGrayAlpha (NXColor, float *, float *);
  43.  
  44. /*
  45.  * Macros to allow dealing with colors without involving alpha.
  46.  * Use these rather than the functions above unless you explicitly
  47.  * wish to deal with alpha values.
  48.  */
  49. #define NXConvertRGBToColor(r, g, b) \
  50.                 NXConvertRGBAToColor(r, g, b, NX_NOALPHA)
  51. #define NXConvertHSBToColor(h, s, b) \
  52. UF            NXConvertHSBAToColor(h, s, b, NX_NOALPHA)
  53. #define NXConvertCMYKToColor(c, m, y, k) \
  54.                 NXConvertCMYKAToColor(c, m, y, k, NX_NOALPHA)
  55. #define NXConvertGrayToColor(g) \
  56.                 NXConvertGrayAlphaToColor(g, NX_NOALPHA)
  57.  
  58. #define NXConvertColorToRGB(color, r, g, b) \
  59.                 NXConvertColorToRGBA(color, r, g, b, NULL)
  60. #define NXConvertColorToHSB(color, h, s, b) \
  61.                 NXConvertColorToHSBA(color, h, s, b, NULL)
  62. #define NXConvertColorToCMYK(color, c, m, y, k) \
  63.                 NXConvertColorToCMYKA(color, c, m, y, k, NULL)
  64. #define NXConvertColorToGray(color, g) \
  65.                 NXConvertColorToGrayAlpha(color, g, NULL)
  66.  
  67. /*
  68.  * Functions to get individual components one at a time. For two or more
  69.  * components, it's more efficient to call NXConvertColorToXXX.
  70.  */
  71. extern float NXRedComponent (NXColor);
  72. extern float NXBlueComponent (NXColor);
  73. extern float NXGreenComponent (NXColor);
  74. extern float NXGrayComponent (NXColor);
  75. extern float NXHueComponent (NXColor);
  76. extern float NXSaturationComponent (NXColor);
  77. extern float NXBrightnessComponent (NXColor);
  78. extern float NXCyanComponent (NXColor);
  79. extern float NXYellowComponent (NXColor);
  80. extern float NXMagentaComponent (NXColor);
  81. extern float NXBlackComponent (NXColor);
  82. extern float NXAlphaComponent (NXColor);
  83.  
  84. /*
  85.  * Functions to set individual components one at a time.  Note that the
  86.  * color argument is not modified; instead, a new color is returned.
  87.  * To change the red component of a color you'd do something like:
  88.  *    myColor = NXChangeRedComponent(myColor, 0.5);
  89.  */
  90. extern NXColor NXChangeRedComponent (NXColor, float);
  91. extern NXColor NXChangeBlueComponent (NXColor, float);
  92. extern NXColor NXChangeGreenComponent (NXColor, float);
  93. extern NXColor NXChangeGrayComponent (NXColor, float);
  94. extern NXColor NXChangeHueComponent (NXColor, float);
  95. extern NXColor NXChangeSaturationComponent (NXColor, float);
  96. extern NXColor NXChangeBrightnessComponent (NXColor, float);
  97. extern NXColor NXChangeCyanComponent (NXColor, float);
  98. extern NXColor NXChangeYellowComponent (NXColor, float);
  99. extern NXColor NXChangeMagentaComponent (NXColor, float);
  100. extern NXColor NXChangeBlackComponent (NXColor, float);
  101. extern NXColor NXChangeAlphaComponent (NXColor, float);
  102.  
  103. /*
  104.  * Misc functions.
  105.  */
  106. extern void NXWriteColor (NXTypedStream *, NXColor);
  107. externUFolor NXReadColor (NXTypedStream *);
  108. extern BOOL NXEqualColor (NXColor, NXColor);
  109. extern NXColor NXReadColorFromPasteboard(id pasteboard);
  110. extern void NXWriteColorToPasteboard(id pasteboard, NXColor color);
  111.  
  112. /*
  113.  * Set the current color to the specified color. NXSetColor() will generate 
  114.  * alpha only if the alpha is specified in the color and the output is going 
  115.  * to a device capable of dealing with alpha.
  116.  */
  117. extern void NXSetColor (NXColor);
  118.  
  119. /*
  120.  * The following functions allow you to get the list and color names of named colors.
  121.  */
  122. extern const char *NXColorListName (NXColor color);
  123. extern const char *NXColorName (NXColor color);
  124. BOOL NXFindColorNamed (const char *colorList, const char *colorName, NXColor *color);
  125.  
  126. /*
  127.  * Some "standard" colors.
  128.  */
  129. #define NX_COLORBLACK   NXConvertGrayToColor(0.0)
  130. #define NX_COLORWHITE   NXConvertGrayToColor(1.0)
  131. #define NX_COLORGRAY    NXConvertGrayToColor(0.5)
  132. #define NX_COLORLTGRAY  NXConvertGrayToColor(2./3.)
  133. #define NX_COLORDKGRAY  NXConvertGrayToColor(1./3.)
  134. #define NX_COLORRED     NXConvertRGBToColor(1.0, 0.0, 0.0)
  135. #define NX_COLORGREEN   NXConvertRGBToColor(0.0, 1.0, 0.0)
  136. #define NX_COLORBLUE    NXConvertRGBToColor(0.0, 0.0, 1.0)
  137. #define NX_COLORCYAN    NXConvertRGBToColor(0.0, 1.0, 1.0)
  138. #define NX_COLORYELLOW  NXConvertRGBToColor(1.0, 1.0, 0.0)
  139. #define NX_COLORMAGENTA NXConvertRGBToColor(1.0, 0.0, 1.0)
  140. #define NX_COLORORANGE  NXConvertRGBToColor(1.0, 0.5, 0.0)
  141. #define NX_COLORPURPLE  NXConvertRGBToColor(0.5, 0.0, 0.5)
  142. #define NX_COLORBROWN   NXConvertRGBToColor(0.6, 0.4, 0.2)
  143.  
  144. #define NX_COLORCLEAR   NXConvertGrayAlphaToColor(0.0, 0.0)
  145.  
  146. /*
  147.  * The following value will be returned by functions returning alpha 
  148.  * if the alpha is not specified in the color.  You can also use NX_NOALPHA
  149.  * as an argument to any function accepting alpha.
  150.  */
  151.  
  152. #define NX_NOALPHA (-1.0)
  153.  
  154.