/// <summary>
        /// Create a Color Picker process with initialColor, useDefinedPosition, texturePath pLeft, pTop, activePingsNeeded,  destroyOnClose
        /// </summary>
        /// <param name="initialColor">Sets the initial color</param>
        /// <param name="useDefinedPosition">Indicates whether a user-defined position is specified </param>
        /// <param name="texturePath">Path to a ColorPicker texture</param>
        /// <param name="pLeft">Left most pixel position of the window</param>
        /// <param name="pTop">Top most pixel position of the window</param>
        /// <param name="activePingsNeeded">If true, window needs frequent "pings" to not automatically close</param>
        /// <param name="destroyOnClose">If true, then destroys the window when closed</param>
        /// <returns>KSP_ColorPicker</returns>
        public static KSP_ColorPicker CreateColorPicker(Color initialColor, bool useDefinedPosition = false, string texturePath = null,
                                                        int pLeft = 0, int pTop = 0, bool activePingsNeeded = true, bool destroyOnClose = true)
        {
            GameObject go = new GameObject();

            colorPickerInstance = go.AddComponent <KSP_ColorPicker>();
            colorPickerInstance.positionLeft = pLeft;
            colorPickerInstance.positionTop  = pTop;
            if (texturePath != null)
            {
                colorPickerInstance.texturePath = texturePath;
            }

            pickerTextures = AvailableTextures();

            // If it's not a rooted path, then assume it's in a subdir of the TEXTURES directory
            if (!System.IO.Path.IsPathRooted(colorPickerInstance.texturePath))
            {
                colorPickerInstance.texturePath = TEXTURES + colorPickerInstance.texturePath;
            }

            colorPickerInstance.destroyOnClose = destroyOnClose;
            colorPickerInstance.FindInitTexture();
            colorPickerInstance.LoadAndInitTexture();
            colorPickerInstance.lastSetColor = initialColor;
            showPicker = true;
            success    = false;
            return(colorPickerInstance);
        }
        void CloseAndDestroy()
        {
            // hide picker
            showPicker = false;

            if (destroyOnClose)
            {
                colorPickerInstance = null;
                Destroy(this);
            }
        }
        void DrawWindowContents(int id)
        {
            GUI.Box(new Rect(3, TITLE_HEIGHT + 3, textureWidth + BOTTOM_RIGHT_MARGIN, textureHeight + BOTTOM_RIGHT_MARGIN), "");

            if (GUI.RepeatButton(new Rect(6, TITLE_HEIGHT + 6, textureWidth + 10, textureHeight + 10), displayPicker, GUIStyle.none))
            {
                int a = (int)Input.mousePosition.x - (int)_windowPos.x;
                int b = textureHeight - (int)((Screen.height - Input.mousePosition.y) - (int)_windowPos.y);

                selectedColor = displayPicker.GetPixel(a, b);

                lastSetColor = selectedColor;
            }

            saturationSlider = GUI.VerticalSlider(new Rect(textureWidth + 13, TITLE_HEIGHT + 6, 10, textureHeight), saturationSlider, 1, -1);
            SetSaturationTexture(lastSetColor);
            selectedColor = lastSetColor + new Color(saturationSlider, saturationSlider, saturationSlider);


            GUI.Box(new Rect(textureWidth + 30, TITLE_HEIGHT + 6, 20, textureHeight), saturationTexture, saturationTextureStyle);

            if (curTextureNum != null)
            {
                if (GUI.Button(new Rect(10, TITLE_HEIGHT + textureHeight + (BOTTOM_RIGHT_MARGIN - BUTTON_HEIGHT) / 2, 50, BUTTON_HEIGHT), "<"))
                {
                    curTextureNum--;
                    if (curTextureNum < 0)
                    {
                        curTextureNum = pickerTextures.Length - 1;
                    }
                    colorPickerInstance.texturePath = TEXTURES + pickerTextures[(int)curTextureNum];
                    reloadTexture = true;
                }
                if (GUI.Button(new Rect(50, TITLE_HEIGHT + textureHeight + (BOTTOM_RIGHT_MARGIN - BUTTON_HEIGHT) / 2, 50, BUTTON_HEIGHT), ">"))
                {
                    curTextureNum++;
                    if (curTextureNum >= pickerTextures.Length)
                    {
                        curTextureNum = 0;
                    }
                    colorPickerInstance.texturePath = TEXTURES + pickerTextures[(int)curTextureNum];
                    reloadTexture = true;
                }
            }

            if (GUI.Button(new Rect(1200, TITLE_HEIGHT + textureHeight + (BOTTOM_RIGHT_MARGIN - BUTTON_HEIGHT) / 2, BUTTON_WIDTH, BUTTON_HEIGHT), "Cancel"))
            {
                // hide picker
                showPicker = false;
                if (destroyOnClose)
                {
                    colorPickerInstance = null;
                    Destroy(this);
                }
            }
            if (GUI.Button(new Rect(10 + textureWidth / 2, TITLE_HEIGHT + textureHeight + (BOTTOM_RIGHT_MARGIN - BUTTON_HEIGHT) / 2, BUTTON_WIDTH, BUTTON_HEIGHT), "Accept"))
            {
                selectedColor = styleTexture.GetPixel(0, 0);
                success       = true;
                CloseAndDestroy();
            }


            GUI.Label(new Rect(textureWidth - BUTTON_WIDTH * 2, TITLE_HEIGHT + textureHeight + (BOTTOM_RIGHT_MARGIN - BUTTON_HEIGHT) / 2, BUTTON_WIDTH * 2, BUTTON_HEIGHT), "Selected Color -->");

            // color display

            styleTexture.SetPixel(0, 0, selectedColor);
            styleTexture.Apply();

            styleTextureStyle.normal.background = styleTexture;
            GUI.Box(new Rect(textureWidth + 10, TITLE_HEIGHT + textureHeight + 10, 30, 30), new GUIContent(""), styleTextureStyle);

            GUI.DragWindow();
        }