@babylonjs/gui 5.0.0-rc.0 → 5.0.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/2D/adtInstrumentation.d.ts +52 -52
  2. package/2D/adtInstrumentation.js +126 -126
  3. package/2D/adtInstrumentation.js.map +1 -1
  4. package/2D/advancedDynamicTexture.d.ts +449 -423
  5. package/2D/advancedDynamicTexture.js +1318 -1286
  6. package/2D/advancedDynamicTexture.js.map +1 -1
  7. package/2D/controls/button.d.ts +135 -97
  8. package/2D/controls/button.js +276 -238
  9. package/2D/controls/button.js.map +1 -1
  10. package/2D/controls/checkbox.d.ts +59 -51
  11. package/2D/controls/checkbox.js +188 -178
  12. package/2D/controls/checkbox.js.map +1 -1
  13. package/2D/controls/colorpicker.d.ts +103 -90
  14. package/2D/controls/colorpicker.js +1417 -1400
  15. package/2D/controls/colorpicker.js.map +1 -1
  16. package/2D/controls/container.d.ts +175 -130
  17. package/2D/controls/container.js +570 -525
  18. package/2D/controls/container.js.map +1 -1
  19. package/2D/controls/control.d.ts +866 -743
  20. package/2D/controls/control.js +2433 -2308
  21. package/2D/controls/control.js.map +1 -1
  22. package/2D/controls/displayGrid.d.ts +53 -55
  23. package/2D/controls/displayGrid.js +245 -245
  24. package/2D/controls/displayGrid.js.map +1 -1
  25. package/2D/controls/ellipse.d.ts +21 -21
  26. package/2D/controls/ellipse.js +85 -85
  27. package/2D/controls/ellipse.js.map +1 -1
  28. package/2D/controls/focusableButton.d.ts +59 -52
  29. package/2D/controls/focusableButton.js +99 -92
  30. package/2D/controls/focusableButton.js.map +1 -1
  31. package/2D/controls/focusableControl.d.ts +34 -34
  32. package/2D/controls/focusableControl.js +1 -1
  33. package/2D/controls/focusableControl.js.map +1 -1
  34. package/2D/controls/grid.d.ts +139 -135
  35. package/2D/controls/grid.js +529 -525
  36. package/2D/controls/grid.js.map +1 -1
  37. package/2D/controls/image.d.ts +204 -197
  38. package/2D/controls/image.js +887 -879
  39. package/2D/controls/image.js.map +1 -1
  40. package/2D/controls/index.d.ts +29 -29
  41. package/2D/controls/index.js +29 -29
  42. package/2D/controls/index.js.map +1 -1
  43. package/2D/controls/inputPassword.d.ts +9 -8
  44. package/2D/controls/inputPassword.js +28 -25
  45. package/2D/controls/inputPassword.js.map +1 -1
  46. package/2D/controls/inputText.d.ts +201 -182
  47. package/2D/controls/inputText.js +1119 -1096
  48. package/2D/controls/inputText.js.map +1 -1
  49. package/2D/controls/line.d.ts +66 -66
  50. package/2D/controls/line.js +271 -271
  51. package/2D/controls/line.js.map +1 -1
  52. package/2D/controls/multiLine.d.ts +75 -77
  53. package/2D/controls/multiLine.js +262 -262
  54. package/2D/controls/multiLine.js.map +1 -1
  55. package/2D/controls/radioButton.d.ts +49 -49
  56. package/2D/controls/radioButton.js +205 -205
  57. package/2D/controls/radioButton.js.map +1 -1
  58. package/2D/controls/rectangle.d.ts +29 -29
  59. package/2D/controls/rectangle.js +150 -150
  60. package/2D/controls/rectangle.js.map +1 -1
  61. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -175
  62. package/2D/controls/scrollViewers/scrollViewer.js +677 -676
  63. package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
  64. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -45
  65. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -263
  66. package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
  67. package/2D/controls/selector.d.ts +263 -209
  68. package/2D/controls/selector.js +692 -629
  69. package/2D/controls/selector.js.map +1 -1
  70. package/2D/controls/sliders/baseSlider.d.ts +82 -78
  71. package/2D/controls/sliders/baseSlider.js +347 -343
  72. package/2D/controls/sliders/baseSlider.js.map +1 -1
  73. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -47
  74. package/2D/controls/sliders/imageBasedSlider.js +192 -188
  75. package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
  76. package/2D/controls/sliders/imageScrollBar.d.ts +65 -61
  77. package/2D/controls/sliders/imageScrollBar.js +263 -256
  78. package/2D/controls/sliders/imageScrollBar.js.map +1 -1
  79. package/2D/controls/sliders/scrollBar.d.ts +38 -34
  80. package/2D/controls/sliders/scrollBar.js +143 -136
  81. package/2D/controls/sliders/scrollBar.js.map +1 -1
  82. package/2D/controls/sliders/slider.d.ts +35 -37
  83. package/2D/controls/sliders/slider.js +271 -271
  84. package/2D/controls/sliders/slider.js.map +1 -1
  85. package/2D/controls/stackPanel.d.ts +64 -56
  86. package/2D/controls/stackPanel.js +246 -236
  87. package/2D/controls/stackPanel.js.map +1 -1
  88. package/2D/controls/statics.d.ts +6 -6
  89. package/2D/controls/statics.js +49 -47
  90. package/2D/controls/statics.js.map +1 -1
  91. package/2D/controls/textBlock.d.ts +175 -172
  92. package/2D/controls/textBlock.js +603 -598
  93. package/2D/controls/textBlock.js.map +1 -1
  94. package/2D/controls/textWrapper.d.ts +13 -13
  95. package/2D/controls/textWrapper.js +101 -101
  96. package/2D/controls/textWrapper.js.map +1 -1
  97. package/2D/controls/toggleButton.d.ts +117 -83
  98. package/2D/controls/toggleButton.js +268 -234
  99. package/2D/controls/toggleButton.js.map +1 -1
  100. package/2D/controls/virtualKeyboard.d.ts +96 -96
  101. package/2D/controls/virtualKeyboard.js +256 -256
  102. package/2D/controls/virtualKeyboard.js.map +1 -1
  103. package/2D/index.d.ts +9 -9
  104. package/2D/index.js +10 -9
  105. package/2D/index.js.map +1 -1
  106. package/2D/math2D.d.ts +117 -117
  107. package/2D/math2D.js +221 -221
  108. package/2D/math2D.js.map +1 -1
  109. package/2D/measure.d.ts +77 -77
  110. package/2D/measure.js +139 -149
  111. package/2D/measure.js.map +1 -1
  112. package/2D/multiLinePoint.d.ts +47 -47
  113. package/2D/multiLinePoint.js +127 -127
  114. package/2D/multiLinePoint.js.map +1 -1
  115. package/2D/style.d.ts +46 -46
  116. package/2D/style.js +97 -97
  117. package/2D/style.js.map +1 -1
  118. package/2D/valueAndUnit.d.ts +89 -89
  119. package/2D/valueAndUnit.js +226 -222
  120. package/2D/valueAndUnit.js.map +1 -1
  121. package/2D/xmlLoader.d.ts +60 -60
  122. package/2D/xmlLoader.js +348 -348
  123. package/2D/xmlLoader.js.map +1 -1
  124. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  125. package/3D/behaviors/defaultBehavior.js +121 -121
  126. package/3D/behaviors/defaultBehavior.js.map +1 -1
  127. package/3D/controls/abstractButton3D.d.ts +15 -15
  128. package/3D/controls/abstractButton3D.js +25 -25
  129. package/3D/controls/abstractButton3D.js.map +1 -1
  130. package/3D/controls/button3D.d.ts +30 -30
  131. package/3D/controls/button3D.js +93 -93
  132. package/3D/controls/button3D.js.map +1 -1
  133. package/3D/controls/container3D.d.ts +72 -72
  134. package/3D/controls/container3D.js +139 -140
  135. package/3D/controls/container3D.js.map +1 -1
  136. package/3D/controls/contentDisplay3D.d.ts +30 -30
  137. package/3D/controls/contentDisplay3D.js +79 -78
  138. package/3D/controls/contentDisplay3D.js.map +1 -1
  139. package/3D/controls/control3D.d.ts +201 -165
  140. package/3D/controls/control3D.js +445 -408
  141. package/3D/controls/control3D.js.map +1 -1
  142. package/3D/controls/cylinderPanel.d.ts +17 -17
  143. package/3D/controls/cylinderPanel.js +66 -66
  144. package/3D/controls/cylinderPanel.js.map +1 -1
  145. package/3D/controls/handMenu.d.ts +28 -28
  146. package/3D/controls/handMenu.js +47 -47
  147. package/3D/controls/handMenu.js.map +1 -1
  148. package/3D/controls/holographicBackplate.d.ts +49 -48
  149. package/3D/controls/holographicBackplate.js +120 -120
  150. package/3D/controls/holographicBackplate.js.map +1 -1
  151. package/3D/controls/holographicButton.d.ts +84 -83
  152. package/3D/controls/holographicButton.js +339 -338
  153. package/3D/controls/holographicButton.js.map +1 -1
  154. package/3D/controls/holographicSlate.d.ts +131 -128
  155. package/3D/controls/holographicSlate.js +431 -428
  156. package/3D/controls/holographicSlate.js.map +1 -1
  157. package/3D/controls/index.d.ts +21 -21
  158. package/3D/controls/index.js +21 -21
  159. package/3D/controls/index.js.map +1 -1
  160. package/3D/controls/meshButton3D.d.ts +21 -21
  161. package/3D/controls/meshButton3D.js +62 -61
  162. package/3D/controls/meshButton3D.js.map +1 -1
  163. package/3D/controls/nearMenu.d.ts +44 -44
  164. package/3D/controls/nearMenu.js +114 -112
  165. package/3D/controls/nearMenu.js.map +1 -1
  166. package/3D/controls/planePanel.d.ts +9 -9
  167. package/3D/controls/planePanel.js +36 -36
  168. package/3D/controls/planePanel.js.map +1 -1
  169. package/3D/controls/scatterPanel.d.ts +18 -18
  170. package/3D/controls/scatterPanel.js +108 -108
  171. package/3D/controls/scatterPanel.js.map +1 -1
  172. package/3D/controls/slider3D.d.ts +81 -80
  173. package/3D/controls/slider3D.js +268 -267
  174. package/3D/controls/slider3D.js.map +1 -1
  175. package/3D/controls/spherePanel.d.ts +17 -17
  176. package/3D/controls/spherePanel.js +67 -67
  177. package/3D/controls/spherePanel.js.map +1 -1
  178. package/3D/controls/stackPanel3D.d.ts +22 -22
  179. package/3D/controls/stackPanel3D.js +107 -107
  180. package/3D/controls/stackPanel3D.js.map +1 -1
  181. package/3D/controls/touchButton3D.d.ts +80 -75
  182. package/3D/controls/touchButton3D.js +233 -227
  183. package/3D/controls/touchButton3D.js.map +1 -1
  184. package/3D/controls/touchHolographicButton.d.ts +110 -109
  185. package/3D/controls/touchHolographicButton.js +445 -445
  186. package/3D/controls/touchHolographicButton.js.map +1 -1
  187. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  188. package/3D/controls/touchHolographicMenu.js +149 -148
  189. package/3D/controls/touchHolographicMenu.js.map +1 -1
  190. package/3D/controls/touchMeshButton3D.d.ts +21 -22
  191. package/3D/controls/touchMeshButton3D.js +62 -62
  192. package/3D/controls/touchMeshButton3D.js.map +1 -1
  193. package/3D/controls/volumeBasedPanel.d.ts +53 -52
  194. package/3D/controls/volumeBasedPanel.js +174 -174
  195. package/3D/controls/volumeBasedPanel.js.map +1 -1
  196. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  197. package/3D/gizmos/gizmoHandle.js +209 -209
  198. package/3D/gizmos/gizmoHandle.js.map +1 -1
  199. package/3D/gizmos/index.d.ts +2 -2
  200. package/3D/gizmos/index.js +2 -2
  201. package/3D/gizmos/index.js.map +1 -1
  202. package/3D/gizmos/slateGizmo.d.ts +57 -57
  203. package/3D/gizmos/slateGizmo.js +369 -369
  204. package/3D/gizmos/slateGizmo.js.map +1 -1
  205. package/3D/gui3DManager.d.ts +94 -94
  206. package/3D/gui3DManager.js +257 -257
  207. package/3D/gui3DManager.js.map +1 -1
  208. package/3D/index.d.ts +5 -5
  209. package/3D/index.js +6 -5
  210. package/3D/index.js.map +1 -1
  211. package/3D/materials/fluent/fluentMaterial.d.ts +91 -90
  212. package/3D/materials/fluent/fluentMaterial.js +292 -281
  213. package/3D/materials/fluent/fluentMaterial.js.map +1 -1
  214. package/3D/materials/fluent/index.d.ts +1 -1
  215. package/3D/materials/fluent/index.js +1 -1
  216. package/3D/materials/fluent/index.js.map +1 -1
  217. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  218. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -6
  219. package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -1
  220. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  221. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -6
  222. package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -1
  223. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -154
  224. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -434
  225. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
  226. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  227. package/3D/materials/fluentBackplate/index.js +1 -1
  228. package/3D/materials/fluentBackplate/index.js.map +1 -1
  229. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  230. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -6
  231. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -1
  232. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  233. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -6
  234. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -1
  235. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -189
  236. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -537
  237. package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
  238. package/3D/materials/fluentButton/index.d.ts +1 -1
  239. package/3D/materials/fluentButton/index.js +1 -1
  240. package/3D/materials/fluentButton/index.js.map +1 -1
  241. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  242. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -6
  243. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -1
  244. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  245. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -6
  246. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -1
  247. package/3D/materials/fluentMaterial.d.ts +4 -4
  248. package/3D/materials/fluentMaterial.js +4 -4
  249. package/3D/materials/fluentMaterial.js.map +1 -1
  250. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  251. package/3D/materials/handle/handleMaterial.js +126 -126
  252. package/3D/materials/handle/handleMaterial.js.map +1 -1
  253. package/3D/materials/handle/index.d.ts +1 -1
  254. package/3D/materials/handle/index.js +1 -1
  255. package/3D/materials/handle/index.js.map +1 -1
  256. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  257. package/3D/materials/handle/shaders/handle.fragment.js +8 -6
  258. package/3D/materials/handle/shaders/handle.fragment.js.map +1 -1
  259. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  260. package/3D/materials/handle/shaders/handle.vertex.js +8 -6
  261. package/3D/materials/handle/shaders/handle.vertex.js.map +1 -1
  262. package/3D/materials/index.d.ts +5 -5
  263. package/3D/materials/index.js +6 -5
  264. package/3D/materials/index.js.map +1 -1
  265. package/3D/materials/mrdl/index.d.ts +3 -3
  266. package/3D/materials/mrdl/index.js +3 -3
  267. package/3D/materials/mrdl/index.js.map +1 -1
  268. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -147
  269. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -409
  270. package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
  271. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +334 -333
  272. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -786
  273. package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
  274. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +334 -333
  275. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -786
  276. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
  277. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  278. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -6
  279. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -1
  280. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  281. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -6
  282. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -1
  283. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  284. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -6
  285. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -1
  286. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  287. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -6
  288. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -1
  289. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  290. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -6
  291. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -1
  292. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  293. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -6
  294. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -1
  295. package/3D/vector3WithInfo.d.ts +16 -16
  296. package/3D/vector3WithInfo.js +23 -23
  297. package/3D/vector3WithInfo.js.map +1 -1
  298. package/index.d.ts +2 -2
  299. package/index.js +3 -2
  300. package/index.js.map +1 -1
  301. package/legacy/legacy.d.ts +1 -1
  302. package/legacy/legacy.js +14 -13
  303. package/legacy/legacy.js.map +1 -1
  304. package/package.json +21 -328
  305. package/readme.md +2 -2
@@ -1,1401 +1,1418 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { Observable } from "@babylonjs/core/Misc/observable.js";
3
- import { Control } from "./control.js";
4
- import { InputText } from "./inputText.js";
5
- import { Rectangle } from "./rectangle.js";
6
- import { Button } from "./button.js";
7
- import { Grid } from "./grid.js";
8
- import { TextBlock } from "../controls/textBlock.js";
9
- import { RegisterClass } from '@babylonjs/core/Misc/typeStore.js';
10
- import { Color3 } from '@babylonjs/core/Maths/math.color.js';
11
- import { serialize } from '@babylonjs/core/Misc/decorators.js';
12
- import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
13
- /** Class used to create color pickers */
14
- var ColorPicker = /** @class */ (function (_super) {
15
- __extends(ColorPicker, _super);
16
- /**
17
- * Creates a new ColorPicker
18
- * @param name defines the control name
19
- */
20
- function ColorPicker(name) {
21
- var _this = _super.call(this, name) || this;
22
- _this.name = name;
23
- _this._value = Color3.Red();
24
- _this._tmpColor = new Color3();
25
- _this._pointerStartedOnSquare = false;
26
- _this._pointerStartedOnWheel = false;
27
- _this._squareLeft = 0;
28
- _this._squareTop = 0;
29
- _this._squareSize = 0;
30
- _this._h = 360;
31
- _this._s = 1;
32
- _this._v = 1;
33
- _this._lastPointerDownId = -1;
34
- /**
35
- * Observable raised when the value changes
36
- */
37
- _this.onValueChangedObservable = new Observable();
38
- // Events
39
- _this._pointerIsDown = false;
40
- _this.value = new Color3(.88, .1, .1);
41
- _this.size = "200px";
42
- _this.isPointerBlocker = true;
43
- return _this;
44
- }
45
- Object.defineProperty(ColorPicker.prototype, "value", {
46
- /** Gets or sets the color of the color picker */
47
- get: function () {
48
- return this._value;
49
- },
50
- set: function (value) {
51
- if (this._value.equals(value)) {
52
- return;
53
- }
54
- this._value.copyFrom(value);
55
- this._value.toHSVToRef(this._tmpColor);
56
- this._h = this._tmpColor.r;
57
- this._s = Math.max(this._tmpColor.g, 0.00001);
58
- this._v = Math.max(this._tmpColor.b, 0.00001);
59
- this._markAsDirty();
60
- if (this._value.r <= ColorPicker._Epsilon) {
61
- this._value.r = 0;
62
- }
63
- if (this._value.g <= ColorPicker._Epsilon) {
64
- this._value.g = 0;
65
- }
66
- if (this._value.b <= ColorPicker._Epsilon) {
67
- this._value.b = 0;
68
- }
69
- if (this._value.r >= 1.0 - ColorPicker._Epsilon) {
70
- this._value.r = 1.0;
71
- }
72
- if (this._value.g >= 1.0 - ColorPicker._Epsilon) {
73
- this._value.g = 1.0;
74
- }
75
- if (this._value.b >= 1.0 - ColorPicker._Epsilon) {
76
- this._value.b = 1.0;
77
- }
78
- this.onValueChangedObservable.notifyObservers(this._value);
79
- },
80
- enumerable: false,
81
- configurable: true
82
- });
83
- Object.defineProperty(ColorPicker.prototype, "width", {
84
- /**
85
- * Gets or sets control width
86
- * @see https://doc.babylonjs.com/how_to/gui#position-and-size
87
- */
88
- get: function () {
89
- return this._width.toString(this._host);
90
- },
91
- set: function (value) {
92
- if (this._width.toString(this._host) === value) {
93
- return;
94
- }
95
- if (this._width.fromString(value)) {
96
- if (this._width.getValue(this._host) === 0) {
97
- value = '1px';
98
- this._width.fromString(value);
99
- }
100
- this._height.fromString(value);
101
- this._markAsDirty();
102
- }
103
- },
104
- enumerable: false,
105
- configurable: true
106
- });
107
- Object.defineProperty(ColorPicker.prototype, "height", {
108
- /**
109
- * Gets or sets control height
110
- * @see https://doc.babylonjs.com/how_to/gui#position-and-size
111
- */
112
- get: function () {
113
- return this._height.toString(this._host);
114
- },
115
- /** Gets or sets control height */
116
- set: function (value) {
117
- if (this._height.toString(this._host) === value) {
118
- return;
119
- }
120
- if (this._height.fromString(value)) {
121
- if (this._height.getValue(this._host) === 0) {
122
- value = '1px';
123
- this._height.fromString(value);
124
- }
125
- this._width.fromString(value);
126
- this._markAsDirty();
127
- }
128
- },
129
- enumerable: false,
130
- configurable: true
131
- });
132
- Object.defineProperty(ColorPicker.prototype, "size", {
133
- /** Gets or sets control size */
134
- get: function () {
135
- return this.width;
136
- },
137
- set: function (value) {
138
- this.width = value;
139
- },
140
- enumerable: false,
141
- configurable: true
142
- });
143
- ColorPicker.prototype._getTypeName = function () {
144
- return "ColorPicker";
145
- };
146
- /** @hidden */
147
- ColorPicker.prototype._preMeasure = function (parentMeasure, context) {
148
- if (parentMeasure.width < parentMeasure.height) {
149
- this._currentMeasure.height = parentMeasure.width;
150
- }
151
- else {
152
- this._currentMeasure.width = parentMeasure.height;
153
- }
154
- };
155
- ColorPicker.prototype._updateSquareProps = function () {
156
- var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
157
- var wheelThickness = radius * .2;
158
- var innerDiameter = (radius - wheelThickness) * 2;
159
- var squareSize = innerDiameter / (Math.sqrt(2));
160
- var offset = radius - squareSize * .5;
161
- this._squareLeft = this._currentMeasure.left + offset;
162
- this._squareTop = this._currentMeasure.top + offset;
163
- this._squareSize = squareSize;
164
- };
165
- ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
166
- var lgh = context.createLinearGradient(left, top, width + left, top);
167
- lgh.addColorStop(0, '#fff');
168
- lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
169
- context.fillStyle = lgh;
170
- context.fillRect(left, top, width, height);
171
- var lgv = context.createLinearGradient(left, top, left, height + top);
172
- lgv.addColorStop(0, 'rgba(0,0,0,0)');
173
- lgv.addColorStop(1, '#000');
174
- context.fillStyle = lgv;
175
- context.fillRect(left, top, width, height);
176
- };
177
- ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
178
- context.beginPath();
179
- context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
180
- context.lineWidth = 3;
181
- context.strokeStyle = '#333333';
182
- context.stroke();
183
- context.beginPath();
184
- context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
185
- context.lineWidth = 3;
186
- context.strokeStyle = '#ffffff';
187
- context.stroke();
188
- };
189
- ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
190
- // Shoudl abstract platform instead of using LastCreatedEngine
191
- var engine = EngineStore.LastCreatedEngine;
192
- if (!engine) {
193
- throw new Error("Invalid engine. Unable to create a canvas.");
194
- }
195
- var canvas = engine.createCanvas(radius * 2, radius * 2);
196
- var context = canvas.getContext("2d");
197
- var image = context.getImageData(0, 0, radius * 2, radius * 2);
198
- var data = image.data;
199
- var color = this._tmpColor;
200
- var maxDistSq = radius * radius;
201
- var innerRadius = radius - thickness;
202
- var minDistSq = innerRadius * innerRadius;
203
- for (var x = -radius; x < radius; x++) {
204
- for (var y = -radius; y < radius; y++) {
205
- var distSq = x * x + y * y;
206
- if (distSq > maxDistSq || distSq < minDistSq) {
207
- continue;
208
- }
209
- var dist = Math.sqrt(distSq);
210
- var ang = Math.atan2(y, x);
211
- Color3.HSVtoRGBToRef(ang * 180 / Math.PI + 180, dist / radius, 1, color);
212
- var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
213
- data[index] = color.r * 255;
214
- data[index + 1] = color.g * 255;
215
- data[index + 2] = color.b * 255;
216
- var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
217
- //apply less alpha to bigger color pickers
218
- var alphaAmount = .2;
219
- var maxAlpha = .2;
220
- var minAlpha = .04;
221
- var lowerRadius = 50;
222
- var upperRadius = 150;
223
- if (radius < lowerRadius) {
224
- alphaAmount = maxAlpha;
225
- }
226
- else if (radius > upperRadius) {
227
- alphaAmount = minAlpha;
228
- }
229
- else {
230
- alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
231
- }
232
- var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
233
- if (alphaRatio < alphaAmount) {
234
- data[index + 3] = 255 * (alphaRatio / alphaAmount);
235
- }
236
- else if (alphaRatio > 1 - alphaAmount) {
237
- data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
238
- }
239
- else {
240
- data[index + 3] = 255;
241
- }
242
- }
243
- }
244
- context.putImageData(image, 0, 0);
245
- return canvas;
246
- };
247
- /** @hidden */
248
- ColorPicker.prototype._draw = function (context) {
249
- context.save();
250
- this._applyStates(context);
251
- var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
252
- var wheelThickness = radius * .2;
253
- var left = this._currentMeasure.left;
254
- var top = this._currentMeasure.top;
255
- if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
256
- this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
257
- }
258
- this._updateSquareProps();
259
- if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
260
- context.shadowColor = this.shadowColor;
261
- context.shadowBlur = this.shadowBlur;
262
- context.shadowOffsetX = this.shadowOffsetX;
263
- context.shadowOffsetY = this.shadowOffsetY;
264
- context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
265
- }
266
- context.drawImage(this._colorWheelCanvas, left, top);
267
- if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
268
- context.shadowBlur = 0;
269
- context.shadowOffsetX = 0;
270
- context.shadowOffsetY = 0;
271
- }
272
- this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
273
- var cx = this._squareLeft + this._squareSize * this._s;
274
- var cy = this._squareTop + this._squareSize * (1 - this._v);
275
- this._drawCircle(cx, cy, radius * .04, context);
276
- var dist = radius - wheelThickness * .5;
277
- cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
278
- cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
279
- this._drawCircle(cx, cy, wheelThickness * .35, context);
280
- context.restore();
281
- };
282
- ColorPicker.prototype._updateValueFromPointer = function (x, y) {
283
- if (this._pointerStartedOnWheel) {
284
- var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
285
- var centerX = radius + this._currentMeasure.left;
286
- var centerY = radius + this._currentMeasure.top;
287
- this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
288
- }
289
- else if (this._pointerStartedOnSquare) {
290
- this._updateSquareProps();
291
- this._s = (x - this._squareLeft) / this._squareSize;
292
- this._v = 1 - (y - this._squareTop) / this._squareSize;
293
- this._s = Math.min(this._s, 1);
294
- this._s = Math.max(this._s, ColorPicker._Epsilon);
295
- this._v = Math.min(this._v, 1);
296
- this._v = Math.max(this._v, ColorPicker._Epsilon);
297
- }
298
- Color3.HSVtoRGBToRef(this._h, this._s, this._v, this._tmpColor);
299
- this.value = this._tmpColor;
300
- };
301
- ColorPicker.prototype._isPointOnSquare = function (x, y) {
302
- this._updateSquareProps();
303
- var left = this._squareLeft;
304
- var top = this._squareTop;
305
- var size = this._squareSize;
306
- if (x >= left && x <= left + size &&
307
- y >= top && y <= top + size) {
308
- return true;
309
- }
310
- return false;
311
- };
312
- ColorPicker.prototype._isPointOnWheel = function (x, y) {
313
- var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
314
- var centerX = radius + this._currentMeasure.left;
315
- var centerY = radius + this._currentMeasure.top;
316
- var wheelThickness = radius * .2;
317
- var innerRadius = radius - wheelThickness;
318
- var radiusSq = radius * radius;
319
- var innerRadiusSq = innerRadius * innerRadius;
320
- var dx = x - centerX;
321
- var dy = y - centerY;
322
- var distSq = dx * dx + dy * dy;
323
- if (distSq <= radiusSq && distSq >= innerRadiusSq) {
324
- return true;
325
- }
326
- return false;
327
- };
328
- ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex, pi) {
329
- if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex, pi)) {
330
- return false;
331
- }
332
- if (this.isReadOnly) {
333
- return true;
334
- }
335
- this._pointerIsDown = true;
336
- this._pointerStartedOnSquare = false;
337
- this._pointerStartedOnWheel = false;
338
- // Invert transform
339
- this._invertTransformMatrix.transformCoordinates(coordinates.x, coordinates.y, this._transformedPosition);
340
- var x = this._transformedPosition.x;
341
- var y = this._transformedPosition.y;
342
- if (this._isPointOnSquare(x, y)) {
343
- this._pointerStartedOnSquare = true;
344
- }
345
- else if (this._isPointOnWheel(x, y)) {
346
- this._pointerStartedOnWheel = true;
347
- }
348
- this._updateValueFromPointer(x, y);
349
- this._host._capturingControl[pointerId] = this;
350
- this._lastPointerDownId = pointerId;
351
- return true;
352
- };
353
- ColorPicker.prototype._onPointerMove = function (target, coordinates, pointerId, pi) {
354
- // Only listen to pointer move events coming from the last pointer to click on the element (To support dual vr controller interaction)
355
- if (pointerId != this._lastPointerDownId) {
356
- return;
357
- }
358
- if (!this.isReadOnly) {
359
- // Invert transform
360
- this._invertTransformMatrix.transformCoordinates(coordinates.x, coordinates.y, this._transformedPosition);
361
- var x = this._transformedPosition.x;
362
- var y = this._transformedPosition.y;
363
- if (this._pointerIsDown) {
364
- this._updateValueFromPointer(x, y);
365
- }
366
- }
367
- _super.prototype._onPointerMove.call(this, target, coordinates, pointerId, pi);
368
- };
369
- ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick, pi) {
370
- this._pointerIsDown = false;
371
- delete this._host._capturingControl[pointerId];
372
- _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick, pi);
373
- };
374
- ColorPicker.prototype._onCanvasBlur = function () {
375
- this._forcePointerUp();
376
- _super.prototype._onCanvasBlur.call(this);
377
- };
378
- /**
379
- * This function expands the color picker by creating a color picker dialog with manual
380
- * color value input and the ability to save colors into an array to be used later in
381
- * subsequent launches of the dialogue.
382
- * @param advancedTexture defines the AdvancedDynamicTexture the dialog is assigned to
383
- * @param options defines size for dialog and options for saved colors. Also accepts last color picked as hex string and saved colors array as hex strings.
384
- * @returns picked color as a hex string and the saved colors array as hex strings.
385
- */
386
- ColorPicker.ShowPickerDialogAsync = function (advancedTexture, options) {
387
- return new Promise(function (resolve, reject) {
388
- // Default options
389
- options.pickerWidth = options.pickerWidth || "640px";
390
- options.pickerHeight = options.pickerHeight || "400px";
391
- options.headerHeight = options.headerHeight || "35px";
392
- options.lastColor = options.lastColor || "#000000";
393
- options.swatchLimit = options.swatchLimit || 20;
394
- options.numSwatchesPerLine = options.numSwatchesPerLine || 10;
395
- // Window size settings
396
- var drawerMaxRows = options.swatchLimit / options.numSwatchesPerLine;
397
- var rawSwatchSize = parseFloat(options.pickerWidth) / options.numSwatchesPerLine;
398
- var gutterSize = Math.floor(rawSwatchSize * 0.25);
399
- var colGutters = gutterSize * (options.numSwatchesPerLine + 1);
400
- var swatchSize = Math.floor((parseFloat(options.pickerWidth) - colGutters) / options.numSwatchesPerLine);
401
- var drawerMaxSize = (swatchSize * drawerMaxRows) + (gutterSize * (drawerMaxRows + 1));
402
- var containerSize = (parseInt(options.pickerHeight) + drawerMaxSize + Math.floor(swatchSize * 0.25)).toString() + "px";
403
- // Button Colors
404
- var buttonColor = "#c0c0c0";
405
- var buttonBackgroundColor = "#535353";
406
- var buttonBackgroundHoverColor = "#414141";
407
- var buttonBackgroundClickColor = "515151";
408
- var buttonDisabledColor = "#555555";
409
- var buttonDisabledBackgroundColor = "#454545";
410
- var currentSwatchesOutlineColor = "#404040";
411
- var luminanceLimitColor = Color3.FromHexString("#dddddd");
412
- var luminanceLimit = luminanceLimitColor.r + luminanceLimitColor.g + luminanceLimitColor.b;
413
- var iconColorDark = "#aaaaaa";
414
- var iconColorLight = "#ffffff";
415
- var closeIconColor;
416
- // Button settings
417
- var buttonFontSize;
418
- var butEdit;
419
- var buttonWidth;
420
- var buttonHeight;
421
- // Input Text Colors
422
- var inputFieldLabels = ["R", "G", "B"];
423
- var inputTextBackgroundColor = "#454545";
424
- var inputTextColor = "#f0f0f0";
425
- // This is the current color as set by either the picker or by entering a value
426
- var currentColor;
427
- // This int is used for naming swatches and serves as the index for calling them from the list
428
- var swatchNumber;
429
- // Menu Panel options. We need to know if the swatchDrawer exists so we can create it if needed.
430
- var swatchDrawer;
431
- var editSwatchMode = false;
432
- // Color InputText fields that will be updated upon value change
433
- var picker;
434
- var rValInt;
435
- var gValInt;
436
- var bValInt;
437
- var rValDec;
438
- var gValDec;
439
- var bValDec;
440
- var hexVal;
441
- var newSwatch;
442
- var lastVal;
443
- var activeField;
444
- /**
445
- * Will update all values for InputText and ColorPicker controls based on the BABYLON.Color3 passed to this function.
446
- * Each InputText control and the ColorPicker control will be tested to see if they are the activeField and if they
447
- * are will receive no update. This is to prevent the input from the user being overwritten.
448
- */
449
- function updateValues(value, inputField) {
450
- activeField = inputField;
451
- var pickedColor = value.toHexString();
452
- newSwatch.background = pickedColor;
453
- if (rValInt.name != activeField) {
454
- rValInt.text = Math.floor(value.r * 255).toString();
455
- }
456
- if (gValInt.name != activeField) {
457
- gValInt.text = Math.floor(value.g * 255).toString();
458
- }
459
- if (bValInt.name != activeField) {
460
- bValInt.text = Math.floor(value.b * 255).toString();
461
- }
462
- if (rValDec.name != activeField) {
463
- rValDec.text = value.r.toString();
464
- }
465
- if (gValDec.name != activeField) {
466
- gValDec.text = value.g.toString();
467
- }
468
- if (bValDec.name != activeField) {
469
- bValDec.text = value.b.toString();
470
- }
471
- if (hexVal.name != activeField) {
472
- var minusPound = pickedColor.split("#");
473
- hexVal.text = minusPound[1];
474
- }
475
- if (picker.name != activeField) {
476
- picker.value = value;
477
- }
478
- }
479
- // When the user enters an integer for R, G, or B we check to make sure it is a valid number and replace if not.
480
- function updateInt(field, channel) {
481
- var newValue = field.text;
482
- var checkVal = /[^0-9]/g.test(newValue);
483
- if (checkVal) {
484
- field.text = lastVal;
485
- return;
486
- }
487
- else {
488
- if (newValue != "") {
489
- if (Math.floor(parseInt(newValue)) < 0) {
490
- newValue = "0";
491
- }
492
- else if (Math.floor(parseInt(newValue)) > 255) {
493
- newValue = "255";
494
- }
495
- else if (isNaN(parseInt(newValue))) {
496
- newValue = "0";
497
- }
498
- }
499
- if (activeField == field.name) {
500
- lastVal = newValue;
501
- }
502
- }
503
- if (newValue != "") {
504
- newValue = parseInt(newValue).toString();
505
- field.text = newValue;
506
- var newSwatchRGB = Color3.FromHexString(newSwatch.background);
507
- if (activeField == field.name) {
508
- if (channel == "r") {
509
- updateValues(new Color3((parseInt(newValue)) / 255, newSwatchRGB.g, newSwatchRGB.b), field.name);
510
- }
511
- else if (channel == "g") {
512
- updateValues(new Color3(newSwatchRGB.r, (parseInt(newValue)) / 255, newSwatchRGB.b), field.name);
513
- }
514
- else {
515
- updateValues(new Color3(newSwatchRGB.r, newSwatchRGB.g, (parseInt(newValue)) / 255), field.name);
516
- }
517
- }
518
- }
519
- }
520
- // When the user enters a float for R, G, or B we check to make sure it is a valid number and replace if not.
521
- function updateFloat(field, channel) {
522
- var newValue = field.text;
523
- var checkVal = /[^0-9\.]/g.test(newValue);
524
- if (checkVal) {
525
- field.text = lastVal;
526
- return;
527
- }
528
- else {
529
- if (newValue != "" && newValue != "." && parseFloat(newValue) != 0) {
530
- if (parseFloat(newValue) < 0.0) {
531
- newValue = "0.0";
532
- }
533
- else if (parseFloat(newValue) > 1.0) {
534
- newValue = "1.0";
535
- }
536
- else if (isNaN(parseFloat(newValue))) {
537
- newValue = "0.0";
538
- }
539
- }
540
- if (activeField == field.name) {
541
- lastVal = newValue;
542
- }
543
- }
544
- if (newValue != "" && newValue != "." && parseFloat(newValue) != 0) {
545
- newValue = parseFloat(newValue).toString();
546
- field.text = newValue;
547
- }
548
- else {
549
- newValue = "0.0";
550
- }
551
- var newSwatchRGB = Color3.FromHexString(newSwatch.background);
552
- if (activeField == field.name) {
553
- if (channel == "r") {
554
- updateValues(new Color3(parseFloat(newValue), newSwatchRGB.g, newSwatchRGB.b), field.name);
555
- }
556
- else if (channel == "g") {
557
- updateValues(new Color3(newSwatchRGB.r, parseFloat(newValue), newSwatchRGB.b), field.name);
558
- }
559
- else {
560
- updateValues(new Color3(newSwatchRGB.r, newSwatchRGB.g, parseFloat(newValue)), field.name);
561
- }
562
- }
563
- }
564
- // Removes the current index from the savedColors array. Drawer can then be regenerated.
565
- function deleteSwatch(index) {
566
- if (options.savedColors) {
567
- options.savedColors.splice(index, 1);
568
- }
569
- if (options.savedColors && options.savedColors.length == 0) {
570
- setEditButtonVisibility(false);
571
- editSwatchMode = false;
572
- }
573
- }
574
- // Creates and styles an individual swatch when updateSwatches is called.
575
- function createSwatch() {
576
- if (options.savedColors && options.savedColors[swatchNumber]) {
577
- if (editSwatchMode) {
578
- var icon = "b";
579
- }
580
- else {
581
- var icon = "";
582
- }
583
- var swatch = Button.CreateSimpleButton("Swatch_" + swatchNumber, icon);
584
- swatch.fontFamily = "BabylonJSglyphs";
585
- var swatchColor = Color3.FromHexString(options.savedColors[swatchNumber]);
586
- var swatchLuminence = swatchColor.r + swatchColor.g + swatchColor.b;
587
- // Set color of outline and textBlock based on luminance of the color swatch so feedback always visible
588
- if (swatchLuminence > luminanceLimit) {
589
- swatch.color = iconColorDark;
590
- }
591
- else {
592
- swatch.color = iconColorLight;
593
- }
594
- swatch.fontSize = Math.floor(swatchSize * 0.7);
595
- swatch.textBlock.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
596
- swatch.height = swatch.width = (swatchSize).toString() + "px";
597
- swatch.background = options.savedColors[swatchNumber];
598
- swatch.thickness = 2;
599
- var metadata_1 = swatchNumber;
600
- swatch.pointerDownAnimation = function () {
601
- swatch.thickness = 4;
602
- };
603
- swatch.pointerUpAnimation = function () {
604
- swatch.thickness = 3;
605
- };
606
- swatch.pointerEnterAnimation = function () {
607
- swatch.thickness = 3;
608
- };
609
- swatch.pointerOutAnimation = function () {
610
- swatch.thickness = 2;
611
- };
612
- swatch.onPointerClickObservable.add(function () {
613
- if (!editSwatchMode) {
614
- if (options.savedColors) {
615
- updateValues(Color3.FromHexString(options.savedColors[metadata_1]), swatch.name);
616
- }
617
- }
618
- else {
619
- deleteSwatch(metadata_1);
620
- updateSwatches("", butSave);
621
- }
622
- });
623
- return swatch;
624
- }
625
- else {
626
- return null;
627
- }
628
- }
629
- // Mode switch to render button text and close symbols on swatch controls
630
- function editSwatches(mode) {
631
- if (mode !== undefined) {
632
- editSwatchMode = mode;
633
- }
634
- if (editSwatchMode) {
635
- for (var i = 0; i < swatchDrawer.children.length; i++) {
636
- var thisButton = swatchDrawer.children[i];
637
- thisButton.textBlock.text = "b";
638
- }
639
- if (butEdit !== undefined) {
640
- butEdit.textBlock.text = "Done";
641
- }
642
- }
643
- else {
644
- for (var i = 0; i < swatchDrawer.children.length; i++) {
645
- var thisButton = swatchDrawer.children[i];
646
- thisButton.textBlock.text = "";
647
- }
648
- if (butEdit !== undefined) {
649
- butEdit.textBlock.text = "Edit";
650
- }
651
- }
652
- }
653
- /**
654
- * When Save Color button is pressed this function will first create a swatch drawer if one is not already
655
- * made. Then all controls are removed from the drawer and we step through the savedColors array and
656
- * creates one swatch per color. It will also set the height of the drawer control based on how many
657
- * saved colors there are and how many can be stored per row.
658
- */
659
- function updateSwatches(color, button) {
660
- if (options.savedColors) {
661
- if (color != "") {
662
- options.savedColors.push(color);
663
- }
664
- swatchNumber = 0;
665
- swatchDrawer.clearControls();
666
- var rowCount = Math.ceil(options.savedColors.length / options.numSwatchesPerLine);
667
- if (rowCount == 0) {
668
- var gutterCount = 0;
669
- }
670
- else {
671
- var gutterCount = rowCount + 1;
672
- }
673
- if (swatchDrawer.rowCount != rowCount + gutterCount) {
674
- var currentRows = swatchDrawer.rowCount;
675
- for (var i = 0; i < currentRows; i++) {
676
- swatchDrawer.removeRowDefinition(0);
677
- }
678
- for (var i = 0; i < rowCount + gutterCount; i++) {
679
- if (i % 2) {
680
- swatchDrawer.addRowDefinition(swatchSize, true);
681
- }
682
- else {
683
- swatchDrawer.addRowDefinition(gutterSize, true);
684
- }
685
- }
686
- }
687
- swatchDrawer.height = ((swatchSize * rowCount) + (gutterCount * gutterSize)).toString() + "px";
688
- for (var y = 1, thisRow = 1; y < rowCount + gutterCount; y += 2, thisRow++) {
689
- // Determine number of buttons to create per row based on the button limit per row and number of saved colors
690
- if (options.savedColors.length > thisRow * options.numSwatchesPerLine) {
691
- var totalButtonsThisRow = options.numSwatchesPerLine;
692
- }
693
- else {
694
- var totalButtonsThisRow = options.savedColors.length - ((thisRow - 1) * options.numSwatchesPerLine);
695
- }
696
- var buttonIterations = (Math.min(Math.max(totalButtonsThisRow, 0), options.numSwatchesPerLine));
697
- for (var x = 0, w = 1; x < buttonIterations; x++) {
698
- if (x > options.numSwatchesPerLine) {
699
- continue;
700
- }
701
- var swatch = createSwatch();
702
- if (swatch != null) {
703
- swatchDrawer.addControl(swatch, y, w);
704
- w += 2;
705
- swatchNumber++;
706
- }
707
- else {
708
- continue;
709
- }
710
- }
711
- }
712
- if (options.savedColors.length >= options.swatchLimit) {
713
- disableButton(button, true);
714
- }
715
- else {
716
- disableButton(button, false);
717
- }
718
- }
719
- }
720
- // Shows or hides edit swatches button depending on if there are saved swatches
721
- function setEditButtonVisibility(enableButton) {
722
- if (enableButton) {
723
- butEdit = Button.CreateSimpleButton("butEdit", "Edit");
724
- butEdit.width = buttonWidth;
725
- butEdit.height = buttonHeight;
726
- butEdit.left = (Math.floor(parseInt(buttonWidth) * 0.1)).toString() + "px";
727
- butEdit.top = (parseFloat(butEdit.left) * -1).toString() + "px";
728
- butEdit.verticalAlignment = Control.VERTICAL_ALIGNMENT_BOTTOM;
729
- butEdit.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
730
- butEdit.thickness = 2;
731
- butEdit.color = buttonColor;
732
- butEdit.fontSize = buttonFontSize;
733
- butEdit.background = buttonBackgroundColor;
734
- butEdit.onPointerEnterObservable.add(function () {
735
- butEdit.background = buttonBackgroundHoverColor;
736
- });
737
- butEdit.onPointerOutObservable.add(function () {
738
- butEdit.background = buttonBackgroundColor;
739
- });
740
- butEdit.pointerDownAnimation = function () {
741
- butEdit.background = buttonBackgroundClickColor;
742
- };
743
- butEdit.pointerUpAnimation = function () {
744
- butEdit.background = buttonBackgroundHoverColor;
745
- };
746
- butEdit.onPointerClickObservable.add(function () {
747
- if (editSwatchMode) {
748
- editSwatchMode = false;
749
- }
750
- else {
751
- editSwatchMode = true;
752
- }
753
- editSwatches();
754
- });
755
- pickerGrid.addControl(butEdit, 1, 0);
756
- }
757
- else {
758
- pickerGrid.removeControl(butEdit);
759
- }
760
- }
761
- // Called when the user hits the limit of saved colors in the drawer.
762
- function disableButton(button, disabled) {
763
- if (disabled) {
764
- button.color = buttonDisabledColor;
765
- button.background = buttonDisabledBackgroundColor;
766
- }
767
- else {
768
- button.color = buttonColor;
769
- button.background = buttonBackgroundColor;
770
- }
771
- }
772
- // Passes last chosen color back to scene and kills dialog by removing from AdvancedDynamicTexture
773
- function closePicker(color) {
774
- if (options.savedColors && options.savedColors.length > 0) {
775
- resolve({
776
- savedColors: options.savedColors,
777
- pickedColor: color
778
- });
779
- }
780
- else {
781
- resolve({
782
- pickedColor: color
783
- });
784
- }
785
- advancedTexture.removeControl(dialogContainer);
786
- }
787
- // Dialogue menu container which will contain both the main dialogue window and the swatch drawer which opens once a color is saved.
788
- var dialogContainer = new Grid();
789
- dialogContainer.name = "Dialog Container";
790
- dialogContainer.width = options.pickerWidth;
791
- if (options.savedColors) {
792
- dialogContainer.height = containerSize;
793
- var topRow = parseInt(options.pickerHeight) / parseInt(containerSize);
794
- dialogContainer.addRowDefinition(topRow, false);
795
- dialogContainer.addRowDefinition(1.0 - topRow, false);
796
- }
797
- else {
798
- dialogContainer.height = options.pickerHeight;
799
- dialogContainer.addRowDefinition(1.0, false);
800
- }
801
- advancedTexture.addControl(dialogContainer);
802
- // Swatch drawer which contains all saved color buttons
803
- if (options.savedColors) {
804
- swatchDrawer = new Grid();
805
- swatchDrawer.name = "Swatch Drawer";
806
- swatchDrawer.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
807
- swatchDrawer.background = buttonBackgroundColor;
808
- swatchDrawer.width = options.pickerWidth;
809
- var initialRows = options.savedColors.length / options.numSwatchesPerLine;
810
- if (initialRows == 0) {
811
- var gutterCount = 0;
812
- }
813
- else {
814
- var gutterCount = initialRows + 1;
815
- }
816
- swatchDrawer.height = ((swatchSize * initialRows) + (gutterCount * gutterSize)).toString() + "px";
817
- swatchDrawer.top = Math.floor(swatchSize * 0.25).toString() + "px";
818
- for (var i = 0; i < (Math.ceil(options.savedColors.length / options.numSwatchesPerLine) * 2) + 1; i++) {
819
- if (i % 2 != 0) {
820
- swatchDrawer.addRowDefinition(swatchSize, true);
821
- }
822
- else {
823
- swatchDrawer.addRowDefinition(gutterSize, true);
824
- }
825
- }
826
- for (var i = 0; i < options.numSwatchesPerLine * 2 + 1; i++) {
827
- if (i % 2 != 0) {
828
- swatchDrawer.addColumnDefinition(swatchSize, true);
829
- }
830
- else {
831
- swatchDrawer.addColumnDefinition(gutterSize, true);
832
- }
833
- }
834
- dialogContainer.addControl(swatchDrawer, 1, 0);
835
- }
836
- // Picker container
837
- var pickerPanel = new Grid();
838
- pickerPanel.name = "Picker Panel";
839
- pickerPanel.height = options.pickerHeight;
840
- var panelHead = parseInt(options.headerHeight) / parseInt(options.pickerHeight);
841
- var pickerPanelRows = [panelHead, 1.0 - panelHead];
842
- pickerPanel.addRowDefinition(pickerPanelRows[0], false);
843
- pickerPanel.addRowDefinition(pickerPanelRows[1], false);
844
- dialogContainer.addControl(pickerPanel, 0, 0);
845
- // Picker container header
846
- var header = new Rectangle();
847
- header.name = "Dialogue Header Bar";
848
- header.background = "#cccccc";
849
- header.thickness = 0;
850
- pickerPanel.addControl(header, 0, 0);
851
- // Header close button
852
- var closeButton = Button.CreateSimpleButton("closeButton", "a");
853
- closeButton.fontFamily = "BabylonJSglyphs";
854
- var headerColor3 = Color3.FromHexString(header.background);
855
- closeIconColor = new Color3(1.0 - headerColor3.r, 1.0 - headerColor3.g, 1.0 - headerColor3.b);
856
- closeButton.color = closeIconColor.toHexString();
857
- closeButton.fontSize = Math.floor(parseInt(options.headerHeight) * 0.6);
858
- closeButton.textBlock.textVerticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
859
- closeButton.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_RIGHT;
860
- closeButton.height = closeButton.width = options.headerHeight;
861
- closeButton.background = header.background;
862
- closeButton.thickness = 0;
863
- closeButton.pointerDownAnimation = function () {
864
- };
865
- closeButton.pointerUpAnimation = function () {
866
- closeButton.background = header.background;
867
- };
868
- closeButton.pointerEnterAnimation = function () {
869
- closeButton.color = header.background;
870
- closeButton.background = "red";
871
- };
872
- closeButton.pointerOutAnimation = function () {
873
- closeButton.color = closeIconColor.toHexString();
874
- closeButton.background = header.background;
875
- };
876
- closeButton.onPointerClickObservable.add(function () {
877
- closePicker(currentSwatch.background);
878
- });
879
- pickerPanel.addControl(closeButton, 0, 0);
880
- // Dialog container body
881
- var dialogBody = new Grid();
882
- dialogBody.name = "Dialogue Body";
883
- dialogBody.background = buttonBackgroundColor;
884
- var dialogBodyCols = [0.4375, 0.5625];
885
- dialogBody.addRowDefinition(1.0, false);
886
- dialogBody.addColumnDefinition(dialogBodyCols[0], false);
887
- dialogBody.addColumnDefinition(dialogBodyCols[1], false);
888
- pickerPanel.addControl(dialogBody, 1, 0);
889
- // Picker grid
890
- var pickerGrid = new Grid();
891
- pickerGrid.name = "Picker Grid";
892
- pickerGrid.addRowDefinition(0.85, false);
893
- pickerGrid.addRowDefinition(0.15, false);
894
- dialogBody.addControl(pickerGrid, 0, 0);
895
- // Picker control
896
- picker = new ColorPicker();
897
- picker.name = "GUI Color Picker";
898
- if (options.pickerHeight < options.pickerWidth) {
899
- picker.width = 0.89;
900
- }
901
- else {
902
- picker.height = 0.89;
903
- }
904
- picker.value = Color3.FromHexString(options.lastColor);
905
- picker.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
906
- picker.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
907
- picker.onPointerDownObservable.add(function () {
908
- activeField = picker.name;
909
- lastVal = "";
910
- editSwatches(false);
911
- });
912
- picker.onValueChangedObservable.add(function (value) {
913
- if (activeField == picker.name) {
914
- updateValues(value, picker.name);
915
- }
916
- });
917
- pickerGrid.addControl(picker, 0, 0);
918
- // Picker body right quarant
919
- var pickerBodyRight = new Grid();
920
- pickerBodyRight.name = "Dialogue Right Half";
921
- pickerBodyRight.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
922
- var pickerBodyRightRows = [0.514, 0.486];
923
- pickerBodyRight.addRowDefinition(pickerBodyRightRows[0], false);
924
- pickerBodyRight.addRowDefinition(pickerBodyRightRows[1], false);
925
- dialogBody.addControl(pickerBodyRight, 1, 1);
926
- // Picker container swatches and buttons
927
- var pickerSwatchesButtons = new Grid();
928
- pickerSwatchesButtons.name = "Swatches and Buttons";
929
- var pickerButtonsCol = [0.417, 0.583];
930
- pickerSwatchesButtons.addRowDefinition(1.0, false);
931
- pickerSwatchesButtons.addColumnDefinition(pickerButtonsCol[0], false);
932
- pickerSwatchesButtons.addColumnDefinition(pickerButtonsCol[1], false);
933
- pickerBodyRight.addControl(pickerSwatchesButtons, 0, 0);
934
- // Picker Swatches quadrant
935
- var pickerSwatches = new Grid();
936
- pickerSwatches.name = "New and Current Swatches";
937
- var pickeSwatchesRows = [0.04, 0.16, 0.64, 0.16];
938
- pickerSwatches.addRowDefinition(pickeSwatchesRows[0], false);
939
- pickerSwatches.addRowDefinition(pickeSwatchesRows[1], false);
940
- pickerSwatches.addRowDefinition(pickeSwatchesRows[2], false);
941
- pickerSwatches.addRowDefinition(pickeSwatchesRows[3], false);
942
- pickerSwatchesButtons.addControl(pickerSwatches, 0, 0);
943
- // Active swatches
944
- var activeSwatches = new Grid();
945
- activeSwatches.name = "Active Swatches";
946
- activeSwatches.width = 0.67;
947
- activeSwatches.addRowDefinition(0.5, false);
948
- activeSwatches.addRowDefinition(0.5, false);
949
- pickerSwatches.addControl(activeSwatches, 2, 0);
950
- var labelWidth = (Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[0] * 0.11));
951
- var labelHeight = (Math.floor(parseInt(options.pickerHeight) * pickerPanelRows[1] * pickerBodyRightRows[0] * pickeSwatchesRows[1] * 0.5));
952
- if (options.pickerWidth > options.pickerHeight) {
953
- var labelTextSize = labelHeight;
954
- }
955
- else {
956
- var labelTextSize = labelWidth;
957
- }
958
- // New color swatch and previous color button
959
- var newText = new TextBlock();
960
- newText.text = "new";
961
- newText.name = "New Color Label";
962
- newText.color = buttonColor;
963
- newText.fontSize = labelTextSize;
964
- pickerSwatches.addControl(newText, 1, 0);
965
- newSwatch = new Rectangle();
966
- newSwatch.name = "New Color Swatch";
967
- newSwatch.background = options.lastColor;
968
- newSwatch.thickness = 0;
969
- activeSwatches.addControl(newSwatch, 0, 0);
970
- var currentSwatch = Button.CreateSimpleButton("currentSwatch", "");
971
- currentSwatch.background = options.lastColor;
972
- currentSwatch.thickness = 0;
973
- currentSwatch.onPointerClickObservable.add(function () {
974
- var revertColor = Color3.FromHexString(currentSwatch.background);
975
- updateValues(revertColor, currentSwatch.name);
976
- editSwatches(false);
977
- });
978
- currentSwatch.pointerDownAnimation = function () { };
979
- currentSwatch.pointerUpAnimation = function () { };
980
- currentSwatch.pointerEnterAnimation = function () { };
981
- currentSwatch.pointerOutAnimation = function () { };
982
- activeSwatches.addControl(currentSwatch, 1, 0);
983
- var swatchOutline = new Rectangle();
984
- swatchOutline.name = "Swatch Outline";
985
- swatchOutline.width = 0.67;
986
- swatchOutline.thickness = 2;
987
- swatchOutline.color = currentSwatchesOutlineColor;
988
- swatchOutline.isHitTestVisible = false;
989
- pickerSwatches.addControl(swatchOutline, 2, 0);
990
- var currentText = new TextBlock();
991
- currentText.name = "Current Color Label";
992
- currentText.text = "current";
993
- currentText.color = buttonColor;
994
- currentText.fontSize = labelTextSize;
995
- pickerSwatches.addControl(currentText, 3, 0);
996
- // Buttons grid
997
- var buttonGrid = new Grid();
998
- buttonGrid.name = "Button Grid";
999
- buttonGrid.height = 0.8;
1000
- var buttonGridRows = 1 / 3;
1001
- buttonGrid.addRowDefinition(buttonGridRows, false);
1002
- buttonGrid.addRowDefinition(buttonGridRows, false);
1003
- buttonGrid.addRowDefinition(buttonGridRows, false);
1004
- pickerSwatchesButtons.addControl(buttonGrid, 0, 1);
1005
- // Determine pixel width and height for all buttons from overall panel dimensions
1006
- buttonWidth = (Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[1] * 0.67)).toString() + "px";
1007
- buttonHeight = (Math.floor(parseInt(options.pickerHeight) * pickerPanelRows[1] * pickerBodyRightRows[0] * (parseFloat(buttonGrid.height.toString()) / 100) * buttonGridRows * 0.7)).toString() + "px";
1008
- // Determine button type size
1009
- if (parseFloat(buttonWidth) > parseFloat(buttonHeight)) {
1010
- buttonFontSize = Math.floor(parseFloat(buttonHeight) * 0.45);
1011
- }
1012
- else {
1013
- buttonFontSize = Math.floor(parseFloat(buttonWidth) * 0.11);
1014
- }
1015
- // Panel Buttons
1016
- var butOK = Button.CreateSimpleButton("butOK", "OK");
1017
- butOK.width = buttonWidth;
1018
- butOK.height = buttonHeight;
1019
- butOK.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
1020
- butOK.thickness = 2;
1021
- butOK.color = buttonColor;
1022
- butOK.fontSize = buttonFontSize;
1023
- butOK.background = buttonBackgroundColor;
1024
- butOK.onPointerEnterObservable.add(function () { butOK.background = buttonBackgroundHoverColor; });
1025
- butOK.onPointerOutObservable.add(function () { butOK.background = buttonBackgroundColor; });
1026
- butOK.pointerDownAnimation = function () {
1027
- butOK.background = buttonBackgroundClickColor;
1028
- };
1029
- butOK.pointerUpAnimation = function () {
1030
- butOK.background = buttonBackgroundHoverColor;
1031
- };
1032
- butOK.onPointerClickObservable.add(function () {
1033
- editSwatches(false);
1034
- closePicker(newSwatch.background);
1035
- });
1036
- buttonGrid.addControl(butOK, 0, 0);
1037
- var butCancel = Button.CreateSimpleButton("butCancel", "Cancel");
1038
- butCancel.width = buttonWidth;
1039
- butCancel.height = buttonHeight;
1040
- butCancel.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
1041
- butCancel.thickness = 2;
1042
- butCancel.color = buttonColor;
1043
- butCancel.fontSize = buttonFontSize;
1044
- butCancel.background = buttonBackgroundColor;
1045
- butCancel.onPointerEnterObservable.add(function () { butCancel.background = buttonBackgroundHoverColor; });
1046
- butCancel.onPointerOutObservable.add(function () { butCancel.background = buttonBackgroundColor; });
1047
- butCancel.pointerDownAnimation = function () {
1048
- butCancel.background = buttonBackgroundClickColor;
1049
- };
1050
- butCancel.pointerUpAnimation = function () {
1051
- butCancel.background = buttonBackgroundHoverColor;
1052
- };
1053
- butCancel.onPointerClickObservable.add(function () {
1054
- editSwatches(false);
1055
- closePicker(currentSwatch.background);
1056
- });
1057
- buttonGrid.addControl(butCancel, 1, 0);
1058
- if (options.savedColors) {
1059
- var butSave = Button.CreateSimpleButton("butSave", "Save");
1060
- butSave.width = buttonWidth;
1061
- butSave.height = buttonHeight;
1062
- butSave.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
1063
- butSave.thickness = 2;
1064
- butSave.fontSize = buttonFontSize;
1065
- if (options.savedColors.length < options.swatchLimit) {
1066
- butSave.color = buttonColor;
1067
- butSave.background = buttonBackgroundColor;
1068
- }
1069
- else {
1070
- disableButton(butSave, true);
1071
- }
1072
- butSave.onPointerEnterObservable.add(function () {
1073
- if (options.savedColors) {
1074
- if (options.savedColors.length < options.swatchLimit) {
1075
- butSave.background = buttonBackgroundHoverColor;
1076
- }
1077
- }
1078
- });
1079
- butSave.onPointerOutObservable.add(function () {
1080
- if (options.savedColors) {
1081
- if (options.savedColors.length < options.swatchLimit) {
1082
- butSave.background = buttonBackgroundColor;
1083
- }
1084
- }
1085
- });
1086
- butSave.pointerDownAnimation = function () {
1087
- if (options.savedColors) {
1088
- if (options.savedColors.length < options.swatchLimit) {
1089
- butSave.background = buttonBackgroundClickColor;
1090
- }
1091
- }
1092
- };
1093
- butSave.pointerUpAnimation = function () {
1094
- if (options.savedColors) {
1095
- if (options.savedColors.length < options.swatchLimit) {
1096
- butSave.background = buttonBackgroundHoverColor;
1097
- }
1098
- }
1099
- };
1100
- butSave.onPointerClickObservable.add(function () {
1101
- if (options.savedColors) {
1102
- if (options.savedColors.length == 0) {
1103
- setEditButtonVisibility(true);
1104
- }
1105
- if (options.savedColors.length < options.swatchLimit) {
1106
- updateSwatches(newSwatch.background, butSave);
1107
- }
1108
- editSwatches(false);
1109
- }
1110
- });
1111
- if (options.savedColors.length > 0) {
1112
- setEditButtonVisibility(true);
1113
- }
1114
- buttonGrid.addControl(butSave, 2, 0);
1115
- }
1116
- // Picker color values input
1117
- var pickerColorValues = new Grid();
1118
- pickerColorValues.name = "Dialog Lower Right";
1119
- pickerColorValues.addRowDefinition(0.02, false);
1120
- pickerColorValues.addRowDefinition(0.63, false);
1121
- pickerColorValues.addRowDefinition(0.21, false);
1122
- pickerColorValues.addRowDefinition(0.14, false);
1123
- pickerBodyRight.addControl(pickerColorValues, 1, 0);
1124
- // RGB values text boxes
1125
- currentColor = Color3.FromHexString(options.lastColor);
1126
- var rgbValuesQuadrant = new Grid();
1127
- rgbValuesQuadrant.name = "RGB Values";
1128
- rgbValuesQuadrant.width = 0.82;
1129
- rgbValuesQuadrant.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
1130
- rgbValuesQuadrant.addRowDefinition(1 / 3, false);
1131
- rgbValuesQuadrant.addRowDefinition(1 / 3, false);
1132
- rgbValuesQuadrant.addRowDefinition(1 / 3, false);
1133
- rgbValuesQuadrant.addColumnDefinition(0.1, false);
1134
- rgbValuesQuadrant.addColumnDefinition(0.2, false);
1135
- rgbValuesQuadrant.addColumnDefinition(0.7, false);
1136
- pickerColorValues.addControl(rgbValuesQuadrant, 1, 0);
1137
- for (var i = 0; i < inputFieldLabels.length; i++) {
1138
- var labelText = new TextBlock();
1139
- labelText.text = inputFieldLabels[i];
1140
- labelText.color = buttonColor;
1141
- labelText.fontSize = buttonFontSize;
1142
- rgbValuesQuadrant.addControl(labelText, i, 0);
1143
- }
1144
- // Input fields for RGB values
1145
- rValInt = new InputText();
1146
- rValInt.width = 0.83;
1147
- rValInt.height = 0.72;
1148
- rValInt.name = "rIntField";
1149
- rValInt.fontSize = buttonFontSize;
1150
- rValInt.text = (currentColor.r * 255).toString();
1151
- rValInt.color = inputTextColor;
1152
- rValInt.background = inputTextBackgroundColor;
1153
- rValInt.onFocusObservable.add(function () {
1154
- activeField = rValInt.name;
1155
- lastVal = rValInt.text;
1156
- editSwatches(false);
1157
- });
1158
- rValInt.onBlurObservable.add(function () {
1159
- if (rValInt.text == "") {
1160
- rValInt.text = "0";
1161
- }
1162
- updateInt(rValInt, "r");
1163
- if (activeField == rValInt.name) {
1164
- activeField = "";
1165
- }
1166
- });
1167
- rValInt.onTextChangedObservable.add(function () {
1168
- if (activeField == rValInt.name) {
1169
- updateInt(rValInt, "r");
1170
- }
1171
- });
1172
- rgbValuesQuadrant.addControl(rValInt, 0, 1);
1173
- gValInt = new InputText();
1174
- gValInt.width = 0.83;
1175
- gValInt.height = 0.72;
1176
- gValInt.name = "gIntField";
1177
- gValInt.fontSize = buttonFontSize;
1178
- gValInt.text = (currentColor.g * 255).toString();
1179
- gValInt.color = inputTextColor;
1180
- gValInt.background = inputTextBackgroundColor;
1181
- gValInt.onFocusObservable.add(function () {
1182
- activeField = gValInt.name;
1183
- lastVal = gValInt.text;
1184
- editSwatches(false);
1185
- });
1186
- gValInt.onBlurObservable.add(function () {
1187
- if (gValInt.text == "") {
1188
- gValInt.text = "0";
1189
- }
1190
- updateInt(gValInt, "g");
1191
- if (activeField == gValInt.name) {
1192
- activeField = "";
1193
- }
1194
- });
1195
- gValInt.onTextChangedObservable.add(function () {
1196
- if (activeField == gValInt.name) {
1197
- updateInt(gValInt, "g");
1198
- }
1199
- });
1200
- rgbValuesQuadrant.addControl(gValInt, 1, 1);
1201
- bValInt = new InputText();
1202
- bValInt.width = 0.83;
1203
- bValInt.height = 0.72;
1204
- bValInt.name = "bIntField";
1205
- bValInt.fontSize = buttonFontSize;
1206
- bValInt.text = (currentColor.b * 255).toString();
1207
- bValInt.color = inputTextColor;
1208
- bValInt.background = inputTextBackgroundColor;
1209
- bValInt.onFocusObservable.add(function () {
1210
- activeField = bValInt.name;
1211
- lastVal = bValInt.text;
1212
- editSwatches(false);
1213
- });
1214
- bValInt.onBlurObservable.add(function () {
1215
- if (bValInt.text == "") {
1216
- bValInt.text = "0";
1217
- }
1218
- updateInt(bValInt, "b");
1219
- if (activeField == bValInt.name) {
1220
- activeField = "";
1221
- }
1222
- });
1223
- bValInt.onTextChangedObservable.add(function () {
1224
- if (activeField == bValInt.name) {
1225
- updateInt(bValInt, "b");
1226
- }
1227
- });
1228
- rgbValuesQuadrant.addControl(bValInt, 2, 1);
1229
- rValDec = new InputText();
1230
- rValDec.width = 0.95;
1231
- rValDec.height = 0.72;
1232
- rValDec.name = "rDecField";
1233
- rValDec.fontSize = buttonFontSize;
1234
- rValDec.text = currentColor.r.toString();
1235
- rValDec.color = inputTextColor;
1236
- rValDec.background = inputTextBackgroundColor;
1237
- rValDec.onFocusObservable.add(function () {
1238
- activeField = rValDec.name;
1239
- lastVal = rValDec.text;
1240
- editSwatches(false);
1241
- });
1242
- rValDec.onBlurObservable.add(function () {
1243
- if (parseFloat(rValDec.text) == 0 || rValDec.text == "") {
1244
- rValDec.text = "0";
1245
- updateFloat(rValDec, "r");
1246
- }
1247
- if (activeField == rValDec.name) {
1248
- activeField = "";
1249
- }
1250
- });
1251
- rValDec.onTextChangedObservable.add(function () {
1252
- if (activeField == rValDec.name) {
1253
- updateFloat(rValDec, "r");
1254
- }
1255
- });
1256
- rgbValuesQuadrant.addControl(rValDec, 0, 2);
1257
- gValDec = new InputText();
1258
- gValDec.width = 0.95;
1259
- gValDec.height = 0.72;
1260
- gValDec.name = "gDecField";
1261
- gValDec.fontSize = buttonFontSize;
1262
- gValDec.text = currentColor.g.toString();
1263
- gValDec.color = inputTextColor;
1264
- gValDec.background = inputTextBackgroundColor;
1265
- gValDec.onFocusObservable.add(function () {
1266
- activeField = gValDec.name;
1267
- lastVal = gValDec.text;
1268
- editSwatches(false);
1269
- });
1270
- gValDec.onBlurObservable.add(function () {
1271
- if (parseFloat(gValDec.text) == 0 || gValDec.text == "") {
1272
- gValDec.text = "0";
1273
- updateFloat(gValDec, "g");
1274
- }
1275
- if (activeField == gValDec.name) {
1276
- activeField = "";
1277
- }
1278
- });
1279
- gValDec.onTextChangedObservable.add(function () {
1280
- if (activeField == gValDec.name) {
1281
- updateFloat(gValDec, "g");
1282
- }
1283
- });
1284
- rgbValuesQuadrant.addControl(gValDec, 1, 2);
1285
- bValDec = new InputText();
1286
- bValDec.width = 0.95;
1287
- bValDec.height = 0.72;
1288
- bValDec.name = "bDecField";
1289
- bValDec.fontSize = buttonFontSize;
1290
- bValDec.text = currentColor.b.toString();
1291
- bValDec.color = inputTextColor;
1292
- bValDec.background = inputTextBackgroundColor;
1293
- bValDec.onFocusObservable.add(function () {
1294
- activeField = bValDec.name;
1295
- lastVal = bValDec.text;
1296
- editSwatches(false);
1297
- });
1298
- bValDec.onBlurObservable.add(function () {
1299
- if (parseFloat(bValDec.text) == 0 || bValDec.text == "") {
1300
- bValDec.text = "0";
1301
- updateFloat(bValDec, "b");
1302
- }
1303
- if (activeField == bValDec.name) {
1304
- activeField = "";
1305
- }
1306
- });
1307
- bValDec.onTextChangedObservable.add(function () {
1308
- if (activeField == bValDec.name) {
1309
- updateFloat(bValDec, "b");
1310
- }
1311
- });
1312
- rgbValuesQuadrant.addControl(bValDec, 2, 2);
1313
- // Hex value input
1314
- var hexValueQuadrant = new Grid();
1315
- hexValueQuadrant.name = "Hex Value";
1316
- hexValueQuadrant.width = 0.82;
1317
- hexValueQuadrant.addRowDefinition(1.0, false);
1318
- hexValueQuadrant.addColumnDefinition(0.1, false);
1319
- hexValueQuadrant.addColumnDefinition(0.9, false);
1320
- pickerColorValues.addControl(hexValueQuadrant, 2, 0);
1321
- var labelText = new TextBlock();
1322
- labelText.text = "#";
1323
- labelText.color = buttonColor;
1324
- labelText.fontSize = buttonFontSize;
1325
- hexValueQuadrant.addControl(labelText, 0, 0);
1326
- hexVal = new InputText();
1327
- hexVal.width = 0.96;
1328
- hexVal.height = 0.72;
1329
- hexVal.name = "hexField";
1330
- hexVal.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
1331
- hexVal.fontSize = buttonFontSize;
1332
- var minusPound = options.lastColor.split("#");
1333
- hexVal.text = minusPound[1];
1334
- hexVal.color = inputTextColor;
1335
- hexVal.background = inputTextBackgroundColor;
1336
- hexVal.onFocusObservable.add(function () {
1337
- activeField = hexVal.name;
1338
- lastVal = hexVal.text;
1339
- editSwatches(false);
1340
- });
1341
- hexVal.onBlurObservable.add(function () {
1342
- if (hexVal.text.length == 3) {
1343
- var val = hexVal.text.split("");
1344
- hexVal.text = val[0] + val[0] + val[1] + val[1] + val[2] + val[2];
1345
- }
1346
- if (hexVal.text == "") {
1347
- hexVal.text = "000000";
1348
- updateValues(Color3.FromHexString(hexVal.text), "b");
1349
- }
1350
- if (activeField == hexVal.name) {
1351
- activeField = "";
1352
- }
1353
- });
1354
- hexVal.onTextChangedObservable.add(function () {
1355
- var newHexValue = hexVal.text;
1356
- var checkHex = /[^0-9A-F]/i.test(newHexValue);
1357
- if ((hexVal.text.length > 6 || checkHex) && activeField == hexVal.name) {
1358
- hexVal.text = lastVal;
1359
- }
1360
- else {
1361
- if (hexVal.text.length < 6) {
1362
- var leadingZero = 6 - hexVal.text.length;
1363
- for (var i = 0; i < leadingZero; i++) {
1364
- newHexValue = "0" + newHexValue;
1365
- }
1366
- }
1367
- if (hexVal.text.length == 3) {
1368
- var val = hexVal.text.split("");
1369
- newHexValue = val[0] + val[0] + val[1] + val[1] + val[2] + val[2];
1370
- }
1371
- newHexValue = "#" + newHexValue;
1372
- if (activeField == hexVal.name) {
1373
- lastVal = hexVal.text;
1374
- updateValues(Color3.FromHexString(newHexValue), hexVal.name);
1375
- }
1376
- }
1377
- });
1378
- hexValueQuadrant.addControl(hexVal, 0, 1);
1379
- if (options.savedColors && options.savedColors.length > 0) {
1380
- updateSwatches("", butSave);
1381
- }
1382
- });
1383
- };
1384
- ColorPicker._Epsilon = 0.000001;
1385
- __decorate([
1386
- serialize()
1387
- ], ColorPicker.prototype, "value", null);
1388
- __decorate([
1389
- serialize()
1390
- ], ColorPicker.prototype, "width", null);
1391
- __decorate([
1392
- serialize()
1393
- ], ColorPicker.prototype, "height", null);
1394
- __decorate([
1395
- serialize()
1396
- ], ColorPicker.prototype, "size", null);
1397
- return ColorPicker;
1398
- }(Control));
1399
- export { ColorPicker };
1400
- RegisterClass("BABYLON.GUI.ColorPicker", ColorPicker);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
3
+ import { Control } from "./control";
4
+ import { InputText } from "./inputText";
5
+ import { Rectangle } from "./rectangle";
6
+ import { Button } from "./button";
7
+ import { Grid } from "./grid";
8
+ import { TextBlock } from "../controls/textBlock";
9
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
10
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
11
+ import { serialize } from "@babylonjs/core/Misc/decorators.js";
12
+ import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
13
+ /** Class used to create color pickers */
14
+ var ColorPicker = /** @class */ (function (_super) {
15
+ __extends(ColorPicker, _super);
16
+ /**
17
+ * Creates a new ColorPicker
18
+ * @param name defines the control name
19
+ */
20
+ function ColorPicker(name) {
21
+ var _this = _super.call(this, name) || this;
22
+ _this.name = name;
23
+ _this._value = Color3.Red();
24
+ _this._tmpColor = new Color3();
25
+ _this._pointerStartedOnSquare = false;
26
+ _this._pointerStartedOnWheel = false;
27
+ _this._squareLeft = 0;
28
+ _this._squareTop = 0;
29
+ _this._squareSize = 0;
30
+ _this._h = 360;
31
+ _this._s = 1;
32
+ _this._v = 1;
33
+ _this._lastPointerDownId = -1;
34
+ /**
35
+ * Observable raised when the value changes
36
+ */
37
+ _this.onValueChangedObservable = new Observable();
38
+ // Events
39
+ _this._pointerIsDown = false;
40
+ _this.value = new Color3(0.88, 0.1, 0.1);
41
+ _this.size = "200px";
42
+ _this.isPointerBlocker = true;
43
+ return _this;
44
+ }
45
+ Object.defineProperty(ColorPicker.prototype, "value", {
46
+ /** Gets or sets the color of the color picker */
47
+ get: function () {
48
+ return this._value;
49
+ },
50
+ set: function (value) {
51
+ if (this._value.equals(value)) {
52
+ return;
53
+ }
54
+ this._value.copyFrom(value);
55
+ this._value.toHSVToRef(this._tmpColor);
56
+ this._h = this._tmpColor.r;
57
+ this._s = Math.max(this._tmpColor.g, 0.00001);
58
+ this._v = Math.max(this._tmpColor.b, 0.00001);
59
+ this._markAsDirty();
60
+ if (this._value.r <= ColorPicker._Epsilon) {
61
+ this._value.r = 0;
62
+ }
63
+ if (this._value.g <= ColorPicker._Epsilon) {
64
+ this._value.g = 0;
65
+ }
66
+ if (this._value.b <= ColorPicker._Epsilon) {
67
+ this._value.b = 0;
68
+ }
69
+ if (this._value.r >= 1.0 - ColorPicker._Epsilon) {
70
+ this._value.r = 1.0;
71
+ }
72
+ if (this._value.g >= 1.0 - ColorPicker._Epsilon) {
73
+ this._value.g = 1.0;
74
+ }
75
+ if (this._value.b >= 1.0 - ColorPicker._Epsilon) {
76
+ this._value.b = 1.0;
77
+ }
78
+ this.onValueChangedObservable.notifyObservers(this._value);
79
+ },
80
+ enumerable: false,
81
+ configurable: true
82
+ });
83
+ Object.defineProperty(ColorPicker.prototype, "width", {
84
+ /**
85
+ * Gets or sets control width
86
+ * @see https://doc.babylonjs.com/how_to/gui#position-and-size
87
+ */
88
+ get: function () {
89
+ return this._width.toString(this._host);
90
+ },
91
+ set: function (value) {
92
+ if (this._width.toString(this._host) === value) {
93
+ return;
94
+ }
95
+ if (this._width.fromString(value)) {
96
+ if (this._width.getValue(this._host) === 0) {
97
+ value = "1px";
98
+ this._width.fromString(value);
99
+ }
100
+ this._height.fromString(value);
101
+ this._markAsDirty();
102
+ }
103
+ },
104
+ enumerable: false,
105
+ configurable: true
106
+ });
107
+ Object.defineProperty(ColorPicker.prototype, "height", {
108
+ /**
109
+ * Gets or sets control height
110
+ * @see https://doc.babylonjs.com/how_to/gui#position-and-size
111
+ */
112
+ get: function () {
113
+ return this._height.toString(this._host);
114
+ },
115
+ /** Gets or sets control height */
116
+ set: function (value) {
117
+ if (this._height.toString(this._host) === value) {
118
+ return;
119
+ }
120
+ if (this._height.fromString(value)) {
121
+ if (this._height.getValue(this._host) === 0) {
122
+ value = "1px";
123
+ this._height.fromString(value);
124
+ }
125
+ this._width.fromString(value);
126
+ this._markAsDirty();
127
+ }
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ Object.defineProperty(ColorPicker.prototype, "size", {
133
+ /** Gets or sets control size */
134
+ get: function () {
135
+ return this.width;
136
+ },
137
+ set: function (value) {
138
+ this.width = value;
139
+ },
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ ColorPicker.prototype._getTypeName = function () {
144
+ return "ColorPicker";
145
+ };
146
+ /**
147
+ * @param parentMeasure
148
+ * @hidden
149
+ */
150
+ ColorPicker.prototype._preMeasure = function (parentMeasure) {
151
+ if (parentMeasure.width < parentMeasure.height) {
152
+ this._currentMeasure.height = parentMeasure.width;
153
+ }
154
+ else {
155
+ this._currentMeasure.width = parentMeasure.height;
156
+ }
157
+ };
158
+ ColorPicker.prototype._updateSquareProps = function () {
159
+ var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * 0.5;
160
+ var wheelThickness = radius * 0.2;
161
+ var innerDiameter = (radius - wheelThickness) * 2;
162
+ var squareSize = innerDiameter / Math.sqrt(2);
163
+ var offset = radius - squareSize * 0.5;
164
+ this._squareLeft = this._currentMeasure.left + offset;
165
+ this._squareTop = this._currentMeasure.top + offset;
166
+ this._squareSize = squareSize;
167
+ };
168
+ ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
169
+ var lgh = context.createLinearGradient(left, top, width + left, top);
170
+ lgh.addColorStop(0, "#fff");
171
+ lgh.addColorStop(1, "hsl(" + hueValue + ", 100%, 50%)");
172
+ context.fillStyle = lgh;
173
+ context.fillRect(left, top, width, height);
174
+ var lgv = context.createLinearGradient(left, top, left, height + top);
175
+ lgv.addColorStop(0, "rgba(0,0,0,0)");
176
+ lgv.addColorStop(1, "#000");
177
+ context.fillStyle = lgv;
178
+ context.fillRect(left, top, width, height);
179
+ };
180
+ ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
181
+ context.beginPath();
182
+ context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
183
+ context.lineWidth = 3;
184
+ context.strokeStyle = "#333333";
185
+ context.stroke();
186
+ context.beginPath();
187
+ context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
188
+ context.lineWidth = 3;
189
+ context.strokeStyle = "#ffffff";
190
+ context.stroke();
191
+ };
192
+ ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
193
+ // Shoudl abstract platform instead of using LastCreatedEngine
194
+ var engine = EngineStore.LastCreatedEngine;
195
+ if (!engine) {
196
+ throw new Error("Invalid engine. Unable to create a canvas.");
197
+ }
198
+ var canvas = engine.createCanvas(radius * 2, radius * 2);
199
+ var context = canvas.getContext("2d");
200
+ var image = context.getImageData(0, 0, radius * 2, radius * 2);
201
+ var data = image.data;
202
+ var color = this._tmpColor;
203
+ var maxDistSq = radius * radius;
204
+ var innerRadius = radius - thickness;
205
+ var minDistSq = innerRadius * innerRadius;
206
+ for (var x = -radius; x < radius; x++) {
207
+ for (var y = -radius; y < radius; y++) {
208
+ var distSq = x * x + y * y;
209
+ if (distSq > maxDistSq || distSq < minDistSq) {
210
+ continue;
211
+ }
212
+ var dist = Math.sqrt(distSq);
213
+ var ang = Math.atan2(y, x);
214
+ Color3.HSVtoRGBToRef((ang * 180) / Math.PI + 180, dist / radius, 1, color);
215
+ var index = (x + radius + (y + radius) * 2 * radius) * 4;
216
+ data[index] = color.r * 255;
217
+ data[index + 1] = color.g * 255;
218
+ data[index + 2] = color.b * 255;
219
+ var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
220
+ //apply less alpha to bigger color pickers
221
+ var alphaAmount = 0.2;
222
+ var maxAlpha = 0.2;
223
+ var minAlpha = 0.04;
224
+ var lowerRadius = 50;
225
+ var upperRadius = 150;
226
+ if (radius < lowerRadius) {
227
+ alphaAmount = maxAlpha;
228
+ }
229
+ else if (radius > upperRadius) {
230
+ alphaAmount = minAlpha;
231
+ }
232
+ else {
233
+ alphaAmount = ((minAlpha - maxAlpha) * (radius - lowerRadius)) / (upperRadius - lowerRadius) + maxAlpha;
234
+ }
235
+ alphaRatio = (dist - innerRadius) / (radius - innerRadius);
236
+ if (alphaRatio < alphaAmount) {
237
+ data[index + 3] = 255 * (alphaRatio / alphaAmount);
238
+ }
239
+ else if (alphaRatio > 1 - alphaAmount) {
240
+ data[index + 3] = 255 * (1.0 - (alphaRatio - (1 - alphaAmount)) / alphaAmount);
241
+ }
242
+ else {
243
+ data[index + 3] = 255;
244
+ }
245
+ }
246
+ }
247
+ context.putImageData(image, 0, 0);
248
+ return canvas;
249
+ };
250
+ /**
251
+ * @param context
252
+ * @hidden
253
+ */
254
+ ColorPicker.prototype._draw = function (context) {
255
+ context.save();
256
+ this._applyStates(context);
257
+ var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * 0.5;
258
+ var wheelThickness = radius * 0.2;
259
+ var left = this._currentMeasure.left;
260
+ var top = this._currentMeasure.top;
261
+ if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
262
+ this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
263
+ }
264
+ this._updateSquareProps();
265
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
266
+ context.shadowColor = this.shadowColor;
267
+ context.shadowBlur = this.shadowBlur;
268
+ context.shadowOffsetX = this.shadowOffsetX;
269
+ context.shadowOffsetY = this.shadowOffsetY;
270
+ context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
271
+ }
272
+ context.drawImage(this._colorWheelCanvas, left, top);
273
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
274
+ context.shadowBlur = 0;
275
+ context.shadowOffsetX = 0;
276
+ context.shadowOffsetY = 0;
277
+ }
278
+ this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
279
+ var cx = this._squareLeft + this._squareSize * this._s;
280
+ var cy = this._squareTop + this._squareSize * (1 - this._v);
281
+ this._drawCircle(cx, cy, radius * 0.04, context);
282
+ var dist = radius - wheelThickness * 0.5;
283
+ cx = left + radius + Math.cos(((this._h - 180) * Math.PI) / 180) * dist;
284
+ cy = top + radius + Math.sin(((this._h - 180) * Math.PI) / 180) * dist;
285
+ this._drawCircle(cx, cy, wheelThickness * 0.35, context);
286
+ context.restore();
287
+ };
288
+ ColorPicker.prototype._updateValueFromPointer = function (x, y) {
289
+ if (this._pointerStartedOnWheel) {
290
+ var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * 0.5;
291
+ var centerX = radius + this._currentMeasure.left;
292
+ var centerY = radius + this._currentMeasure.top;
293
+ this._h = (Math.atan2(y - centerY, x - centerX) * 180) / Math.PI + 180;
294
+ }
295
+ else if (this._pointerStartedOnSquare) {
296
+ this._updateSquareProps();
297
+ this._s = (x - this._squareLeft) / this._squareSize;
298
+ this._v = 1 - (y - this._squareTop) / this._squareSize;
299
+ this._s = Math.min(this._s, 1);
300
+ this._s = Math.max(this._s, ColorPicker._Epsilon);
301
+ this._v = Math.min(this._v, 1);
302
+ this._v = Math.max(this._v, ColorPicker._Epsilon);
303
+ }
304
+ Color3.HSVtoRGBToRef(this._h, this._s, this._v, this._tmpColor);
305
+ this.value = this._tmpColor;
306
+ };
307
+ ColorPicker.prototype._isPointOnSquare = function (x, y) {
308
+ this._updateSquareProps();
309
+ var left = this._squareLeft;
310
+ var top = this._squareTop;
311
+ var size = this._squareSize;
312
+ if (x >= left && x <= left + size && y >= top && y <= top + size) {
313
+ return true;
314
+ }
315
+ return false;
316
+ };
317
+ ColorPicker.prototype._isPointOnWheel = function (x, y) {
318
+ var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * 0.5;
319
+ var centerX = radius + this._currentMeasure.left;
320
+ var centerY = radius + this._currentMeasure.top;
321
+ var wheelThickness = radius * 0.2;
322
+ var innerRadius = radius - wheelThickness;
323
+ var radiusSq = radius * radius;
324
+ var innerRadiusSq = innerRadius * innerRadius;
325
+ var dx = x - centerX;
326
+ var dy = y - centerY;
327
+ var distSq = dx * dx + dy * dy;
328
+ if (distSq <= radiusSq && distSq >= innerRadiusSq) {
329
+ return true;
330
+ }
331
+ return false;
332
+ };
333
+ ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex, pi) {
334
+ if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex, pi)) {
335
+ return false;
336
+ }
337
+ if (this.isReadOnly) {
338
+ return true;
339
+ }
340
+ this._pointerIsDown = true;
341
+ this._pointerStartedOnSquare = false;
342
+ this._pointerStartedOnWheel = false;
343
+ // Invert transform
344
+ this._invertTransformMatrix.transformCoordinates(coordinates.x, coordinates.y, this._transformedPosition);
345
+ var x = this._transformedPosition.x;
346
+ var y = this._transformedPosition.y;
347
+ if (this._isPointOnSquare(x, y)) {
348
+ this._pointerStartedOnSquare = true;
349
+ }
350
+ else if (this._isPointOnWheel(x, y)) {
351
+ this._pointerStartedOnWheel = true;
352
+ }
353
+ this._updateValueFromPointer(x, y);
354
+ this._host._capturingControl[pointerId] = this;
355
+ this._lastPointerDownId = pointerId;
356
+ return true;
357
+ };
358
+ ColorPicker.prototype._onPointerMove = function (target, coordinates, pointerId, pi) {
359
+ // Only listen to pointer move events coming from the last pointer to click on the element (To support dual vr controller interaction)
360
+ if (pointerId != this._lastPointerDownId) {
361
+ return;
362
+ }
363
+ if (!this.isReadOnly) {
364
+ // Invert transform
365
+ this._invertTransformMatrix.transformCoordinates(coordinates.x, coordinates.y, this._transformedPosition);
366
+ var x = this._transformedPosition.x;
367
+ var y = this._transformedPosition.y;
368
+ if (this._pointerIsDown) {
369
+ this._updateValueFromPointer(x, y);
370
+ }
371
+ }
372
+ _super.prototype._onPointerMove.call(this, target, coordinates, pointerId, pi);
373
+ };
374
+ ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick, pi) {
375
+ this._pointerIsDown = false;
376
+ delete this._host._capturingControl[pointerId];
377
+ _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick, pi);
378
+ };
379
+ ColorPicker.prototype._onCanvasBlur = function () {
380
+ this._forcePointerUp();
381
+ _super.prototype._onCanvasBlur.call(this);
382
+ };
383
+ /**
384
+ * This function expands the color picker by creating a color picker dialog with manual
385
+ * color value input and the ability to save colors into an array to be used later in
386
+ * subsequent launches of the dialogue.
387
+ * @param advancedTexture defines the AdvancedDynamicTexture the dialog is assigned to
388
+ * @param options defines size for dialog and options for saved colors. Also accepts last color picked as hex string and saved colors array as hex strings.
389
+ * @param options.pickerWidth
390
+ * @param options.pickerHeight
391
+ * @param options.headerHeight
392
+ * @param options.lastColor
393
+ * @param options.swatchLimit
394
+ * @param options.numSwatchesPerLine
395
+ * @param options.savedColors
396
+ * @returns picked color as a hex string and the saved colors array as hex strings.
397
+ */
398
+ ColorPicker.ShowPickerDialogAsync = function (advancedTexture, options) {
399
+ return new Promise(function (resolve) {
400
+ // Default options
401
+ options.pickerWidth = options.pickerWidth || "640px";
402
+ options.pickerHeight = options.pickerHeight || "400px";
403
+ options.headerHeight = options.headerHeight || "35px";
404
+ options.lastColor = options.lastColor || "#000000";
405
+ options.swatchLimit = options.swatchLimit || 20;
406
+ options.numSwatchesPerLine = options.numSwatchesPerLine || 10;
407
+ // Window size settings
408
+ var drawerMaxRows = options.swatchLimit / options.numSwatchesPerLine;
409
+ var rawSwatchSize = parseFloat(options.pickerWidth) / options.numSwatchesPerLine;
410
+ var gutterSize = Math.floor(rawSwatchSize * 0.25);
411
+ var colGutters = gutterSize * (options.numSwatchesPerLine + 1);
412
+ var swatchSize = Math.floor((parseFloat(options.pickerWidth) - colGutters) / options.numSwatchesPerLine);
413
+ var drawerMaxSize = swatchSize * drawerMaxRows + gutterSize * (drawerMaxRows + 1);
414
+ var containerSize = (parseInt(options.pickerHeight) + drawerMaxSize + Math.floor(swatchSize * 0.25)).toString() + "px";
415
+ // Button Colors
416
+ var buttonColor = "#c0c0c0";
417
+ var buttonBackgroundColor = "#535353";
418
+ var buttonBackgroundHoverColor = "#414141";
419
+ var buttonBackgroundClickColor = "515151";
420
+ var buttonDisabledColor = "#555555";
421
+ var buttonDisabledBackgroundColor = "#454545";
422
+ var currentSwatchesOutlineColor = "#404040";
423
+ var luminanceLimitColor = Color3.FromHexString("#dddddd");
424
+ var luminanceLimit = luminanceLimitColor.r + luminanceLimitColor.g + luminanceLimitColor.b;
425
+ var iconColorDark = "#aaaaaa";
426
+ var iconColorLight = "#ffffff";
427
+ // Button settings
428
+ var buttonFontSize;
429
+ var butEdit;
430
+ // Input Text Colors
431
+ var inputFieldLabels = ["R", "G", "B"];
432
+ var inputTextBackgroundColor = "#454545";
433
+ var inputTextColor = "#f0f0f0";
434
+ // This int is used for naming swatches and serves as the index for calling them from the list
435
+ var swatchNumber;
436
+ // Menu Panel options. We need to know if the swatchDrawer exists so we can create it if needed.
437
+ var swatchDrawer;
438
+ var editSwatchMode = false;
439
+ // Color InputText fields that will be updated upon value change
440
+ var butSave;
441
+ var lastVal;
442
+ var activeField;
443
+ // Dialog menu container which will contain both the main dialogue window and the swatch drawer which opens once a color is saved.
444
+ var dialogContainer = new Grid();
445
+ dialogContainer.name = "Dialog Container";
446
+ dialogContainer.width = options.pickerWidth;
447
+ if (options.savedColors) {
448
+ dialogContainer.height = containerSize;
449
+ var topRow = parseInt(options.pickerHeight) / parseInt(containerSize);
450
+ dialogContainer.addRowDefinition(topRow, false);
451
+ dialogContainer.addRowDefinition(1.0 - topRow, false);
452
+ }
453
+ else {
454
+ dialogContainer.height = options.pickerHeight;
455
+ dialogContainer.addRowDefinition(1.0, false);
456
+ }
457
+ advancedTexture.addControl(dialogContainer);
458
+ // Swatch drawer which contains all saved color buttons
459
+ if (options.savedColors) {
460
+ swatchDrawer = new Grid();
461
+ swatchDrawer.name = "Swatch Drawer";
462
+ swatchDrawer.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
463
+ swatchDrawer.background = buttonBackgroundColor;
464
+ swatchDrawer.width = options.pickerWidth;
465
+ var initialRows = options.savedColors.length / options.numSwatchesPerLine;
466
+ var gutterCount = void 0;
467
+ if (initialRows == 0) {
468
+ gutterCount = 0;
469
+ }
470
+ else {
471
+ gutterCount = initialRows + 1;
472
+ }
473
+ swatchDrawer.height = (swatchSize * initialRows + gutterCount * gutterSize).toString() + "px";
474
+ swatchDrawer.top = Math.floor(swatchSize * 0.25).toString() + "px";
475
+ for (var i = 0; i < Math.ceil(options.savedColors.length / options.numSwatchesPerLine) * 2 + 1; i++) {
476
+ if (i % 2 != 0) {
477
+ swatchDrawer.addRowDefinition(swatchSize, true);
478
+ }
479
+ else {
480
+ swatchDrawer.addRowDefinition(gutterSize, true);
481
+ }
482
+ }
483
+ for (var i = 0; i < options.numSwatchesPerLine * 2 + 1; i++) {
484
+ if (i % 2 != 0) {
485
+ swatchDrawer.addColumnDefinition(swatchSize, true);
486
+ }
487
+ else {
488
+ swatchDrawer.addColumnDefinition(gutterSize, true);
489
+ }
490
+ }
491
+ dialogContainer.addControl(swatchDrawer, 1, 0);
492
+ }
493
+ // Picker container
494
+ var pickerPanel = new Grid();
495
+ pickerPanel.name = "Picker Panel";
496
+ pickerPanel.height = options.pickerHeight;
497
+ var panelHead = parseInt(options.headerHeight) / parseInt(options.pickerHeight);
498
+ var pickerPanelRows = [panelHead, 1.0 - panelHead];
499
+ pickerPanel.addRowDefinition(pickerPanelRows[0], false);
500
+ pickerPanel.addRowDefinition(pickerPanelRows[1], false);
501
+ dialogContainer.addControl(pickerPanel, 0, 0);
502
+ // Picker container header
503
+ var header = new Rectangle();
504
+ header.name = "Dialogue Header Bar";
505
+ header.background = "#cccccc";
506
+ header.thickness = 0;
507
+ pickerPanel.addControl(header, 0, 0);
508
+ // Header close button
509
+ var closeButton = Button.CreateSimpleButton("closeButton", "a");
510
+ closeButton.fontFamily = "coreglyphs";
511
+ var headerColor3 = Color3.FromHexString(header.background);
512
+ var closeIconColor = new Color3(1.0 - headerColor3.r, 1.0 - headerColor3.g, 1.0 - headerColor3.b);
513
+ closeButton.color = closeIconColor.toHexString();
514
+ closeButton.fontSize = Math.floor(parseInt(options.headerHeight) * 0.6);
515
+ closeButton.textBlock.textVerticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
516
+ closeButton.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_RIGHT;
517
+ closeButton.height = closeButton.width = options.headerHeight;
518
+ closeButton.background = header.background;
519
+ closeButton.thickness = 0;
520
+ closeButton.pointerDownAnimation = function () { };
521
+ closeButton.pointerUpAnimation = function () {
522
+ closeButton.background = header.background;
523
+ };
524
+ closeButton.pointerEnterAnimation = function () {
525
+ closeButton.color = header.background;
526
+ closeButton.background = "red";
527
+ };
528
+ closeButton.pointerOutAnimation = function () {
529
+ closeButton.color = closeIconColor.toHexString();
530
+ closeButton.background = header.background;
531
+ };
532
+ closeButton.onPointerClickObservable.add(function () {
533
+ closePicker(currentSwatch.background);
534
+ });
535
+ pickerPanel.addControl(closeButton, 0, 0);
536
+ // Dialog container body
537
+ var dialogBody = new Grid();
538
+ dialogBody.name = "Dialogue Body";
539
+ dialogBody.background = buttonBackgroundColor;
540
+ var dialogBodyCols = [0.4375, 0.5625];
541
+ dialogBody.addRowDefinition(1.0, false);
542
+ dialogBody.addColumnDefinition(dialogBodyCols[0], false);
543
+ dialogBody.addColumnDefinition(dialogBodyCols[1], false);
544
+ pickerPanel.addControl(dialogBody, 1, 0);
545
+ // Picker grid
546
+ var pickerGrid = new Grid();
547
+ pickerGrid.name = "Picker Grid";
548
+ pickerGrid.addRowDefinition(0.85, false);
549
+ pickerGrid.addRowDefinition(0.15, false);
550
+ dialogBody.addControl(pickerGrid, 0, 0);
551
+ // Picker control
552
+ var picker = new ColorPicker();
553
+ picker.name = "GUI Color Picker";
554
+ if (options.pickerHeight < options.pickerWidth) {
555
+ picker.width = 0.89;
556
+ }
557
+ else {
558
+ picker.height = 0.89;
559
+ }
560
+ picker.value = Color3.FromHexString(options.lastColor);
561
+ picker.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
562
+ picker.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
563
+ picker.onPointerDownObservable.add(function () {
564
+ activeField = picker.name;
565
+ lastVal = "";
566
+ editSwatches(false);
567
+ });
568
+ picker.onValueChangedObservable.add(function (value) {
569
+ // value is a color3
570
+ if (activeField == picker.name) {
571
+ updateValues(value, picker.name);
572
+ }
573
+ });
574
+ pickerGrid.addControl(picker, 0, 0);
575
+ // Picker body right quarant
576
+ var pickerBodyRight = new Grid();
577
+ pickerBodyRight.name = "Dialogue Right Half";
578
+ pickerBodyRight.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
579
+ var pickerBodyRightRows = [0.514, 0.486];
580
+ pickerBodyRight.addRowDefinition(pickerBodyRightRows[0], false);
581
+ pickerBodyRight.addRowDefinition(pickerBodyRightRows[1], false);
582
+ dialogBody.addControl(pickerBodyRight, 1, 1);
583
+ // Picker container swatches and buttons
584
+ var pickerSwatchesButtons = new Grid();
585
+ pickerSwatchesButtons.name = "Swatches and Buttons";
586
+ var pickerButtonsCol = [0.417, 0.583];
587
+ pickerSwatchesButtons.addRowDefinition(1.0, false);
588
+ pickerSwatchesButtons.addColumnDefinition(pickerButtonsCol[0], false);
589
+ pickerSwatchesButtons.addColumnDefinition(pickerButtonsCol[1], false);
590
+ pickerBodyRight.addControl(pickerSwatchesButtons, 0, 0);
591
+ // Picker Swatches quadrant
592
+ var pickerSwatches = new Grid();
593
+ pickerSwatches.name = "New and Current Swatches";
594
+ var pickeSwatchesRows = [0.04, 0.16, 0.64, 0.16];
595
+ pickerSwatches.addRowDefinition(pickeSwatchesRows[0], false);
596
+ pickerSwatches.addRowDefinition(pickeSwatchesRows[1], false);
597
+ pickerSwatches.addRowDefinition(pickeSwatchesRows[2], false);
598
+ pickerSwatches.addRowDefinition(pickeSwatchesRows[3], false);
599
+ pickerSwatchesButtons.addControl(pickerSwatches, 0, 0);
600
+ // Active swatches
601
+ var activeSwatches = new Grid();
602
+ activeSwatches.name = "Active Swatches";
603
+ activeSwatches.width = 0.67;
604
+ activeSwatches.addRowDefinition(0.5, false);
605
+ activeSwatches.addRowDefinition(0.5, false);
606
+ pickerSwatches.addControl(activeSwatches, 2, 0);
607
+ var labelWidth = Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[0] * 0.11);
608
+ var labelHeight = Math.floor(parseInt(options.pickerHeight) * pickerPanelRows[1] * pickerBodyRightRows[0] * pickeSwatchesRows[1] * 0.5);
609
+ var labelTextSize;
610
+ if (options.pickerWidth > options.pickerHeight) {
611
+ labelTextSize = labelHeight;
612
+ }
613
+ else {
614
+ labelTextSize = labelWidth;
615
+ }
616
+ // New color swatch and previous color button
617
+ var newText = new TextBlock();
618
+ newText.text = "new";
619
+ newText.name = "New Color Label";
620
+ newText.color = buttonColor;
621
+ newText.fontSize = labelTextSize;
622
+ pickerSwatches.addControl(newText, 1, 0);
623
+ var newSwatch = new Rectangle();
624
+ newSwatch.name = "New Color Swatch";
625
+ newSwatch.background = options.lastColor;
626
+ newSwatch.thickness = 0;
627
+ activeSwatches.addControl(newSwatch, 0, 0);
628
+ var currentSwatch = Button.CreateSimpleButton("currentSwatch", "");
629
+ currentSwatch.background = options.lastColor;
630
+ currentSwatch.thickness = 0;
631
+ currentSwatch.onPointerClickObservable.add(function () {
632
+ var revertColor = Color3.FromHexString(currentSwatch.background);
633
+ updateValues(revertColor, currentSwatch.name);
634
+ editSwatches(false);
635
+ });
636
+ currentSwatch.pointerDownAnimation = function () { };
637
+ currentSwatch.pointerUpAnimation = function () { };
638
+ currentSwatch.pointerEnterAnimation = function () { };
639
+ currentSwatch.pointerOutAnimation = function () { };
640
+ activeSwatches.addControl(currentSwatch, 1, 0);
641
+ var swatchOutline = new Rectangle();
642
+ swatchOutline.name = "Swatch Outline";
643
+ swatchOutline.width = 0.67;
644
+ swatchOutline.thickness = 2;
645
+ swatchOutline.color = currentSwatchesOutlineColor;
646
+ swatchOutline.isHitTestVisible = false;
647
+ pickerSwatches.addControl(swatchOutline, 2, 0);
648
+ var currentText = new TextBlock();
649
+ currentText.name = "Current Color Label";
650
+ currentText.text = "current";
651
+ currentText.color = buttonColor;
652
+ currentText.fontSize = labelTextSize;
653
+ pickerSwatches.addControl(currentText, 3, 0);
654
+ // Buttons grid
655
+ var buttonGrid = new Grid();
656
+ buttonGrid.name = "Button Grid";
657
+ buttonGrid.height = 0.8;
658
+ var buttonGridRows = 1 / 3;
659
+ buttonGrid.addRowDefinition(buttonGridRows, false);
660
+ buttonGrid.addRowDefinition(buttonGridRows, false);
661
+ buttonGrid.addRowDefinition(buttonGridRows, false);
662
+ pickerSwatchesButtons.addControl(buttonGrid, 0, 1);
663
+ // Determine pixel width and height for all buttons from overall panel dimensions
664
+ var buttonWidth = Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[1] * 0.67).toString() + "px";
665
+ var buttonHeight = Math.floor(parseInt(options.pickerHeight) * pickerPanelRows[1] * pickerBodyRightRows[0] * (parseFloat(buttonGrid.height.toString()) / 100) * buttonGridRows * 0.7).toString() + "px";
666
+ // Determine button type size
667
+ if (parseFloat(buttonWidth) > parseFloat(buttonHeight)) {
668
+ buttonFontSize = Math.floor(parseFloat(buttonHeight) * 0.45);
669
+ }
670
+ else {
671
+ buttonFontSize = Math.floor(parseFloat(buttonWidth) * 0.11);
672
+ }
673
+ // Panel Buttons
674
+ var butOK = Button.CreateSimpleButton("butOK", "OK");
675
+ butOK.width = buttonWidth;
676
+ butOK.height = buttonHeight;
677
+ butOK.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
678
+ butOK.thickness = 2;
679
+ butOK.color = buttonColor;
680
+ butOK.fontSize = buttonFontSize;
681
+ butOK.background = buttonBackgroundColor;
682
+ butOK.onPointerEnterObservable.add(function () {
683
+ butOK.background = buttonBackgroundHoverColor;
684
+ });
685
+ butOK.onPointerOutObservable.add(function () {
686
+ butOK.background = buttonBackgroundColor;
687
+ });
688
+ butOK.pointerDownAnimation = function () {
689
+ butOK.background = buttonBackgroundClickColor;
690
+ };
691
+ butOK.pointerUpAnimation = function () {
692
+ butOK.background = buttonBackgroundHoverColor;
693
+ };
694
+ butOK.onPointerClickObservable.add(function () {
695
+ editSwatches(false);
696
+ closePicker(newSwatch.background);
697
+ });
698
+ buttonGrid.addControl(butOK, 0, 0);
699
+ var butCancel = Button.CreateSimpleButton("butCancel", "Cancel");
700
+ butCancel.width = buttonWidth;
701
+ butCancel.height = buttonHeight;
702
+ butCancel.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
703
+ butCancel.thickness = 2;
704
+ butCancel.color = buttonColor;
705
+ butCancel.fontSize = buttonFontSize;
706
+ butCancel.background = buttonBackgroundColor;
707
+ butCancel.onPointerEnterObservable.add(function () {
708
+ butCancel.background = buttonBackgroundHoverColor;
709
+ });
710
+ butCancel.onPointerOutObservable.add(function () {
711
+ butCancel.background = buttonBackgroundColor;
712
+ });
713
+ butCancel.pointerDownAnimation = function () {
714
+ butCancel.background = buttonBackgroundClickColor;
715
+ };
716
+ butCancel.pointerUpAnimation = function () {
717
+ butCancel.background = buttonBackgroundHoverColor;
718
+ };
719
+ butCancel.onPointerClickObservable.add(function () {
720
+ editSwatches(false);
721
+ closePicker(currentSwatch.background);
722
+ });
723
+ buttonGrid.addControl(butCancel, 1, 0);
724
+ if (options.savedColors) {
725
+ butSave = Button.CreateSimpleButton("butSave", "Save");
726
+ butSave.width = buttonWidth;
727
+ butSave.height = buttonHeight;
728
+ butSave.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
729
+ butSave.thickness = 2;
730
+ butSave.fontSize = buttonFontSize;
731
+ if (options.savedColors.length < options.swatchLimit) {
732
+ butSave.color = buttonColor;
733
+ butSave.background = buttonBackgroundColor;
734
+ }
735
+ else {
736
+ disableButton(butSave, true);
737
+ }
738
+ butSave.onPointerEnterObservable.add(function () {
739
+ if (options.savedColors) {
740
+ if (options.savedColors.length < options.swatchLimit) {
741
+ butSave.background = buttonBackgroundHoverColor;
742
+ }
743
+ }
744
+ });
745
+ butSave.onPointerOutObservable.add(function () {
746
+ if (options.savedColors) {
747
+ if (options.savedColors.length < options.swatchLimit) {
748
+ butSave.background = buttonBackgroundColor;
749
+ }
750
+ }
751
+ });
752
+ butSave.pointerDownAnimation = function () {
753
+ if (options.savedColors) {
754
+ if (options.savedColors.length < options.swatchLimit) {
755
+ butSave.background = buttonBackgroundClickColor;
756
+ }
757
+ }
758
+ };
759
+ butSave.pointerUpAnimation = function () {
760
+ if (options.savedColors) {
761
+ if (options.savedColors.length < options.swatchLimit) {
762
+ butSave.background = buttonBackgroundHoverColor;
763
+ }
764
+ }
765
+ };
766
+ butSave.onPointerClickObservable.add(function () {
767
+ if (options.savedColors) {
768
+ if (options.savedColors.length == 0) {
769
+ setEditButtonVisibility(true);
770
+ }
771
+ if (options.savedColors.length < options.swatchLimit) {
772
+ updateSwatches(newSwatch.background, butSave);
773
+ }
774
+ editSwatches(false);
775
+ }
776
+ });
777
+ if (options.savedColors.length > 0) {
778
+ setEditButtonVisibility(true);
779
+ }
780
+ buttonGrid.addControl(butSave, 2, 0);
781
+ }
782
+ // Picker color values input
783
+ var pickerColorValues = new Grid();
784
+ pickerColorValues.name = "Dialog Lower Right";
785
+ pickerColorValues.addRowDefinition(0.02, false);
786
+ pickerColorValues.addRowDefinition(0.63, false);
787
+ pickerColorValues.addRowDefinition(0.21, false);
788
+ pickerColorValues.addRowDefinition(0.14, false);
789
+ pickerBodyRight.addControl(pickerColorValues, 1, 0);
790
+ // RGB values text boxes
791
+ var currentColor = Color3.FromHexString(options.lastColor);
792
+ var rgbValuesQuadrant = new Grid();
793
+ rgbValuesQuadrant.name = "RGB Values";
794
+ rgbValuesQuadrant.width = 0.82;
795
+ rgbValuesQuadrant.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
796
+ rgbValuesQuadrant.addRowDefinition(1 / 3, false);
797
+ rgbValuesQuadrant.addRowDefinition(1 / 3, false);
798
+ rgbValuesQuadrant.addRowDefinition(1 / 3, false);
799
+ rgbValuesQuadrant.addColumnDefinition(0.1, false);
800
+ rgbValuesQuadrant.addColumnDefinition(0.2, false);
801
+ rgbValuesQuadrant.addColumnDefinition(0.7, false);
802
+ pickerColorValues.addControl(rgbValuesQuadrant, 1, 0);
803
+ for (var i = 0; i < inputFieldLabels.length; i++) {
804
+ var labelText_1 = new TextBlock();
805
+ labelText_1.text = inputFieldLabels[i];
806
+ labelText_1.color = buttonColor;
807
+ labelText_1.fontSize = buttonFontSize;
808
+ rgbValuesQuadrant.addControl(labelText_1, i, 0);
809
+ }
810
+ // Input fields for RGB values
811
+ var rValInt = new InputText();
812
+ rValInt.width = 0.83;
813
+ rValInt.height = 0.72;
814
+ rValInt.name = "rIntField";
815
+ rValInt.fontSize = buttonFontSize;
816
+ rValInt.text = (currentColor.r * 255).toString();
817
+ rValInt.color = inputTextColor;
818
+ rValInt.background = inputTextBackgroundColor;
819
+ rValInt.onFocusObservable.add(function () {
820
+ activeField = rValInt.name;
821
+ lastVal = rValInt.text;
822
+ editSwatches(false);
823
+ });
824
+ rValInt.onBlurObservable.add(function () {
825
+ if (rValInt.text == "") {
826
+ rValInt.text = "0";
827
+ }
828
+ updateInt(rValInt, "r");
829
+ if (activeField == rValInt.name) {
830
+ activeField = "";
831
+ }
832
+ });
833
+ rValInt.onTextChangedObservable.add(function () {
834
+ if (activeField == rValInt.name) {
835
+ updateInt(rValInt, "r");
836
+ }
837
+ });
838
+ rgbValuesQuadrant.addControl(rValInt, 0, 1);
839
+ var gValInt = new InputText();
840
+ gValInt.width = 0.83;
841
+ gValInt.height = 0.72;
842
+ gValInt.name = "gIntField";
843
+ gValInt.fontSize = buttonFontSize;
844
+ gValInt.text = (currentColor.g * 255).toString();
845
+ gValInt.color = inputTextColor;
846
+ gValInt.background = inputTextBackgroundColor;
847
+ gValInt.onFocusObservable.add(function () {
848
+ activeField = gValInt.name;
849
+ lastVal = gValInt.text;
850
+ editSwatches(false);
851
+ });
852
+ gValInt.onBlurObservable.add(function () {
853
+ if (gValInt.text == "") {
854
+ gValInt.text = "0";
855
+ }
856
+ updateInt(gValInt, "g");
857
+ if (activeField == gValInt.name) {
858
+ activeField = "";
859
+ }
860
+ });
861
+ gValInt.onTextChangedObservable.add(function () {
862
+ if (activeField == gValInt.name) {
863
+ updateInt(gValInt, "g");
864
+ }
865
+ });
866
+ rgbValuesQuadrant.addControl(gValInt, 1, 1);
867
+ var bValInt = new InputText();
868
+ bValInt.width = 0.83;
869
+ bValInt.height = 0.72;
870
+ bValInt.name = "bIntField";
871
+ bValInt.fontSize = buttonFontSize;
872
+ bValInt.text = (currentColor.b * 255).toString();
873
+ bValInt.color = inputTextColor;
874
+ bValInt.background = inputTextBackgroundColor;
875
+ bValInt.onFocusObservable.add(function () {
876
+ activeField = bValInt.name;
877
+ lastVal = bValInt.text;
878
+ editSwatches(false);
879
+ });
880
+ bValInt.onBlurObservable.add(function () {
881
+ if (bValInt.text == "") {
882
+ bValInt.text = "0";
883
+ }
884
+ updateInt(bValInt, "b");
885
+ if (activeField == bValInt.name) {
886
+ activeField = "";
887
+ }
888
+ });
889
+ bValInt.onTextChangedObservable.add(function () {
890
+ if (activeField == bValInt.name) {
891
+ updateInt(bValInt, "b");
892
+ }
893
+ });
894
+ rgbValuesQuadrant.addControl(bValInt, 2, 1);
895
+ var rValDec = new InputText();
896
+ rValDec.width = 0.95;
897
+ rValDec.height = 0.72;
898
+ rValDec.name = "rDecField";
899
+ rValDec.fontSize = buttonFontSize;
900
+ rValDec.text = currentColor.r.toString();
901
+ rValDec.color = inputTextColor;
902
+ rValDec.background = inputTextBackgroundColor;
903
+ rValDec.onFocusObservable.add(function () {
904
+ activeField = rValDec.name;
905
+ lastVal = rValDec.text;
906
+ editSwatches(false);
907
+ });
908
+ rValDec.onBlurObservable.add(function () {
909
+ if (parseFloat(rValDec.text) == 0 || rValDec.text == "") {
910
+ rValDec.text = "0";
911
+ updateFloat(rValDec, "r");
912
+ }
913
+ if (activeField == rValDec.name) {
914
+ activeField = "";
915
+ }
916
+ });
917
+ rValDec.onTextChangedObservable.add(function () {
918
+ if (activeField == rValDec.name) {
919
+ updateFloat(rValDec, "r");
920
+ }
921
+ });
922
+ rgbValuesQuadrant.addControl(rValDec, 0, 2);
923
+ var gValDec = new InputText();
924
+ gValDec.width = 0.95;
925
+ gValDec.height = 0.72;
926
+ gValDec.name = "gDecField";
927
+ gValDec.fontSize = buttonFontSize;
928
+ gValDec.text = currentColor.g.toString();
929
+ gValDec.color = inputTextColor;
930
+ gValDec.background = inputTextBackgroundColor;
931
+ gValDec.onFocusObservable.add(function () {
932
+ activeField = gValDec.name;
933
+ lastVal = gValDec.text;
934
+ editSwatches(false);
935
+ });
936
+ gValDec.onBlurObservable.add(function () {
937
+ if (parseFloat(gValDec.text) == 0 || gValDec.text == "") {
938
+ gValDec.text = "0";
939
+ updateFloat(gValDec, "g");
940
+ }
941
+ if (activeField == gValDec.name) {
942
+ activeField = "";
943
+ }
944
+ });
945
+ gValDec.onTextChangedObservable.add(function () {
946
+ if (activeField == gValDec.name) {
947
+ updateFloat(gValDec, "g");
948
+ }
949
+ });
950
+ rgbValuesQuadrant.addControl(gValDec, 1, 2);
951
+ var bValDec = new InputText();
952
+ bValDec.width = 0.95;
953
+ bValDec.height = 0.72;
954
+ bValDec.name = "bDecField";
955
+ bValDec.fontSize = buttonFontSize;
956
+ bValDec.text = currentColor.b.toString();
957
+ bValDec.color = inputTextColor;
958
+ bValDec.background = inputTextBackgroundColor;
959
+ bValDec.onFocusObservable.add(function () {
960
+ activeField = bValDec.name;
961
+ lastVal = bValDec.text;
962
+ editSwatches(false);
963
+ });
964
+ bValDec.onBlurObservable.add(function () {
965
+ if (parseFloat(bValDec.text) == 0 || bValDec.text == "") {
966
+ bValDec.text = "0";
967
+ updateFloat(bValDec, "b");
968
+ }
969
+ if (activeField == bValDec.name) {
970
+ activeField = "";
971
+ }
972
+ });
973
+ bValDec.onTextChangedObservable.add(function () {
974
+ if (activeField == bValDec.name) {
975
+ updateFloat(bValDec, "b");
976
+ }
977
+ });
978
+ rgbValuesQuadrant.addControl(bValDec, 2, 2);
979
+ // Hex value input
980
+ var hexValueQuadrant = new Grid();
981
+ hexValueQuadrant.name = "Hex Value";
982
+ hexValueQuadrant.width = 0.82;
983
+ hexValueQuadrant.addRowDefinition(1.0, false);
984
+ hexValueQuadrant.addColumnDefinition(0.1, false);
985
+ hexValueQuadrant.addColumnDefinition(0.9, false);
986
+ pickerColorValues.addControl(hexValueQuadrant, 2, 0);
987
+ var labelText = new TextBlock();
988
+ labelText.text = "#";
989
+ labelText.color = buttonColor;
990
+ labelText.fontSize = buttonFontSize;
991
+ hexValueQuadrant.addControl(labelText, 0, 0);
992
+ var hexVal = new InputText();
993
+ hexVal.width = 0.96;
994
+ hexVal.height = 0.72;
995
+ hexVal.name = "hexField";
996
+ hexVal.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
997
+ hexVal.fontSize = buttonFontSize;
998
+ var minusPound = options.lastColor.split("#");
999
+ hexVal.text = minusPound[1];
1000
+ hexVal.color = inputTextColor;
1001
+ hexVal.background = inputTextBackgroundColor;
1002
+ hexVal.onFocusObservable.add(function () {
1003
+ activeField = hexVal.name;
1004
+ lastVal = hexVal.text;
1005
+ editSwatches(false);
1006
+ });
1007
+ hexVal.onBlurObservable.add(function () {
1008
+ if (hexVal.text.length == 3) {
1009
+ var val = hexVal.text.split("");
1010
+ hexVal.text = val[0] + val[0] + val[1] + val[1] + val[2] + val[2];
1011
+ }
1012
+ if (hexVal.text == "") {
1013
+ hexVal.text = "000000";
1014
+ updateValues(Color3.FromHexString(hexVal.text), "b");
1015
+ }
1016
+ if (activeField == hexVal.name) {
1017
+ activeField = "";
1018
+ }
1019
+ });
1020
+ hexVal.onTextChangedObservable.add(function () {
1021
+ var newHexValue = hexVal.text;
1022
+ var checkHex = /[^0-9A-F]/i.test(newHexValue);
1023
+ if ((hexVal.text.length > 6 || checkHex) && activeField == hexVal.name) {
1024
+ hexVal.text = lastVal;
1025
+ }
1026
+ else {
1027
+ if (hexVal.text.length < 6) {
1028
+ var leadingZero = 6 - hexVal.text.length;
1029
+ for (var i = 0; i < leadingZero; i++) {
1030
+ newHexValue = "0" + newHexValue;
1031
+ }
1032
+ }
1033
+ if (hexVal.text.length == 3) {
1034
+ var val = hexVal.text.split("");
1035
+ newHexValue = val[0] + val[0] + val[1] + val[1] + val[2] + val[2];
1036
+ }
1037
+ newHexValue = "#" + newHexValue;
1038
+ if (activeField == hexVal.name) {
1039
+ lastVal = hexVal.text;
1040
+ updateValues(Color3.FromHexString(newHexValue), hexVal.name);
1041
+ }
1042
+ }
1043
+ });
1044
+ hexValueQuadrant.addControl(hexVal, 0, 1);
1045
+ if (options.savedColors && options.savedColors.length > 0) {
1046
+ updateSwatches("", butSave);
1047
+ }
1048
+ /**
1049
+ * Will update all values for InputText and ColorPicker controls based on the BABYLON.Color3 passed to this function.
1050
+ * Each InputText control and the ColorPicker control will be tested to see if they are the activeField and if they
1051
+ * are will receive no update. This is to prevent the input from the user being overwritten.
1052
+ * @param value
1053
+ * @param inputField
1054
+ */
1055
+ function updateValues(value, inputField) {
1056
+ activeField = inputField;
1057
+ var pickedColor = value.toHexString();
1058
+ newSwatch.background = pickedColor;
1059
+ if (rValInt.name != activeField) {
1060
+ rValInt.text = Math.floor(value.r * 255).toString();
1061
+ }
1062
+ if (gValInt.name != activeField) {
1063
+ gValInt.text = Math.floor(value.g * 255).toString();
1064
+ }
1065
+ if (bValInt.name != activeField) {
1066
+ bValInt.text = Math.floor(value.b * 255).toString();
1067
+ }
1068
+ if (rValDec.name != activeField) {
1069
+ rValDec.text = value.r.toString();
1070
+ }
1071
+ if (gValDec.name != activeField) {
1072
+ gValDec.text = value.g.toString();
1073
+ }
1074
+ if (bValDec.name != activeField) {
1075
+ bValDec.text = value.b.toString();
1076
+ }
1077
+ if (hexVal.name != activeField) {
1078
+ var minusPound_1 = pickedColor.split("#");
1079
+ hexVal.text = minusPound_1[1];
1080
+ }
1081
+ if (picker.name != activeField) {
1082
+ picker.value = value;
1083
+ }
1084
+ }
1085
+ // When the user enters an integer for R, G, or B we check to make sure it is a valid number and replace if not.
1086
+ function updateInt(field, channel) {
1087
+ var newValue = field.text;
1088
+ var checkVal = /[^0-9]/g.test(newValue);
1089
+ if (checkVal) {
1090
+ field.text = lastVal;
1091
+ return;
1092
+ }
1093
+ else {
1094
+ if (newValue != "") {
1095
+ if (Math.floor(parseInt(newValue)) < 0) {
1096
+ newValue = "0";
1097
+ }
1098
+ else if (Math.floor(parseInt(newValue)) > 255) {
1099
+ newValue = "255";
1100
+ }
1101
+ else if (isNaN(parseInt(newValue))) {
1102
+ newValue = "0";
1103
+ }
1104
+ }
1105
+ if (activeField == field.name) {
1106
+ lastVal = newValue;
1107
+ }
1108
+ }
1109
+ if (newValue != "") {
1110
+ newValue = parseInt(newValue).toString();
1111
+ field.text = newValue;
1112
+ var newSwatchRGB = Color3.FromHexString(newSwatch.background);
1113
+ if (activeField == field.name) {
1114
+ if (channel == "r") {
1115
+ updateValues(new Color3(parseInt(newValue) / 255, newSwatchRGB.g, newSwatchRGB.b), field.name);
1116
+ }
1117
+ else if (channel == "g") {
1118
+ updateValues(new Color3(newSwatchRGB.r, parseInt(newValue) / 255, newSwatchRGB.b), field.name);
1119
+ }
1120
+ else {
1121
+ updateValues(new Color3(newSwatchRGB.r, newSwatchRGB.g, parseInt(newValue) / 255), field.name);
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ // When the user enters a float for R, G, or B we check to make sure it is a valid number and replace if not.
1127
+ function updateFloat(field, channel) {
1128
+ var newValue = field.text;
1129
+ var checkVal = /[^0-9.]/g.test(newValue);
1130
+ if (checkVal) {
1131
+ field.text = lastVal;
1132
+ return;
1133
+ }
1134
+ else {
1135
+ if (newValue != "" && newValue != "." && parseFloat(newValue) != 0) {
1136
+ if (parseFloat(newValue) < 0.0) {
1137
+ newValue = "0.0";
1138
+ }
1139
+ else if (parseFloat(newValue) > 1.0) {
1140
+ newValue = "1.0";
1141
+ }
1142
+ else if (isNaN(parseFloat(newValue))) {
1143
+ newValue = "0.0";
1144
+ }
1145
+ }
1146
+ if (activeField == field.name) {
1147
+ lastVal = newValue;
1148
+ }
1149
+ }
1150
+ if (newValue != "" && newValue != "." && parseFloat(newValue) != 0) {
1151
+ newValue = parseFloat(newValue).toString();
1152
+ field.text = newValue;
1153
+ }
1154
+ else {
1155
+ newValue = "0.0";
1156
+ }
1157
+ var newSwatchRGB = Color3.FromHexString(newSwatch.background);
1158
+ if (activeField == field.name) {
1159
+ if (channel == "r") {
1160
+ updateValues(new Color3(parseFloat(newValue), newSwatchRGB.g, newSwatchRGB.b), field.name);
1161
+ }
1162
+ else if (channel == "g") {
1163
+ updateValues(new Color3(newSwatchRGB.r, parseFloat(newValue), newSwatchRGB.b), field.name);
1164
+ }
1165
+ else {
1166
+ updateValues(new Color3(newSwatchRGB.r, newSwatchRGB.g, parseFloat(newValue)), field.name);
1167
+ }
1168
+ }
1169
+ }
1170
+ // Removes the current index from the savedColors array. Drawer can then be regenerated.
1171
+ function deleteSwatch(index) {
1172
+ if (options.savedColors) {
1173
+ options.savedColors.splice(index, 1);
1174
+ }
1175
+ if (options.savedColors && options.savedColors.length == 0) {
1176
+ setEditButtonVisibility(false);
1177
+ editSwatchMode = false;
1178
+ }
1179
+ }
1180
+ // Creates and styles an individual swatch when updateSwatches is called.
1181
+ function createSwatch() {
1182
+ if (options.savedColors && options.savedColors[swatchNumber]) {
1183
+ var icon = void 0;
1184
+ if (editSwatchMode) {
1185
+ icon = "b";
1186
+ }
1187
+ else {
1188
+ icon = "";
1189
+ }
1190
+ var swatch_1 = Button.CreateSimpleButton("Swatch_" + swatchNumber, icon);
1191
+ swatch_1.fontFamily = "coreglyphs";
1192
+ var swatchColor = Color3.FromHexString(options.savedColors[swatchNumber]);
1193
+ var swatchLuminence = swatchColor.r + swatchColor.g + swatchColor.b;
1194
+ // Set color of outline and textBlock based on luminance of the color swatch so feedback always visible
1195
+ if (swatchLuminence > luminanceLimit) {
1196
+ swatch_1.color = iconColorDark;
1197
+ }
1198
+ else {
1199
+ swatch_1.color = iconColorLight;
1200
+ }
1201
+ swatch_1.fontSize = Math.floor(swatchSize * 0.7);
1202
+ swatch_1.textBlock.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
1203
+ swatch_1.height = swatch_1.width = swatchSize.toString() + "px";
1204
+ swatch_1.background = options.savedColors[swatchNumber];
1205
+ swatch_1.thickness = 2;
1206
+ var metadata_1 = swatchNumber;
1207
+ swatch_1.pointerDownAnimation = function () {
1208
+ swatch_1.thickness = 4;
1209
+ };
1210
+ swatch_1.pointerUpAnimation = function () {
1211
+ swatch_1.thickness = 3;
1212
+ };
1213
+ swatch_1.pointerEnterAnimation = function () {
1214
+ swatch_1.thickness = 3;
1215
+ };
1216
+ swatch_1.pointerOutAnimation = function () {
1217
+ swatch_1.thickness = 2;
1218
+ };
1219
+ swatch_1.onPointerClickObservable.add(function () {
1220
+ if (!editSwatchMode) {
1221
+ if (options.savedColors) {
1222
+ updateValues(Color3.FromHexString(options.savedColors[metadata_1]), swatch_1.name);
1223
+ }
1224
+ }
1225
+ else {
1226
+ deleteSwatch(metadata_1);
1227
+ updateSwatches("", butSave);
1228
+ }
1229
+ });
1230
+ return swatch_1;
1231
+ }
1232
+ else {
1233
+ return null;
1234
+ }
1235
+ }
1236
+ // Mode switch to render button text and close symbols on swatch controls
1237
+ function editSwatches(mode) {
1238
+ if (mode !== undefined) {
1239
+ editSwatchMode = mode;
1240
+ }
1241
+ var thisButton;
1242
+ if (editSwatchMode) {
1243
+ for (var i = 0; i < swatchDrawer.children.length; i++) {
1244
+ thisButton = swatchDrawer.children[i];
1245
+ thisButton.textBlock.text = "b";
1246
+ }
1247
+ if (butEdit !== undefined) {
1248
+ butEdit.textBlock.text = "Done";
1249
+ }
1250
+ }
1251
+ else {
1252
+ for (var i = 0; i < swatchDrawer.children.length; i++) {
1253
+ thisButton = swatchDrawer.children[i];
1254
+ thisButton.textBlock.text = "";
1255
+ }
1256
+ if (butEdit !== undefined) {
1257
+ butEdit.textBlock.text = "Edit";
1258
+ }
1259
+ }
1260
+ }
1261
+ /**
1262
+ * When Save Color button is pressed this function will first create a swatch drawer if one is not already
1263
+ * made. Then all controls are removed from the drawer and we step through the savedColors array and
1264
+ * creates one swatch per color. It will also set the height of the drawer control based on how many
1265
+ * saved colors there are and how many can be stored per row.
1266
+ * @param color
1267
+ * @param button
1268
+ */
1269
+ function updateSwatches(color, button) {
1270
+ if (options.savedColors) {
1271
+ if (color != "") {
1272
+ options.savedColors.push(color);
1273
+ }
1274
+ swatchNumber = 0;
1275
+ swatchDrawer.clearControls();
1276
+ var rowCount = Math.ceil(options.savedColors.length / options.numSwatchesPerLine);
1277
+ var gutterCount = void 0;
1278
+ if (rowCount == 0) {
1279
+ gutterCount = 0;
1280
+ }
1281
+ else {
1282
+ gutterCount = rowCount + 1;
1283
+ }
1284
+ if (swatchDrawer.rowCount != rowCount + gutterCount) {
1285
+ var currentRows = swatchDrawer.rowCount;
1286
+ for (var i = 0; i < currentRows; i++) {
1287
+ swatchDrawer.removeRowDefinition(0);
1288
+ }
1289
+ for (var i = 0; i < rowCount + gutterCount; i++) {
1290
+ if (i % 2) {
1291
+ swatchDrawer.addRowDefinition(swatchSize, true);
1292
+ }
1293
+ else {
1294
+ swatchDrawer.addRowDefinition(gutterSize, true);
1295
+ }
1296
+ }
1297
+ }
1298
+ swatchDrawer.height = (swatchSize * rowCount + gutterCount * gutterSize).toString() + "px";
1299
+ for (var y = 1, thisRow = 1; y < rowCount + gutterCount; y += 2, thisRow++) {
1300
+ // Determine number of buttons to create per row based on the button limit per row and number of saved colors
1301
+ var totalButtonsThisRow = void 0;
1302
+ if (options.savedColors.length > thisRow * options.numSwatchesPerLine) {
1303
+ totalButtonsThisRow = options.numSwatchesPerLine;
1304
+ }
1305
+ else {
1306
+ totalButtonsThisRow = options.savedColors.length - (thisRow - 1) * options.numSwatchesPerLine;
1307
+ }
1308
+ var buttonIterations = Math.min(Math.max(totalButtonsThisRow, 0), options.numSwatchesPerLine);
1309
+ for (var x = 0, w = 1; x < buttonIterations; x++) {
1310
+ if (x > options.numSwatchesPerLine) {
1311
+ continue;
1312
+ }
1313
+ var swatch = createSwatch();
1314
+ if (swatch != null) {
1315
+ swatchDrawer.addControl(swatch, y, w);
1316
+ w += 2;
1317
+ swatchNumber++;
1318
+ }
1319
+ else {
1320
+ continue;
1321
+ }
1322
+ }
1323
+ }
1324
+ if (options.savedColors.length >= options.swatchLimit) {
1325
+ disableButton(button, true);
1326
+ }
1327
+ else {
1328
+ disableButton(button, false);
1329
+ }
1330
+ }
1331
+ }
1332
+ // Shows or hides edit swatches button depending on if there are saved swatches
1333
+ function setEditButtonVisibility(enableButton) {
1334
+ if (enableButton) {
1335
+ butEdit = Button.CreateSimpleButton("butEdit", "Edit");
1336
+ butEdit.width = buttonWidth;
1337
+ butEdit.height = buttonHeight;
1338
+ butEdit.left = Math.floor(parseInt(buttonWidth) * 0.1).toString() + "px";
1339
+ butEdit.top = (parseFloat(butEdit.left) * -1).toString() + "px";
1340
+ butEdit.verticalAlignment = Control.VERTICAL_ALIGNMENT_BOTTOM;
1341
+ butEdit.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
1342
+ butEdit.thickness = 2;
1343
+ butEdit.color = buttonColor;
1344
+ butEdit.fontSize = buttonFontSize;
1345
+ butEdit.background = buttonBackgroundColor;
1346
+ butEdit.onPointerEnterObservable.add(function () {
1347
+ butEdit.background = buttonBackgroundHoverColor;
1348
+ });
1349
+ butEdit.onPointerOutObservable.add(function () {
1350
+ butEdit.background = buttonBackgroundColor;
1351
+ });
1352
+ butEdit.pointerDownAnimation = function () {
1353
+ butEdit.background = buttonBackgroundClickColor;
1354
+ };
1355
+ butEdit.pointerUpAnimation = function () {
1356
+ butEdit.background = buttonBackgroundHoverColor;
1357
+ };
1358
+ butEdit.onPointerClickObservable.add(function () {
1359
+ if (editSwatchMode) {
1360
+ editSwatchMode = false;
1361
+ }
1362
+ else {
1363
+ editSwatchMode = true;
1364
+ }
1365
+ editSwatches();
1366
+ });
1367
+ pickerGrid.addControl(butEdit, 1, 0);
1368
+ }
1369
+ else {
1370
+ pickerGrid.removeControl(butEdit);
1371
+ }
1372
+ }
1373
+ // Called when the user hits the limit of saved colors in the drawer.
1374
+ function disableButton(button, disabled) {
1375
+ if (disabled) {
1376
+ button.color = buttonDisabledColor;
1377
+ button.background = buttonDisabledBackgroundColor;
1378
+ }
1379
+ else {
1380
+ button.color = buttonColor;
1381
+ button.background = buttonBackgroundColor;
1382
+ }
1383
+ }
1384
+ // Passes last chosen color back to scene and kills dialog by removing from AdvancedDynamicTexture
1385
+ function closePicker(color) {
1386
+ if (options.savedColors && options.savedColors.length > 0) {
1387
+ resolve({
1388
+ savedColors: options.savedColors,
1389
+ pickedColor: color,
1390
+ });
1391
+ }
1392
+ else {
1393
+ resolve({
1394
+ pickedColor: color,
1395
+ });
1396
+ }
1397
+ advancedTexture.removeControl(dialogContainer);
1398
+ }
1399
+ });
1400
+ };
1401
+ ColorPicker._Epsilon = 0.000001;
1402
+ __decorate([
1403
+ serialize()
1404
+ ], ColorPicker.prototype, "value", null);
1405
+ __decorate([
1406
+ serialize()
1407
+ ], ColorPicker.prototype, "width", null);
1408
+ __decorate([
1409
+ serialize()
1410
+ ], ColorPicker.prototype, "height", null);
1411
+ __decorate([
1412
+ serialize()
1413
+ ], ColorPicker.prototype, "size", null);
1414
+ return ColorPicker;
1415
+ }(Control));
1416
+ export { ColorPicker };
1417
+ RegisterClass("BABYLON.GUI.ColorPicker", ColorPicker);
1401
1418
  //# sourceMappingURL=colorpicker.js.map