64 _CPColorPanelSwatches _swatchView;
65 _CPColorPanelPreview _previewView;
69 CPArray _colorPickers;
85 + (void)provideColorPickerClass:(Class)aColorPickerSubclass
105 + (void)setPickerMode:(CPColorPanelMode)mode
108 [panel setMode:mode];
118 styleMask:(CPTitledWindowMask | CPClosableWindowMask | CPResizableWindowMask)];
125 [
self setLevel:CPFloatingWindowLevel];
143 [_previewView setBackgroundColor:_color];
145 [CPApp sendAction:@selector(changeColor:) to:nil from:self];
147 if (_target && _action)
148 [CPApp sendAction:_action to:_target from:self];
154 [_activePicker setColor:_color];
155 [_opacitySlider setFloatValue:[_color alphaComponent]];
163 - (void)setColor:(
CPColor)aColor updatePicker:(BOOL)bool
168 [_activePicker setColor:_color];
181 return [_opacitySlider floatValue];
188 - (void)setTarget:(
id)aTarget
207 - (void)setAction:(selector)anAction
224 - (void)setMode:(CPColorPanelMode)mode
229 - (void)_setPicker:(
id)sender
231 var picker = _colorPickers[[sender tag]],
232 view = [picker provideNewView:NO];
235 view = [picker provideNewView:YES];
237 if (view == _currentView)
241 [view setFrame:[_currentView frame]];
247 [view setFrameSize:CGSizeMake(bounds.size.width - 10, bounds.size.height - height)];
248 [view setFrameOrigin:CGPointMake(5, height)];
251 [_currentView removeFromSuperview];
252 [[
self contentView] addSubview:view];
255 _activePicker = picker;
257 [picker setColor:[
self color]];
263 - (CPColorPanelMode)mode
268 - (void)orderFront:(
id)aSender
270 [
self _loadContentsIfNecessary];
275 - (void)_loadContentsIfNecessary
285 var count = [ColorPickerClasses count];
286 for (var i = 0; i < count; i++)
289 currentPicker = [[currentPickerClass alloc] initWithPickerMask:0 colorPanel:self];
291 _colorPickers.push(currentPicker);
294 var contentView = [
self contentView],
295 bounds = [contentView bounds];
297 _toolbar = [[
CPView alloc] initWithFrame:CGRectMake(0, 6, CGRectGetWidth(bounds), TOOLBAR_HEIGHT)];
298 [_toolbar setAutoresizingMask:CPViewWidthSizable];
301 leftOffset = (CGRectGetWidth(
bounds) - totalToolbarWidth) / 2.0,
302 buttonForLater = nil;
304 for (var i = 0; i < count; i++)
306 var image = [_colorPickers[i] provideNewButtonImage],
307 highlightImage = [_colorPickers[i] provideNewAlternateButtonImage],
308 button = [[
CPButton alloc] initWithFrame:CGRectMake(leftOffset + i * (ICON_WIDTH + ICON_PADDING), 0, ICON_WIDTH, ICON_WIDTH)];
311 [button setTarget:self];
312 [button setAction:@selector(_setPicker:)];
313 [button setBordered:NO];
314 [button setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
316 [button setImage:image];
317 [button setAlternateImage:highlightImage];
319 [_toolbar addSubview:button];
322 buttonForLater = button;
326 var previewBox = [[
CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10, CGRectGetWidth(bounds) - 86, PREVIEW_HEIGHT)];
328 _previewView = [[_CPColorPanelPreview alloc] initWithFrame:CGRectInset([previewBox bounds], 2.0, 2.0)];
330 [_previewView setColorPanel:self];
331 [_previewView setAutoresizingMask:CPViewWidthSizable];
334 [previewBox setAutoresizingMask:CPViewWidthSizable];
336 [previewBox addSubview:_previewView];
338 var _previewLabel = [[
CPTextField alloc] initWithFrame:CGRectMake(10, TOOLBAR_HEIGHT + 10, 60, 15)];
339 [_previewLabel setStringValue:"Preview:"];
341 [_previewLabel setAlignment:CPRightTextAlignment];
344 var swatchBox = [[
CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10 + PREVIEW_HEIGHT + 5, CGRectGetWidth(bounds) - 86, SWATCH_HEIGHT + 2.0)];
347 [swatchBox setAutoresizingMask:CPViewWidthSizable];
349 _swatchView = [[_CPColorPanelSwatches alloc] initWithFrame:CGRectInset([swatchBox bounds], 1.0, 1.0)];
351 [_swatchView setColorPanel:self];
352 [_swatchView setAutoresizingMask:CPViewWidthSizable];
354 [swatchBox addSubview:_swatchView];
356 var _swatchLabel = [[
CPTextField alloc] initWithFrame:CGRectMake(10, TOOLBAR_HEIGHT + 8 + PREVIEW_HEIGHT + 6, 60, 15)];
357 [_swatchLabel setStringValue:"Swatches:"];
359 [_swatchLabel setAlignment:CPRightTextAlignment];
362 var opacityLabel = [[
CPTextField alloc] initWithFrame:CGRectMake(10, TOOLBAR_HEIGHT + PREVIEW_HEIGHT + 35, 60, 20)];
363 [opacityLabel setStringValue:"Opacity:"];
365 [opacityLabel setAlignment:CPRightTextAlignment];
367 _opacitySlider = [[
CPSlider alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + PREVIEW_HEIGHT + 34, CGRectGetWidth(bounds) - 86, 20.0)];
369 [_opacitySlider setMinValue:0.0];
370 [_opacitySlider setMaxValue:1.0];
371 [_opacitySlider setAutoresizingMask:CPViewWidthSizable];
373 [_opacitySlider setTarget:self];
374 [_opacitySlider setAction:@selector(setOpacity:)];
376 [contentView addSubview:_toolbar];
377 [contentView addSubview:previewBox];
378 [contentView addSubview:_previewLabel];
379 [contentView addSubview:swatchBox];
380 [contentView addSubview:_swatchLabel];
381 [contentView addSubview:opacityLabel];
382 [contentView addSubview:_opacitySlider];
388 [_previewView setBackgroundColor:_color];
391 [
self _setPicker:buttonForLater];
394 - (void)setOpacity:(
id)sender
397 alpha = [sender floatValue];
410 @implementation _CPColorPanelSwatches :
CPView 418 - (id)initWithFrame:(CGRect)aFrame
420 self = [
super initWithFrame:aFrame];
424 [
self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
428 _swatchCookie = [[
CPCookie alloc] initWithName:CPColorPanelSwatchesCookie];
429 var colorList = [
self startingColorList];
433 for (var i = 0; i < 50; i++)
436 var view = [[
CPView alloc] initWithFrame:CGRectMake(13 * i + 1, 1, 12, 12)],
437 fillView = [[
CPView alloc] initWithFrame:CGRectInset([view bounds], 1.0, 1.0)];
439 [view setBackgroundColor:whiteColor];
440 [fillView setBackgroundColor:(i < colorList.length) ? colorList[i] : whiteColor];
442 [view addSubview:fillView];
444 [
self addSubview:view];
446 _swatches.push(view);
457 - (CPArray)startingColorList
459 var cookieValue = [_swatchCookie value];
476 var cookieValue = eval(cookieValue);
478 return [cookieValue arrayByApplyingBlock:function(value)
484 - (CPArray)saveColorList
488 for (var i = 0; i < _swatches.length; i++)
491 var future =
new Date();
492 future.setYear(2019);
494 [_swatchCookie setValue:JSON.stringify(result) expires:future domain:nil];
507 - (
CPColor)colorAtIndex:(
int)index
509 return [[_swatches[index] subviews][0] backgroundColor];
512 - (void)setColor:(
CPColor)aColor atIndex:(
int)index
515 [[_swatches[index] subviews][0] setBackgroundColor:aColor];
516 [
self saveColorList];
519 - (void)mouseUp:(
CPEvent)anEvent
524 if (!CGRectContainsPoint(
bounds, point) || point.x > [
self bounds].size.width - 1 || point.x < 1)
527 [_colorPanel setColor:[
self colorAtIndex:FLOOR(point.x / 13)] updatePicker:YES];
530 - (void)mouseDragged:(
CPEvent)anEvent
534 if (point.x > [
self bounds].size.width - 1 || point.x < 1)
539 var swatch = _swatches[FLOOR(point.x / 13)];
542 _dragColor = [[swatch subviews][0] backgroundColor];
547 var dragView = [[
CPView alloc] initWithFrame:bounds],
548 dragFillView = [[
CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
551 [dragFillView setBackgroundColor:_dragColor];
553 [dragView addSubview:dragFillView];
555 [
self dragView:dragView
556 at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
557 offset:CGPointMake(0.0, 0.0)
570 - (void)performDragOperation:(
id )aSender
572 var location = [
self convertPoint:[aSender draggingLocation] fromView:nil],
573 pasteboard = [aSender draggingPasteboard],
576 if (![pasteboard availableTypeFromArray:[
CPColorDragType]] || location.x > [
self bounds].size.width - 1 || location.x < 1)
585 @implementation _CPColorPanelPreview :
CPView 590 - (id)initWithFrame:(CGRect)aFrame
592 self = [
super initWithFrame:aFrame];
594 [
self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
601 _colorPanel = aPanel;
609 - (void)performDragOperation:(
id )aSender
611 var pasteboard = [aSender draggingPasteboard];
617 [_colorPanel setColor:color updatePicker:YES];
625 - (void)mouseDragged:(
CPEvent)anEvent
631 var
bounds = CGRectMake(0, 0, 15, 15);
634 var dragView = [[
CPView alloc] initWithFrame:bounds],
635 dragFillView = [[
CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
638 [dragFillView setBackgroundColor:[
self backgroundColor]];
640 [dragView addSubview:dragFillView];
642 [
self dragView:dragView
643 at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
644 offset:CGPointMake(0.0, 0.0)
CPColor colorWithHexString:(string hex)
CPColorPanel sharedColorPanel()
void setMaxSize:(CGSize aSize)
CPColorPanelColorDidChangeNotification
void setTitle:(CPString aTitle)
BOOL setData:forType:(CPData aData, [forType] CPString aType)
CGPoint locationInWindow()
void setColor:(CPColor aColor)
void postNotificationName:object:(CPString aNotificationName, [object] id anObject)
Unarchives objects created using CPKeyedArchiver.
CPNotificationCenter defaultCenter()
id initWithContentRect:styleMask:(CGRect aContentRect, [styleMask] unsigned aStyleMask)
void orderFront:(id aSender)
Implements keyed archiving of object graphs (e.g. for storing data).
An immutable string (collection of characters).
void setFloatingPanel:(BOOL isFloatingPanel)
CPColor backgroundColor()
CPColor colorWithWhite:alpha:(float white, [alpha] float alpha)
void setBecomesKeyOnlyIfNeeded:(BOOL shouldBecomeKeyOnlyIfNeeded)
var CPColorPanelSwatchesCookie
void setLevel:(int aLevel)
void setColor:updatePicker:(CPColor aColor, [updatePicker] BOOL bool)
unsigned declareTypes:owner:(CPArray types, [owner] id anOwner)
id unarchiveObjectWithData:(CPData aData)
Sends messages (CPNotification) between objects.
global CPApp CPWheelColorPickerMode
void provideColorPickerClass:(Class aColorPickerSubclass)
void setMinSize:(CGSize aSize)
id pasteboardWithName:(CPString aName)
CPData archivedDataWithRootObject:(id anObject)