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