@babylonjs/gui 9.13.0 → 9.15.0

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