diff --git a/ChangeLog b/ChangeLog index 908dd34ba..ad45d846f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-06-02 Alexander Malmberg + + Add basic color picker bundles: the wheel color picker and the + standard rgb/hsb/cmyk/gray picker. + * GNUmakefile: Add ColorPickers subproject. + * ColorPickers/: New files. + Sun May 26 13:46:58 2002 Nicola Pero * Source/NSMatrix.m diff --git a/ColorPickers/English.lproj/StandardPicker.strings b/ColorPickers/English.lproj/StandardPicker.strings new file mode 100644 index 000000000..eff6556cd --- /dev/null +++ b/ColorPickers/English.lproj/StandardPicker.strings @@ -0,0 +1,39 @@ +/*** +English.lproj/StandardPicker.strings +updated by make_strings 2002-05-23 16:24:57 +0200 +add comments above this one +***/ + + +/*** Strings from GSCMYKColorPicker.m ***/ +/* File: GSCMYKColorPicker.m:50 */ +"Black" = "Black"; +/* File: GSCMYKColorPicker.m:47 */ +"Cyan" = "Cyan"; +/* File: GSCMYKColorPicker.m:48 */ +"Magenta" = "Magenta"; +/* File: GSCMYKColorPicker.m:49 */ +"Yellow" = "Yellow"; + + +/*** Strings from GSGrayColorPicker.m ***/ +/* File: GSGrayColorPicker.m:50 */ +"White" = "White"; + + +/*** Strings from GSHSBColorPicker.m ***/ +/* File: GSHSBColorPicker.m:49 */ +"Brightness" = "Brightness"; +/* File: GSHSBColorPicker.m:47 */ +"Hue" = "Hue"; +/* File: GSHSBColorPicker.m:48 */ +"Saturation" = "Saturation"; + + +/*** Strings from GSRGBColorPicker.m ***/ +/* File: GSRGBColorPicker.m:50 */ +"Blue" = "Blue"; +/* File: GSRGBColorPicker.m:49 */ +"Green" = "Green"; +/* File: GSRGBColorPicker.m:48 */ +"Red" = "Red"; diff --git a/ColorPickers/French.lproj/StandardPicker.strings b/ColorPickers/French.lproj/StandardPicker.strings new file mode 100644 index 000000000..05f854640 --- /dev/null +++ b/ColorPickers/French.lproj/StandardPicker.strings @@ -0,0 +1,39 @@ +/*** +French.lproj/StandardPicker.strings +updated by make_strings 2002-05-23 16:24:57 +0200 +add comments above this one +***/ + + +/*** Strings from GSCMYKColorPicker.m ***/ +/* File: GSCMYKColorPicker.m:50 */ +"Black" = "Noir"; +/* File: GSCMYKColorPicker.m:47 */ +"Cyan" = "Cyan"; +/* File: GSCMYKColorPicker.m:48 */ +"Magenta" = "Magenta"; +/* File: GSCMYKColorPicker.m:49 */ +"Yellow" = "Jaune"; + + +/*** Strings from GSGrayColorPicker.m ***/ +/* File: GSGrayColorPicker.m:50 */ +"White" = "Luminosit\u00e9"; + + +/*** Strings from GSHSBColorPicker.m ***/ +/* File: GSHSBColorPicker.m:49 */ +"Brightness" = "Luminosit\u00e9"; +/* File: GSHSBColorPicker.m:47 */ +"Hue" = "Teinte"; +/* File: GSHSBColorPicker.m:48 */ +"Saturation" = "Saturation"; + + +/*** Strings from GSRGBColorPicker.m ***/ +/* File: GSRGBColorPicker.m:50 */ +"Blue" = "Bleu"; +/* File: GSRGBColorPicker.m:49 */ +"Green" = "Vert"; +/* File: GSRGBColorPicker.m:48 */ +"Red" = "Rouge"; diff --git a/ColorPickers/GNUmakefile b/ColorPickers/GNUmakefile new file mode 100644 index 000000000..dd2ae3871 --- /dev/null +++ b/ColorPickers/GNUmakefile @@ -0,0 +1,77 @@ +# +# ColorPickers makefile for GNUstep GUI +# +# Copyright (C) 2000 Free Software Foundation, Inc. +# +# Author: Fred Kiefer +# Author: Alexander Malmberg +# Date: May 2002 +# +# This file is part of the GNUstep GUI. +# +# 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. +# +# If you are interested in a warranty or support for this source code, +# contact Scott Christley at scottc@net-community.com +# +# 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, +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES = ../gui.make +include $(GNUSTEP_MAKEFILES)/common.make + +# The color picker bundle to be compiled +#BUNDLE_NAME = StandardPicker NamedPicker WheelPicker +BUNDLE_NAME = StandardPicker WheelPicker + +BUNDLE_INSTALL_DIR = $(GNUSTEP_INSTALLATION_DIR)/Library/ColorPickers + +ADDITIONAL_INCLUDE_DIRS += -I../Headers -I../Headers/gnustep + +# The Objective-C source files to be compiled +StandardPicker_OBJC_FILES = GSStandardColorPicker.m \ + GSRGBColorPicker.m \ + GSCMYKColorPicker.m \ + GSHSBColorPicker.m \ + GSGrayColorPicker.m +NamedPicker_OBJC_FILES = GSNamedColorPicker.m +WheelPicker_OBJC_FILES = GSWheelColorPicker.m + +# The class to load +StandardPicker_PRINCIPAL_CLASS = GSStandardColorPicker +NamedPicker_PRINCIPAL_CLASS = GSNamedColorPicker +WheelPicker_PRINCIPAL_CLASS = GSWheelColorPicker + +# The Resource files to be copied into the app's resources directory +StandardPicker_RESOURCE_FILES = GSRGBColorPicker.tiff \ + GSHSBColorPicker.tiff \ + GSGrayColorPicker.tiff \ + GSCMYKColorPicker.tiff +StandardPicker_LOCALIZED_RESOURCE_FILES = StandardPicker.strings +StandardPicker_LANGUAGES = English French Swedish + +NamedPicker_RESOURCE_FILES = GSNamedColorPicker.tiff +WheelPicker_RESOURCE_FILES = GSWheelColorPicker.tiff + +-include GNUmakefile.preamble + +-include GNUmakefile.local + +include $(GNUSTEP_MAKEFILES)/bundle.make + +-include GNUmakefile.postamble + diff --git a/ColorPickers/GSCMYKColorPicker.h b/ColorPickers/GSCMYKColorPicker.h new file mode 100644 index 000000000..8e86973d2 --- /dev/null +++ b/ColorPickers/GSCMYKColorPicker.h @@ -0,0 +1,44 @@ +/* GSCMYKColorPicker.h + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: Febuary 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include + +#include "GSStandardColorPicker.h" + +@interface GSCMYKColorPicker : GSStandardCSColorPicker +{ + NSString *r_names[4]; + NSSlider *r_sliders[4]; + NSTextField *r_fields[4]; + float r_values[4]; +} + +-(void) _setColorFromValues; +-(void) setColor:(NSColor *)color; + +@end + diff --git a/ColorPickers/GSCMYKColorPicker.m b/ColorPickers/GSCMYKColorPicker.m new file mode 100644 index 000000000..93ab101a5 --- /dev/null +++ b/ColorPickers/GSCMYKColorPicker.m @@ -0,0 +1,115 @@ +/* GSCMYKColorPicker.m + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: Febuary 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "GSCMYKColorPicker.h" + +@implementation GSCMYKColorPicker + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelCMYKModeMask) + { + NSBundle *b; + + self = [super initWithPickerMask: aMask + colorPanel: colorPanel]; + if (!self) + return nil; + + numFields = 4; + currentMode = NSColorPanelCMYKModeMask; + + b = [NSBundle bundleForClass: [self class]]; + r_names[0] = NSLocalizedStringFromTableInBundle(@"Cyan",@"StandardPicker",b,@""); + r_names[1] = NSLocalizedStringFromTableInBundle(@"Magenta",@"StandardPicker",b,@""); + r_names[2] = NSLocalizedStringFromTableInBundle(@"Yellow",@"StandardPicker",b,@""); + r_names[3] = NSLocalizedStringFromTableInBundle(@"Black",@"StandardPicker",b,@""); + names = r_names; + + sliders = r_sliders; + fields = r_fields; + values = r_values; + maxValue = 100; + return self; + } + RELEASE(self); + return nil; +} + +- (void)setColor:(NSColor *)color +{ + float cyan, magenta, yellow, black, alpha; + NSColor *c; + + if (updating) + return; + updating = YES; + + c = [color colorUsingColorSpaceName: NSDeviceCMYKColorSpace]; + [c getCyan: &cyan magenta: &magenta yellow: &yellow + black: &black alpha: &alpha]; + + values[0] = cyan * 100; + values[1] = magenta * 100; + values[2] = yellow * 100; + values[3] = black * 100; + [self _valuesChanged]; + + updating = NO; +} + +-(void) _setColorFromValues +{ + float cyan = values[0] / 100; + float magenta = values[1] / 100; + float yellow = values[2] / 100; + float black = values[3] / 100; + float alpha = [_colorPanel alpha]; + NSColor *c = [NSColor colorWithDeviceCyan: cyan + magenta: magenta + yellow: yellow + black: black + alpha: alpha]; + [_colorPanel setColor: c]; +} + + +- (void) loadViews +{ + [super loadViews]; + [sliders[0] setMaxValue: 100]; + [sliders[1] setMaxValue: 100]; + [sliders[2] setMaxValue: 100]; + [sliders[3] setMaxValue: 100]; + [(GSColorSliderCell *)[sliders[0] cell] _setColorSliderCellMode: 4]; + [(GSColorSliderCell *)[sliders[1] cell] _setColorSliderCellMode: 5]; + [(GSColorSliderCell *)[sliders[2] cell] _setColorSliderCellMode: 6]; + [(GSColorSliderCell *)[sliders[3] cell] _setColorSliderCellMode: 7]; +} + +@end + diff --git a/ColorPickers/GSCMYKColorPicker.tiff b/ColorPickers/GSCMYKColorPicker.tiff new file mode 100644 index 000000000..55e326cd9 Binary files /dev/null and b/ColorPickers/GSCMYKColorPicker.tiff differ diff --git a/ColorPickers/GSGrayColorPicker.h b/ColorPickers/GSGrayColorPicker.h new file mode 100644 index 000000000..2f449c2c0 --- /dev/null +++ b/ColorPickers/GSGrayColorPicker.h @@ -0,0 +1,44 @@ +/* GSGrayColorPicker.h + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: January 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include + +#include "GSStandardColorPicker.h" + +@interface GSGrayColorPicker : GSStandardCSColorPicker +{ + NSString *r_names[1]; + NSSlider *r_sliders[1]; + NSTextField *r_fields[1]; + float r_values[1]; +} + +-(void) _setColorFromValues; +-(void) setColor:(NSColor *)color; + +@end + diff --git a/ColorPickers/GSGrayColorPicker.m b/ColorPickers/GSGrayColorPicker.m new file mode 100644 index 000000000..d17ccd094 --- /dev/null +++ b/ColorPickers/GSGrayColorPicker.m @@ -0,0 +1,129 @@ +/* GSGrayColorPicker.m + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: January 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "GSGrayColorPicker.h" + +#include + +@implementation GSGrayColorPicker + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelGrayModeMask) + { + NSBundle *b; + + self = [super initWithPickerMask: aMask + colorPanel: colorPanel]; + if (!self) + return nil; + + numFields = 1; + currentMode = NSColorPanelGrayModeMask; + maxValue = 100; + + b = [NSBundle bundleForClass: [self class]]; + r_names[0] = NSLocalizedStringFromTableInBundle(@"White",@"StandardPicker",b,@""); + names = r_names; + + sliders = r_sliders; + fields = r_fields; + values = r_values; + return self; + } + RELEASE(self); + return nil; +} + +- (void)setColor:(NSColor *)color +{ + float white, alpha; + NSColor *c; + + if (updating) + return; + updating = YES; + + c = [color colorUsingColorSpaceName: NSCalibratedWhiteColorSpace]; + [c getWhite: &white alpha: &alpha]; + + values[0] = white * 100; + [self _valuesChanged]; + + updating = NO; +} + +-(void) _setColorFromValues +{ + float white = values[0] / 100; + float alpha = [_colorPanel alpha]; + NSColor *c = [NSColor colorWithCalibratedWhite: white + alpha: alpha]; + [_colorPanel setColor: c]; +} + + +- (void) loadViews +{ + int i; + GSHbox *hb; + NSColorWell *well; + + [super loadViews]; + [sliders[0] setMaxValue: 100]; + [(GSColorSliderCell *)[sliders[0] cell] _setColorSliderCellMode: 0]; + + hb = [[GSHbox alloc] init]; + [hb setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; + + for (i = 0; i < 7; i++) + { + well = [[NSColorWell alloc] initWithFrame: NSMakeRect(0, 0, 20, 20)]; + [well setColor: [NSColor colorWithCalibratedWhite: (i / 6.0) alpha: 1.0]]; + [well setBordered: NO]; + //[well setTarget: self]; + //[well setAction: @selector(takeColor:)]; + [hb addView: well enablingXResizing: NO]; + RELEASE(well); + } + + [baseView putView: hb + atRow: 0 + column: 0 + withXMargins: 0 + yMargins: 4]; + DESTROY(hb); +} + + +- (void) takeColor: (id) sender +{ + [self setColor: [sender color]]; +} + +@end + diff --git a/ColorPickers/GSGrayColorPicker.tiff b/ColorPickers/GSGrayColorPicker.tiff new file mode 100644 index 000000000..b04ccf807 Binary files /dev/null and b/ColorPickers/GSGrayColorPicker.tiff differ diff --git a/ColorPickers/GSHSBColorPicker.h b/ColorPickers/GSHSBColorPicker.h new file mode 100644 index 000000000..33e53b161 --- /dev/null +++ b/ColorPickers/GSHSBColorPicker.h @@ -0,0 +1,44 @@ +/* GSHSBColorPicker.h + + Copyright (C) 2000 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: December 2000 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include + +#include "GSStandardColorPicker.h" + +@interface GSHSBColorPicker : GSStandardCSColorPicker +{ + NSString *r_names[3]; + NSSlider *r_sliders[3]; + NSTextField *r_fields[3]; + float r_values[3]; +} + +-(void) _setColorFromValues; +-(void) setColor:(NSColor *)color; + +@end + diff --git a/ColorPickers/GSHSBColorPicker.m b/ColorPickers/GSHSBColorPicker.m new file mode 100644 index 000000000..dd36ccf6d --- /dev/null +++ b/ColorPickers/GSHSBColorPicker.m @@ -0,0 +1,127 @@ +/* GSHSBColorPicker.m + + Copyright (C) 2000 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: December 2000 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "GSHSBColorPicker.h" + +@implementation GSHSBColorPicker + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelHSBModeMask) + { + NSBundle *b; + + self = [super initWithPickerMask: aMask + colorPanel: colorPanel]; + if (!self) + return nil; + + numFields = 3; + currentMode = NSColorPanelHSBModeMask; + + b = [NSBundle bundleForClass: [self class]]; + r_names[0] = NSLocalizedStringFromTableInBundle(@"Hue",@"StandardPicker",b,@""); + r_names[1] = NSLocalizedStringFromTableInBundle(@"Saturation",@"StandardPicker",b,@""); + r_names[2] = NSLocalizedStringFromTableInBundle(@"Brightness",@"StandardPicker",b,@""); + names = r_names; + + sliders = r_sliders; + fields = r_fields; + values = r_values; + return self; + } + RELEASE(self); + return nil; +} + +- (void)setColor:(NSColor *)color +{ + float hue, saturation, brightness, alpha; + NSColor *c; + + if (updating) + return; + updating = YES; + + c = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; + [c getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha]; + + values[0] = hue * 360; + values[1] = saturation * 100; + values[2] = brightness * 100; + [self _valuesChanged]; + + [(GSColorSliderCell *)[sliders[0] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [(GSColorSliderCell *)[sliders[1] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [(GSColorSliderCell *)[sliders[2] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [sliders[0] setNeedsDisplay: YES]; + [sliders[1] setNeedsDisplay: YES]; + [sliders[2] setNeedsDisplay: YES]; + + updating = NO; +} + +-(void) _setColorFromValues +{ + float hue = values[0] / 360; + float saturation = values[1] / 100; + float brightness = values[2] / 100; + float alpha = [_colorPanel alpha]; + NSColor *c = [NSColor colorWithCalibratedHue: hue + saturation: saturation + brightness: brightness + alpha: alpha]; + [_colorPanel setColor: c]; + + [(GSColorSliderCell *)[sliders[0] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [(GSColorSliderCell *)[sliders[1] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [(GSColorSliderCell *)[sliders[2] cell] + _setColorSliderCellValues: hue : saturation : brightness]; + [sliders[0] setNeedsDisplay: YES]; + [sliders[1] setNeedsDisplay: YES]; + [sliders[2] setNeedsDisplay: YES]; +} + + +- (void) loadViews +{ + [super loadViews]; + [sliders[0] setMaxValue: 360]; + [sliders[1] setMaxValue: 100]; + [sliders[2] setMaxValue: 100]; + [(GSColorSliderCell *)[sliders[0] cell] _setColorSliderCellMode: 8]; + [(GSColorSliderCell *)[sliders[1] cell] _setColorSliderCellMode: 9]; + [(GSColorSliderCell *)[sliders[2] cell] _setColorSliderCellMode: 10]; +} + +@end + diff --git a/ColorPickers/GSHSBColorPicker.tiff b/ColorPickers/GSHSBColorPicker.tiff new file mode 100644 index 000000000..9c2a0408f Binary files /dev/null and b/ColorPickers/GSHSBColorPicker.tiff differ diff --git a/ColorPickers/GSNamedColorPicker.m b/ColorPickers/GSNamedColorPicker.m new file mode 100644 index 000000000..0ac27b47f --- /dev/null +++ b/ColorPickers/GSNamedColorPicker.m @@ -0,0 +1,215 @@ +/* GSNamedColorPicker.m + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: January 2001 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include + +@interface GSNamedColorPicker: NSColorPicker +{ + NSView *baseView; + NSComboBox *cb; + NSBrowser *browser; + NSColorList *currentList; + NSArray *lists; +} + +- (void) loadViews; +- (void) listSelected: (int)index; +- (void) colorSelected: (int)index; + +@end + +@implementation GSNamedColorPicker + +- (void) dealloc +{ + RELEASE(cb); + RELEASE(browser); + RELEASE(baseView); + RELEASE(lists); + [super dealloc]; +} + +- (void) finishInstantiate +{ +} + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelColorListModeMask) + { + ASSIGN(lists, [NSColorList availableColorLists]); + return [super initWithPickerMask: aMask + colorPanel: colorPanel]; + } + RELEASE(self); + return nil; +} + +- (int)currentMode +{ + return NSColorListModeColorPanel; +} + +- (BOOL)supportsMode:(int)mode +{ + return mode == NSColorListModeColorPanel; +} + +- (NSView *)provideNewView:(BOOL)initialRequest +{ + if (initialRequest) + { + [self loadViews]; + } + return baseView; +} + +- (void)setColor:(NSColor *)color +{ + NSColor *c = [color colorUsingColorSpaceName: NSNamedColorSpace]; + NSString *list; + NSString *name; + + if (c == nil) + return; + + list = [c catalogNameComponent]; + name = [c colorNameComponent]; +} + +- (void) loadViews +{ + baseView = [[NSView alloc] initWithFrame: NSMakeRect(0, 0, 200, 110)]; + [baseView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; + + cb = [[NSComboBox alloc] initWithFrame: NSMakeRect(0, 85, 196, 20)]; + [cb setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)]; + [cb setUsesDataSource: YES]; + [cb setDataSource: self]; + [cb setDelegate: self]; + [cb setEditable: NO]; + [baseView addSubview: cb]; + + browser = [[NSBrowser alloc] initWithFrame: NSMakeRect(0, 5, 196, 75)]; + [browser setDelegate: self]; + [browser setMaxVisibleColumns: 1]; + [browser setAllowsMultipleSelection: NO]; + [browser setAllowsEmptySelection: NO]; + [browser setHasHorizontalScroller: NO]; + [browser setTitled: NO]; + [browser setTakesTitleFromPreviousColumn: NO]; + [browser setPath: @"/"]; + [browser setTarget: self]; + [browser setDoubleAction: @selector(colorSelected:)]; + [browser setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; + [baseView addSubview: browser]; +} + +- (void) listSelected: (int)index +{ + currentList = [lists objectAtIndex: index]; + [browser validateVisibleColumns]; +} + +- (void) colorSelected: (int)index +{ +} + +-(NSString *)browser: (NSBrowser *)sender + titleOfColumn: (int)column +{ + return nil; +} + +-(void)browser: (NSBrowser *)sender +createRowsForColumn: (int)column + inMatrix: (NSMatrix *)matrix +{ + int i; + int count; + NSBrowserCell *cell; + NSColor *cl; + NSArray *keys = [currentList allKeys]; + NSString *name; + + count = [keys count]; + NSLog(@"In create with %@ %d", currentList, count); + + if (count) + { + [matrix addColumn]; + for (i = 0; i < count; i++) + { + if (i > 0) + [matrix addRow]; + name = [keys objectAtIndex: i]; + cl = [currentList colorWithKey: name]; + cell = [matrix cellAtRow: i + column: 0]; + [cell setStringValue: name]; + [cell setRepresentedObject: cl]; + [cell setLeaf: YES]; + } + } +} + +- (BOOL) browser: (NSBrowser*)sender + selectRow: (int)row + inColumn: (int)column +{ +} + +- (void)browser: (NSBrowser *)sender +willDisplayCell: (id)cell + atRow: (int)row + column: (int)column +{ +} + +- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox +{ + return [lists count]; +} + +- (id)comboBox:(NSComboBox *)aComboBox +objectValueForItemAtIndex:(int)index +{ + return [(NSColorList*)[lists objectAtIndex: index] name]; +} + +- (unsigned int)comboBox:(NSComboBox *)aComboBox + indexOfItemWithStringValue:(NSString *)string +{ + return [lists indexOfObject: [NSColorList colorListNamed: string]]; +} + +- (void)comboBoxSelectionDidChange:(NSNotification *)notification +{ + NSLog(@"Selection changed"); + [self listSelected: [cb indexOfSelectedItem]]; +} + +@end diff --git a/ColorPickers/GSNamedColorPicker.tiff b/ColorPickers/GSNamedColorPicker.tiff new file mode 100644 index 000000000..18a5cfa6c Binary files /dev/null and b/ColorPickers/GSNamedColorPicker.tiff differ diff --git a/ColorPickers/GSRGBColorPicker.h b/ColorPickers/GSRGBColorPicker.h new file mode 100644 index 000000000..7985b2a22 --- /dev/null +++ b/ColorPickers/GSRGBColorPicker.h @@ -0,0 +1,43 @@ +/* GSRGBColorPicker.h + + Copyright (C) 2000 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: December 2000 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include +#include + +#include "GSStandardColorPicker.h" + +@interface GSRGBColorPicker : GSStandardCSColorPicker +{ + NSString *r_names[3]; + NSSlider *r_sliders[3]; + NSTextField *r_fields[3]; + float r_values[3]; +} + +-(void) _setColorFromValues; +-(void) setColor:(NSColor *)color; + +@end + diff --git a/ColorPickers/GSRGBColorPicker.m b/ColorPickers/GSRGBColorPicker.m new file mode 100644 index 000000000..5f52a8eba --- /dev/null +++ b/ColorPickers/GSRGBColorPicker.m @@ -0,0 +1,108 @@ +/* GSRGBColorPicker.m + + Copyright (C) 2000 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: December 2000 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "GSRGBColorPicker.h" + +@implementation GSRGBColorPicker + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelRGBModeMask) + { + NSBundle *b; + self = [super initWithPickerMask: aMask + colorPanel: colorPanel]; + if (!self) + return nil; + + b = [NSBundle bundleForClass: [self class]]; + + numFields = 3; + currentMode = NSColorPanelRGBModeMask; + maxValue = 255; + + r_names[0] = NSLocalizedStringFromTableInBundle(@"Red",@"StandardPicker",b,@""); + r_names[1] = NSLocalizedStringFromTableInBundle(@"Green",@"StandardPicker",b,@""); + r_names[2] = NSLocalizedStringFromTableInBundle(@"Blue",@"StandardPicker",b,@""); + names = r_names; + + sliders = r_sliders; + fields = r_fields; + values = r_values; + return self; + } + RELEASE(self); + return nil; +} + +- (void)setColor:(NSColor *)color +{ + float red, green, blue, alpha; + NSColor *c; + + if (updating) + return; + updating = YES; + + c = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; + [c getRed: &red green: &green blue: &blue alpha: &alpha]; + + values[0] = red * 255; + values[1] = green * 255; + values[2] = blue * 255; + [self _valuesChanged]; + + updating = NO; +} + +-(void) _setColorFromValues +{ + float red = values[0] / 255; + float green = values[1] / 255; + float blue = values[2] / 255; + float alpha = [_colorPanel alpha]; + NSColor *c = [NSColor colorWithCalibratedRed: red + green: green + blue: blue + alpha: alpha]; + [_colorPanel setColor: c]; +} + + +- (void) loadViews +{ + [super loadViews]; + [sliders[0] setMaxValue: 255]; + [sliders[1] setMaxValue: 255]; + [sliders[2] setMaxValue: 255]; + [(GSColorSliderCell *)[sliders[0] cell] _setColorSliderCellMode: 1]; + [(GSColorSliderCell *)[sliders[1] cell] _setColorSliderCellMode: 2]; + [(GSColorSliderCell *)[sliders[2] cell] _setColorSliderCellMode: 3]; +} + +@end + diff --git a/ColorPickers/GSRGBColorPicker.tiff b/ColorPickers/GSRGBColorPicker.tiff new file mode 100644 index 000000000..2e4a5dc48 Binary files /dev/null and b/ColorPickers/GSRGBColorPicker.tiff differ diff --git a/ColorPickers/GSStandardColorPicker.h b/ColorPickers/GSStandardColorPicker.h new file mode 100644 index 000000000..69f5ba448 --- /dev/null +++ b/ColorPickers/GSStandardColorPicker.h @@ -0,0 +1,70 @@ +/* GSStandardColorPicker.h + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: Febuary 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef GSStandardColorPicker_h +#define GSStandardColorPicker_h + +@class GSTable,NSSlider,NSTextField; + +@interface GSStandardCSColorPicker: NSColorPicker +{ + GSTable *baseView;; + + int numFields; + int currentMode; + + NSString **names; + NSSlider **sliders; + NSTextField **fields; + float *values; + int maxValue; + + BOOL updating; +} + +- (void) sliderChanged: (id) sender; +- (void) loadViews; + + +-(void) _valuesChanged; + +/* subclasses should implement these and -init... */ +-(void) _setColorFromValues; +-(void) setColor:(NSColor *)color; + +@end + +@interface GSColorSliderCell : NSSliderCell +{ + int mode; + float values[3]; +} +-(void) _setColorSliderCellMode: (int)m; +-(void) _setColorSliderCellValues: (float)a : (float)b : (float)c; +@end + +#endif + diff --git a/ColorPickers/GSStandardColorPicker.m b/ColorPickers/GSStandardColorPicker.m new file mode 100644 index 000000000..58ac32a7c --- /dev/null +++ b/ColorPickers/GSStandardColorPicker.m @@ -0,0 +1,628 @@ +/* GSStandardColorPicker.m + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Fred Kiefer + Date: Febuary 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include +#include +#include "GSRGBColorPicker.h" +#include "GSHSBColorPicker.h" +#include "GSCMYKColorPicker.h" +#include "GSGrayColorPicker.h" + +@interface GSStandardColorPicker: NSColorPicker +{ + GSTable *baseView; + NSBox *pickerBox; + NSButtonCell *imageCell; + NSMatrix *pickerMatrix; + NSMutableArray *pickers; + id currentPicker; +} + +- (void) loadViews; +- (void) _showNewPicker: (id) sender; + +@end + +@implementation GSStandardColorPicker + +- (void) dealloc +{ + RELEASE(pickers); + RELEASE(pickerBox); + RELEASE(pickerMatrix); + RELEASE(baseView); + [super dealloc]; +} + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & (NSColorPanelRGBModeMask | NSColorPanelHSBModeMask | + NSColorPanelCMYKModeMask | NSColorPanelGrayModeMask)) + { + NSColorPicker *picker; + + pickers = [[NSMutableArray alloc] init]; + picker = [[GSGrayColorPicker alloc] initWithPickerMask: aMask + colorPanel: colorPanel]; + if (picker != nil) + { + [pickers addObject: picker]; + RELEASE(picker); + } + picker = [[GSRGBColorPicker alloc] initWithPickerMask: aMask + colorPanel: colorPanel]; + if (picker != nil) + { + [pickers addObject: picker]; + RELEASE(picker); + } + picker = [[GSCMYKColorPicker alloc] initWithPickerMask: aMask + colorPanel: colorPanel]; + if (picker != nil) + { + [pickers addObject: picker]; + RELEASE(picker); + } + picker = [[GSHSBColorPicker alloc] initWithPickerMask: aMask + colorPanel: colorPanel]; + if (picker != nil) + { + [pickers addObject: picker]; + RELEASE(picker); + } + + currentPicker = [pickers lastObject]; + return [super initWithPickerMask: aMask + colorPanel: colorPanel]; + } + RELEASE(self); + return nil; +} + +- (int)currentMode +{ + return [currentPicker currentMode]; +} + +- (void)setMode:(int)mode +{ + int i, count; + + if (mode == [self currentMode]) + return; + + count = [pickers count]; + for (i = 0; i < count; i++) + { + if ([[pickers objectAtIndex: i] supportsMode: mode]) + { + [pickerMatrix selectCellWithTag: i]; + [self _showNewPicker: pickerMatrix]; + [currentPicker setMode: mode]; + break; + } + } +} + +- (BOOL)supportsMode:(int)mode +{ + return ((mode == NSGrayModeColorPanel) || + (mode == NSRGBModeColorPanel) || + (mode == NSCMYKModeColorPanel) || + (mode == NSHSBModeColorPanel)); +} + +- (void)insertNewButtonImage:(NSImage *)newImage + in:(NSButtonCell *)newButtonCell +{ + // Store the image button cell + imageCell = newButtonCell; + [super insertNewButtonImage: newImage + in: newButtonCell]; +} + +- (NSView *)provideNewView:(BOOL)initialRequest +{ + if (initialRequest) + { + [self loadViews]; + } + return baseView; +} + +- (NSImage *)provideNewButtonImage +{ + return [currentPicker provideNewButtonImage]; +} + +- (void)setColor:(NSColor *)color +{ + [currentPicker setColor: color]; +} + +- (void) loadViews +{ + NSEnumerator *enumerator; + id picker; + NSButtonCell *cell; + NSMutableArray *cells = [NSMutableArray new]; + int i, count; + + // Initaliase all the sub pickers + enumerator = [pickers objectEnumerator]; + + while ((picker = [enumerator nextObject]) != nil) + [picker provideNewView: YES]; + + baseView = [[GSTable alloc] initWithNumberOfRows: 3 numberOfColumns: 1]; + [baseView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [baseView setYResizingEnabled: NO forRow: 1]; + [baseView setYResizingEnabled: NO forRow: 2]; + + // Prototype cell for the matrix + cell = [[NSButtonCell alloc] initImageCell: nil]; + [cell setButtonType: NSOnOffButton]; + [cell setBordered: YES]; + + pickerMatrix = [[NSMatrix alloc] initWithFrame: NSMakeRect(0,0,0,0) + mode: NSRadioModeMatrix + prototype: cell + numberOfRows: 0 + numberOfColumns: 0]; + RELEASE(cell); + [pickerMatrix setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; + [pickerMatrix setIntercellSpacing: NSMakeSize(1, 0)]; + [pickerMatrix setAutosizesCells: YES]; + + count = [pickers count]; + for (i = 0; i < count; i++) + { + cell = [[pickerMatrix prototype] copy]; + [cell setTag: i]; + picker = [pickers objectAtIndex: i]; + [picker insertNewButtonImage: [picker provideNewButtonImage] in: cell]; + [cells addObject: cell]; + RELEASE(cell); + } + + [pickerMatrix addRowWithCells: cells]; + [pickerMatrix setCellSize: NSMakeSize(1, 36)]; + [pickerMatrix setTarget: self]; + [pickerMatrix setAction: @selector(_showNewPicker:)]; + + pickerBox = [[NSBox alloc] init]; + [pickerBox setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [baseView putView: pickerBox + atRow: 0 + column: 0 + withMargins: 0]; + [pickerBox setTitlePosition: NSNoTitle]; + [pickerBox setBorderType: NSNoBorder]; + [pickerBox setContentView: [currentPicker provideNewView: NO]]; + + [baseView putView: pickerMatrix + atRow: 1 + column: 0 + withMargins: 0]; + + { + NSBox *b = [[NSBox alloc] initWithFrame: NSMakeRect(0,0,0,2)]; + [b setAutoresizingMask: NSViewWidthSizable]; + [b setTitlePosition: NSNoTitle]; + [b setBorderType: NSGrooveBorder]; + [baseView putView: b + atRow: 2 + column: 0 + withMinXMargin: 0 + maxXMargin: 0 + minYMargin: 4 + maxYMargin: 0]; + DESTROY(b); + } +} + +- (void) _showNewPicker: (id) sender +{ + NSView *currentView = [currentPicker provideNewView: NO]; + + //NSLog(@"Old View size %@", NSStringFromRect([currentView frame])); + currentPicker = [pickers objectAtIndex: [sender selectedColumn]]; + [currentPicker setColor: [_colorPanel color]]; + //NSLog(@"Base View size %@", NSStringFromRect([baseView frame])); +/* [baseView putView: [currentPicker provideNewView: NO] + atRow: 0 + column: 0 + withMargins: 0];*/ + [pickerBox setContentView: [currentPicker provideNewView: NO]]; + currentView = [currentPicker provideNewView: NO]; + + //NSLog(@"New View size %@", NSStringFromRect([currentView frame])); + // Show the new image + [imageCell setImage: [[sender selectedCell] image]]; +} + +@end + + +#include "GSStandardColorPicker.h" + + +#include +#include + + +#define KNOB_WIDTH 6 + +@implementation GSColorSliderCell : NSSliderCell + +-(void) _setColorSliderCellMode: (int)m +{ + mode = m; + switch (mode) + { + case 0: + case 1: + case 2: + case 3: + case 10: + [_titleCell setTextColor: [NSColor whiteColor]]; + break; + case 4: + case 5: + case 6: + case 7: + [_titleCell setTextColor: [NSColor blackColor]]; + break; + } + [_titleCell setAlignment: NSLeftTextAlignment]; +} + +-(void) _setColorSliderCellValues: (float)a : (float)b : (float)c +{ + values[0] = a; + values[1] = b; + values[2] = c; + if (mode == 8 || mode == 9) + { + if (c>0.7) + [_titleCell setTextColor: [NSColor blackColor]]; + else + [_titleCell setTextColor: [NSColor whiteColor]]; + } +} + +- (NSRect) knobRectFlipped: (BOOL)flipped +{ + NSPoint origin; + float floatValue = [self floatValue]; + + if (_isVertical && flipped) + { + floatValue = _maxValue + _minValue - floatValue; + } + + floatValue = (floatValue - _minValue) / (_maxValue - _minValue); + + origin = _trackRect.origin; + if (_isVertical == YES) + { + origin.y += (_trackRect.size.height - KNOB_WIDTH) * floatValue; + return NSMakeRect (origin.x, origin.y, _trackRect.size.width, KNOB_WIDTH); + } + else + { + origin.x += (_trackRect.size.width - KNOB_WIDTH) * floatValue; + return NSMakeRect (origin.x, origin.y, KNOB_WIDTH, _trackRect.size.height); + } +} + +- (void) drawKnob: (NSRect)knobRect +{ + [[NSColor blackColor] set]; + NSDrawButton(knobRect, knobRect); +} + +-(void) drawBarInside: (NSRect)r flipped: (BOOL)flipped +{ + float i, f; + for (i = r.origin.x; i < r.origin.x + r.size.width; i += 1) + { + f = (0.5 + i) / r.size.width; + switch (mode) + { + case 0: PSsetgray(f); break; + + case 1: PSsetrgbcolor(f, 0, 0); break; + case 2: PSsetrgbcolor(0, f, 0); break; + case 3: PSsetrgbcolor(0, 0, f); break; + + case 4: PSsetcmykcolor(f, 0, 0, 0); break; + case 5: PSsetcmykcolor(0, f, 0, 0); break; + case 6: PSsetcmykcolor(0, 0, f, 0); break; + case 7: PSsetcmykcolor(0, 0, 0, f); break; + + case 8: PSsethsbcolor(f, values[1], values[2]); break; + case 9: PSsethsbcolor(values[0], f, values[2]); break; + case 10: PSsethsbcolor(values[0], values[1], f); break; + } + if (i + 1 < r.origin.x + r.size.width) + PSrectfill(i, r.origin.y, 1, r.size.height); + else + PSrectfill(i, r.origin.y, r.size.width - i, r.size.height); + } + + if (_isVertical == NO) + { + [_titleCell drawInteriorWithFrame: r inView: _control_view]; + } +} + +-(void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView +{ + _isVertical = (cellFrame.size.height > cellFrame.size.width); + cellFrame = [self drawingRectForBounds: cellFrame]; + + cellFrame.origin.x -= 1; + cellFrame.origin.y -= 1; + cellFrame.size.width += 2; + cellFrame.size.height += 2; + + [controlView lockFocus]; + + _trackRect = cellFrame; + + [self drawBarInside: cellFrame flipped: [controlView isFlipped]]; + + [self drawKnob]; + [controlView unlockFocus]; +} + +- (float) knobThickness +{ + return KNOB_WIDTH; +} + +@end + + +@implementation GSStandardCSColorPicker + +- (void) dealloc +{ + int i; + for (i = 0; i < numFields; i++) + { + RELEASE(sliders[i]); + RELEASE(fields[i]); + } + RELEASE(baseView); + [super dealloc]; +} + +- (int)currentMode +{ + return currentMode; +} + +- (BOOL)supportsMode:(int)mode +{ + return currentMode == NSRGBModeColorPanel; +} + +- (NSView *)provideNewView:(BOOL)initialRequest +{ + if (initialRequest) + { + [self loadViews]; + } + return baseView; +} + +- (void)setColor:(NSColor *)color +{ + [self subclassResponsibility: _cmd]; +} + +- (void) loadViews +{ + int i; + + baseView = [[GSTable alloc] initWithNumberOfRows: numFields + 2 numberOfColumns: 2]; + /* keep a single resizable but empty row at the bottom so it sucks up any + extra space in the box that contains us */ + for (i = 1; i < numFields + 2; i++) + [baseView setYResizingEnabled: NO forRow: i]; + [baseView setXResizingEnabled: YES forColumn: 0]; + [baseView setXResizingEnabled: NO forColumn: 1]; + [baseView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; + + for (i = 0; i < numFields; i++) + { + NSSlider *s; + s = sliders[i] = [[NSSlider alloc] initWithFrame: NSMakeRect(0, 0, 0, 16)]; + [s setCell: [[GSColorSliderCell alloc] init]]; + [s setContinuous: YES]; + [s setMinValue: 0.0]; + [s setTitle: names[i]]; + [s setTarget: self]; + [s setAction: @selector(sliderChanged:)]; + + [[s cell] setBezeled: YES]; + [s setAutoresizingMask: NSViewWidthSizable]; + + [baseView putView: s + atRow: numFields - i + column: 0 + withMinXMargin: 0 + maxXMargin: 0 + minYMargin: 0 + maxYMargin: i?6:2]; + } + + if (maxValue) + { + NSTextField *tv; + GSHbox *hb=[[GSHbox alloc] init]; + + tv=[[NSTextField alloc] init]; + [tv setStringValue: @"0"]; + [tv setEditable: 0]; + [tv setFont: [NSFont userFontOfSize: 10.0]]; + [tv setTextColor: [NSColor darkGrayColor]]; + [tv setDrawsBackground: NO]; + [tv setBordered: NO]; + [tv setSelectable: NO]; + [tv setBezeled: NO]; + [tv sizeToFit]; + [tv setAutoresizingMask: NSViewMaxXMargin]; + [hb addView: tv]; + DESTROY(tv); + + tv=[[NSTextField alloc] init]; + [tv setIntValue: maxValue]; + [tv setEditable: 0]; + [tv setFont: [NSFont userFontOfSize: 10.0]]; + [tv setTextColor: [NSColor darkGrayColor]]; + [tv setDrawsBackground: NO]; + [tv setBordered: NO]; + [tv setSelectable: NO]; + [tv setBezeled: NO]; + [tv sizeToFit]; + [tv setAutoresizingMask: NSViewMinXMargin]; + [hb addView: tv]; + DESTROY(tv); + + [hb setAutoresizingMask: NSViewWidthSizable]; + [baseView putView: hb + atRow: numFields + 1 + column: 0 + withMargins: 0]; + DESTROY(hb); + } + else + { + NSTextField *tv; + NSView *v; + NSRect frame; + + tv=[[NSTextField alloc] init]; + [tv setStringValue: @"0"]; + [tv setEditable: 0]; + [tv setFont: [NSFont userFontOfSize: 10.0]]; + [tv setTextColor: [NSColor darkGrayColor]]; + [tv setDrawsBackground: NO]; + [tv setBordered: NO]; + [tv setSelectable: NO]; + [tv setBezeled: NO]; + [tv sizeToFit]; + frame=[tv frame]; + DESTROY(tv); + v = [[NSView alloc] initWithFrame: frame]; + [baseView putView: v + atRow: numFields + 1 + column: 0 + withMargins: 0]; + DESTROY(v); + } + + for (i = 0; i < numFields; i++) + { + NSTextField *f; + f = fields[i] = [[NSTextField alloc] init]; + [f setStringValue: @"255"]; /* just to get a good size */ + [f setFont: [NSFont userFontOfSize: 10.0]]; + [f sizeToFit]; + [f setFrameSize: NSMakeSize([f frame].size.width * 1.5, [f frame].size.height)]; + [f setDelegate: self]; + [baseView putView: f + atRow: numFields - i + column: 1 + withMinXMargin: 3 + maxXMargin: 0 + minYMargin: 0 + maxYMargin: 0]; + } +} + +- (void) sliderChanged: (id) sender +{ + int i; + + if (updating) + return; + updating = YES; + + for (i = 0; i + Date: Febuary 2001 + Author: Alexander Malmberg + Date: May 2002 + + This file is part of GNUstep. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include + +#ifndef PI +#define PI 3.141592653589793 +#endif + +#include +#include +#include + + +@interface GSColorWheel : NSView +{ + float hue, saturation, brightness; + + id target; + SEL action; +} + +-(float) hue; +-(float) saturation; + +-(void) setHue: (float)h saturation: (float)s brightness: (float)brightness; + +-(void) setTarget: (id)t; +-(void) setAction: (SEL)a; + +@end + +@implementation GSColorWheel + +-(void) setTarget: (id)t +{ + target = t; +} +-(void) setAction: (SEL)a +{ + action = a; +} + +-(float) hue +{ + return hue; +} +-(float) saturation +{ + return saturation; +} + +-(void) setHue: (float)h saturation: (float)s brightness: (float)b +{ + if (hue == h && saturation == s && brightness == b) + return; + hue = h; + saturation = s; + brightness = b; + [self setNeedsDisplay: YES]; +} + +-(BOOL) isOpaque +{ + return YES; +} + +-(void) drawRect: (NSRect)rect +{ + NSRect frame = [self bounds]; + float cx, cy, cr; + float x, y; + float r, a; + float dx, dy; + + cx = (frame.origin.x + frame.size.width) / 2; + cy = (frame.origin.y + frame.size.height) / 2; + + cr = frame.size.width; + if (cr > frame.size.height) + cr = frame.size.height; + + cr = cr / 2 - 2; + + rect.origin.x = floor(rect.origin.x); + rect.origin.y = floor(rect.origin.y); + rect.size.width = ceil(rect.size.width) + 1; + rect.size.height = ceil(rect.size.height) + 1; + + [[NSColor windowBackgroundColor] set]; + NSRectFill(rect); + + for (y = rect.origin.y; y < rect.origin.y + rect.size.height; y++) + { + for (x = rect.origin.x; x < rect.origin.x + rect.size.width; x++) + { + dx = x - cx; + dy = y - cy; + + r = dx * dx + dy * dy; + r = sqrt(r); + r /= cr; + if (r > 1) + continue; + + a = atan2(dy, dx); + a = a / 2.0 / PI; + if (a < 0) + a += 1; + + PSsethsbcolor(a, r, brightness); + PSrectfill(x,y,1,1); + } + } + + a = hue * 2 * PI; + r = saturation * cr; + + x = cos(a) * r + cx; + y = sin(a) * r + cy; + + PSsetgray(0); + PSrectstroke(x - 2, y - 2, 4, 4); + PSsetgray(1); + PSrectfill(x - 1, y - 1, 2, 2); +} + + +- (void) mouseDown: (NSEvent *)theEvent +{ + NSApplication *app = [NSApplication sharedApplication]; + unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask + | NSLeftMouseDraggedMask | NSMouseMovedMask + | NSPeriodicMask; + NSPoint point = [self convertPoint: [theEvent locationInWindow] + fromView: nil]; + NSEventType eventType = [theEvent type]; + NSDate *distantFuture = [NSDate distantFuture]; + + float new_hue, new_saturation; + float old_x, old_y; + + NSRect frame = [self bounds]; + float cx, cy, cr; + float dx, dy; + cx = (frame.origin.x + frame.size.width) / 2; + cy = (frame.origin.y + frame.size.height) / 2; + cr = frame.size.width; + if (cr > frame.size.height) + cr = frame.size.height; + cr = cr / 2 - 2; + + + [NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05]; + [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode]; + + new_hue = hue; + new_saturation = saturation; + + do + { + if (eventType != NSPeriodic) + { + point = [self convertPoint: [theEvent locationInWindow] + fromView: nil]; + + dx = point.x - cx; + dy = point.y - cy; + + new_saturation = dx * dx + dy * dy; + new_saturation = sqrt(new_saturation); + new_saturation /= cr; + if (new_saturation > 1) + new_saturation = 1; + + new_hue = atan2(dy, dx); + new_hue = new_hue / 2.0 / PI; + if (new_hue < 0) + new_hue += 1; + } + else + { + if (new_hue != hue || new_saturation != saturation) + { + old_x = cos(hue * 2 * PI) * saturation * cr + cx; + old_y = sin(hue * 2 * PI) * saturation * cr + cy; + + hue = new_hue; + saturation = new_saturation; + + [self lockFocus]; + [self drawRect: NSMakeRect(old_x - 3, old_y - 3, 6, 6)]; + [self drawRect: NSMakeRect(point.x - 3, point.y - 3, 6, 6)]; + [self unlockFocus]; + [_window flushWindow]; + + if (target) + [target performSelector: action withObject: self]; + } + } + + theEvent = [app nextEventMatchingMask: eventMask + untilDate: distantFuture + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + eventType = [theEvent type]; + } while (eventType != NSLeftMouseUp); + [NSEvent stopPeriodicEvents]; +} + +@end + + +#define KNOB_WIDTH 6 + +@interface GSColorWheelSliderCell : NSSliderCell +{ + float values[2]; +} +-(void) _setColorWheelSliderCellValues: (float)a : (float)b; +@end + +@implementation GSColorWheelSliderCell : NSSliderCell + +-(void) _setColorWheelSliderCellValues: (float)a : (float)b +{ + values[0] = a; + values[1] = b; +} + +- (NSRect) knobRectFlipped: (BOOL)flipped +{ + NSPoint origin; + float floatValue = [self floatValue]; + + if (_isVertical && flipped) + { + floatValue = _maxValue + _minValue - floatValue; + } + + floatValue = (floatValue - _minValue) / (_maxValue - _minValue); + + origin = _trackRect.origin; + if (_isVertical == YES) + { + origin.y += (_trackRect.size.height - KNOB_WIDTH) * floatValue; + return NSMakeRect (origin.x, origin.y, _trackRect.size.width, KNOB_WIDTH); + } + else + { + origin.x += (_trackRect.size.width - KNOB_WIDTH) * floatValue; + return NSMakeRect (origin.x, origin.y, KNOB_WIDTH, _trackRect.size.height); + } +} + +- (void) drawKnob: (NSRect)knobRect +{ + [[NSColor blackColor] set]; + NSDrawButton(knobRect, knobRect); +} + +-(void) drawBarInside: (NSRect)r flipped: (BOOL)flipped +{ + float i, f; + for (i = r.origin.y; i < r.origin.y + r.size.height; i += 1) + { + f = (0.5 + i) / r.size.height; + PSsethsbcolor(values[0], values[1], f); + if (i + 1 < r.origin.y + r.size.height) + PSrectfill(r.origin.x, i, r.size.width, 1); + else + PSrectfill(r.origin.x, i, r.size.width, r.size.height - i); + } +} + +-(void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView +{ + _isVertical = (cellFrame.size.height > cellFrame.size.width); + cellFrame = [self drawingRectForBounds: cellFrame]; + + cellFrame.origin.x -= 1; + cellFrame.origin.y -= 1; + cellFrame.size.width += 2; + cellFrame.size.height += 2; + + [controlView lockFocus]; + + _trackRect = cellFrame; + + [self drawBarInside: cellFrame flipped: [controlView isFlipped]]; + + [self drawKnob]; + [controlView unlockFocus]; +} + +- (float) knobThickness +{ + return KNOB_WIDTH; +} + +@end + + +@interface GSWheelColorPicker: NSColorPicker +{ + GSHbox *baseView; + NSSlider *brightnessSlider; + GSColorWheel *wheel; +} + +- (void) sliderChanged: (id) sender; +- (void) loadViews; + +@end + +@implementation GSWheelColorPicker + +- (void) dealloc +{ + RELEASE(baseView); + [super dealloc]; +} + +- (id)initWithPickerMask:(int)aMask + colorPanel:(NSColorPanel *)colorPanel +{ + if (aMask & NSColorPanelWheelModeMask) + return [super initWithPickerMask: aMask + colorPanel: colorPanel]; + RELEASE(self); + return nil; +} + +- (int)currentMode +{ + return NSWheelModeColorPanel; +} + +- (BOOL)supportsMode:(int)mode +{ + return mode == NSWheelModeColorPanel; +} + +- (NSView *)provideNewView:(BOOL)initialRequest +{ + if (initialRequest) + { + [self loadViews]; + } + return baseView; +} + +- (void)setColor:(NSColor *)color +{ + float hue, saturation, brightness, alpha; + NSColor *c; + + c = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; + [c getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha]; + + [(GSColorWheelSliderCell *)[brightnessSlider cell] + _setColorWheelSliderCellValues: hue : saturation]; + [brightnessSlider setNeedsDisplay: YES]; + [brightnessSlider setFloatValue: brightness]; + [wheel setHue: hue saturation: saturation brightness: brightness]; +} + +- (void) loadViews +{ + NSSlider *s; + + baseView = [[GSHbox alloc] init]; + [baseView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; + + wheel = [[GSColorWheel alloc] init]; + [wheel setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [wheel setTarget: self]; + [wheel setAction: @selector(sliderChanged:)]; + [baseView addView: wheel]; + + s = brightnessSlider = [[NSSlider alloc] initWithFrame: NSMakeRect(0,0,16,0)]; + [s setAutoresizingMask: NSViewHeightSizable]; + [s setCell: [[GSColorWheelSliderCell alloc] init]]; + [s setContinuous: NO]; + [s setMinValue: 0.0]; + [s setMaxValue: 1.0]; + [s setTarget: self]; + [s setAction: @selector(sliderChanged:)]; + [[s cell] setBezeled: YES]; + + [baseView addView: brightnessSlider enablingXResizing: NO]; +} + +- (void) sliderChanged: (id) sender +{ + float brightness = [brightnessSlider floatValue]; + float hue = [wheel hue]; + float saturation = [wheel saturation]; + float alpha = [_colorPanel alpha]; + NSColor *c; + + [(GSColorWheelSliderCell *)[brightnessSlider cell] + _setColorWheelSliderCellValues: hue : saturation]; + [brightnessSlider setNeedsDisplay: YES]; + + c = [NSColor colorWithCalibratedHue: hue + saturation: saturation + brightness: brightness + alpha: alpha]; + [_colorPanel setColor: c]; +} + +@end + diff --git a/ColorPickers/GSWheelColorPicker.tiff b/ColorPickers/GSWheelColorPicker.tiff new file mode 100644 index 000000000..04686e3a1 Binary files /dev/null and b/ColorPickers/GSWheelColorPicker.tiff differ diff --git a/ColorPickers/Swedish.lproj/StandardPicker.strings b/ColorPickers/Swedish.lproj/StandardPicker.strings new file mode 100644 index 000000000..4e1785328 --- /dev/null +++ b/ColorPickers/Swedish.lproj/StandardPicker.strings @@ -0,0 +1,46 @@ +/*** +Swedish.lproj/StandardPicker.strings +updated by make_strings 2002-05-23 16:24:57 +0200 +add comments above this one +***/ + + +/*** Unmatched/untranslated keys ***/ + +/* File: GSCMYKColorPicker.m:47 */ +/* Flag: untranslated */ +"Cyan" = "Cyan"; + +/* File: GSCMYKColorPicker.m:48 */ +/* Flag: untranslated */ +"Magenta" = "Magenta"; + + +/*** Strings from GSCMYKColorPicker.m ***/ +/* File: GSCMYKColorPicker.m:50 */ +"Black" = "Svart"; +/* File: GSCMYKColorPicker.m:49 */ +"Yellow" = "Gul"; + + +/*** Strings from GSGrayColorPicker.m ***/ +/* File: GSGrayColorPicker.m:50 */ +"White" = "Vit"; + + +/*** Strings from GSHSBColorPicker.m ***/ +/* File: GSHSBColorPicker.m:49 */ +"Brightness" = "Ljus"; +/* File: GSHSBColorPicker.m:47 */ +"Hue" = "Nyans"; +/* File: GSHSBColorPicker.m:48 */ +"Saturation" = "M\u00e4ttnad"; + + +/*** Strings from GSRGBColorPicker.m ***/ +/* File: GSRGBColorPicker.m:50 */ +"Blue" = "Bl\ue5"; +/* File: GSRGBColorPicker.m:49 */ +"Green" = "G\u00f6n"; +/* File: GSRGBColorPicker.m:48 */ +"Red" = "R\u00f6d"; diff --git a/GNUmakefile b/GNUmakefile index cea2c6f6e..9e9661e6e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -53,6 +53,7 @@ Tools \ Panels \ PrinterTypes \ TextConverters \ +ColorPickers \ KeyBindings \ Resources