diff --git a/AppKit/CPColorPanel.j b/AppKit/CPColorPanel.j index 2656791c88..d13cd6cb88 100644 --- a/AppKit/CPColorPanel.j +++ b/AppKit/CPColorPanel.j @@ -21,21 +21,21 @@ */ @import "CPButton.j" -@import "CPColorPicker.j" @import "CPCookie.j" @import "CPPanel.j" -@import "CPSliderColorPicker.j" @import "CPView.j" - CPColorPanelColorDidChangeNotification = @"CPColorPanelColorDidChangeNotification"; var PREVIEW_HEIGHT = 20.0, TOOLBAR_HEIGHT = 32.0, - SWATCH_HEIGHT = 14.0; - -var SharedColorPanel = nil; + SWATCH_HEIGHT = 14.0, + ICON_WIDTH = 32.0, + ICON_PADDING = 12.0; +var SharedColorPanel = nil, + ColorPickerClasses = []; + /* A color wheel @global @@ -54,7 +54,7 @@ CPColorPickerViewHeight = 370; /*! @class CPColorPanel - CPColorPanel provides a reusable panel that can be used + CPColorPanel provides a reusable panel that can be used displayed on screen to prompt the user for a color selection. To obtain the panel, call the sharedColorPanel method. */ @@ -67,11 +67,8 @@ CPColorPickerViewHeight = 370; CPTextField _previewLabel; CPTextField _swatchLabel; - CPView _currentView; - - CPColorPicker _activePicker; - CPColorPicker _wheelPicker; - CPColorPicker _sliderPicker; + CPArray _colorPickers; + CPView _currentView; CPColor _color; @@ -81,6 +78,15 @@ CPColorPickerViewHeight = 370; int _mode; } +/*! + A list of color pickers is collected here, and any color panel created will contain + any picker in this list up to this point. In other words, call before creating a color panel. +*/ ++ (void)provideColorPickerClass:(Class)aColorPickerSubclass +{ + ColorPickerClasses.push(aColorPickerSubclass); +} + /*! Returns (and if necessary, creates) the shared color panel. */ @@ -207,26 +213,38 @@ CPColorPickerViewHeight = 370; */ - (void)setMode:(CPColorPanelMode)mode { - if(mode == _mode) - return; - - var frame = CPRectCreateCopy([_currentView frame]); - [_currentView removeFromSuperview]; + _mode = mode; +} + +- (void)_setPicker:(id)sender +{ + var picker = _colorPickers[[sender tag]], + view = [picker provideNewView:NO]; - switch(mode) + if (!view) + view = [picker provideNewView:YES]; + + if (view == _currentView) + return; + + if (_currentView) + [view setFrame:[_currentView frame]]; + else { - case CPWheelColorPickerMode: _activePicker = _wheelPicker; break; - case CPSliderColorPickerMode: _activePicker = _sliderPicker; break; + var height = (TOOLBAR_HEIGHT+10+PREVIEW_HEIGHT+5+SWATCH_HEIGHT+10), + bounds = [[self contentView] bounds]; + + [view setFrameSize: CPSizeMake(bounds.size.width - 10, bounds.size.height - height)]; + [view setFrameOrigin: CPPointMake(5, height)]; } - _currentView = [_activePicker provideNewView: NO]; - [_activePicker setColor: _color]; - - _mode = mode; - - [_currentView setFrame: frame]; - [_currentView setAutoresizingMask: (CPViewWidthSizable | CPViewHeightSizable)]; - [[self contentView] addSubview: _currentView]; + [_currentView removeFromSuperview]; + [[self contentView] addSubview:view]; + + _currentView = view; + _activePicker = picker; + + [picker setColor:[self color]]; } /*! @@ -240,7 +258,6 @@ CPColorPickerViewHeight = 370; - (void)orderFront:(id)aSender { [self _loadContentsIfNecessary]; - [super orderFront:aSender]; } @@ -249,13 +266,49 @@ CPColorPickerViewHeight = 370; { if (_toolbar) return; - + + _colorPickers = []; + + var count = [ColorPickerClasses count]; + for (var i=0; i -@import -@import -@import - +@import +@import "CPColorPanel.j" /*! @class CPColorPicker @@ -109,7 +106,9 @@ -(id)initView { aFrame = CPRectMake(0, 0, CPColorPickerViewWidth, CPColorPickerViewHeight); + _pickerView = [[CPView alloc] initWithFrame:aFrame]; + [_pickerView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; var path = [[CPBundle bundleForClass: CPColorPicker] pathForResource:@"brightness_bar.png"]; @@ -194,6 +193,16 @@ _brightnessBarImage.style.backgroundColor = "#"+[[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:100] hexString]; } +- (CPImage)provideNewButtonImage +{ + return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:CPColorPicker] pathForResource:"wheel_button.png"] size:CGSizeMake(32, 32)]; +} + +- (CPImage)provideNewAlternateButtonImage +{ + return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:CPColorPicker] pathForResource:"wheel_button_h.png"] size:CGSizeMake(32, 32)]; +} + @end /* @ignore */ @@ -362,5 +371,6 @@ { return -(((degrees - 360) / 180) * PI); } + +@end -@end \ No newline at end of file diff --git a/AppKit/CPSliderColorPicker.j b/AppKit/CPSliderColorPicker.j index 7dedd0296a..c808e1ac1e 100644 --- a/AppKit/CPSliderColorPicker.j +++ b/AppKit/CPSliderColorPicker.j @@ -20,13 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import - -@import -@import -@import -@import - +@import "CPColorPicker.j" /* @ignore @@ -69,8 +63,10 @@ -(id)initView { aFrame = CPRectMake(0, 0, CPColorPickerViewWidth, CPColorPickerViewHeight); + _contentView = [[CPView alloc] initWithFrame:aFrame]; - + [_contentView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; + _rgbLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 10, 100, 20)]; [_rgbLabel setStringValue: "RGB"]; [_rgbLabel setTextColor:[CPColor whiteColor]]; @@ -404,5 +400,14 @@ _blueValue.value = ROUND([_blueSlider floatValue] * 255); } +- (CPImage)provideNewButtonImage +{ + return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:CPColorPicker] pathForResource:"slider_button.png"] size:CGSizeMake(32, 32)]; +} + +- (CPImage)provideNewAlternateButtonImage +{ + return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:CPColorPicker] pathForResource:"slider_button_h.png"] size:CGSizeMake(32, 32)]; +} @end