pbt.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. // jsEditor Manipulation
  2. var PBT = function() {
  3. this.decorationStyles = new Array();
  4. this.decorations = new Array();
  5. var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
  6. this.clearDecorLines = function() {
  7. this.decorations = jsEditor.deltaDecorations(this.decorations, []);
  8. }
  9. this.setDecorLines = function (lineRanges) {
  10. this.decorationStyles = [];
  11. var endLineNm = jsEditor.getModel()._lines.length;
  12. this.decorationStyles.push({ range: new monaco.Range(1,1,endLineNm,1), options: { isWholeLine: true, inlineClassName: 'pbt-fade' }});
  13. for(var i = 0; i < lineRanges.length; i +=2) {
  14. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, linesDecorationsClassName: 'pbt-margin-decor-on' }});
  15. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, className: 'pbt-back-highlight' }});
  16. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, inlineClassName: 'pbt-darken' }});
  17. }
  18. this.decorations = jsEditor.deltaDecorations([this.decorations], this.decorationStyles);
  19. }
  20. this.replaceLines = function(lineRange, text) {
  21. jsEditor.executeEdits("", [
  22. { range: new monaco.Range(parseInt(lineRange[0]), 1, parseInt(lineRange[1]), 100000), text: text}
  23. ]);
  24. }
  25. this.replaceText = function(line, start, end, text) {
  26. jsEditor.executeEdits("", [
  27. { range: new monaco.Range(line, start, line, end), text: text}
  28. ]);
  29. }
  30. this.getLineText = function(lineNm) {
  31. return jsEditor.getModel().getLineContent(lineNm);
  32. }
  33. this.hideLines = function(lineRanges) {
  34. var ranges = [];
  35. for(var i = 0; i < lineRanges.length; i +=2) {
  36. ranges.push(new monaco.Range(parseInt(lineRanges[i]), 1, parseInt(lineRanges[i + 1]), 100000));
  37. }
  38. jsEditor.setHiddenAreas(ranges);
  39. }
  40. this.editOn = function() {
  41. jsEditor.updateOptions({readOnly: false});
  42. }
  43. this.editOff = function() {
  44. jsEditor.updateOptions({readOnly: true});
  45. }
  46. //hide menu items
  47. this.hideMenu = function() {
  48. var headings = document.getElementsByClassName('category');
  49. for (var i = 0; i < headings.length; i ++) {
  50. headings[i].style.visibility = 'hidden';
  51. }
  52. headings = document.getElementsByClassName('category right');
  53. for (var i = 0; i < headings.length; i ++) {
  54. headings[i].style.visibility = 'visible';
  55. }
  56. }
  57. //Standard GUI Dialogues
  58. this.StandardDialog = function(options) {
  59. options = options||{};
  60. var width = options.width||0.5;
  61. var height = options.height||0.25;
  62. var top = options.top||0;
  63. var left = options.left||0;
  64. var verticalAlignment = options.verticalAlignment||BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  65. var horizontalAlignment = options.horizontalAlignment||BABYLON.GUI.Control.HORIZONTAL_LEFT;
  66. var text = options.text||"Playground Based Tutorial";
  67. if(options.useImage === undefined) {
  68. var useImage = true;
  69. }
  70. else {
  71. var useImage = false;
  72. }
  73. var imageURL = options.imageURL||"LogoPBT.png";
  74. var textBlockWidth = 0.95;
  75. var textBlockLeft = "2%";
  76. this.container = new BABYLON.GUI.Rectangle();
  77. this.container.verticalAlignment = verticalAlignment;
  78. this.container.horizontalAlignment = horizontalAlignment;
  79. this.container.width = width;
  80. this.container.height = height;
  81. this.container.cornerRadius = 10;
  82. this.container.color = "#364249";
  83. this.container.thickness = 4;
  84. this.container.background = "#CDC8F9";
  85. this.container.top = top;
  86. this.container.left = left;
  87. advancedTexture.addControl(this.container);
  88. if(useImage) {
  89. this.logoPBT = BABYLON.GUI.Button.CreateImageOnlyButton("but", imageURL);
  90. this.logoPBT.width = "100px";
  91. this.logoPBT.height = "100px";
  92. this.logoPBT.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  93. this.logoPBT.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  94. this.logoPBT.top = 2;
  95. this.logoPBT.left=2;
  96. this.logoPBT.color = "#CDC8F9";
  97. this.container.addControl(this.logoPBT);
  98. textBlockWidth = 0.6;
  99. textBlockLeft = "35%";
  100. }
  101. this.textBlock = new BABYLON.GUI.TextBlock("text", text);
  102. this.textBlock.width = textBlockWidth;
  103. this.textBlock.height = 0.7
  104. this.textBlock.textWrapping = true;
  105. this.textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  106. this.textBlock.color = "#364249";
  107. this.textBlock.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  108. this.textBlock.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  109. this.textBlock.left = textBlockLeft;
  110. this.textBlock.top = 2;
  111. this.container.addControl(this.textBlock);
  112. this.nextButton = BABYLON.GUI.Button.CreateSimpleButton("nextbut", "Next >");
  113. this.nextButton.width = 0.2
  114. this.nextButton.height = 0.15;
  115. this.nextButton.color = "white";
  116. this.nextButton.cornerRadius = 5;
  117. this.nextButton.background = "#364249";
  118. this.nextButton.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  119. this.nextButton.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  120. this.nextButton.left = "78%";
  121. this.nextButton.top = "80%";
  122. this.container.addControl(this.nextButton);
  123. this.prevButton = BABYLON.GUI.Button.CreateSimpleButton("prevbut", "< Prev");
  124. this.prevButton.width = 0.2
  125. this.prevButton.height = 0.15;
  126. this.prevButton.color = "white";
  127. this.prevButton.cornerRadius = 5;
  128. this.prevButton.background = "#364249";
  129. this.prevButton.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  130. this.prevButton.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  131. this.prevButton.left = "2%";
  132. this.prevButton.top = "80%";
  133. this.container.addControl(this.prevButton);
  134. this.showNext = function() {
  135. this.nextButton.isVisible = true;
  136. }
  137. this.hideNext = function() {
  138. this.nextButton.isVisible = false;
  139. }
  140. this.getNextButton = function() {
  141. return this.nextButton;
  142. }
  143. this.prevClick = function(func) {
  144. this.prevButton.onPointerUpObservable.add(function() {
  145. func();
  146. });
  147. }
  148. this.showPrev = function() {
  149. this.prevButton.isVisible = true;
  150. }
  151. this.hidePrev = function() {
  152. this.prevButton.isVisible = false;
  153. }
  154. this.setWidth = function(width) {
  155. this.container.width = width;
  156. }
  157. this.setHeight = function(height) {
  158. this.container.height = height;
  159. }
  160. this.setTop = function(top) {
  161. this.container.top = top;
  162. }
  163. this.setLeft = function(left) {
  164. this.container.left = left;
  165. }
  166. this.getWidth = function() {
  167. return this.container.width;
  168. }
  169. this.getHeight = function() {
  170. return this.container.height;
  171. }
  172. this.getTop = function() {
  173. return this.container.top;
  174. }
  175. this.getLeft = function() {
  176. return this.container.left;
  177. }
  178. this.setHorizontalAlignment = function(hrzAlgn) {
  179. this.container.horizontalAlignment = hrzAlgn;
  180. }
  181. this.setVerticalAlignment = function(vrtAlign) {
  182. this.container.VerticalAlignmenv = vrtAlign;
  183. }
  184. this.setText = function(text) {
  185. this.textBlock.text = text;
  186. }
  187. this.show = function() {
  188. this.container.isVisible = true;
  189. }
  190. this.hide = function() {
  191. this.container.isVisible = false;
  192. }
  193. return this;
  194. }
  195. //Radio and Checkbox Button GUI
  196. this.ButtonGroup = function(name, type) {
  197. this.name = name;
  198. var type = type||"C";
  199. type = type.substr(0,1).toUpperCase();
  200. if(type !="R") {
  201. if(type != "C") {
  202. type = "C";
  203. }
  204. }
  205. this.type = type;
  206. this.buttons = new Array();
  207. this.addButton = function(text, func, checked) {
  208. this.buttons.push({
  209. text: text||"",
  210. func: func||null,
  211. checked: checked||false
  212. });
  213. }
  214. return this;
  215. }
  216. this.SelectionDialog = function(options) {
  217. options = options||{};
  218. var justStarted = true;
  219. var width = options.width||0.15;
  220. var top = options.top||0;
  221. var left = options.left||0;
  222. var verticalAlignment = options.verticalAlignment||BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
  223. var horizontalAlignment = options.horizontalAlignment||BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  224. var groups = options.groups;
  225. this.container = new BABYLON.GUI.Rectangle();
  226. this.container.verticalAlignment = verticalAlignment;
  227. this.container.horizontalAlignment = horizontalAlignment;
  228. this.container.width = 0.25;
  229. var height = 36 * groups.length;
  230. for(var i = 0; i < groups.length; i++) {
  231. height += 32 * groups[i].buttons.length;
  232. }
  233. this.container.height = height + "px";
  234. this.container.cornerRadius = 10;
  235. this.container.color = "#364249";
  236. this.container.thickness = 4;
  237. this.container.background = "#CDC8F9";
  238. this.container.top = top;
  239. this.container.left = left;
  240. advancedTexture.addControl(this.container);
  241. var panel = new BABYLON.GUI.StackPanel();
  242. panel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  243. panel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  244. panel.top = 5;
  245. panel.left = 5;
  246. this.container.addControl(panel);
  247. var addRadio = function(text, parent, group, func, checked) {
  248. checked = checked || false;
  249. var button = new BABYLON.GUI.RadioButton();
  250. button.width = "20px";
  251. button.height = "20px";
  252. button.color = "#364249";
  253. button.background = "white";
  254. button.group = group;
  255. button.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  256. button.justStarted = true;
  257. button.func = func;
  258. button.onIsCheckedChangedObservable.add(function(state) {
  259. if (state && !justStarted) {
  260. func();
  261. }
  262. });
  263. var header = BABYLON.GUI.Control.AddHeader(button, text, "200px", { isHorizontal: true, controlFirst: true });
  264. header.height = "30px";
  265. parent.addControl(header);
  266. button.isChecked = checked;
  267. }
  268. var addCheckbox = function(text, parent, func, checked) {
  269. checked = checked || false;
  270. var button = new BABYLON.GUI.Checkbox();
  271. button.width = "20px";
  272. button.height = "20px";
  273. button.color = "#364249";
  274. button.background = "white";
  275. button.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  276. button.onIsCheckedChangedObservable.add(function(state) {
  277. func();
  278. });
  279. var header = BABYLON.GUI.Control.AddHeader(button, text, "200px", { isHorizontal: true, controlFirst: true });
  280. header.height = "30px";
  281. parent.addControl(header);
  282. button.isChecked = checked;
  283. }
  284. var groupHeader = function(name) {
  285. var groupHeading = new BABYLON.GUI.TextBlock("groupHead", name);
  286. groupHeading.width = 0.9;
  287. groupHeading.height = "30px";
  288. groupHeading.textWrapping = true;
  289. groupHeading.color = "black";
  290. groupHeading.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  291. groupHeading.left = "-2px";
  292. panel.addControl(groupHeading);
  293. }
  294. var addSpacer = function(name) {
  295. var separator = new BABYLON.GUI.Rectangle();
  296. separator.width = 1;
  297. separator.height = "2px";
  298. separator.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  299. separator.background = "#364249";
  300. separator.color = "#364249";
  301. panel.addControl(separator);
  302. groupHeader(name);
  303. }
  304. this.addGroup = function(group) {
  305. if(group.type == "R") {
  306. for(var i = 0; i < group.buttons.length; i++) {
  307. addRadio(group.buttons[i].text, panel, group.name, group.buttons[i].func, group.buttons[i].checked);
  308. }
  309. }
  310. else {
  311. for(var i = 0; i < group.buttons.length; i++) {
  312. addCheckbox(group.buttons[i].text, panel, group.buttons[i].func, group.buttons[i].checked);
  313. }
  314. }
  315. }
  316. groupHeader(groups[0].name);
  317. this.addGroup(groups[0]);
  318. for(var i = 1; i < groups.length; i++) {
  319. addSpacer(groups[i].name);
  320. this.addGroup(groups[i]);
  321. }
  322. justStarted = false;
  323. this.setWidth = function(width) {
  324. this.container.width = width;
  325. }
  326. this.setTop = function(top) {
  327. this.container.top = top;
  328. }
  329. this.setLeft = function(left) {
  330. this.container.left = left;
  331. }
  332. this.getWidth = function() {
  333. return this.container.width;
  334. }
  335. this.getTop = function() {
  336. return this.container.top;
  337. }
  338. this.getLeft = function() {
  339. return this.container.left;
  340. }
  341. this.setHorizontalAlignment = function(hrzAlgn) {
  342. this.container.horizontalAlignment = hrzAlgn;
  343. }
  344. this.setVerticalAlignment = function(vrtAlign) {
  345. this.container.VerticalAlignmenv = vrtAlign;
  346. }
  347. this.show = function() {
  348. this.container.isVisible = true;
  349. }
  350. this.hide = function() {
  351. this.container.isVisible = false;
  352. }
  353. return this;
  354. }
  355. }
  356. showBJSPGMenu = function() {
  357. var headings = document.getElementsByClassName('category');
  358. for (var i = 0; i < headings.length; i ++) {
  359. headings[i].style.visibility = 'visible';
  360. }
  361. }