From 3e35e3d8a80329622a4b52a113a0fa86e1c367fa Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 21 Apr 2013 14:32:10 +0100 Subject: [PATCH] Fixed: CPColorPicker not working with fixed CPColor colorWithHue: implementation. --- AppKit/CPColorPicker.j | 14 +++++++------- AppKit/CPSliderColorPicker.j | 21 ++++++++++++--------- Tests/AppKit/CPColorTest.j | 3 +++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/AppKit/CPColorPicker.j b/AppKit/CPColorPicker.j index 7a1d43961..14aed7793 100644 --- a/AppKit/CPColorPicker.j +++ b/AppKit/CPColorPicker.j @@ -158,12 +158,12 @@ brightness = [_brightnessSlider floatValue]; [_hueSaturationView setWheelBrightness:brightness / 100.0]; - [_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hue saturation:saturation brightness:100]]; + [_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hue / 360.0 saturation:saturation / 100.0 brightness:1]]; var colorPanel = [self colorPanel], opacity = [colorPanel opacity]; - _cachedColor = [CPColor colorWithHue:hue saturation:saturation brightness:brightness alpha:opacity]; + _cachedColor = [CPColor colorWithHue:hue / 360.0 saturation:saturation / 100.0 brightness:brightness / 100.0 alpha:opacity]; [[self colorPanel] setColor:_cachedColor]; } @@ -194,10 +194,10 @@ var hsb = [newColor hsbComponents]; [_hueSaturationView setPositionToColor:newColor]; - [_brightnessSlider setFloatValue:hsb[2]]; - [_hueSaturationView setWheelBrightness:hsb[2] / 100.0]; + [_brightnessSlider setFloatValue:hsb[2] * 100.0]; + [_hueSaturationView setWheelBrightness:hsb[2]]; - [_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:100]]; + [_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:1]]; } - (CPImage)provideNewButtonImage @@ -366,8 +366,8 @@ { var hsb = [aColor hsbComponents], bounds = [self bounds], - angle = [self degreesToRadians:hsb[0]], - distance = (hsb[1] / 100.0) * _radius; + angle = [self degreesToRadians:hsb[0] * 360.0], + distance = hsb[1] * _radius; [self setAngle:angle distance:distance]; } diff --git a/AppKit/CPSliderColorPicker.j b/AppKit/CPSliderColorPicker.j index 38aa8427c..7e7f997b4 100644 --- a/AppKit/CPSliderColorPicker.j +++ b/AppKit/CPSliderColorPicker.j @@ -146,7 +146,7 @@ [_hueLabel setTextColor:[CPColor blackColor]]; _hueSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 143, aFrame.size.width - 70, 20)]; - [_hueSlider setMaxValue:359.0]; + [_hueSlider setMaxValue:0.999]; [_hueSlider setMinValue:0.0]; [_hueSlider setTarget:self]; [_hueSlider setAction:@selector(sliderChanged:)]; @@ -165,7 +165,7 @@ [_saturationLabel setTextColor:[CPColor blackColor]]; _saturationSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 168, aFrame.size.width - 70, 20)]; - [_saturationSlider setMaxValue:100.0]; + [_saturationSlider setMaxValue:1.0]; [_saturationSlider setMinValue:0.0]; [_saturationSlider setTarget:self]; [_saturationSlider setAction:@selector(sliderChanged:)]; @@ -184,7 +184,7 @@ [_brightnessLabel setTextColor:[CPColor blackColor]]; _brightnessSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 194, aFrame.size.width - 70, 20)]; - [_brightnessSlider setMaxValue:100.0]; + [_brightnessSlider setMaxValue:1.0]; [_brightnessSlider setMinValue:0.0]; [_brightnessSlider setTarget:self]; [_brightnessSlider setAction:@selector(sliderChanged:)]; @@ -282,6 +282,9 @@ - (void)setColor:(CPColor)aColor { + if (!aColor) + [CPException raise:CPInvalidArgumentException reason:"aColor can't be nil"]; + [self updateRGBSliders:aColor]; [self updateHSBSliders:aColor]; [self updateHex:aColor]; @@ -313,9 +316,9 @@ - (void)updateLabels { - [_hueValue setStringValue:ROUND([_hueSlider floatValue])]; - [_saturationValue setStringValue:ROUND([_saturationSlider floatValue])]; - [_brightnessValue setStringValue:ROUND([_brightnessSlider floatValue])]; + [_hueValue setStringValue:ROUND([_hueSlider floatValue] * 360.0)]; + [_saturationValue setStringValue:ROUND([_saturationSlider floatValue] * 100.0)]; + [_brightnessValue setStringValue:ROUND([_brightnessSlider floatValue] * 100.0)]; [_redValue setStringValue:ROUND([_redSlider floatValue] * 255)]; [_greenValue setStringValue:ROUND([_greenSlider floatValue] * 255)]; @@ -363,15 +366,15 @@ [self sliderChanged:_blueSlider]; break; - case _hueValue: [_hueSlider setFloatValue:MAX(MIN(ROUND(value), 360), 0)]; + case _hueValue: [_hueSlider setFloatValue:MAX(MIN(ROUND(value), 360) / 360.0, 0)]; [self sliderChanged:_hueSlider]; break; - case _saturationValue: [_saturationSlider setFloatValue:MAX(MIN(ROUND(value), 100), 0)]; + case _saturationValue: [_saturationSlider setFloatValue:MAX(MIN(ROUND(value), 100) / 100.0, 0)]; [self sliderChanged:_saturationSlider]; break; - case _brightnessValue: [_brightnessSlider setFloatValue:MAX(MIN(ROUND(value), 100), 0)]; + case _brightnessValue: [_brightnessSlider setFloatValue:MAX(MIN(ROUND(value), 100) / 100.0, 0)]; [self sliderChanged:_brightnessSlider]; break; } diff --git a/Tests/AppKit/CPColorTest.j b/Tests/AppKit/CPColorTest.j index 53048543a..b357a6805 100644 --- a/Tests/AppKit/CPColorTest.j +++ b/Tests/AppKit/CPColorTest.j @@ -43,6 +43,9 @@ var hsb = [[CPColor colorWithHue:0.9 saturation:0.8 brightness:0.7] hsbComponents]; [self assert:[0.9, 0.8, 0.7] equals:[Math.round(hsb[0] * 10) / 10, Math.round(hsb[1] * 10) / 10, Math.round(hsb[2] * 10) / 10]]; + + hsb = [[CPColor colorWithHue:0.999 saturation:0.8 brightness:0.7] hsbComponents]; + [self assert:[0.999, 0.8, 0.7] equals:[Math.round(hsb[0] * 1000) / 1000, Math.round(hsb[1] * 10) / 10, Math.round(hsb[2] * 10) / 10]]; } - (void)testIsEqual_