PageRenderTime 37ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/Frameworks/AppKit/browser.platform/CPColorPanel.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 366 lines | 366 code | 0 blank | 0 comment | 0 complexity | 58bd868c0eae64b03eeac7186f647c1f MD5 | raw file
  1i;10;CPButton.ji;10;CPCookie.ji;9;CPPanel.ji;8;CPView.jc;16235;
  2CPColorPanelColorDidChangeNotification="CPColorPanelColorDidChangeNotification";
  3var _1=20,_2=32,_3=14,_4=32,_5=12;
  4var _6=nil,_7=[];
  5CPWheelColorPickerMode=1;
  6CPSliderColorPickerMode=2;
  7CPColorPickerViewWidth=265,CPColorPickerViewHeight=370;
  8var _8=objj_allocateClassPair(CPPanel,"CPColorPanel"),_9=_8.isa;
  9class_addIvars(_8,[new objj_ivar("_toolbar"),new objj_ivar("_swatchView"),new objj_ivar("_previewView"),new objj_ivar("_opacitySlider"),new objj_ivar("_colorPickers"),new objj_ivar("_currentView"),new objj_ivar("_activePicker"),new objj_ivar("_color"),new objj_ivar("_target"),new objj_ivar("_action"),new objj_ivar("_mode")]);
 10objj_registerClassPair(_8);
 11objj_addClassForBundle(_8,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 12class_addMethods(_8,[new objj_method(sel_getUid("init"),function(_a,_b){
 13with(_a){
 14_a=objj_msgSendSuper({receiver:_a,super_class:objj_getClass("CPPanel")},"initWithContentRect:styleMask:",CGRectMake(500,50,219,370),(CPTitledWindowMask|CPClosableWindowMask|CPResizableWindowMask));
 15if(_a){
 16objj_msgSend(objj_msgSend(_a,"contentView"),"setBackgroundColor:",objj_msgSend(CPColor,"colorWithWhite:alpha:",0.95,1));
 17objj_msgSend(_a,"setTitle:","Color Panel");
 18objj_msgSend(_a,"setLevel:",CPFloatingWindowLevel);
 19objj_msgSend(_a,"setFloatingPanel:",YES);
 20objj_msgSend(_a,"setBecomesKeyOnlyIfNeeded:",YES);
 21objj_msgSend(_a,"setMinSize:",CGSizeMake(219,342));
 22objj_msgSend(_a,"setMaxSize:",CGSizeMake(323,537));
 23}
 24return _a;
 25}
 26}),new objj_method(sel_getUid("setColor:"),function(_c,_d,_e){
 27with(_c){
 28_color=_e;
 29objj_msgSend(_previewView,"setBackgroundColor:",_color);
 30objj_msgSend(CPApp,"sendAction:to:from:",sel_getUid("changeColor:"),nil,_c);
 31if(_target&&_action){
 32objj_msgSend(CPApp,"sendAction:to:from:",_action,_target,_c);
 33}
 34objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPColorPanelColorDidChangeNotification,_c);
 35objj_msgSend(_activePicker,"setColor:",_color);
 36objj_msgSend(_opacitySlider,"setFloatValue:",objj_msgSend(_color,"alphaComponent"));
 37}
 38}),new objj_method(sel_getUid("setColor:updatePicker:"),function(_f,_10,_11,_12){
 39with(_f){
 40objj_msgSend(_f,"setColor:",_11);
 41if(_12){
 42objj_msgSend(_activePicker,"setColor:",_color);
 43}
 44}
 45}),new objj_method(sel_getUid("color"),function(_13,_14){
 46with(_13){
 47return _color;
 48}
 49}),new objj_method(sel_getUid("opacity"),function(_15,_16){
 50with(_15){
 51return objj_msgSend(_opacitySlider,"floatValue");
 52}
 53}),new objj_method(sel_getUid("setTarget:"),function(_17,_18,_19){
 54with(_17){
 55_target=_19;
 56}
 57}),new objj_method(sel_getUid("target"),function(_1a,_1b){
 58with(_1a){
 59return _target;
 60}
 61}),new objj_method(sel_getUid("setAction:"),function(_1c,_1d,_1e){
 62with(_1c){
 63_action=_1e;
 64}
 65}),new objj_method(sel_getUid("action"),function(_1f,_20){
 66with(_1f){
 67return _action;
 68}
 69}),new objj_method(sel_getUid("setMode:"),function(_21,_22,_23){
 70with(_21){
 71_mode=_23;
 72}
 73}),new objj_method(sel_getUid("_setPicker:"),function(_24,_25,_26){
 74with(_24){
 75var _27=_colorPickers[objj_msgSend(_26,"tag")],_28=objj_msgSend(_27,"provideNewView:",NO);
 76if(!_28){
 77_28=objj_msgSend(_27,"provideNewView:",YES);
 78}
 79if(_28==_currentView){
 80return;
 81}
 82if(_currentView){
 83objj_msgSend(_28,"setFrame:",objj_msgSend(_currentView,"frame"));
 84}else{
 85var _29=(_2+10+_1+5+_3+32),_2a=objj_msgSend(objj_msgSend(_24,"contentView"),"bounds");
 86objj_msgSend(_28,"setFrameSize:",CPSizeMake(_2a.size.width-10,_2a.size.height-_29));
 87objj_msgSend(_28,"setFrameOrigin:",CPPointMake(5,_29));
 88}
 89objj_msgSend(_currentView,"removeFromSuperview");
 90objj_msgSend(objj_msgSend(_24,"contentView"),"addSubview:",_28);
 91_currentView=_28;
 92_activePicker=_27;
 93objj_msgSend(_27,"setColor:",objj_msgSend(_24,"color"));
 94}
 95}),new objj_method(sel_getUid("mode"),function(_2b,_2c){
 96with(_2b){
 97return _mode;
 98}
 99}),new objj_method(sel_getUid("orderFront:"),function(_2d,_2e,_2f){
100with(_2d){
101objj_msgSend(_2d,"_loadContentsIfNecessary");
102objj_msgSendSuper({receiver:_2d,super_class:objj_getClass("CPPanel")},"orderFront:",_2f);
103}
104}),new objj_method(sel_getUid("_loadContentsIfNecessary"),function(_30,_31){
105with(_30){
106if(_toolbar){
107return;
108}
109if(!_color){
110_color=objj_msgSend(CPColor,"whiteColor");
111}
112_colorPickers=[];
113var _32=objj_msgSend(_7,"count");
114for(var i=0;i<_32;i++){
115var _34=_7[i],_35=objj_msgSend(objj_msgSend(_34,"alloc"),"initWithPickerMask:colorPanel:",0,_30);
116_colorPickers.push(_35);
117}
118var _36=objj_msgSend(_30,"contentView"),_37=objj_msgSend(_36,"bounds");
119_toolbar=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectMake(0,6,CGRectGetWidth(_37),_2));
120objj_msgSend(_toolbar,"setAutoresizingMask:",CPViewWidthSizable);
121var _38=_32*_4+(_32-1)*_5,_39=(CGRectGetWidth(_37)-_38)/2,_3a=nil;
122for(var i=0;i<_32;i++){
123var _3b=objj_msgSend(_colorPickers[i],"provideNewButtonImage"),_3c=objj_msgSend(_colorPickers[i],"provideNewAlternateButtonImage"),_3d=objj_msgSend(objj_msgSend(CPButton,"alloc"),"initWithFrame:",CGRectMake(_39+i*(_4+_5),0,_4,_4));
124objj_msgSend(_3d,"setTag:",i);
125objj_msgSend(_3d,"setTarget:",_30);
126objj_msgSend(_3d,"setAction:",sel_getUid("_setPicker:"));
127objj_msgSend(_3d,"setBordered:",NO);
128objj_msgSend(_3d,"setAutoresizingMask:",CPViewMinXMargin|CPViewMaxXMargin);
129objj_msgSend(_3d,"setImage:",_3b);
130objj_msgSend(_3d,"setAlternateImage:",_3c);
131objj_msgSend(_toolbar,"addSubview:",_3d);
132if(!_3a){
133_3a=_3d;
134}
135}
136var _3e=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectMake(76,_2+10,CGRectGetWidth(_37)-86,_1));
137_previewView=objj_msgSend(objj_msgSend(_CPColorPanelPreview,"alloc"),"initWithFrame:",CGRectInset(objj_msgSend(_3e,"bounds"),2,2));
138objj_msgSend(_previewView,"setColorPanel:",_30);
139objj_msgSend(_previewView,"setAutoresizingMask:",CPViewWidthSizable);
140objj_msgSend(_3e,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithWhite:alpha:",0.8,1));
141objj_msgSend(_3e,"setAutoresizingMask:",CPViewWidthSizable);
142objj_msgSend(_3e,"addSubview:",_previewView);
143var _3f=objj_msgSend(objj_msgSend(CPTextField,"alloc"),"initWithFrame:",CPRectMake(10,_2+10,60,15));
144objj_msgSend(_3f,"setStringValue:","Preview:");
145objj_msgSend(_3f,"setTextColor:",objj_msgSend(CPColor,"blackColor"));
146objj_msgSend(_3f,"setAlignment:",CPRightTextAlignment);
147var _40=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectMake(76,_2+10+_1+5,CGRectGetWidth(_37)-86,_3+2));
148objj_msgSend(_40,"setBackgroundColor:",objj_msgSend(CPColor,"colorWithWhite:alpha:",0.8,1));
149objj_msgSend(_40,"setAutoresizingMask:",CPViewWidthSizable);
150_swatchView=objj_msgSend(objj_msgSend(_CPColorPanelSwatches,"alloc"),"initWithFrame:",CGRectInset(objj_msgSend(_40,"bounds"),1,1));
151objj_msgSend(_swatchView,"setColorPanel:",_30);
152objj_msgSend(_swatchView,"setAutoresizingMask:",CPViewWidthSizable);
153objj_msgSend(_40,"addSubview:",_swatchView);
154var _41=objj_msgSend(objj_msgSend(CPTextField,"alloc"),"initWithFrame:",CPRectMake(10,_2+8+_1+6,60,15));
155objj_msgSend(_41,"setStringValue:","Swatches:");
156objj_msgSend(_41,"setTextColor:",objj_msgSend(CPColor,"blackColor"));
157objj_msgSend(_41,"setAlignment:",CPRightTextAlignment);
158var _42=objj_msgSend(objj_msgSend(CPTextField,"alloc"),"initWithFrame:",CPRectMake(10,_2+_1+35,60,20));
159objj_msgSend(_42,"setStringValue:","Opacity:");
160objj_msgSend(_42,"setTextColor:",objj_msgSend(CPColor,"blackColor"));
161objj_msgSend(_42,"setAlignment:",CPRightTextAlignment);
162_opacitySlider=objj_msgSend(objj_msgSend(CPSlider,"alloc"),"initWithFrame:",CGRectMake(76,_2+_1+34,CGRectGetWidth(_37)-86,20));
163objj_msgSend(_opacitySlider,"setMinValue:",0);
164objj_msgSend(_opacitySlider,"setMaxValue:",1);
165objj_msgSend(_opacitySlider,"setTarget:",_30);
166objj_msgSend(_opacitySlider,"setAction:",sel_getUid("setOpacity:"));
167objj_msgSend(_36,"addSubview:",_toolbar);
168objj_msgSend(_36,"addSubview:",_3e);
169objj_msgSend(_36,"addSubview:",_3f);
170objj_msgSend(_36,"addSubview:",_40);
171objj_msgSend(_36,"addSubview:",_41);
172objj_msgSend(_36,"addSubview:",_42);
173objj_msgSend(_36,"addSubview:",_opacitySlider);
174_target=nil;
175_action=nil;
176_activePicker=nil;
177objj_msgSend(_previewView,"setBackgroundColor:",_color);
178if(_3a){
179objj_msgSend(_30,"_setPicker:",_3a);
180}
181}
182}),new objj_method(sel_getUid("setOpacity:"),function(_43,_44,_45){
183with(_43){
184var _46=objj_msgSend(objj_msgSend(_43,"color"),"components"),_47=objj_msgSend(_45,"floatValue");
185objj_msgSend(_43,"setColor:updatePicker:",objj_msgSend(_color,"colorWithAlphaComponent:",_47),YES);
186}
187})]);
188class_addMethods(_9,[new objj_method(sel_getUid("provideColorPickerClass:"),function(_48,_49,_4a){
189with(_48){
190_7.push(_4a);
191}
192}),new objj_method(sel_getUid("sharedColorPanel"),function(_4b,_4c){
193with(_4b){
194if(!_6){
195_6=objj_msgSend(objj_msgSend(CPColorPanel,"alloc"),"init");
196}
197return _6;
198}
199}),new objj_method(sel_getUid("setPickerMode:"),function(_4d,_4e,_4f){
200with(_4d){
201var _50=objj_msgSend(CPColorPanel,"sharedColorPanel");
202objj_msgSend(_50,"setMode:",_4f);
203}
204})]);
205CPColorDragType="CPColorDragType";
206var _51="CPColorPanelSwatchesCookie";
207var _8=objj_allocateClassPair(CPView,"_CPColorPanelSwatches"),_9=_8.isa;
208class_addIvars(_8,[new objj_ivar("_swatches"),new objj_ivar("_dragColor"),new objj_ivar("_colorPanel"),new objj_ivar("_swatchCookie")]);
209objj_registerClassPair(_8);
210objj_addClassForBundle(_8,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
211class_addMethods(_8,[new objj_method(sel_getUid("initWithFrame:"),function(_52,_53,_54){
212with(_52){
213_52=objj_msgSendSuper({receiver:_52,super_class:objj_getClass("CPView")},"initWithFrame:",_54);
214objj_msgSend(_52,"setBackgroundColor:",objj_msgSend(CPColor,"grayColor"));
215objj_msgSend(_52,"registerForDraggedTypes:",objj_msgSend(CPArray,"arrayWithObjects:",CPColorDragType));
216var _55=objj_msgSend(CPColor,"whiteColor");
217_swatchCookie=objj_msgSend(objj_msgSend(CPCookie,"alloc"),"initWithName:",_51);
218var _56=objj_msgSend(_52,"startingColorList");
219_swatches=[];
220for(var i=0;i<50;i++){
221var _58=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CPRectMake(13*i+1,1,12,12)),_59=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectInset(objj_msgSend(_58,"bounds"),1,1));
222objj_msgSend(_58,"setBackgroundColor:",_55);
223objj_msgSend(_59,"setBackgroundColor:",(i<_56.length)?_56[i]:_55);
224objj_msgSend(_58,"addSubview:",_59);
225objj_msgSend(_52,"addSubview:",_58);
226_swatches.push(_58);
227}
228return _52;
229}
230}),new objj_method(sel_getUid("isOpaque"),function(_5a,_5b){
231with(_5a){
232return YES;
233}
234}),new objj_method(sel_getUid("startingColorList"),function(_5c,_5d){
235with(_5c){
236var _5e=objj_msgSend(_swatchCookie,"value");
237if(_5e==""){
238return [objj_msgSend(CPColor,"blackColor"),objj_msgSend(CPColor,"darkGrayColor"),objj_msgSend(CPColor,"grayColor"),objj_msgSend(CPColor,"lightGrayColor"),objj_msgSend(CPColor,"whiteColor"),objj_msgSend(CPColor,"redColor"),objj_msgSend(CPColor,"greenColor"),objj_msgSend(CPColor,"blueColor"),objj_msgSend(CPColor,"yellowColor")];
239}
240var _5e=eval(_5e);
241var _5f=[];
242for(var i=0;i<_5e.length;i++){
243_5f.push(objj_msgSend(CPColor,"colorWithHexString:",_5e[i]));
244}
245return _5f;
246}
247}),new objj_method(sel_getUid("saveColorList"),function(_61,_62){
248with(_61){
249var _63=[];
250for(var i=0;i<_swatches.length;i++){
251_63.push(objj_msgSend(objj_msgSend(objj_msgSend(_swatches[i],"subviews")[0],"backgroundColor"),"hexString"));
252}
253var _65=new Date();
254_65.setYear(2019);
255objj_msgSend(_swatchCookie,"setValue:expires:domain:",CPJSObjectCreateJSON(_63),_65,nil);
256}
257}),new objj_method(sel_getUid("setColorPanel:"),function(_66,_67,_68){
258with(_66){
259_colorPanel=_68;
260}
261}),new objj_method(sel_getUid("colorPanel"),function(_69,_6a){
262with(_69){
263return _colorPanel;
264}
265}),new objj_method(sel_getUid("colorAtIndex:"),function(_6b,_6c,_6d){
266with(_6b){
267return objj_msgSend(objj_msgSend(_swatches[_6d],"subviews")[0],"backgroundColor");
268}
269}),new objj_method(sel_getUid("setColor:atIndex:"),function(_6e,_6f,_70,_71){
270with(_6e){
271objj_msgSend(objj_msgSend(_swatches[_71],"subviews")[0],"setBackgroundColor:",_70);
272objj_msgSend(_6e,"saveColorList");
273}
274}),new objj_method(sel_getUid("mouseUp:"),function(_72,_73,_74){
275with(_72){
276var _75=objj_msgSend(_72,"convertPoint:fromView:",objj_msgSend(_74,"locationInWindow"),nil);
277if(_75.x>objj_msgSend(_72,"bounds").size.width-1||_75.x<1){
278return NO;
279}
280objj_msgSend(_colorPanel,"setColor:updatePicker:",objj_msgSend(_72,"colorAtIndex:",FLOOR(_75.x/13)),YES);
281}
282}),new objj_method(sel_getUid("mouseDragged:"),function(_76,_77,_78){
283with(_76){
284var _79=objj_msgSend(_76,"convertPoint:fromView:",objj_msgSend(_78,"locationInWindow"),nil);
285if(_79.x>objj_msgSend(_76,"bounds").size.width-1||_79.x<1){
286return NO;
287}
288objj_msgSend(objj_msgSend(CPPasteboard,"pasteboardWithName:",CPDragPboard),"declareTypes:owner:",objj_msgSend(CPArray,"arrayWithObject:",CPColorDragType),_76);
289var _7a=_swatches[FLOOR(_79.x/13)];
290_dragColor=objj_msgSend(objj_msgSend(_7a,"subviews")[0],"backgroundColor");
291var _7b=CPRectCreateCopy(objj_msgSend(_7a,"bounds"));
292var _7c=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",_7b);
293dragFillView=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectInset(_7b,1,1));
294objj_msgSend(_7c,"setBackgroundColor:",objj_msgSend(CPColor,"blackColor"));
295objj_msgSend(dragFillView,"setBackgroundColor:",_dragColor);
296objj_msgSend(_7c,"addSubview:",dragFillView);
297objj_msgSend(_76,"dragView:at:offset:event:pasteboard:source:slideBack:",_7c,CPPointMake(_79.x-_7b.size.width/2,_79.y-_7b.size.height/2),CPPointMake(0,0),_78,nil,_76,YES);
298}
299}),new objj_method(sel_getUid("pasteboard:provideDataForType:"),function(_7d,_7e,_7f,_80){
300with(_7d){
301if(_80==CPColorDragType){
302objj_msgSend(_7f,"setData:forType:",_dragColor,_80);
303}
304}
305}),new objj_method(sel_getUid("performDragOperation:"),function(_81,_82,_83){
306with(_81){
307var _84=objj_msgSend(_81,"convertPoint:fromView:",objj_msgSend(_83,"draggingLocation"),nil),_85=objj_msgSend(_83,"draggingPasteboard"),_86=nil;
308if(!objj_msgSend(_85,"availableTypeFromArray:",[CPColorDragType])||_84.x>objj_msgSend(_81,"bounds").size.width-1||_84.x<1){
309return NO;
310}
311objj_msgSend(_81,"setColor:atIndex:",objj_msgSend(_85,"dataForType:",CPColorDragType),FLOOR(_84.x/13));
312}
313})]);
314var _8=objj_allocateClassPair(CPView,"_CPColorPanelPreview"),_9=_8.isa;
315class_addIvars(_8,[new objj_ivar("_colorPanel")]);
316objj_registerClassPair(_8);
317objj_addClassForBundle(_8,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
318class_addMethods(_8,[new objj_method(sel_getUid("initWithFrame:"),function(_87,_88,_89){
319with(_87){
320_87=objj_msgSendSuper({receiver:_87,super_class:objj_getClass("CPView")},"initWithFrame:",_89);
321objj_msgSend(_87,"registerForDraggedTypes:",objj_msgSend(CPArray,"arrayWithObjects:",CPColorDragType));
322return _87;
323}
324}),new objj_method(sel_getUid("setColorPanel:"),function(_8a,_8b,_8c){
325with(_8a){
326_colorPanel=_8c;
327}
328}),new objj_method(sel_getUid("colorPanel"),function(_8d,_8e){
329with(_8d){
330return _colorPanel;
331}
332}),new objj_method(sel_getUid("performDragOperation:"),function(_8f,_90,_91){
333with(_8f){
334var _92=objj_msgSend(_91,"draggingPasteboard");
335if(!objj_msgSend(_92,"availableTypeFromArray:",[CPColorDragType])){
336return NO;
337}
338var _93=objj_msgSend(_92,"dataForType:",CPColorDragType);
339objj_msgSend(_colorPanel,"setColor:updatePicker:",_93,YES);
340}
341}),new objj_method(sel_getUid("isOpaque"),function(_94,_95){
342with(_94){
343return YES;
344}
345}),new objj_method(sel_getUid("mouseDragged:"),function(_96,_97,_98){
346with(_96){
347var _99=objj_msgSend(_96,"convertPoint:fromView:",objj_msgSend(_98,"locationInWindow"),nil);
348objj_msgSend(objj_msgSend(CPPasteboard,"pasteboardWithName:",CPDragPboard),"declareTypes:owner:",objj_msgSend(CPArray,"arrayWithObject:",CPColorDragType),_96);
349var _9a=CPRectMake(0,0,15,15);
350var _9b=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",_9a);
351dragFillView=objj_msgSend(objj_msgSend(CPView,"alloc"),"initWithFrame:",CGRectInset(_9a,1,1));
352objj_msgSend(_9b,"setBackgroundColor:",objj_msgSend(CPColor,"blackColor"));
353objj_msgSend(dragFillView,"setBackgroundColor:",objj_msgSend(_96,"backgroundColor"));
354objj_msgSend(_9b,"addSubview:",dragFillView);
355objj_msgSend(_96,"dragView:at:offset:event:pasteboard:source:slideBack:",_9b,CPPointMake(_99.x-_9a.size.width/2,_99.y-_9a.size.height/2),CPPointMake(0,0),_98,nil,_96,YES);
356}
357}),new objj_method(sel_getUid("pasteboard:provideDataForType:"),function(_9c,_9d,_9e,_9f){
358with(_9c){
359if(_9f==CPColorDragType){
360objj_msgSend(_9e,"setData:forType:",objj_msgSend(_9c,"backgroundColor"),_9f);
361}
362}
363})]);
364i;15;CPColorPicker.ji;21;CPSliderColorPicker.jc;155;
365objj_msgSend(CPColorPanel,"provideColorPickerClass:",CPColorWheelColorPicker);
366objj_msgSend(CPColorPanel,"provideColorPickerClass:",CPSliderColorPicker);