protected virtual PaletteData drawColorsAndPercentages(PaletteData data)
    {
        GUILayoutUtility.GetRect(Screen.width, 10);

        adjustPCTBefore = GUILayout.Toggle(adjustPCTBefore, " adjust percentage to the left");

        Rect colorChangerRect = GUILayoutUtility.GetRect(Screen.width, data.colors.Length * colorChangerRowHeight);

        colorChangerRect.x     += colorChangeLeftMargin;
        colorChangerRect.width -= colorChangeRightMargin;

        GUILayoutUtility.GetRect(Screen.width, 10);

        float startY = colorChangerRect.y + 10;

        for (int i = 0; i < data.colors.Length; i++)
        {
            // draw a little preview of the current color
            Rect colRect = new Rect(colorChangerRect.x, startY,
                                    150, colorChangerRowHeight);

            Color currentColor = data.colors [i];
            Color newColor     = EditorGUI.ColorField(colRect, currentColor);

            string currentHex = JSONPersistor.ColorToHex(currentColor);

            Rect hexRect = new Rect(colorChangerRect.x + colRect.width + colorChangeMarginBetween,
                                    startY, hexFieldWidth, colorChangerRowHeight);

            string newHex = EditorGUI.TextField(hexRect, currentHex);

            if (!currentHex.Equals(newHex))
            {
                data.colors [i] = JSONPersistor.HexToColor(newHex);
            }
            else if (!currentColor.ToString().Equals(newColor.ToString()))
            {
                data.colors [i] = newColor;
                data.alphas [i] = newColor.a;
            }

            float currentPct = data.percentages [i];
            float maxPct     = 1.0f - (data.percentages.Length - 1) * this.minPct;
            //Debug.Log ("max % " + maxPct);

            Rect silderRect = new Rect(colorChangerRect.x + colRect.width + colorChangeMarginBetween + hexRect.width + colorChangeMarginBetween, startY,
                                       colorChangerRect.width - colorChangeMarginBetween - colRect.width - colorChangeMarginBetween - hexRect.width,
                                       colorChangerRowHeight);

            float newPct = EditorGUI.Slider(silderRect, currentPct, this.minPct, maxPct);
            data = adjustPct(data, i, newPct, currentPct, maxPct);


            startY += colorChangerRowHeight;
        }

        return(data);
    }
 public static string[] getHexArrayFromColors(Color[] colors)
 {
     string[] hexArray = new string[colors.Length];
     for (int i = 0; i < colors.Length; i++)
     {
         hexArray [i] = JSONPersistor.ColorToHex(colors [i]);
     }
     return(hexArray);
 }
    protected virtual PaletteData drawColorPalette(PaletteData data, bool showHexValues = false)
    {
        // palette height silder
        //height = EditorGUILayout.Slider ("Height", height, 100, 200);

        GUILayout.Space(10);

        //paletteHeight = height;
        EditorGUILayout.BeginHorizontal();

        data.name = EditorGUILayout.TextField("Palette name: ", data.name);

        EditorGUILayout.EndHorizontal();

        GUILayout.Space(10);

        Rect paletteRect;

        if (showHexValues)
        {
            paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight + paletteTopMargin);
        }
        else
        {
            paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight);
        }


        if (data.colors != null)
        {
            // show the palette
            float start = 20;

            for (int i = 0; i < data.colors.Length; i++)
            {
                Color col      = data.colors [i];
                float colWidth = data.percentages [i] * (Screen.width - 35);

                //Debug.Log (i + " starts " + start + " width " + colWidth);
                float yPos = paletteRect.position.y;

                if (showHexValues)
                {
                    yPos = paletteRect.position.y + paletteTopMargin;
                }

                Rect colRect = new Rect(start, yPos, colWidth,
                                        paletteHeight - paletteBotMargin);

                EditorGUIUtility.DrawColorSwatch(colRect, col);

                Rect lableRect = colRect;
                lableRect.width  = 60;
                lableRect.height = 15;

                lableRect.y -= paletteTopMargin * 0.5f;

                if (i % 2 == 0)
                {
                    lableRect.y -= 15;
                }

                if (showHexValues)
                {
                    string hexString    = JSONPersistor.ColorToHex(col);
                    Rect   labelHexRect = new Rect(lableRect);
                    labelHexRect.width = hexFieldWidth;


                    string newHex = EditorGUI.TextField(labelHexRect, hexString);

                    if (!newHex.Equals(JSONPersistor.ColorToHex(col)))
                    {
                        data.colors [i] = JSONPersistor.HexToColor(newHex);
                    }
                }


                start += colWidth;
            }
        }

        return(data);
    }