PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1I;21;Foundation/CPObject.ji;14;CPColorPanel.jc;10196;
  2var _1=objj_allocateClassPair(CPObject,"CPColorPicker"),_2=_1.isa;
  3class_addIvars(_1,[new objj_ivar("_panel"),new objj_ivar("_mask")]);
  4objj_registerClassPair(_1);
  5objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  6class_addMethods(_1,[new objj_method(sel_getUid("initWithPickerMask:colorPanel:"),function(_3,_4,_5,_6){
  7with(_3){
  8_3=objj_msgSendSuper({receiver:_3,super_class:objj_getClass("CPObject")},"init");
  9_panel=_6;
 10_mask=_5;
 11return _3;
 12}
 13}),new objj_method(sel_getUid("colorPanel"),function(_7,_8){
 14with(_7){
 15return _panel;
 16}
 17}),new objj_method(sel_getUid("provideNewButtonImage"),function(_9,_a){
 18with(_9){
 19return nil;
 20}
 21}),new objj_method(sel_getUid("setMode:"),function(_b,_c,_d){
 22with(_b){
 23return;
 24}
 25}),new objj_method(sel_getUid("setColor:"),function(_e,_f,_10){
 26with(_e){
 27return;
 28}
 29})]);
 30var _1=objj_allocateClassPair(CPColorPicker,"CPColorWheelColorPicker"),_2=_1.isa;
 31class_addIvars(_1,[new objj_ivar("_pickerView"),new objj_ivar("_brightnessSlider"),new objj_ivar("_hueSaturationView"),new objj_ivar("_cachedColor")]);
 32objj_registerClassPair(_1);
 33objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 34class_addMethods(_1,[new objj_method(sel_getUid("initWithPickerMask:colorPanel:"),function(_11,_12,_13,_14){
 35with(_11){
 36return objj_msgSendSuper({receiver:_11,super_class:objj_getClass("CPColorPicker")},"initWithPickerMask:colorPanel:",_13,_14);
 37}
 38}),new objj_method(sel_getUid("initView"),function(_15,_16){
 39with(_15){
 40aFrame=CPRectMake(0,0,CPColorPickerViewWidth,CPColorPickerViewHeight);
 41_pickerView=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",aFrame);
 42objj_msgSend(_pickerView,"setAutoresizingMask:",CPViewWidthSizable|CPViewHeightSizable);
 43_brightnessSlider=objj_msgSend(objj_msgSend(CPSlider,"alloc"),"initWithFrame:",CGRectMake(0,(aFrame.size.height-34),aFrame.size.width,15));
 44objj_msgSend(_brightnessSlider,"setValue:forThemeAttribute:",15,"track-width");
 45objj_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");
 46objj_msgSend(_brightnessSlider,"setMinValue:",0);
 47objj_msgSend(_brightnessSlider,"setMaxValue:",100);
 48objj_msgSend(_brightnessSlider,"setFloatValue:",100);
 49objj_msgSend(_brightnessSlider,"setTarget:",_15);
 50objj_msgSend(_brightnessSlider,"setAction:",sel_getUid("brightnessSliderDidChange:"));
 51objj_msgSend(_brightnessSlider,"setAutoresizingMask:",CPViewWidthSizable|CPViewMinYMargin);
 52_hueSaturationView=objj_msgSend(objj_msgSend(__CPColorWheel,"alloc"),"initWithFrame:",CPRectMake(0,0,aFrame.size.width,aFrame.size.height-38));
 53objj_msgSend(_hueSaturationView,"setDelegate:",_15);
 54objj_msgSend(_hueSaturationView,"setAutoresizingMask:",(CPViewWidthSizable|CPViewHeightSizable));
 55objj_msgSend(_pickerView,"addSubview:",_hueSaturationView);
 56objj_msgSend(_pickerView,"addSubview:",_brightnessSlider);
 57}
 58}),new objj_method(sel_getUid("brightnessSliderDidChange:"),function(_17,_18,_19){
 59with(_17){
 60objj_msgSend(_17,"updateColor");
 61}
 62}),new objj_method(sel_getUid("colorWheelDidChange:"),function(_1a,_1b,_1c){
 63with(_1a){
 64objj_msgSend(_1a,"updateColor");
 65}
 66}),new objj_method(sel_getUid("updateColor"),function(_1d,_1e){
 67with(_1d){
 68var hue=objj_msgSend(_hueSaturationView,"angle"),_20=objj_msgSend(_hueSaturationView,"distance"),_21=objj_msgSend(_brightnessSlider,"floatValue");
 69objj_msgSend(_hueSaturationView,"setWheelBrightness:",_21/100);
 70objj_msgSend(_brightnessSlider,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithHue:saturation:brightness:",hue,_20,100));
 71var _22=objj_msgSend(_1d,"colorPanel"),_23=objj_msgSend(_22,"opacity");
 72_cachedColor=objj_msgSend(CPColor,"colorWithHue:saturation:brightness:alpha:",hue,_20,_21,_23);
 73objj_msgSend(objj_msgSend(_1d,"colorPanel"),"setColor:",_cachedColor);
 74}
 75}),new objj_method(sel_getUid("supportsMode:"),function(_24,_25,_26){
 76with(_24){
 77return (_26==CPWheelColorPickerMode)?YES:NO;
 78}
 79}),new objj_method(sel_getUid("currentMode"),function(_27,_28){
 80with(_27){
 81return CPWheelColorPickerMode;
 82}
 83}),new objj_method(sel_getUid("provideNewView:"),function(_29,_2a,_2b){
 84with(_29){
 85if(_2b){
 86objj_msgSend(_29,"initView");
 87}
 88return _pickerView;
 89}
 90}),new objj_method(sel_getUid("setColor:"),function(_2c,_2d,_2e){
 91with(_2c){
 92if(objj_msgSend(_2e,"isEqual:",_cachedColor)){
 93return;
 94}
 95var hsb=objj_msgSend(_2e,"hsbComponents");
 96objj_msgSend(_hueSaturationView,"setPositionToColor:",_2e);
 97objj_msgSend(_brightnessSlider,"setFloatValue:",hsb[2]);
 98objj_msgSend(_hueSaturationView,"setWheelBrightness:",hsb[2]/100);
 99objj_msgSend(_brightnessSlider,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithHue:saturation:brightness:",hsb[0],hsb[1],100));
100}
101}),new objj_method(sel_getUid("provideNewButtonImage"),function(_30,_31){
102with(_30){
103return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_button.png"),CGSizeMake(32,32));
104}
105}),new objj_method(sel_getUid("provideNewAlternateButtonImage"),function(_32,_33){
106with(_32){
107return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_button_h.png"),CGSizeMake(32,32));
108}
109})]);
110var _1=objj_allocateClassPair(CPView,"__CPColorWheel"),_2=_1.isa;
111class_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")]);
112objj_registerClassPair(_1);
113objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
114class_addMethods(_1,[new objj_method(sel_getUid("initWithFrame:"),function(_34,_35,_36){
115with(_34){
116_34=objj_msgSendSuper({receiver:_34,super_class:objj_getClass("CPView")},"initWithFrame:",_36);
117var _37=objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel.png");
118_wheelImage=new Image();
119_wheelImage.src=_37;
120_wheelImage.style.position="absolute";
121_37=objj_msgSend(objj_msgSend(CPBundle,"bundleForClass:",CPColorPicker),"pathForResource:","wheel_black.png");
122_blackWheelImage=new Image();
123_blackWheelImage.src=_37;
124_blackWheelImage.style.opacity="0";
125_blackWheelImage.style.filter="alpha(opacity=0)";
126_blackWheelImage.style.position="absolute";
127_DOMElement.appendChild(_wheelImage);
128_DOMElement.appendChild(_blackWheelImage);
129objj_msgSend(_34,"setWheelSize:",_36.size);
130_crosshair=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CPRectMake(_radius-2,_radius-2,4,4));
131objj_msgSend(_crosshair,"setBackgroundColor:",objj_msgSend(CPColor,"blackColor"));
132var _38=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectInset(objj_msgSend(_crosshair,"bounds"),1,1));
133objj_msgSend(_38,"setBackgroundColor:",objj_msgSend(CPColor,"whiteColor"));
134objj_msgSend(_crosshair,"addSubview:",_38);
135objj_msgSend(_34,"addSubview:",_crosshair);
136return _34;
137}
138}),new objj_method(sel_getUid("setWheelBrightness:"),function(_39,_3a,_3b){
139with(_39){
140_blackWheelImage.style.opacity=1-_3b;
141_blackWheelImage.style.filter="alpha(opacity="+(1-_3b)*100+")";
142}
143}),new objj_method(sel_getUid("setFrameSize:"),function(_3c,_3d,_3e){
144with(_3c){
145objj_msgSendSuper({receiver:_3c,super_class:objj_getClass("CPView")},"setFrameSize:",_3e);
146objj_msgSend(_3c,"setWheelSize:",_3e);
147}
148}),new objj_method(sel_getUid("setWheelSize:"),function(_3f,_40,_41){
149with(_3f){
150var min=MIN(_41.width,_41.height);
151_blackWheelImage.style.width=min;
152_blackWheelImage.style.height=min;
153_blackWheelImage.width=min;
154_blackWheelImage.height=min;
155_blackWheelImage.style.top=(_41.height-min)/2+"px";
156_blackWheelImage.style.left=(_41.width-min)/2+"px";
157_wheelImage.style.width=min;
158_wheelImage.style.height=min;
159_wheelImage.width=min;
160_wheelImage.height=min;
161_wheelImage.style.top=(_41.height-min)/2+"px";
162_wheelImage.style.left=(_41.width-min)/2+"px";
163_radius=min/2;
164objj_msgSend(_3f,"setAngle:distance:",objj_msgSend(_3f,"degreesToRadians:",_angle),(_distance/100)*_radius);
165}
166}),new objj_method(sel_getUid("setDelegate:"),function(_43,_44,_45){
167with(_43){
168_delegate=_45;
169}
170}),new objj_method(sel_getUid("delegate"),function(_46,_47){
171with(_46){
172return _delegate;
173}
174}),new objj_method(sel_getUid("angle"),function(_48,_49){
175with(_48){
176return _angle;
177}
178}),new objj_method(sel_getUid("distance"),function(_4a,_4b){
179with(_4a){
180return _distance;
181}
182}),new objj_method(sel_getUid("mouseDown:"),function(_4c,_4d,_4e){
183with(_4c){
184objj_msgSend(_4c,"reposition:",_4e);
185}
186}),new objj_method(sel_getUid("mouseDragged:"),function(_4f,_50,_51){
187with(_4f){
188objj_msgSend(_4f,"reposition:",_51);
189}
190}),new objj_method(sel_getUid("reposition:"),function(_52,_53,_54){
191with(_52){
192var _55=objj_msgSend(_52,"bounds"),_56=objj_msgSend(_52,"convertPoint:fromView:",objj_msgSend(_54,"locationInWindow"),nil);
193var _57=CGRectGetMidX(_55);
194var _58=CGRectGetMidY(_55);
195var _59=MIN(SQRT((_56.x-_57)*(_56.x-_57)+(_56.y-_58)*(_56.y-_58)),_radius);
196var _5a=ATAN2(_56.y-_58,_56.x-_57);
197objj_msgSend(_52,"setAngle:distance:",_5a,_59);
198objj_msgSend(_delegate,"colorWheelDidChange:",_52);
199}
200}),new objj_method(sel_getUid("setAngle:distance:"),function(_5b,_5c,_5d,_5e){
201with(_5b){
202var _5f=objj_msgSend(_5b,"bounds");
203var _60=CGRectGetMidX(_5f);
204var _61=CGRectGetMidY(_5f);
205_angle=objj_msgSend(_5b,"radiansToDegrees:",_5d);
206_distance=(_5e/_radius)*100;
207objj_msgSend(_crosshair,"setFrameOrigin:",CPPointMake(COS(_5d)*_5e+_60-2,SIN(_5d)*_5e+_61-2));
208}
209}),new objj_method(sel_getUid("setPositionToColor:"),function(_62,_63,_64){
210with(_62){
211var hsb=objj_msgSend(_64,"hsbComponents"),_66=objj_msgSend(_62,"bounds");
212var _67=objj_msgSend(_62,"degreesToRadians:",hsb[0]),_68=(hsb[1]/100)*_radius;
213objj_msgSend(_62,"setAngle:distance:",_67,_68);
214}
215}),new objj_method(sel_getUid("radiansToDegrees:"),function(_69,_6a,_6b){
216with(_69){
217return ((-_6b/PI)*180+360)%360;
218}
219}),new objj_method(sel_getUid("degreesToRadians:"),function(_6c,_6d,_6e){
220with(_6c){
221return -(((_6e-360)/180)*PI);
222}
223})]);