1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSColor.m
|
|
|
|
|
|
|
|
The colorful color class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
1997-08-18 17:10:23 +00:00
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
|
|
|
#include <AppKit/NSColorPrivate.h>
|
|
|
|
#include <AppKit/NSView.h>
|
1997-08-04 20:42:56 +00:00
|
|
|
#include <AppKit/NSGraphics.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
// Class variables
|
1996-12-05 13:07:59 +00:00
|
|
|
static BOOL gnustep_gui_ignores_alpha = YES;
|
1996-09-12 19:24:32 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSColor
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSColor class])
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// Set the version number
|
|
|
|
[self setVersion:2];
|
|
|
|
|
|
|
|
// ignore alpha by default
|
|
|
|
gnustep_gui_ignores_alpha = YES;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Creating an NSColor from Component Values
|
|
|
|
//
|
|
|
|
+ (NSColor *)colorWithCalibratedHue:(float)hue
|
|
|
|
saturation:(float)saturation
|
|
|
|
brightness:(float)brightness
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSCalibratedRGBColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_HSB_ACTIVE];
|
|
|
|
[c setHue: hue];
|
|
|
|
[c setSaturation: saturation];
|
|
|
|
[c setBrightness: brightness];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithCalibratedRed:(float)red
|
|
|
|
green:(float)green
|
|
|
|
blue:(float)blue
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
1996-09-12 19:24:32 +00:00
|
|
|
[c setColorSpaceName: NSCalibratedRGBColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_RGB_ACTIVE];
|
|
|
|
[c setRed: red];
|
|
|
|
[c setGreen: green];
|
|
|
|
[c setBlue: blue];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithCalibratedWhite:(float)white
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSCalibratedWhiteColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_WHITE_ACTIVE];
|
|
|
|
[c setWhite: white];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithCatalogName:(NSString *)listName
|
|
|
|
colorName:(NSString *)colorName
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithDeviceCyan:(float)cyan
|
|
|
|
magenta:(float)magenta
|
|
|
|
yellow:(float)yellow
|
|
|
|
black:(float)black
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSDeviceCMYKColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_CMYK_ACTIVE];
|
|
|
|
[c setCyan: cyan];
|
|
|
|
[c setMagenta: magenta];
|
|
|
|
[c setYellow: yellow];
|
|
|
|
[c setBlack: black];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithDeviceHue:(float)hue
|
|
|
|
saturation:(float)saturation
|
|
|
|
brightness:(float)brightness
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSDeviceRGBColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_HSB_ACTIVE];
|
|
|
|
[c setHue: hue];
|
|
|
|
[c setSaturation: saturation];
|
|
|
|
[c setBrightness: brightness];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithDeviceRed:(float)red
|
|
|
|
green:(float)green
|
|
|
|
blue:(float)blue
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSDeviceRGBColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_RGB_ACTIVE];
|
|
|
|
[c setRed: red];
|
|
|
|
[c setGreen: green];
|
|
|
|
[c setBlue: blue];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)colorWithDeviceWhite:(float)white
|
|
|
|
alpha:(float)alpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSColor *c;
|
|
|
|
|
|
|
|
c = [[[NSColor alloc] init] autorelease];
|
|
|
|
[c setColorSpaceName: NSDeviceWhiteColorSpace];
|
|
|
|
[c setActiveComponent: GNUSTEP_GUI_WHITE_ACTIVE];
|
|
|
|
[c setWhite: white];
|
|
|
|
[c setAlpha: alpha];
|
|
|
|
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Creating an NSColor With Preset Components
|
|
|
|
//
|
|
|
|
+ (NSColor *)blackColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedWhite: NSBlack alpha: 1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)blueColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:0
|
|
|
|
green:0
|
|
|
|
blue:1.0
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)brownColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:0.6
|
|
|
|
green:0.4
|
|
|
|
blue:0.2
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)clearColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
NSColor *c;
|
|
|
|
c = [self colorWithCalibratedRed:0
|
|
|
|
green:1.0
|
|
|
|
blue:1.0
|
|
|
|
alpha:1.0];
|
|
|
|
[c setClear:YES];
|
|
|
|
return c;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)cyanColor
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// Why does OpenStep say RGB color space instead of CMYK?
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:0
|
|
|
|
green:1.0
|
|
|
|
blue:1.0
|
|
|
|
alpha:1.0];
|
1996-09-12 19:24:32 +00:00
|
|
|
#if 0
|
|
|
|
return [self colorWithCalibratedCyan: 1.0
|
|
|
|
magenta:0
|
|
|
|
yellow:0
|
|
|
|
black:0
|
|
|
|
alpha:1.0];
|
|
|
|
#endif
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)darkGrayColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedWhite: NSDarkGray alpha: 1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)grayColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedWhite: NSGray alpha: 1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)greenColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:0
|
|
|
|
green:1.0
|
|
|
|
blue:0
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)lightGrayColor
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedWhite: NSLightGray alpha: 1];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)magentaColor
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// Why does OpenStep say RGB color space instead of CMYK?
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:1.0
|
|
|
|
green:0
|
|
|
|
blue:1.0
|
|
|
|
alpha:1.0];
|
1996-09-12 19:24:32 +00:00
|
|
|
#if 0
|
|
|
|
return [self colorWithCalibratedCyan:0
|
|
|
|
magenta:1.0
|
|
|
|
yellow:0
|
|
|
|
black:0
|
|
|
|
alpha:1.0];
|
|
|
|
#endif
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)orangeColor;
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:1.0
|
|
|
|
green:0.5
|
|
|
|
blue:0
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)purpleColor;
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:0.5
|
|
|
|
green:0
|
|
|
|
blue:0.5
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)redColor;
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:1.0
|
|
|
|
green:0
|
|
|
|
blue:0
|
|
|
|
alpha:1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)whiteColor;
|
|
|
|
{
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedWhite: NSWhite alpha: 1.0];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSColor *)yellowColor
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// Why does OpenStep say RGB color space instead of CMYK?
|
1996-12-05 13:07:59 +00:00
|
|
|
return [self colorWithCalibratedRed:1.0
|
|
|
|
green:1.0
|
|
|
|
blue:0
|
|
|
|
alpha:1.0];
|
1996-09-12 19:24:32 +00:00
|
|
|
#if 0
|
|
|
|
return [self colorWithCalibratedCyan:0
|
|
|
|
magenta:0
|
|
|
|
yellow:1.0
|
|
|
|
black:0
|
1996-05-30 20:03:15 +00:00
|
|
|
alpha:1];
|
1996-09-12 19:24:32 +00:00
|
|
|
#endif
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Ignoring Alpha Components
|
|
|
|
//
|
|
|
|
+ (BOOL)ignoresAlpha
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return gnustep_gui_ignores_alpha;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)setIgnoresAlpha:(BOOL)flag
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
gnustep_gui_ignores_alpha = flag;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Copying and Pasting
|
|
|
|
//
|
|
|
|
+ (NSColor *)colorFromPasteboard:(NSPasteboard *)pasteBoard
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1996-09-12 19:24:32 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
|
|
|
|
colorspace_name = @"";
|
|
|
|
catalog_name = @"";
|
|
|
|
color_name = @"";
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Retrieving a Set of Components
|
|
|
|
//
|
|
|
|
- (void)getCyan:(float *)cyan
|
|
|
|
magenta:(float *)magenta
|
|
|
|
yellow:(float *)yellow
|
|
|
|
black:(float *)black
|
|
|
|
alpha:(float *)alpha
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
// Only set what is wanted
|
|
|
|
// If not a CMYK color then you get bogus values
|
|
|
|
if (cyan)
|
|
|
|
*cyan = CMYK_component.cyan;
|
|
|
|
if (magenta)
|
|
|
|
*magenta = CMYK_component.magenta;
|
|
|
|
if (yellow)
|
|
|
|
*yellow = CMYK_component.yellow;
|
|
|
|
if (black)
|
|
|
|
*black = CMYK_component.black;
|
|
|
|
if (alpha)
|
|
|
|
*alpha = alpha_component;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)getHue:(float *)hue
|
|
|
|
saturation:(float *)saturation
|
|
|
|
brightness:(float *)brightness
|
|
|
|
alpha:(float *)alpha
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
// Only set what is wanted
|
|
|
|
// If not an HSB color then you get bogus values
|
|
|
|
if (hue)
|
|
|
|
*hue = HSB_component.hue;
|
|
|
|
if (saturation)
|
|
|
|
*saturation = HSB_component.saturation;
|
|
|
|
if (brightness)
|
|
|
|
*brightness = HSB_component.brightness;
|
|
|
|
if (alpha)
|
|
|
|
*alpha = alpha_component;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)getRed:(float *)red
|
|
|
|
green:(float *)green
|
|
|
|
blue:(float *)blue
|
|
|
|
alpha:(float *)alpha
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
// Only set what is wanted
|
|
|
|
// If not an RGB color then you get bogus values
|
|
|
|
if (red)
|
|
|
|
*red = RGB_component.red;
|
|
|
|
if (green)
|
|
|
|
*green = RGB_component.green;
|
|
|
|
if (blue)
|
|
|
|
*blue = RGB_component.blue;
|
|
|
|
if (alpha)
|
|
|
|
*alpha = alpha_component;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)getWhite:(float *)white
|
|
|
|
alpha:(float *)alpha
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
// Only set what is wanted
|
|
|
|
// If not a grayscale color then you get bogus values
|
|
|
|
if (white)
|
|
|
|
*white = white_component;
|
|
|
|
if (alpha)
|
|
|
|
*alpha = alpha_component;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieving Individual Components
|
|
|
|
//
|
|
|
|
- (float)alphaComponent
|
|
|
|
{
|
|
|
|
return alpha_component;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)blackComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return CMYK_component.black;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)blueComponent
|
|
|
|
{
|
|
|
|
return RGB_component.blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)brightnessComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return HSB_component.brightness;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)catalogNameComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return catalog_name;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)colorNameComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return color_name;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)cyanComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return CMYK_component.cyan;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)greenComponent
|
|
|
|
{
|
|
|
|
return RGB_component.green;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)hueComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return HSB_component.hue;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)localizedCatalogNameComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// +++ how do we localize?
|
|
|
|
return catalog_name;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)localizedColorNameComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// +++ how do we localize?
|
|
|
|
return color_name;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)magentaComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return CMYK_component.magenta;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)redComponent
|
|
|
|
{
|
|
|
|
return RGB_component.red;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)saturationComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return HSB_component.saturation;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)whiteComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return white_component;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)yellowComponent
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return CMYK_component.yellow;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Converting to Another Color Space
|
|
|
|
//
|
|
|
|
- (NSString *)colorSpaceName
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
return colorspace_name;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace
|
|
|
|
device:(NSDictionary *)deviceDescription
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Changing the Color
|
|
|
|
//
|
|
|
|
- (NSColor *)blendedColorWithFraction:(float)fraction
|
|
|
|
ofColor:(NSColor *)aColor
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSColor *)colorWithAlphaComponent:(float)alpha
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copying and Pasting
|
|
|
|
//
|
|
|
|
- (void)writeToPasteboard:(NSPasteboard *)pasteBoard
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Drawing
|
|
|
|
//
|
|
|
|
- (void)drawSwatchInRect:(NSRect)rect
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)set
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Destroying
|
|
|
|
//
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
// Version 1
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &RGB_component.red];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &RGB_component.green];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &RGB_component.blue];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &alpha_component];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_clear];
|
1996-09-12 19:24:32 +00:00
|
|
|
|
|
|
|
// Version 2
|
|
|
|
[aCoder encodeObject: colorspace_name];
|
|
|
|
[aCoder encodeObject: catalog_name];
|
|
|
|
[aCoder encodeObject: color_name];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &CMYK_component.cyan];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &CMYK_component.magenta];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &CMYK_component.yellow];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &CMYK_component.black];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &HSB_component.hue];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &HSB_component.saturation];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &HSB_component.brightness];
|
|
|
|
[aCoder encodeValueOfObjCType: "f" at: &white_component];
|
|
|
|
[aCoder encodeValueOfObjCType: "i" at: &active_component];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
1996-09-12 19:24:32 +00:00
|
|
|
NSString *s;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
// Version 1
|
1996-05-30 20:03:15 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &RGB_component.red];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &RGB_component.green];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &RGB_component.blue];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &alpha_component];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_clear];
|
|
|
|
|
1996-09-12 19:24:32 +00:00
|
|
|
// Get our class name
|
1997-02-18 00:29:25 +00:00
|
|
|
s = NSStringFromClass(isa);
|
1996-09-12 19:24:32 +00:00
|
|
|
|
|
|
|
// Version 2
|
1996-12-05 13:07:59 +00:00
|
|
|
// +++ Coding cannot return class version yet
|
|
|
|
// if ([aDecoder versionForClassName: s] > 1)
|
1996-09-12 19:24:32 +00:00
|
|
|
{
|
|
|
|
colorspace_name = [aDecoder decodeObject];
|
|
|
|
catalog_name = [aDecoder decodeObject];
|
|
|
|
color_name = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &CMYK_component.cyan];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &CMYK_component.magenta];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &CMYK_component.yellow];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &CMYK_component.black];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &HSB_component.hue];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &HSB_component.saturation];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &HSB_component.brightness];
|
|
|
|
[aDecoder decodeValueOfObjCType: "f" at: &white_component];
|
|
|
|
[aDecoder decodeValueOfObjCType: "i" at: &active_component];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
1996-09-12 19:24:32 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Private methods
|
|
|
|
//
|
|
|
|
@implementation NSColor (GNUstepPrivate)
|
|
|
|
|
|
|
|
- (void)setColorSpaceName:(NSString *)str
|
|
|
|
{
|
|
|
|
colorspace_name = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCatalogName:(NSString *)str
|
|
|
|
{
|
|
|
|
catalog_name = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setColorName:(NSString *)str
|
|
|
|
{
|
|
|
|
color_name = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB component values
|
|
|
|
- (void)setRed:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
RGB_component.red = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setGreen:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
RGB_component.green = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBlue:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
RGB_component.blue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CMYK component values
|
|
|
|
- (void)setCyan:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
CMYK_component.cyan = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMagenta:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
CMYK_component.magenta = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setYellow:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
CMYK_component.yellow = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBlack:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
CMYK_component.black = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// HSB component values
|
|
|
|
- (void)setHue:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
HSB_component.hue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSaturation:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
HSB_component.saturation = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBrightness:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
HSB_component.brightness = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grayscale
|
|
|
|
- (void)setWhite:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
white_component = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlpha:(float)value
|
|
|
|
{
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 1) value = 1;
|
|
|
|
alpha_component = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setActiveComponent:(int)value
|
|
|
|
{
|
|
|
|
active_component = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setClear:(BOOL)flag
|
|
|
|
{
|
|
|
|
is_clear = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Implementation of the NSCoder additions
|
|
|
|
//
|
|
|
|
@implementation NSCoder (NSCoderAdditions)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Converting an Archived NXColor to an NSColor
|
|
|
|
//
|
|
|
|
- (NSColor *)decodeNXColor
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|