/Frameworks/AppKit/browser.platform/CPColorPicker.j
http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 223 lines · 223 code · 0 blank · 0 comment · 0 complexity · a65818236b4b7bc1a220476b2a73b829 MD5 · raw file
- I;21;Foundation/CPObject.ji;14;CPColorPanel.jc;10196;
- var _1=objj_allocateClassPair(CPObject,"CPColorPicker"),_2=_1.isa;
- class_addIvars(_1,[new objj_ivar("_panel"),new objj_ivar("_mask")]);
- objj_registerClassPair(_1);
- objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
- class_addMethods(_1,[new objj_method(sel_getUid("initWithPickerMask:colorPanel:"),function(_3,_4,_5,_6){
- with(_3){
- _3=objj_msgSendSuper({receiver:_3,super_class:objj_getClass("CPObject")},"init");
- _panel=_6;
- _mask=_5;
- return _3;
- }
- }),new objj_method(sel_getUid("colorPanel"),function(_7,_8){
- with(_7){
- return _panel;
- }
- }),new objj_method(sel_getUid("provideNewButtonImage"),function(_9,_a){
- with(_9){
- return nil;
- }
- }),new objj_method(sel_getUid("setMode:"),function(_b,_c,_d){
- with(_b){
- return;
- }
- }),new objj_method(sel_getUid("setColor:"),function(_e,_f,_10){
- with(_e){
- return;
- }
- })]);
- var _1=objj_allocateClassPair(CPColorPicker,"CPColorWheelColorPicker"),_2=_1.isa;
- class_addIvars(_1,[new objj_ivar("_pickerView"),new objj_ivar("_brightnessSlider"),new objj_ivar("_hueSaturationView"),new objj_ivar("_cachedColor")]);
- objj_registerClassPair(_1);
- objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
- class_addMethods(_1,[new objj_method(sel_getUid("initWithPickerMask:colorPanel:"),function(_11,_12,_13,_14){
- with(_11){
- return objj_msgSendSuper({receiver:_11,super_class:objj_getClass("CPColorPicker")},"initWithPickerMask:colorPanel:",_13,_14);
- }
- }),new objj_method(sel_getUid("initView"),function(_15,_16){
- with(_15){
- aFrame=CPRectMake(0,0,CPColorPickerViewWidth,CPColorPickerViewHeight);
- _pickerView=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",aFrame);
- objj_msgSend(_pickerView,"setAutoresizingMask:",CPViewWidthSizable|CPViewHeightSizable);
- _brightnessSlider=objj_msgSend(objj_msgSend(CPSlider,"alloc"),"initWithFrame:",CGRectMake(0,(aFrame.size.height-34),aFrame.size.width,15));
- objj_msgSend(_brightnessSlider,"setValue:forThemeAttribute:",15,"track-width");
- objj_msgSend(_brightnessSlider,"setValue:forThemeAttribute:",objj_msgSend(CPColor,"colorWithPatternImage:",objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:",objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",objj_msgSend(CPColorPicker,"class")),"pathForResource:","brightness_bar.png"))),"track-color");
- objj_msgSend(_brightnessSlider,"setMinValue:",0);
- objj_msgSend(_brightnessSlider,"setMaxValue:",100);
- objj_msgSend(_brightnessSlider,"setFloatValue:",100);
- objj_msgSend(_brightnessSlider,"setTarget:",_15);
- objj_msgSend(_brightnessSlider,"setAction:",sel_getUid("brightnessSliderDidChange:"));
- objj_msgSend(_brightnessSlider,"setAutoresizingMask:",CPViewWidthSizable|CPViewMinYMargin);
- _hueSaturationView=objj_msgSend(objj_msgSend(__CPColorWheel,"alloc"),"initWithFrame:",CPRectMake(0,0,aFrame.size.width,aFrame.size.height-38));
- objj_msgSend(_hueSaturationView,"setDelegate:",_15);
- objj_msgSend(_hueSaturationView,"setAutoresizingMask:",(CPViewWidthSizable|CPViewHeightSizable));
- objj_msgSend(_pickerView,"addSubview:",_hueSaturationView);
- objj_msgSend(_pickerView,"addSubview:",_brightnessSlider);
- }
- }),new objj_method(sel_getUid("brightnessSliderDidChange:"),function(_17,_18,_19){
- with(_17){
- objj_msgSend(_17,"updateColor");
- }
- }),new objj_method(sel_getUid("colorWheelDidChange:"),function(_1a,_1b,_1c){
- with(_1a){
- objj_msgSend(_1a,"updateColor");
- }
- }),new objj_method(sel_getUid("updateColor"),function(_1d,_1e){
- with(_1d){
- var hue=objj_msgSend(_hueSaturationView,"angle"),_20=objj_msgSend(_hueSaturationView,"distance"),_21=objj_msgSend(_brightnessSlider,"floatValue");
- objj_msgSend(_hueSaturationView,"setWheelBrightness:",_21/100);
- objj_msgSend(_brightnessSlider,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithHue:saturation:brightness:",hue,_20,100));
- var _22=objj_msgSend(_1d,"colorPanel"),_23=objj_msgSend(_22,"opacity");
- _cachedColor=objj_msgSend(CPColor,"colorWithHue:saturation:brightness:alpha:",hue,_20,_21,_23);
- objj_msgSend(objj_msgSend(_1d,"colorPanel"),"setColor:",_cachedColor);
- }
- }),new objj_method(sel_getUid("supportsMode:"),function(_24,_25,_26){
- with(_24){
- return (_26==CPWheelColorPickerMode)?YES:NO;
- }
- }),new objj_method(sel_getUid("currentMode"),function(_27,_28){
- with(_27){
- return CPWheelColorPickerMode;
- }
- }),new objj_method(sel_getUid("provideNewView:"),function(_29,_2a,_2b){
- with(_29){
- if(_2b){
- objj_msgSend(_29,"initView");
- }
- return _pickerView;
- }
- }),new objj_method(sel_getUid("setColor:"),function(_2c,_2d,_2e){
- with(_2c){
- if(objj_msgSend(_2e,"isEqual:",_cachedColor)){
- return;
- }
- var hsb=objj_msgSend(_2e,"hsbComponents");
- objj_msgSend(_hueSaturationView,"setPositionToColor:",_2e);
- objj_msgSend(_brightnessSlider,"setFloatValue:",hsb[2]);
- objj_msgSend(_hueSaturationView,"setWheelBrightness:",hsb[2]/100);
- objj_msgSend(_brightnessSlider,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithHue:saturation:brightness:",hsb[0],hsb[1],100));
- }
- }),new objj_method(sel_getUid("provideNewButtonImage"),function(_30,_31){
- with(_30){
- return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_button.png"),CGSizeMake(32,32));
- }
- }),new objj_method(sel_getUid("provideNewAlternateButtonImage"),function(_32,_33){
- with(_32){
- return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_button_h.png"),CGSizeMake(32,32));
- }
- })]);
- var _1=objj_allocateClassPair(CPView,"__CPColorWheel"),_2=_1.isa;
- class_addIvars(_1,[new objj_ivar("_wheelImage"),new objj_ivar("_blackWheelImage"),new objj_ivar("_crosshair"),new objj_ivar("_delegate"),new objj_ivar("_angle"),new objj_ivar("_distance"),new objj_ivar("_radius")]);
- objj_registerClassPair(_1);
- objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
- class_addMethods(_1,[new objj_method(sel_getUid("initWithFrame:"),function(_34,_35,_36){
- with(_34){
- _34=objj_msgSendSuper({receiver:_34,super_class:objj_getClass("CPView")},"initWithFrame:",_36);
- var _37=objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel.png");
- _wheelImage=new Image();
- _wheelImage.src=_37;
- _wheelImage.style.position="absolute";
- _37=objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_black.png");
- _blackWheelImage=new Image();
- _blackWheelImage.src=_37;
- _blackWheelImage.style.opacity="0";
- _blackWheelImage.style.filter="alpha(opacity=0)";
- _blackWheelImage.style.position="absolute";
- _DOMElement.appendChild(_wheelImage);
- _DOMElement.appendChild(_blackWheelImage);
- objj_msgSend(_34,"setWheelSize:",_36.size);
- _crosshair=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CPRectMake(_radius-2,_radius-2,4,4));
- objj_msgSend(_crosshair,"setBackgroundColor:",objj_msgSend(CPColor,"blackColor"));
- var _38=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectInset(objj_msgSend(_crosshair,"bounds"),1,1));
- objj_msgSend(_38,"setBackgroundColor:",objj_msgSend(CPColor,"whiteColor"));
- objj_msgSend(_crosshair,"addSubview:",_38);
- objj_msgSend(_34,"addSubview:",_crosshair);
- return _34;
- }
- }),new objj_method(sel_getUid("setWheelBrightness:"),function(_39,_3a,_3b){
- with(_39){
- _blackWheelImage.style.opacity=1-_3b;
- _blackWheelImage.style.filter="alpha(opacity="+(1-_3b)*100+")";
- }
- }),new objj_method(sel_getUid("setFrameSize:"),function(_3c,_3d,_3e){
- with(_3c){
- objj_msgSendSuper({receiver:_3c,super_class:objj_getClass("CPView")},"setFrameSize:",_3e);
- objj_msgSend(_3c,"setWheelSize:",_3e);
- }
- }),new objj_method(sel_getUid("setWheelSize:"),function(_3f,_40,_41){
- with(_3f){
- var min=MIN(_41.width,_41.height);
- _blackWheelImage.style.width=min;
- _blackWheelImage.style.height=min;
- _blackWheelImage.width=min;
- _blackWheelImage.height=min;
- _blackWheelImage.style.top=(_41.height-min)/2+"px";
- _blackWheelImage.style.left=(_41.width-min)/2+"px";
- _wheelImage.style.width=min;
- _wheelImage.style.height=min;
- _wheelImage.width=min;
- _wheelImage.height=min;
- _wheelImage.style.top=(_41.height-min)/2+"px";
- _wheelImage.style.left=(_41.width-min)/2+"px";
- _radius=min/2;
- objj_msgSend(_3f,"setAngle:distance:",objj_msgSend(_3f,"degreesToRadians:",_angle),(_distance/100)*_radius);
- }
- }),new objj_method(sel_getUid("setDelegate:"),function(_43,_44,_45){
- with(_43){
- _delegate=_45;
- }
- }),new objj_method(sel_getUid("delegate"),function(_46,_47){
- with(_46){
- return _delegate;
- }
- }),new objj_method(sel_getUid("angle"),function(_48,_49){
- with(_48){
- return _angle;
- }
- }),new objj_method(sel_getUid("distance"),function(_4a,_4b){
- with(_4a){
- return _distance;
- }
- }),new objj_method(sel_getUid("mouseDown:"),function(_4c,_4d,_4e){
- with(_4c){
- objj_msgSend(_4c,"reposition:",_4e);
- }
- }),new objj_method(sel_getUid("mouseDragged:"),function(_4f,_50,_51){
- with(_4f){
- objj_msgSend(_4f,"reposition:",_51);
- }
- }),new objj_method(sel_getUid("reposition:"),function(_52,_53,_54){
- with(_52){
- var _55=objj_msgSend(_52,"bounds"),_56=objj_msgSend(_52,"convertPoint:fromView:",objj_msgSend(_54,"locationInWindow"),nil);
- var _57=CGRectGetMidX(_55);
- var _58=CGRectGetMidY(_55);
- var _59=MIN(SQRT((_56.x-_57)*(_56.x-_57)+(_56.y-_58)*(_56.y-_58)),_radius);
- var _5a=ATAN2(_56.y-_58,_56.x-_57);
- objj_msgSend(_52,"setAngle:distance:",_5a,_59);
- objj_msgSend(_delegate,"colorWheelDidChange:",_52);
- }
- }),new objj_method(sel_getUid("setAngle:distance:"),function(_5b,_5c,_5d,_5e){
- with(_5b){
- var _5f=objj_msgSend(_5b,"bounds");
- var _60=CGRectGetMidX(_5f);
- var _61=CGRectGetMidY(_5f);
- _angle=objj_msgSend(_5b,"radiansToDegrees:",_5d);
- _distance=(_5e/_radius)*100;
- objj_msgSend(_crosshair,"setFrameOrigin:",CPPointMake(COS(_5d)*_5e+_60-2,SIN(_5d)*_5e+_61-2));
- }
- }),new objj_method(sel_getUid("setPositionToColor:"),function(_62,_63,_64){
- with(_62){
- var hsb=objj_msgSend(_64,"hsbComponents"),_66=objj_msgSend(_62,"bounds");
- var _67=objj_msgSend(_62,"degreesToRadians:",hsb[0]),_68=(hsb[1]/100)*_radius;
- objj_msgSend(_62,"setAngle:distance:",_67,_68);
- }
- }),new objj_method(sel_getUid("radiansToDegrees:"),function(_69,_6a,_6b){
- with(_69){
- return ((-_6b/PI)*180+360)%360;
- }
- }),new objj_method(sel_getUid("degreesToRadians:"),function(_6c,_6d,_6e){
- with(_6c){
- return -(((_6e-360)/180)*PI);
- }
- })]);