1/* GSHSBColorPicker.m
2
3   Copyright (C) 2000 Free Software Foundation, Inc.
4
5   Author:  Fred Kiefer <FredKiefer@gmx.de>
6   Date: December 2000
7   Author: Alexander Malmberg <alexander@malmberg.org>
8   Date: May 2002
9
10   This file is part of GNUstep.
11
12   This library is free software; you can redistribute it and/or
13   modify it under the terms of the GNU Lesser General Public
14   License as published by the Free Software Foundation; either
15   version 2 of the License, or (at your option) any later version.
16
17   This library is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
20   Lesser General Public License for more details.
21
22   You should have received a copy of the GNU Lesser General Public
23   License along with this library; see the file COPYING.LIB.
24   If not, see <http://www.gnu.org/licenses/> or write to the
25   Free Software Foundation, 51 Franklin Street, Fifth Floor,
26   Boston, MA 02110-1301, USA.
27*/
28
29#include "GSHSBColorPicker.h"
30
31@implementation GSHSBColorPicker
32
33- (id)initWithPickerMask:(int)aMask
34              colorPanel:(NSColorPanel *)colorPanel
35{
36  if (aMask & NSColorPanelHSBModeMask)
37    {
38      NSBundle *b;
39
40      self = [super initWithPickerMask: aMask
41                colorPanel: colorPanel];
42      if (!self)
43        return nil;
44
45      numFields = 3;
46      currentMode = NSColorPanelHSBModeMask;
47
48      b = [NSBundle bundleForClass: [self class]];
49      r_names[0] = NSLocalizedStringFromTableInBundle(@"Hue",@"StandardPicker",b,@"");
50      r_names[1] = NSLocalizedStringFromTableInBundle(@"Saturation",@"StandardPicker",b,@"");
51      r_names[2] = NSLocalizedStringFromTableInBundle(@"Brightness",@"StandardPicker",b,@"");
52      names = r_names;
53
54      sliders = r_sliders;
55      fields = r_fields;
56      values = r_values;
57      return self;
58    }
59  RELEASE(self);
60  return nil;
61}
62
63- (void)setColor:(NSColor *)color
64{
65  CGFloat hue, saturation, brightness, alpha;
66  NSColor *c;
67
68  if (updating)
69    return;
70  updating = YES;
71
72  c = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
73  [c getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha];
74
75  values[0] = hue * 360;
76  values[1] = saturation * 100;
77  values[2] = brightness * 100;
78  [self _valuesChanged];
79
80  [(GSColorSliderCell *)[sliders[0] cell]
81    _setColorSliderCellValues: hue : saturation : brightness];
82  [(GSColorSliderCell *)[sliders[1] cell]
83    _setColorSliderCellValues: hue : saturation : brightness];
84  [(GSColorSliderCell *)[sliders[2] cell]
85    _setColorSliderCellValues: hue : saturation : brightness];
86  [sliders[0] setNeedsDisplay: YES];
87  [sliders[1] setNeedsDisplay: YES];
88  [sliders[2] setNeedsDisplay: YES];
89
90  updating = NO;
91}
92
93-(void) _setColorFromValues
94{
95  float hue = values[0] / 360;
96  float saturation = values[1] / 100;
97  float brightness  = values[2] / 100;
98  float alpha = [_colorPanel alpha];
99  NSColor *c = [NSColor colorWithCalibratedHue: hue
100                        saturation: saturation
101                        brightness: brightness
102                        alpha: alpha];
103  [_colorPanel setColor: c];
104
105  [(GSColorSliderCell *)[sliders[0] cell]
106    _setColorSliderCellValues: hue : saturation : brightness];
107  [(GSColorSliderCell *)[sliders[1] cell]
108    _setColorSliderCellValues: hue : saturation : brightness];
109  [(GSColorSliderCell *)[sliders[2] cell]
110    _setColorSliderCellValues: hue : saturation : brightness];
111  [sliders[0] setNeedsDisplay: YES];
112  [sliders[1] setNeedsDisplay: YES];
113  [sliders[2] setNeedsDisplay: YES];
114}
115
116
117- (void) loadViews
118{
119  [super loadViews];
120  [sliders[0] setMaxValue: 360];
121  [sliders[1] setMaxValue: 100];
122  [sliders[2] setMaxValue: 100];
123  [(GSColorSliderCell *)[sliders[0] cell] _setColorSliderCellMode: 8];
124  [(GSColorSliderCell *)[sliders[1] cell] _setColorSliderCellMode: 9];
125  [(GSColorSliderCell *)[sliders[2] cell] _setColorSliderCellMode: 10];
126}
127
128@end
129
130