/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

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