203 linhas
5.9 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. progress {
  11. background-color: #f3f3f3;
  12. border: 0;
  13. height: 18px;
  14. border-radius: 9px;
  15. }
  16. progress::-webkit-progress-bar {
  17. background-color: #f3f3f3;
  18. border: 1px solid #000000;
  19. padding: 2px 2px;
  20. height: 20px;
  21. border-radius: 0px;
  22. }
  23. progress::-webkit-progress-value {
  24. background-color: #22BB22;
  25. border: 0px;
  26. height: 14px;
  27. border-radius: 0px;
  28. }
  29. </style>
  30. <!--
  31. -->
  32. <title>Mesh Viewer NaCl</title>
  33. <script type="text/javascript">
  34. NaClModule = null; // Global application object.
  35. MeshCodeModule = null;
  36. statusText = 'NO-STATUS';
  37. window.setTimeout("Tick()", 100);
  38. document.getElementById('prout').style.top = 0;
  39. function Tick() {
  40. window.setTimeout("Tick()", 100);
  41. var truc = parseInt(document.getElementById('prout').style.top);
  42. //document.getElementById('prout').style.top = truc + 1 + "px";
  43. var statusField = document.getElementById('tick_field');
  44. if (statusField) {
  45. statusField.innerHTML = truc;
  46. }
  47. }
  48. // Indicate load success.
  49. function moduleDidLoad() {
  50. NaClModule = document.getElementById('ID_NaClModule');
  51. MeshCodeModule = document.getElementById('ID_MeshCode');
  52. //document.getElementById('listener').style.visibility = "visible";
  53. //document.getElementById('canvas_loading').style.display = "none";
  54. //document.getElementById('ID_NaClModule').width = 640;
  55. //document.getElementById('ID_NaClModule').height = 480;
  56. updateStatus('Rock n\' Roll !!');
  57. }
  58. // The 'message' event handler. This handler is fired when the NaCl module
  59. // posts a message to the browser by calling PPB_Messaging.PostMessage()
  60. // (in C) or pp::Instance.PostMessage() (in C++). This implementation
  61. // simply displays the content of the message in an alert panel.
  62. function handleMessage(message_event) {
  63. alert(message_event.data);
  64. }
  65. // If the page loads before the Native Client module loads, then set the
  66. // status message indicating that the module is still loading. Otherwise,
  67. // do not change the status message.
  68. function pageDidLoad() {
  69. if (NaClModule == null) {
  70. updateStatus('Please wait, loading ...');
  71. } else {
  72. // It's possible that the Native Client module onload event fired
  73. // before the page's onload event. In this case, the status message
  74. // will reflect 'SUCCESS', but won't be displayed. This call will
  75. // display the current message.
  76. updateStatus();
  77. }
  78. }
  79. // Set the global status message. If the element with id 'statusField'
  80. // exists, then set its HTML to the status message as well.
  81. // opt_message The message test. If this is null or undefined, then
  82. // attempt to set the element with id 'statusField' to the value of
  83. // |statusText|.
  84. function updateStatus(opt_message) {
  85. if (opt_message)
  86. statusText = opt_message;
  87. var statusField = document.getElementById('status_field');
  88. if (statusField) {
  89. statusField.innerHTML = statusText;
  90. }
  91. }
  92. function moduleLoadProgress(event)
  93. {
  94. var progressBar = document.getElementById("p");
  95. var statusField = document.getElementById('status_field');
  96. if (event.lengthComputable) {
  97. progressBar.max = event.total;
  98. progressBar.value = event.loaded;
  99. var load_progress = ((event.loaded / event.total) * 100.0);
  100. status_field.innerHTML = 'Loading [' + load_progress.toFixed(0) + '%]';
  101. }
  102. else {
  103. progressBar.value = -1;
  104. status_field.innerHTML = 'Computing progress ...'
  105. }
  106. }
  107. function SendMeshData()
  108. {
  109. if (NaClModule)
  110. {
  111. NaClModule.postMessage(MeshCodeModule.value);
  112. //NaClModule.postMessage("sc#f8f afcb 1 1 1 0");
  113. alert("Data sent");
  114. }
  115. else
  116. alert("Module not loaded");
  117. }
  118. </script>
  119. </head>
  120. <body onload="pageDidLoad()">
  121. <h1>Mesh Viewer : Native Client version.</h1>
  122. <p>
  123. <div>
  124. <table border="1" cellspacing="0" cellpadding="0" style="width:770px;height:200px">
  125. <tr border="0"> <td border="0" align="center">
  126. <div id="status_field">NO-STATUS</div>
  127. <progress id=p align="left"></progress>
  128. <script type="text/javascript">
  129. var progressBar = document.getElementById("p");
  130. progressBar.max = 100;
  131. progressBar.value = 100;
  132. </script>
  133. <!--
  134. <script>
  135. var progressBar = document.getElementById("p"), client = new XMLHttpRequest()
  136. client.open("GET", "magical-unicorns")
  137. client.onprogress = function (pe) {
  138. if (pe.lengthComputable) {
  139. progressBar.max = pe.total
  140. progressBar.value = pe.loaded
  141. }
  142. }
  143. client.onloadend = function (pe) {
  144. progressBar.value = pe.loaded
  145. }
  146. client.send()
  147. progressBar.max = pe.total;
  148. progressBar.value = pe.loaded;
  149. </script>
  150. -->
  151. </td> </tr>
  152. </table>
  153. </div>
  154. </p>
  155. <h2>Status</h2>
  156. <div id="tick_field"></div>
  157. <div id="bouton">
  158. <textarea id="ID_MeshCode" rows="5" cols="80">
  159. //This is a comment
  160. sc#f8f afcb 1 1 1 0
  161. </textarea>
  162. </div>
  163. <div>
  164. <button onclick="SendMeshData()">Update Mesh</button>
  165. </div>
  166. <div id="listener" >
  167. <script type="text/javascript">
  168. var listener = document.getElementById('listener');
  169. listener.addEventListener('load', moduleDidLoad, true);
  170. listener.addEventListener('progress', moduleLoadProgress, true);
  171. listener.addEventListener('message', handleMessage, true);
  172. </script>
  173. <div id="nacl_div">
  174. <embed name="nacl_module"
  175. id="ID_NaClModule"
  176. width=770 height=200
  177. src="meshviewer_nacl.nmf"
  178. type="application/x-nacl" />
  179. </div>
  180. </div>
  181. </body>
  182. </html>