47 - (id)initWithPickerMask:(
int)aMask colorPanel:(
CPColorPanel)aPanel
49 if (
self = [super
init])
80 - (void)setMode:(CPColorPanelMode)mode
102 __CPColorWheel _hueSaturationView;
107 - (id)initWithPickerMask:(
int)mask colorPanel:(
CPColorPanel)owningColorPanel
116 _pickerView = [[
CPView alloc] initWithFrame:aFrame];
117 [_pickerView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
119 _brightnessSlider = [[
CPSlider alloc] initWithFrame:CGRectMake(0, (aFrame.size.height - 34), aFrame.size.width, 15)];
121 [_brightnessSlider setValue:15.0 forThemeAttribute:@"track-width"];
125 [_brightnessSlider setMinValue:0.0];
126 [_brightnessSlider setMaxValue:100.0];
127 [_brightnessSlider setFloatValue:100.0];
129 [_brightnessSlider setTarget:self];
130 [_brightnessSlider setAction:@selector(brightnessSliderDidChange:)];
131 [_brightnessSlider setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];
133 _hueSaturationView = [[__CPColorWheel alloc] initWithFrame:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height - 38)];
134 [_hueSaturationView setDelegate:self];
135 [_hueSaturationView setAutoresizingMask:(CPViewWidthSizable | CPViewHeightSizable)];
137 [_pickerView addSubview:_hueSaturationView];
138 [_pickerView addSubview:_brightnessSlider];
141 - (void)brightnessSliderDidChange:(
id)sender
146 - (void)colorWheelDidChange:(
id)sender
153 var hue = [_hueSaturationView angle],
154 saturation = [_hueSaturationView distance],
155 brightness = [_brightnessSlider floatValue];
157 [_hueSaturationView setWheelBrightness:brightness / 100.0];
168 - (BOOL)supportsMode:(
int)mode
178 - (
CPView)provideNewView:(BOOL)initialRequest
188 if ([newColor
isEqual:_cachedColor])
193 [_hueSaturationView setPositionToColor:newColor];
194 [_brightnessSlider setFloatValue:hsb[2] * 100.0];
195 [_hueSaturationView setWheelBrightness:hsb[2]];
213 @implementation __CPColorWheel :
CPView 215 DOMElement _wheelImage;
216 DOMElement _blackWheelImage;
228 - (id)initWithFrame:(CGRect)aFrame
230 if (
self = [super initWithFrame:aFrame])
235 _wheelImage =
new Image();
236 _wheelImage.src = path;
237 _wheelImage.style.position =
"absolute";
241 _blackWheelImage =
new Image();
242 _blackWheelImage.src = path;
243 _blackWheelImage.style.opacity =
"0";
244 _blackWheelImage.style.filter =
"alpha(opacity=0)";
245 _blackWheelImage.style.position =
"absolute";
247 _DOMElement.appendChild(_wheelImage);
248 _DOMElement.appendChild(_blackWheelImage);
251 [
self setWheelSize:aFrame.size];
253 _crosshair = [[
CPView alloc] initWithFrame:CGRectMake(_radius - 2, _radius - 2, 4, 4)];
256 var view = [[
CPView alloc] initWithFrame:CGRectInset([_crosshair bounds], 1.0, 1.0)];
259 [_crosshair addSubview:view];
261 [
self addSubview:_crosshair];
267 - (void)setWheelBrightness:(
float)brightness
270 _blackWheelImage.style.opacity = 1.0 - brightness;
271 _blackWheelImage.style.filter =
"alpha(opacity=" + (1.0 - brightness) * 100 + ")"
275 - (void)setFrameSize:(CGSize)aSize
277 [
super setFrameSize:aSize];
278 [
self setWheelSize:aSize];
281 - (void)setWheelSize:(CGSize)aSize
283 var min = MIN(aSize.width, aSize.height);
286 _blackWheelImage.style.width = min;
287 _blackWheelImage.style.height = min;
288 _blackWheelImage.width = min;
289 _blackWheelImage.height = min;
290 _blackWheelImage.style.top = (aSize.height - min) / 2.0 + "px";
291 _blackWheelImage.style.left = (aSize.width - min) / 2.0 + "px";
293 _wheelImage.style.width = min;
294 _wheelImage.style.height = min;
295 _wheelImage.width = min;
296 _wheelImage.height = min;
297 _wheelImage.style.top = (aSize.height - min) / 2.0 + "px";
298 _wheelImage.style.left = (aSize.width - min) / 2.0 + "px";
303 [
self setAngle:[
self degreesToRadians:_angle] distance:(_distance / 100.0) * _radius];
306 - (void)setDelegate:(
id)aDelegate
308 _delegate = aDelegate;
326 - (void)mouseDown:(
CPEvent)anEvent
328 [
self reposition:anEvent];
331 - (void)mouseDragged:(
CPEvent)anEvent
333 [
self reposition:anEvent];
336 - (void)reposition:(
CPEvent)anEvent
338 var
bounds = [
self bounds],
340 midX = CGRectGetMidX(
bounds),
341 midY = CGRectGetMidY(
bounds),
342 distance = MIN(SQRT((location.x - midX) * (location.x - midX) + (location.y - midY) * (location.y - midY)), _radius),
343 angle = ATAN2(location.y - midY, location.x - midX);
345 [
self setAngle:angle distance:distance];
347 [_delegate colorWheelDidChange:self];
350 - (void)setAngle:(
int)angle distance:(
float)distance
352 var
bounds = [
self bounds],
353 midX = CGRectGetMidX(
bounds),
354 midY = CGRectGetMidY(
bounds);
356 _angle = [
self radiansToDegrees:angle];
357 _distance = (distance / _radius) * 100.0;
359 [_crosshair setFrameOrigin:CGPointMake(COS(angle) * distance + midX - 2.0, SIN(angle) * distance + midY - 2.0)];
362 - (void)setPositionToColor:(
CPColor)aColor
366 angle = [
self degreesToRadians:hsb[0] * 360.0],
367 distance = hsb[1] * _radius;
369 [
self setAngle:angle distance:distance];
372 - (int)radiansToDegrees:(
float)radians
374 return ((-radians / PI) * 180 + 360) % 360;
377 - (float)degreesToRadians:(
float)degrees
379 return -(((degrees - 360) / 180) * PI);
CPColor colorWithPatternImage:(CPImage anImage)
CGPoint locationInWindow()
void setColor:(CPColor aColor)
CPString pathForResource:(CPString aFilename)
CPColorPanel colorPanel()
id initWithContentsOfFile:size:(CPString aFilename, [size] CGSize aSize)
CPColor colorWithHue:saturation:brightness:alpha:(float hue, [saturation] float saturation, [brightness] float brightness, [alpha] float alpha)
CPColor colorWithHue:saturation:brightness:(float hue, [saturation] float saturation, [brightness] float brightness)
global CPApp CPWheelColorPickerMode
CPBundle bundleForClass:(Class aClass)
id initWithPickerMask:colorPanel:(int aMask, [colorPanel] CPColorPanel aPanel)