Exemplo n.º 1
0
        /// <summary>
        /// Extracts from colorlovers, the percentages only the pixel-width, so it as to be divied with the totalwidth
        /// </summary>
        /// <returns>The from colorlovers.</returns>
        /// <param name="doc">Document.</param>
        /// <param name="loadPercentages">If set to <c>true</c> load percentages.</param>
        public static PaletteData extractFromColorlovers(Document doc, bool loadPercentages)
        {
            int         colorCount   = 0;
            int         percentCount = 0;
            PaletteData palette      = new PaletteData();

/*
 *                                              IEnumerable<Tag> headerTags = doc.FindAll ("h1");
 *                                              foreach (Tag headerTag in headerTags) {
 * //								if (!string.IsNullOrEmpty (headerTag.c)) {
 *
 *
 *                                                              //palette.name = headerTag.ToString ();
 *                                                              Debug.Log (headerTag.ToString ().HtmlDecode ());
 *                                                              //["class"] == "feature-detail-container") {
 *
 * //								}
 *                                              }
 */


            IEnumerable <Tag> links = doc.FindAll("a");


            foreach (Tag a in links)
            {
                if (a ["class"] == "left pointer block")
                {
                    string style = a ["style"];
                    //Debug.Log ("style.Split (';') " + style.Split (';').Length);

                    foreach (string styleCss in style.Split(';'))
                    {
                        if (loadPercentages && styleCss.Contains("width"))
                        {
                            string width = styleCss.Split(':') [1];
                            width = width.Substring(0, width.IndexOf("px"));
                            float widthF = float.Parse(width.Trim());

                            //Debug.Log ("found % " + widthF + " from " + styleCss);

                            palette.totalWidth += widthF;
                            palette.percentages [percentCount++] = widthF;
                        }
                        else if (styleCss.Contains("background-color"))
                        {
                            string bgColor = styleCss.Split(':') [1];
                            bgColor = bgColor.Trim().Substring(1);
                            palette.colors [colorCount++] = JSONPersistor.HexToColor(bgColor);
                        }
                    }

                    //Debug.Log (style);
                }
            }

//						Debug.Log (palette.percentages [0]);

            return(palette);
        }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
 public static Color[] getColorsArrayFromHex(string[] hexArray)
 {
     Color[] colors = new Color[hexArray.Length];
     for (int i = 0; i < hexArray.Length; i++)
     {
         colors [i] = JSONPersistor.HexToColor(hexArray [i]);
     }
     return(colors);
 }
Exemplo n.º 4
0
        public static PaletteData extractFromPLTTS(Document doc, bool loadPercent)
        {
            int         colorCount   = 0;
            int         percentCount = 0;
            PaletteData palette      = new PaletteData();

            Tag colorBlock = doc.Find(".palette-colors");

            //Debug.Log (colorBlock);

            foreach (Element colorDiv in colorBlock.Children)
            {
                if (!string.IsNullOrEmpty(colorDiv.ToString().Trim()))
                {
                    // can contain empty Elements!

                    //Tag colorTag = (HtmlSharp.Elements.Tags.Div)colorDiv;
                    Tag colorTag = (Tag)colorDiv;

                    string style = colorTag ["style"];
                    foreach (string styleCss in style.Split(';'))
                    {
                        if (loadPercent && styleCss.Contains("width"))
                        {
                            string width = styleCss.Split(':') [1];
                            width = width.Substring(0, width.IndexOf("%"));
                            float widthF = float.Parse(width.Trim());
                            palette.totalWidth += widthF / 100;
                            palette.percentages [percentCount++] = widthF / 100;
                        }
                        else if (styleCss.Contains("background-color"))
                        {
                            string bgColor = styleCss.Split(':') [1];
                            bgColor = bgColor.Trim().Substring(1);
                            palette.colors [colorCount++] = JSONPersistor.HexToColor(bgColor);
                        }
                    }

                    //Debug.Log (style);
                }
            }

            if (!loadPercent)
            {
                palette.percentages = PaletteData.getDefaultPercentages();
            }

            return(palette);
        }
Exemplo n.º 5
0
    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);
    }