No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

415 líneas
15 KiB

  1. <DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright (c) 2012 The Native Client Authors. All rights reserved.
  5. Use of this source code is governed by a BSD-style license that can be
  6. found in the LICENSE file.
  7. -->
  8. <head>
  9. <style type="text/css">
  10. body
  11. {
  12. font:12px Consolas;
  13. }
  14. #status_field
  15. {
  16. font:12px Consolas;
  17. }
  18. button
  19. {
  20. font:14px Consolas;
  21. }
  22. textarea
  23. {
  24. font:14px Consolas;
  25. }
  26. progress
  27. {
  28. background-color: #f3f3f3;
  29. border: 0;
  30. height: 18px;
  31. width: 200px;
  32. border-radius: 9px;
  33. }
  34. progress::-webkit-progress-bar
  35. {
  36. background-color: #f3f3f3;
  37. border: 1px solid #000000;
  38. padding: 2px 2px;
  39. height: 20px;
  40. border-radius: 0px;
  41. }
  42. progress::-webkit-progress-value
  43. {
  44. background-color: #22BB22;
  45. border: 0px;
  46. height: 14px;
  47. border-radius: 0px;
  48. }
  49. #listener
  50. {
  51. position: relative;
  52. }
  53. #progress_bar
  54. {
  55. position: absolute;
  56. top: 40%;
  57. left: 40%;
  58. z-index: 3;
  59. }
  60. #DIV_nacl_div
  61. {
  62. position: absolute;
  63. top: 2px;
  64. left: 2px;
  65. z-index: -1;
  66. }
  67. #BGCanvas
  68. {
  69. border:1px solid #000000;
  70. }
  71. #DIV_command0
  72. {
  73. margin-left: 5px;
  74. }
  75. </style>
  76. <title>Mesh Viewer NaCl</title>
  77. <script src="./TypeDictionnary.js"></script>
  78. <script type="text/javascript">
  79. var EasyMeshDict = new TypeDictionnary("EasyMesh");
  80. function GetCmdDictionnary() { return EasyMeshDict; }
  81. </script>
  82. <script src="./EasyMeshDictionnary.js"></script>
  83. <script type="text/javascript">
  84. nacl_div = null; // Global application object.
  85. nacl_module = null; // Global application object.
  86. mesh_code_module = null;
  87. code_helper_cmd = [null, null];
  88. code_helper_arg = null;
  89. code_helper_cmt = null;
  90. code_helper_var = null;
  91. code_helper_alpha = null;
  92. status_text = 'NO-STATUS';
  93. window.setTimeout("Tick()", 100);
  94. window.setTimeout("Init()", 100);
  95. function Init()
  96. {
  97. nacl_div = document.getElementById('DIV_nacl_div');
  98. mesh_code_module = document.getElementById('DIV_MeshCode');
  99. code_helper_cmd[0] = document.getElementById('DIV_command0');
  100. code_helper_cmd[1] = document.getElementById('DIV_command1');
  101. code_helper_arg = document.getElementById('DIV_args');
  102. code_helper_cmt = document.getElementById('DIV_comment');
  103. code_helper_var = document.getElementById('DIV_var_usage');
  104. code_helper_alpha = document.getElementById('DIV_alphabet');
  105. code_helper_alpha.innerHTML = '&nbsp;[';
  106. for (var a = 'a'.charCodeAt(0); a <= 'z'.charCodeAt(0); a++)
  107. {
  108. var stop = false;
  109. for (var i = 0; !stop && i < EasyMeshDict.m_cmds.length; i++)
  110. {
  111. for (var j = 0; j < EasyMeshDict.m_cmds[i].m_name.length; j++)
  112. {
  113. if (EasyMeshDict.m_cmds[i].m_name[j][0] == String.fromCharCode(a))
  114. {
  115. code_helper_alpha.innerHTML += '<b>' + String.fromCharCode(a) + '</b>';
  116. stop = true;
  117. break;
  118. }
  119. }
  120. }
  121. if (!stop)
  122. code_helper_alpha.innerHTML += '.';
  123. }
  124. code_helper_alpha.innerHTML += ']&nbsp;<br>&nbsp;';
  125. }
  126. function Tick()
  127. {
  128. window.setTimeout("Tick()", 100);
  129. /* -- cmd lookup code. */
  130. if (mesh_code_module != undefined)
  131. {
  132. var cmd_size = 8;
  133. var found = FindMatchingCommand(mesh_code_module);
  134. if (found.match_list.length > 0)
  135. {
  136. var type_list = new Array();
  137. code_helper_cmd[0].innerHTML = "";
  138. code_helper_cmd[1].innerHTML = "";
  139. code_helper_arg.innerHTML = "";
  140. code_helper_cmt.innerHTML = "";
  141. //Go through the found matches and show them.
  142. for (var i = 0; i < found.match_list.length; i++)
  143. {
  144. var cur_match = EasyMeshDict.m_cmds[found.match_list[i]];
  145. code_helper_cmd[0].innerHTML += '[';
  146. var max = cur_match.m_name.length;
  147. var word = 0;
  148. for (var j = 0; j < max; j++)
  149. {
  150. var mth = found.match;
  151. var cmd = cur_match.m_name[j];
  152. //Matching start caracters should be bold
  153. if (mth == cmd.slice(0, mth.length))
  154. {
  155. code_helper_cmd[word].innerHTML += '&nbsp;';
  156. code_helper_cmd[word].innerHTML += '<b>' + mth + '</b>';
  157. code_helper_cmd[word].innerHTML += cmd.slice(mth.length, cmd.length);
  158. word++;
  159. }
  160. }
  161. //Complete empty command by <br> so commands in the two columns are on the same line
  162. word = (word > 0)?(2):(0);
  163. while (word-- > 0)
  164. code_helper_cmd[word].innerHTML += "<br>";
  165. //Go through the arguments and show them
  166. if (found.match_list.length < 4 && i == 0)
  167. {
  168. code_helper_arg.innerHTML += "&nbsp;>&nbsp;";
  169. if (cur_match.m_arg != undefined)
  170. {
  171. max = cur_match.m_arg.length;
  172. var found_optional = false;
  173. for (var j = 0; j < max; j++)
  174. {
  175. if (cur_match.m_arg[j].m_optional != undefined && found_optional == false)
  176. {
  177. var tab = '<br>'; for (var l = 0; l < 5; l++) tab += '&nbsp;';
  178. code_helper_arg.innerHTML += tab + 'Opt: [';
  179. found_optional = true;
  180. }
  181. else if (j > 0)
  182. code_helper_arg.innerHTML += ', ';
  183. //Types are bold
  184. code_helper_arg.innerHTML += '<b>' + cur_match.m_arg[j].m_type + '</b> ';
  185. type_list[type_list.length] = cur_match.m_arg[j].m_type;
  186. //Names are not
  187. code_helper_arg.innerHTML += cur_match.m_arg[j].m_name;
  188. if (cur_match.m_arg[j].m_optional != undefined)
  189. code_helper_arg.innerHTML += ' = <b>' + cur_match.m_arg[j].m_optional + '</b>';
  190. }
  191. if (found_optional == true)
  192. code_helper_arg.innerHTML += '] ';
  193. code_helper_arg.innerHTML += '&nbsp;<br>';
  194. }
  195. //Add the comment
  196. if (cur_match.m_comment != undefined)
  197. {
  198. var tb_i = 16; var in_i = 8;
  199. var tab = '<br>';
  200. if (cur_match.m_arg == undefined) { tb_i -= 8; in_i -= 8; }
  201. for (var l = 0; l < in_i; l++) code_helper_arg.innerHTML += '&nbsp;';
  202. for (var l = 0; l < tb_i; l++) tab += '&nbsp;';
  203. code_helper_arg.innerHTML += cur_match.m_comment + '&nbsp;';
  204. while (code_helper_arg.innerHTML.indexOf('\n') > -1)
  205. code_helper_arg.innerHTML = code_helper_arg.innerHTML.replace('\n', tab);
  206. }
  207. }
  208. }
  209. //Go through the type list and bold the used ones.
  210. if (EasyMeshDict.m_vars != undefined)
  211. {
  212. code_helper_var.innerHTML = "";
  213. var max = EasyMeshDict.m_vars.length;
  214. for (var j = 0; j < max; j++)
  215. {
  216. var cur_var = EasyMeshDict.m_vars[j];
  217. code_helper_var.innerHTML += "&nbsp;>&nbsp;";
  218. var k = 0;
  219. for (; k < type_list.length; k++)
  220. if (cur_var.m_type == type_list[k])
  221. break;
  222. //Bold the used variables
  223. if (k < type_list.length)
  224. code_helper_var.innerHTML += "<b>" + cur_var.m_type + "</b>";
  225. else
  226. code_helper_var.innerHTML += cur_var.m_type;
  227. if (cur_var.m_syntax != undefined)
  228. {
  229. var align_size = 9;
  230. var cmd_size = cur_var.m_type.length + 3;
  231. for (var m = 0; m < cur_var.m_syntax.length; m++)
  232. {
  233. for (var l = 0; l < align_size - cmd_size; l++)
  234. code_helper_var.innerHTML += "&nbsp;";
  235. code_helper_var.innerHTML += cur_var.m_syntax[m] + "<br>";
  236. cmd_size = 0;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. else
  243. {
  244. code_helper_cmd[0].innerHTML = "[ ...&nbsp;";
  245. code_helper_cmd[1].innerHTML = "";
  246. code_helper_arg.innerHTML = "";
  247. code_helper_cmt.innerHTML = "";
  248. }
  249. }
  250. /* -- */
  251. }
  252. // Indicate load success.
  253. function moduleDidLoad() {
  254. nacl_module = document.getElementById('ID_NaClModule');
  255. mesh_code_module = document.getElementById('DIV_MeshCode');
  256. updateStatus('Rock n\' Roll !!');
  257. var progress_bar = document.getElementById('progress_bar');
  258. progress_bar.style.visibility = "hidden";
  259. }
  260. // The 'message' event handler. This handler is fired when the NaCl module
  261. // posts a message to the browser by calling PPB_Messaging.PostMessage()
  262. // (in C) or pp::Instance.PostMessage() (in C++). This implementation
  263. // simply displays the content of the message in an alert panel.
  264. function handleMessage(message_event) {
  265. alert(message_event.data);
  266. }
  267. // If the page loads before the Native Client module loads, then set the
  268. // status message indicating that the module is still loading. Otherwise,
  269. // do not change the status message.
  270. function pageDidLoad() {
  271. if (nacl_module == null) {
  272. updateStatus('Please wait, loading ...');
  273. } else {
  274. // It's possible that the Native Client module onload event fired
  275. // before the page's onload event. In this case, the status message
  276. // will reflect 'SUCCESS', but won't be displayed. This call will
  277. // display the current message.
  278. updateStatus();
  279. }
  280. }
  281. // Set the global status message. If the element with id 'statusField'
  282. // exists, then set its HTML to the status message as well.
  283. // opt_message The message test. If this is null or undefined, then
  284. // attempt to set the element with id 'statusField' to the value of
  285. // |status_text|.
  286. function updateStatus(opt_message) {
  287. if (opt_message)
  288. status_text = opt_message;
  289. var statusField = document.getElementById('status_field');
  290. if (statusField) {
  291. statusField.innerHTML = status_text;
  292. }
  293. }
  294. function moduleCrash(event)
  295. {
  296. alert("Module has crashed !");
  297. //nacl_module.src = null;
  298. }
  299. function moduleLoadProgress(event)
  300. {
  301. var progressBar = document.getElementById("p");
  302. var statusField = document.getElementById('status_field');
  303. if (event.lengthComputable)
  304. {
  305. progressBar.max = event.total;
  306. progressBar.value = event.loaded;
  307. var load_progress = ((event.loaded / event.total) * 100.0);
  308. status_field.innerHTML = 'Please wait, loading [' + load_progress.toFixed(0) + '%]';
  309. }
  310. else
  311. {
  312. progressBar.value = -1;
  313. status_field.innerHTML = 'Computing progress ...'
  314. }
  315. }
  316. //Called by the "Send Mesh Command !" button
  317. function SendMeshData()
  318. {
  319. if (nacl_module)
  320. nacl_module.postMessage(mesh_code_module.value);
  321. else
  322. alert("Module not loaded");
  323. }
  324. </script>
  325. </head>
  326. <body onload="pageDidLoad()">
  327. <h1>Mesh Viewer : Native Client version.</h1>
  328. <p>
  329. <div id="final_div">
  330. <div id="listener" align="center" style="width:770px;height:200px">
  331. <canvas id="BGCanvas" width="772" height="202"></canvas>
  332. <div id="progress_bar">
  333. <div id="status_field">NO-STATUS</div>
  334. <progress id="p" align="left" width="200"></progress>
  335. </div>
  336. <div id="DIV_nacl_div">
  337. <param name="wmode" value="opaque"/>
  338. <embed name="nacl_module"
  339. id="ID_NaClModule"
  340. width=770 height=200
  341. src="meshviewer_nacl.nmf"
  342. type="application/x-nacl" />
  343. </div>
  344. <script type="text/javascript">
  345. var listener = document.getElementById('listener');
  346. listener.addEventListener('load', moduleDidLoad, true);
  347. listener.addEventListener('progress', moduleLoadProgress, true);
  348. listener.addEventListener('message', handleMessage, true);
  349. listener.addEventListener('crash', moduleCrash, true);
  350. </script>
  351. </div>
  352. </div>
  353. </p>
  354. <div><button onclick="SendMeshData()">Send Mesh Command !</button></div>
  355. <table border="0" cellpadding="0" cellspacing="0">
  356. <tr>
  357. <td>
  358. <div id="bouton">
  359. <textarea autofocus id="DIV_MeshCode" rows="6" cols="94" style="font: 14px Consolas; resize: none;">//This is a comment
  360. sc#f8f afcb 1 1 1 0</textarea>
  361. </div>
  362. </td>
  363. <td valign="top" rowspan="3">&nbsp;</td>
  364. <td valign="top" rowspan="3">
  365. <div><b><u>Variable Types usage :</u></b></div>
  366. <div id="DIV_var_usage"></div>
  367. </td>
  368. </tr>
  369. <tr>
  370. <td>
  371. <div id="DIV_alphabet"></div>
  372. </td>
  373. </tr>
  374. <tr>
  375. <td valign="top">
  376. <table border="0" cellpadding="0" cellspacing="0">
  377. <tr>
  378. <td valign="top"><div id="DIV_command0"></div></td>
  379. <td valign="top"><div id="DIV_command1"></div></td>
  380. <td valign="top"><div id="DIV_args" ></div></td>
  381. <td valign="top"><div id="DIV_comment" ></div></td>
  382. </tr>
  383. </table>
  384. </td>
  385. </tr>
  386. </table>
  387. </body>
  388. </html>