Add NSColorSpace and some new methods for NSColor.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25365 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2007-07-31 20:50:44 +00:00
parent 94a4f0fd3d
commit 0f4badf295
6 changed files with 420 additions and 4 deletions

View file

@ -1,3 +1,12 @@
2007-07-31 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSColorSpace.h,
* Source/NSColorSpace.m: New files.
* GNUMakefile: Add NSColorSpace.
* Headers/AppKit/NSColor.h,
* Source/NSColor.m: Add MacOSX 10.4 methods.
Code mostly by Nikolaus Schaller <hns@computer.org>.
2007-07-28 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSBrowser.h,

View file

@ -38,6 +38,7 @@
@class NSDictionary;
@class NSPasteboard;
@class NSImage;
@class NSColorSpace;
typedef enum _NSControlTint {
NSDefaultControlTint,
@ -168,6 +169,16 @@ typedef enum _NSControlSize {
- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace;
- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace
device:(NSDictionary *)deviceDescription;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
// + (NSColor *)colorWithCIColor:(CIColor *)color;
+ (NSColor *)colorWithColorSpace:(NSColorSpace *)space
components:(const float *)comp
count:(int)number;
- (NSColorSpace *)colorSpace;
- (NSColor *)colorUsingColorSpace:(NSColorSpace *)space;
- (void)getComponents:(float *)components;
- (int)numberOfComponents;
#endif
//
// Changing the Color
@ -187,6 +198,10 @@ typedef enum _NSControlSize {
//
- (void)drawSwatchInRect:(NSRect)rect;
- (void)set;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
- (void)setFill;
- (void)setStroke;
#endif
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
//
@ -195,14 +210,20 @@ typedef enum _NSControlSize {
- (NSColor*) highlightWithLevel: (float)level;
- (NSColor*) shadowWithLevel: (float)level;
+ (NSColor*) colorWithPatternImage:(NSImage*)image;
+ (NSColor*) colorForControlTint:(NSControlTint)controlTint;
+ (NSColor*)colorWithPatternImage:(NSImage*)image;
+ (NSColor*)colorForControlTint:(NSControlTint)controlTint;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
+ (NSControlTint)currentControlTint;
#endif
//
// System colors stuff.
//
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
+ (NSColor*) alternateSelectedControlColor;
+ (NSColor*) alternateSelectedControlTextColor;
#endif
+ (NSColor*) controlBackgroundColor;
+ (NSColor*) controlColor;
+ (NSColor*) controlHighlightColor;
@ -233,7 +254,9 @@ typedef enum _NSControlSize {
+ (NSColor*) windowFrameColor;
+ (NSColor*) windowFrameTextColor;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
+ (NSArray*) controlAlternatingRowBackgroundColors;
#endif
// Pattern colour
- (NSImage*) patternImage;

View file

@ -0,0 +1,72 @@
/*
NSColorSpace.h
The color space class
Copyright (C) 2007 Free Software Foundation, Inc.
Author: H. Nikolaus Schaller <hns@computer.org>
Date: 2007
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
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSColorSpace
#define _GNUstep_H_NSColorSpace
#import <GNUstepBase/GSVersionMacros.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
#import <Foundation/Foundation.h>
typedef enum _NSColorSpaceModel
{
NSUnknownColorSpaceModel = -1,
NSGrayColorSpaceModel,
NSRGBColorSpaceModel,
NSCMYKColorSpaceModel,
NSLABColorSpaceModel,
NSDeviceNColorSpaceModel
} NSColorSpaceModel;
@interface NSColorSpace : NSObject <NSCoding>
{
NSColorSpaceModel _colorSpaceModel;
NSData *_iccData;
void *_colorSyncProfile;
}
+ (NSColorSpace *)deviceCMYKColorSpace;
+ (NSColorSpace *)deviceGrayColorSpace;
+ (NSColorSpace *)deviceRGBColorSpace;
+ (NSColorSpace *)genericCMYKColorSpace;
+ (NSColorSpace *)genericGrayColorSpace;
+ (NSColorSpace *)genericRGBColorSpace;
- (NSColorSpaceModel)colorSpaceModel;
- (void *)colorSyncProfile;
- (NSData *)ICCProfileData;
- (id)initWithColorSyncProfile:(void *)prof;
- (id)initWithICCProfileData:(NSData *)iccData;
- (NSString *)localizedName;
- (int)numberOfColorComponents;
@end
#endif // MAC_OS_X_VERSION_10_4
#endif // _GNUstep_H_NSColorSpace

View file

@ -73,6 +73,7 @@ NSColor.m \
NSColorList.m \
NSColorPanel.m \
NSColorPicker.m \
NSColorSpace.m \
NSColorWell.m \
NSComboBox.m \
NSComboBoxCell.m \
@ -253,6 +254,7 @@ NSColor.h \
NSColorList.h \
NSColorPanel.h \
NSColorPicker.h \
NSColorSpace.h \
NSColorWell.h \
NSComboBox.h \
NSComboBoxCell.h \

View file

@ -40,6 +40,7 @@
#include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h"
#include "AppKit/NSColorSpace.h"
#include "AppKit/NSPasteboard.h"
#include "AppKit/NSView.h"
#include "AppKit/NSImage.h"
@ -485,8 +486,24 @@ systemColorWithName(NSString *name)
+ (NSColor*) colorForControlTint: (NSControlTint)controlTint
{
// TODO
return nil;
switch (controlTint)
{
default:
case NSDefaultControlTint:
return [self colorForControlTint: [self currentControlTint]];
case NSGraphiteControlTint:
// FIXME
case NSClearControlTint:
// FIXME
case NSBlueControlTint:
return [NSColor blueColor];
}
}
+ (NSControlTint) currentControlTint;
{
// FIXME: should be made a system setting
return NSBlueControlTint;
}
+ (NSColor*) colorWithPatternImage: (NSImage*)image
@ -1143,6 +1160,54 @@ systemColorWithName(NSString *name)
return nil;
}
+ (NSColor *) colorWithColorSpace: (NSColorSpace *)space
components: (const float *)comp
count: (int)number
{
// FIXME
return nil;
}
/*
FIXME: This method does it the wrong way around. We should store the
actual colour space and get the colour space name from there.
*/
- (NSColorSpace *) colorSpace
{
NSString *name = [self colorSpaceName];
if ([name isEqualToString: NSCalibratedRGBColorSpace])
return [NSColorSpace genericRGBColorSpace];
if ([name isEqualToString: NSDeviceRGBColorSpace])
return [NSColorSpace deviceRGBColorSpace];
if ([name isEqualToString: NSCalibratedBlackColorSpace]
|| [name isEqualToString: NSCalibratedWhiteColorSpace])
return [NSColorSpace genericGrayColorSpace];
if ([name isEqualToString: NSDeviceBlackColorSpace]
|| [name isEqualToString: NSDeviceWhiteColorSpace])
return [NSColorSpace deviceGrayColorSpace];
if ([name isEqualToString: NSDeviceCMYKColorSpace])
return [NSColorSpace deviceCMYKColorSpace];
return nil;
}
- (NSColor *) colorUsingColorSpace: (NSColorSpace *)space
{
// FIXME
return nil;
}
- (int) numberOfComponents
{
return [[self colorSpace] numberOfColorComponents];
}
- (void) getComponents: (float *)components
{
// FIXME
}
//
// Changing the Color
//
@ -1225,6 +1290,28 @@ systemColorWithName(NSString *name)
[[self colorUsingColorSpaceName: NSDeviceRGBColorSpace] set];
}
- (void) setFill
{
int num = [self numberOfComponents];
float values[num + 1];
NSGraphicsContext *ctxt = GSCurrentContext();
[self getComponents: values];
[ctxt GSSetFillColorspace: [self colorSpace]];
[ctxt GSSetFillColor: values];
}
- (void) setStroke
{
int num = [self numberOfComponents];
float values[num + 1];
NSGraphicsContext *ctxt = GSCurrentContext();
[ctxt GSSetStrokeColorspace: [self colorSpace]];
[self getComponents: values];
[ctxt GSSetStrokeColor: values];
}
//
// NSCoding protocol
//
@ -1875,6 +1962,17 @@ systemColorWithName(NSString *name)
return _white_component;
}
- (void) getComponents: (float *)components;
{
components[0] = _white_component;
components[1] = _alpha_component;
}
- (int) numberOfComponents
{
return 1;
}
- (NSString*) description
{
NSMutableString *desc;
@ -2160,6 +2258,20 @@ systemColorWithName(NSString *name)
return _yellow_component;
}
- (void) getComponents: (float *)components;
{
components[0] = _cyan_component;
components[1] = _magenta_component;
components[2] = _yellow_component;
components[3] = _black_component;
components[4] = _alpha_component;
}
- (int) numberOfComponents
{
return 4;
}
- (NSString*) description
{
NSMutableString *desc;
@ -2399,6 +2511,19 @@ systemColorWithName(NSString *name)
return _brightness_component;
}
- (void) getComponents: (float *)components;
{
components[0] = _red_component;
components[1] = _green_component;
components[2] = _blue_component;
components[4] = _alpha_component;
}
- (int) numberOfComponents
{
return 3;
}
- (void) getHue: (float*)hue
saturation: (float*)saturation
brightness: (float*)brightness

185
Source/NSColorSpace.m Normal file
View file

@ -0,0 +1,185 @@
/*
NSColorSpace.h
The color space class
Copyright (C) 2007 Free Software Foundation, Inc.
Author: H. Nikolaus Schaller <hns@computer.org>
Date: 2007
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
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/Foundation.h>
#import <AppKit/NSColorSpace.h>
@implementation NSColorSpace
- (id) _initWithColorSpaceModel: (NSColorSpaceModel)model
{
if ((self = [super init]))
{
// FIXME: Load corresponding data
_colorSpaceModel = model;
}
return self;
}
#define COLORSPACE(model) \
static NSColorSpace *csp; \
if (!csp) \
csp = [[self alloc] _initWithColorSpaceModel: model]; \
return csp;
+ (NSColorSpace *) deviceCMYKColorSpace
{
COLORSPACE(NSCMYKColorSpaceModel);
}
+ (NSColorSpace *) deviceGrayColorSpace
{
COLORSPACE(NSGrayColorSpaceModel);
}
+ (NSColorSpace *) deviceRGBColorSpace
{
COLORSPACE(NSRGBColorSpaceModel);
}
+ (NSColorSpace *) genericCMYKColorSpace
{
COLORSPACE(NSCMYKColorSpaceModel);
}
+ (NSColorSpace *) genericGrayColorSpace
{
COLORSPACE(NSGrayColorSpaceModel);
}
+ (NSColorSpace *) genericRGBColorSpace
{
COLORSPACE(NSRGBColorSpaceModel);
}
- (id) initWithColorSyncProfile: (void *)prof
{
if ((self = [super init]))
{
_colorSyncProfile = prof;
_colorSpaceModel = NSUnknownColorSpaceModel;
}
return self;
}
- (id) initWithICCProfileData: (NSData *)iccData
{
if ((self = [super init]))
{
ASSIGN(_iccData, iccData);
_colorSpaceModel = NSUnknownColorSpaceModel;
}
return self;
}
-(void) dealloc
{
// FIXME: Free _colorSyncProfile
TEST_RELEASE(_iccData);
[super dealloc];
}
- (NSColorSpaceModel) colorSpaceModel
{
return _colorSpaceModel;
}
- (void *) colorSyncProfile
{
return _colorSyncProfile;
}
- (NSData *) ICCProfileData
{
if (!_iccData)
{
// FIXME: Try to compute this from _colorSyncProfile
}
return _iccData;
}
- (NSString *) localizedName
{
switch (_colorSpaceModel)
{
default:
case NSUnknownColorSpaceModel:
return NSLocalizedString(@"unknown", @"color space");
case NSGrayColorSpaceModel:
return NSLocalizedString(@"Grayscale", @"color space");
case NSRGBColorSpaceModel:
return NSLocalizedString(@"RGB", @"color space");
case NSCMYKColorSpaceModel:
return NSLocalizedString(@"CMYK", @"color space");
case NSLABColorSpaceModel:
return NSLocalizedString(@"LAB", @"color space");
case NSDeviceNColorSpaceModel:
return NSLocalizedString(@"DeviceN", @"color space");
}
}
- (int) numberOfColorComponents
{
switch (_colorSpaceModel)
{
default:
case NSUnknownColorSpaceModel: return 0;
case NSGrayColorSpaceModel: return 1;
case NSRGBColorSpaceModel: return 3;
case NSCMYKColorSpaceModel: return 4;
case NSLABColorSpaceModel: return 3; // FIXME
case NSDeviceNColorSpaceModel: return 3; // FIXME
}
}
- (void) encodeWithCoder: (NSCoder *)coder
{
// FIXME
if ([coder allowsKeyedCoding])
{
}
else
{
}
}
- (id) initWithCoder: (NSCoder *)aDecoder
{
// FIXME
if ([aDecoder allowsKeyedCoding])
{
}
else
{
}
return self;
}
@end