/Frameworks/AppKit/rhino.platform/CPImage.j

http://github.com/polymar/polish · Unknown · 284 lines · 284 code · 0 blank · 0 comment · 0 complexity · d1b9d868f1a668d74df888e95528be09 MD5 · raw file

  1. I;21;Foundation/CPBundle.jI;33;Foundation/CPNotificationCenter.jI;21;Foundation/CPObject.jI;22;Foundation/CPRunLoop.jI;21;Foundation/CPString.ji;12;CPGeometry.jc;8936;
  2. CPImageLoadStatusInitialized=0;
  3. CPImageLoadStatusLoading=1;
  4. CPImageLoadStatusCompleted=2;
  5. CPImageLoadStatusCancelled=3;
  6. CPImageLoadStatusInvalidData=4;
  7. CPImageLoadStatusUnexpectedEOF=5;
  8. CPImageLoadStatusReadError=6;
  9. CPImageDidLoadNotification="CPImageDidLoadNotification";
  10. CPImageInBundle=function(_1,_2,_3){
  11. if(!_3){
  12. _3=objj_msgSend(CPBundle,"mainBundle");
  13. }
  14. if(_2){
  15. return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(_3,"pathForResource:",_1),_2);
  16. }
  17. return objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:",objj_msgSend(_3,"pathForResource:",_1));
  18. };
  19. var _4=objj_getClass("CPBundle");
  20. if(!_4){
  21. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPBundle\""));
  22. }
  23. var _5=_4.isa;
  24. class_addMethods(_4,[new objj_method(sel_getUid("pathForResource:"),function(_6,_7,_8){
  25. with(_6){
  26. return objj_msgSend(_6,"resourcePath")+"/"+_8;
  27. }
  28. })]);
  29. var _4=objj_allocateClassPair(CPObject,"CPImage"),_5=_4.isa;
  30. class_addIvars(_4,[new objj_ivar("_size"),new objj_ivar("_filename"),new objj_ivar("_delegate"),new objj_ivar("_loadStatus"),new objj_ivar("_image")]);
  31. objj_registerClassPair(_4);
  32. objj_addClassForBundle(_4,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  33. class_addMethods(_4,[new objj_method(sel_getUid("initByReferencingFile:size:"),function(_9,_a,_b,_c){
  34. with(_9){
  35. _9=objj_msgSendSuper({receiver:_9,super_class:objj_getClass("CPObject")},"init");
  36. if(_9){
  37. _size=CPSizeCreateCopy(_c);
  38. _filename=_b;
  39. _loadStatus=CPImageLoadStatusInitialized;
  40. }
  41. return _9;
  42. }
  43. }),new objj_method(sel_getUid("initWithContentsOfFile:size:"),function(_d,_e,_f,_10){
  44. with(_d){
  45. _d=objj_msgSend(_d,"initByReferencingFile:size:",_f,_10);
  46. if(_d){
  47. objj_msgSend(_d,"load");
  48. }
  49. return _d;
  50. }
  51. }),new objj_method(sel_getUid("initWithContentsOfFile:"),function(_11,_12,_13){
  52. with(_11){
  53. _11=objj_msgSend(_11,"initByReferencingFile:size:",_13,CGSizeMake(-1,-1));
  54. if(_11){
  55. objj_msgSend(_11,"load");
  56. }
  57. return _11;
  58. }
  59. }),new objj_method(sel_getUid("filename"),function(_14,_15){
  60. with(_14){
  61. return _filename;
  62. }
  63. }),new objj_method(sel_getUid("setSize:"),function(_16,_17,_18){
  64. with(_16){
  65. _size=CGSizeMakeCopy(_18);
  66. }
  67. }),new objj_method(sel_getUid("size"),function(_19,_1a){
  68. with(_19){
  69. return _size;
  70. }
  71. }),new objj_method(sel_getUid("setDelegate:"),function(_1b,_1c,_1d){
  72. with(_1b){
  73. _delegate=_1d;
  74. }
  75. }),new objj_method(sel_getUid("delegate"),function(_1e,_1f){
  76. with(_1e){
  77. return _delegate;
  78. }
  79. }),new objj_method(sel_getUid("loadStatus"),function(_20,_21){
  80. with(_20){
  81. return _loadStatus;
  82. }
  83. }),new objj_method(sel_getUid("load"),function(_22,_23){
  84. with(_22){
  85. if(_loadStatus==CPImageLoadStatusLoading||_loadStatus==CPImageLoadStatusCompleted){
  86. return;
  87. }
  88. _loadStatus=CPImageLoadStatusLoading;
  89. _image=new Image();
  90. var _24=YES;
  91. _image.onload=function(){
  92. if(_24){
  93. window.setTimeout(function(){
  94. objj_msgSend(_22,"_imageDidLoad");
  95. },0);
  96. }else{
  97. objj_msgSend(_22,"_imageDidLoad");
  98. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"limitDateForMode:",CPDefaultRunLoopMode);
  99. }
  100. objj_msgSend(_22,"_derefFromImage");
  101. };
  102. _image.onerror=function(){
  103. if(_24){
  104. window.setTimeout(function(){
  105. objj_msgSend(_22,"_imageDidError");
  106. },0);
  107. }else{
  108. objj_msgSend(_22,"_imageDidError");
  109. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"limitDateForMode:",CPDefaultRunLoopMode);
  110. }
  111. objj_msgSend(_22,"_derefFromImage");
  112. };
  113. _image.onabort=function(){
  114. if(_24){
  115. window.setTimeout(function(){
  116. objj_msgSend(_22,"_imageDidAbort");
  117. },0);
  118. }else{
  119. objj_msgSend(_22,"_imageDidAbort");
  120. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"limitDateForMode:",CPDefaultRunLoopMode);
  121. }
  122. objj_msgSend(_22,"_derefFromImage");
  123. };
  124. _image.src=_filename;
  125. _24=NO;
  126. }
  127. }),new objj_method(sel_getUid("isThreePartImage"),function(_25,_26){
  128. with(_25){
  129. return NO;
  130. }
  131. }),new objj_method(sel_getUid("isNinePartImage"),function(_27,_28){
  132. with(_27){
  133. return NO;
  134. }
  135. }),new objj_method(sel_getUid("_derefFromImage"),function(_29,_2a){
  136. with(_29){
  137. _image.onload=null;
  138. _image.onerror=null;
  139. _image.onabort=null;
  140. }
  141. }),new objj_method(sel_getUid("_imageDidLoad"),function(_2b,_2c){
  142. with(_2b){
  143. _loadStatus=CPImageLoadStatusCompleted;
  144. if(!_size||(_size.width==-1&&_size.height==-1)){
  145. _size=CGSizeMake(_image.width,_image.height);
  146. }
  147. objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPImageDidLoadNotification,_2b);
  148. if(objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("imageDidLoad:"))){
  149. objj_msgSend(_delegate,"imageDidLoad:",_2b);
  150. }
  151. }
  152. }),new objj_method(sel_getUid("_imageDidError"),function(_2d,_2e){
  153. with(_2d){
  154. _loadStatus=CPImageLoadStatusReadError;
  155. if(objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("imageDidError:"))){
  156. objj_msgSend(_delegate,"imageDidError:",_2d);
  157. }
  158. }
  159. }),new objj_method(sel_getUid("_imageDidAbort"),function(_2f,_30){
  160. with(_2f){
  161. _loadStatus=CPImageLoadStatusCancelled;
  162. if(objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("imageDidAbort:"))){
  163. objj_msgSend(_delegate,"imageDidAbort:",_2f);
  164. }
  165. }
  166. })]);
  167. var _4=objj_getClass("CPImage");
  168. if(!_4){
  169. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPImage\""));
  170. }
  171. var _5=_4.isa;
  172. class_addMethods(_4,[new objj_method(sel_getUid("initWithCoder:"),function(_31,_32,_33){
  173. with(_31){
  174. return objj_msgSend(_31,"initWithContentsOfFile:size:",objj_msgSend(_33,"decodeObjectForKey:","CPFilename"),objj_msgSend(_33,"decodeSizeForKey:","CPSize"));
  175. }
  176. }),new objj_method(sel_getUid("encodeWithCoder:"),function(_34,_35,_36){
  177. with(_34){
  178. objj_msgSend(_36,"encodeObject:forKey:",_filename,"CPFilename");
  179. objj_msgSend(_36,"encodeSize:forKey:",_size,"CPSize");
  180. }
  181. })]);
  182. var _4=objj_allocateClassPair(CPObject,"CPThreePartImage"),_5=_4.isa;
  183. class_addIvars(_4,[new objj_ivar("_imageSlices"),new objj_ivar("_isVertical")]);
  184. objj_registerClassPair(_4);
  185. objj_addClassForBundle(_4,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  186. class_addMethods(_4,[new objj_method(sel_getUid("initWithImageSlices:isVertical:"),function(_37,_38,_39,_3a){
  187. with(_37){
  188. _37=objj_msgSendSuper({receiver:_37,super_class:objj_getClass("CPObject")},"init");
  189. if(_37){
  190. _imageSlices=_39;
  191. _isVertical=_3a;
  192. }
  193. return _37;
  194. }
  195. }),new objj_method(sel_getUid("filename"),function(_3b,_3c){
  196. with(_3b){
  197. return "";
  198. }
  199. }),new objj_method(sel_getUid("imageSlices"),function(_3d,_3e){
  200. with(_3d){
  201. return _imageSlices;
  202. }
  203. }),new objj_method(sel_getUid("isVertical"),function(_3f,_40){
  204. with(_3f){
  205. return _isVertical;
  206. }
  207. }),new objj_method(sel_getUid("isThreePartImage"),function(_41,_42){
  208. with(_41){
  209. return YES;
  210. }
  211. }),new objj_method(sel_getUid("isNinePartImage"),function(_43,_44){
  212. with(_43){
  213. return NO;
  214. }
  215. })]);
  216. var _45="CPThreePartImageImageSlicesKey",_46="CPThreePartImageIsVerticalKey";
  217. var _4=objj_getClass("CPThreePartImage");
  218. if(!_4){
  219. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPThreePartImage\""));
  220. }
  221. var _5=_4.isa;
  222. class_addMethods(_4,[new objj_method(sel_getUid("initWithCoder:"),function(_47,_48,_49){
  223. with(_47){
  224. _47=objj_msgSendSuper({receiver:_47,super_class:objj_getClass("CPObject")},"init");
  225. if(_47){
  226. _imageSlices=objj_msgSend(_49,"decodeObjectForKey:",_45);
  227. _isVertical=objj_msgSend(_49,"decodeBoolForKey:",_46);
  228. }
  229. return _47;
  230. }
  231. }),new objj_method(sel_getUid("encodeWithCoder:"),function(_4a,_4b,_4c){
  232. with(_4a){
  233. objj_msgSend(_4c,"encodeObject:forKey:",_imageSlices,_45);
  234. objj_msgSend(_4c,"encodeBool:forKey:",_isVertical,_46);
  235. }
  236. })]);
  237. var _4=objj_allocateClassPair(CPObject,"CPNinePartImage"),_5=_4.isa;
  238. class_addIvars(_4,[new objj_ivar("_imageSlices")]);
  239. objj_registerClassPair(_4);
  240. objj_addClassForBundle(_4,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  241. class_addMethods(_4,[new objj_method(sel_getUid("initWithImageSlices:"),function(_4d,_4e,_4f){
  242. with(_4d){
  243. _4d=objj_msgSendSuper({receiver:_4d,super_class:objj_getClass("CPObject")},"init");
  244. if(_4d){
  245. _imageSlices=_4f;
  246. }
  247. return _4d;
  248. }
  249. }),new objj_method(sel_getUid("filename"),function(_50,_51){
  250. with(_50){
  251. return "";
  252. }
  253. }),new objj_method(sel_getUid("imageSlices"),function(_52,_53){
  254. with(_52){
  255. return _imageSlices;
  256. }
  257. }),new objj_method(sel_getUid("isThreePartImage"),function(_54,_55){
  258. with(_54){
  259. return NO;
  260. }
  261. }),new objj_method(sel_getUid("isNinePartImage"),function(_56,_57){
  262. with(_56){
  263. return YES;
  264. }
  265. })]);
  266. var _58="CPNinePartImageImageSlicesKey";
  267. var _4=objj_getClass("CPNinePartImage");
  268. if(!_4){
  269. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPNinePartImage\""));
  270. }
  271. var _5=_4.isa;
  272. class_addMethods(_4,[new objj_method(sel_getUid("initWithCoder:"),function(_59,_5a,_5b){
  273. with(_59){
  274. _59=objj_msgSendSuper({receiver:_59,super_class:objj_getClass("CPObject")},"init");
  275. if(_59){
  276. _imageSlices=objj_msgSend(_5b,"decodeObjectForKey:",_58);
  277. }
  278. return _59;
  279. }
  280. }),new objj_method(sel_getUid("encodeWithCoder:"),function(_5c,_5d,_5e){
  281. with(_5c){
  282. objj_msgSend(_5e,"encodeObject:forKey:",_imageSlices,_58);
  283. }
  284. })]);