Example #1
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if (fontSize == 0)
            {
                toFill.Clear();
                return;
            }

            m_DisableDirty = true;

            if (font != null)
            {
                m_DisableFontTextureRebuiltCallback = true;
                cachedTextGenerator.Populate(IconDecoder.Decode(text), GetGenerationSettings(rectTransform.rect.size));
                Rect    rect            = rectTransform.rect;
                Vector2 textAnchorPivot = GetTextAnchorPivot(alignment);
                Vector2 zero            = Vector2.zero;
                zero.x = textAnchorPivot.x != 1.0 ? rect.xMin : rect.xMax;
                zero.y = textAnchorPivot.y != 0.0 ? rect.yMax : rect.yMin;
                Vector2          vector2 = PixelAdjustPoint(zero) - zero;
                IList <UIVertex> verts   = cachedTextGenerator.verts;
                float            num1    = 1f / pixelsPerUnit;
                int num2 = verts.Count - 4;
                toFill.Clear();

                if (vector2 != Vector2.zero)
                {
                    for (int index1 = 0; index1 < num2; ++index1)
                    {
                        int index2 = index1 & 3;
                        m_TempVerts[index2]             = verts[index1];
                        m_TempVerts[index2].position   *= num1;
                        m_TempVerts[index2].position.x += vector2.x;
                        m_TempVerts[index2].position.y += vector2.y;

                        if (index2 == 3)
                        {
                            toFill.AddUIVertexQuad(m_TempVerts);
                        }
                    }
                }
                else
                {
                    for (int index1 = 0; index1 < num2; ++index1)
                    {
                        int index2 = index1 & 3;
                        m_TempVerts[index2]           = verts[index1];
                        m_TempVerts[index2].position *= num1;

                        if (index2 == 3)
                        {
                            toFill.AddUIVertexQuad(m_TempVerts);
                        }
                    }
                }
                m_DisableFontTextureRebuiltCallback = false;
            }

            m_DisableDirty = false;
        }
Example #2
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo and multiple selected objects.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetDatas">The VectorImageDatas to modify.</param>
        /// <param name="objectsToUndo">The objects to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="visualReference">The VectorImageData to use for the 'current' values in the control if the VectorImageData values are different.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataMultiField(string label, VectorImageData[] targetDatas, Object[] objectsToUndo, Action onIconPickAction = null, VectorImageData visualReference = null)
        {
            if (targetDatas.ToList().TrueForAll(data => data == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = targetDatas.ToList().First(data => data != null);
            }

            string   code      = visualReference.glyph.unicode;
            string   name      = visualReference.glyph.name;
            Font     font      = visualReference.font;
            GUIStyle iconStyle = new GUIStyle {
                font = font, fontSize = vectorIconSize
            };

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(label);
                if (EditorGUI.indentLevel > 0)
                {
                    //  2 is a good 'base' offset when there are indents
                    EditorGUILayout.LabelField("", GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                }

                if (!string.IsNullOrEmpty(name))
                {
                    GUIContent iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);
                    EditorGUILayout.LabelField(iconGUIContent, iconStyle, GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));

                    if (EditorGUI.indentLevel > 0)
                    {
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                    }

                    GUILayout.FlexibleSpace();
                }
                else
                {
                    EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                {
                    VectorImagePickerWindow.Show(targetDatas, objectsToUndo, onIconPickAction);
                }
            }

            return(true);
        }
Example #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty code      = property.FindPropertyRelative("m_Glyph.m_Unicode");
            SerializedProperty name      = property.FindPropertyRelative("m_Glyph.m_Name");
            SerializedProperty font      = property.FindPropertyRelative("m_Font");
            GUIStyle           iconStyle = new GUIStyle {
                font = (Font)font.objectReferenceValue, fontSize = 16
            };

            RectOffset offset = new RectOffset(0, 0, -1, -3);

            position        = offset.Add(position);
            position.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 0;

            offsetH -= EditorGUI.PrefixLabel(new Rect(position.x + offsetH, position.y, 40, position.height), label).width;

            offsetH += 40;

            if (!string.IsNullOrEmpty(name.stringValue))
            {
                GUIContent iconLabel = new GUIContent(IconDecoder.Decode(code.stringValue));
                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, 16, position.height), iconLabel, iconStyle);

                float iconWidth = iconStyle.CalcSize(iconLabel).x;
                offsetH += iconWidth + 2f;

                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - offsetH - 80, position.height), name.stringValue);
            }
            else
            {
                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - 70 - 56, position.height), "No icon selected");
            }

            if (GUI.Button(new Rect(position.width - 74, position.y, 70, position.height), "Pick Icon"))
            {
                VectorImagePickerWindow.Show((VectorImageData)fieldInfo.GetValue(property.serializedObject.targetObject), property.serializedObject.targetObject);
            }
            if (GUI.Button(new Rect(position.width - 2, position.y, 18, position.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
            }))
            {
                VectorImageData data = ((VectorImageData)fieldInfo.GetValue(property.serializedObject.targetObject));
                data.font  = null;
                data.glyph = null;
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
        }
Example #4
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            if (fontSize == 0)
            {
                return;
            }

            string cache = text;

            m_DisableDirty = true;
            text           = IconDecoder.Decode(text);
            base.OnPopulateMesh(toFill);
            text           = cache;
            m_DisableDirty = false;
        }
        public static void DrawIconPickLine(VectorImageData data, Object objectToRefresh, bool indent = false)
        {
            using (new GUILayout.HorizontalScope())
            {
                if (data.font == null)
                {
                    data.font = VectorImageManager.GetIconFont(VectorImageManager.GetAllIconSetNames()[0]);
                }

                GUIStyle iconGuiStyle = new GUIStyle { font = VectorImageManager.GetIconFont(data.font.name) };

                EditorGUILayout.PrefixLabel("Icon");

                if (indent)
                {
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.LabelField(IconDecoder.Decode(data.glyph.unicode), iconGuiStyle, GUILayout.Width(18f));
                EditorGUILayout.LabelField(data.glyph.name, GUILayout.MaxWidth(100f), GUILayout.MinWidth(0f));

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Pick icon", EditorStyles.miniButton, GUILayout.MaxWidth(60f)))
                {
                    Show(data, objectToRefresh);
                    return;
                }

                if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(20f)))
                {
                    for (int i = 0; i < m_VectorImageDatas.Length; i++)
                    {
                        m_VectorImageDatas[i] = null;
                    }
                    return;
                }

                if (indent)
                {
                    EditorGUI.indentLevel++;
                }
            }
        }
Example #6
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetData">The VectorImageData to modify.</param>
        /// <param name="objectToUndo">The object to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="disableIfMultipleObjectsSelected">Is this field drawn disabled if multiple GameObjects are selected?</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataField(string label, VectorImageData targetData, Object objectToUndo, Action onIconPickAction = null, bool disableIfMultipleObjectsSelected = true)
        {
            using (new DisabledScope(TooManySelected(!disableIfMultipleObjectsSelected)))
            {
                string   code      = targetData.glyph.unicode;
                string   name      = targetData.glyph.name;
                Font     font      = targetData.font;
                GUIStyle iconStyle = new GUIStyle {
                    font = font, fontSize = vectorIconSize
                };
                using (new GUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel(label);
                    if (EditorGUI.indentLevel > 0)
                    {
                        //  2 is a good 'base' offset when there are indents
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        GUIContent iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);
                        EditorGUILayout.LabelField(iconGUIContent, iconStyle, GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));

                        if (EditorGUI.indentLevel > 0)
                        {
                            EditorGUILayout.LabelField("", GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    }

                    if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                    {
                        VectorImagePickerWindow.Show(targetData, objectToUndo, onIconPickAction);
                    }
                }
            }

            return(true);
        }
Example #7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GetProperties(property);

            Rect pos = position;

            pos.height = EditorGUI.GetPropertyHeight(m_ImageDataType);

            float labelWidth = GUI.skin.GetStyle("Label").CalcSize(label).x;

            float i = EditorGUI.PrefixLabel(new Rect(pos.x, pos.y, labelWidth, pos.height), label).width;

            pos.x     -= i - 54;
            pos.width += i - 55;

            if (property.name.Equals("m_ToggleOnIcon") || property.name.Equals("m_ToggleOffIcon"))
            {
                pos.x     += 33;
                pos.width -= 33;
            }
            else if (property.name.Equals("m_TabIcon"))
            {
                pos.x     -= 3;
                pos.width += 3;
            }

            if (m_ImageDataType.enumValueIndex == 0)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_Sprite);
                EditorGUI.PropertyField(pos, m_Sprite, GUIContent.none);
            }

            if (m_ImageDataType.enumValueIndex == 1)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_VectorImageData);

                SerializedProperty code      = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Unicode");
                SerializedProperty name      = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Name");
                SerializedProperty font      = m_VectorImageData.FindPropertyRelative("m_Font");
                GUIStyle           iconStyle = new GUIStyle {
                    font = (Font)font.objectReferenceValue
                };

                float pickButtonWidth    = 70;
                float pickButtonPadding  = 88;
                float clearButtonWidth   = 18;
                float clearButtonPadding = 14;

                if (!string.IsNullOrEmpty(name.stringValue))
                {
                    EditorGUI.LabelField(new Rect(pos.x, pos.y, 16, pos.height), IconDecoder.Decode(code.stringValue),
                                         iconStyle);
                    pos.x     += 16;
                    pos.width -= 16;
                    EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, position.height), name.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(
                        new Rect(pos.x, pos.y, pos.width - (pickButtonWidth + clearButtonWidth), pos.height),
                        "No icon selected");
                }

                if (GUI.Button(new Rect((pos.x + pos.width) - pickButtonPadding, pos.y, pickButtonWidth, pos.height),
                               "Pick Icon"))
                {
                    VectorImagePickerWindow.Show(
                        ((ImageData)fieldInfo.GetValue(m_VectorImageData.serializedObject.targetObject))
                        .vectorImageData, property.serializedObject.targetObject);
                }

                if (GUI.Button(new Rect((pos.x + pos.width - 1) - clearButtonPadding, pos.y, clearButtonWidth, pos.height),
                               IconDecoder.Decode(@"\ue14c"),
                               new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                }))
                {
                    VectorImageData data =
                        (((ImageData)fieldInfo.GetValue(m_VectorImageData.serializedObject.targetObject))
                         .vectorImageData);
                    data.font  = null;
                    data.glyph = null;
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }
            }
        }
Example #8
0
        private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
        {
            SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty itemText = itemData.FindPropertyRelative("m_Text");

            SerializedProperty itemSprite = itemData.FindPropertyRelative("m_ImageData.m_Sprite");

            SerializedProperty itemCode  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Unicode");
            SerializedProperty itemName  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Name");
            GUIStyle           iconStyle = new GUIStyle {
                font = (Font)itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Font").objectReferenceValue
            };

            SerializedProperty itemImageType = itemData.FindPropertyRelative("m_ImageData.m_ImageDataType");

            RectOffset offset = new RectOffset(0, 0, -1, -3);

            rect        = offset.Add(rect);
            rect.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 0;

            EditorGUI.LabelField(new Rect(rect.x, rect.y, 16, rect.height), index.ToString());
            offsetH += 16;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 35, rect.height), "Text", EditorStyles.boldLabel);
            offsetH += 35;

            EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, (rect.width / 3) - offsetH, rect.height), itemText, GUIContent.none);
            offsetH += (rect.width / 3) - offsetH + 8;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 32, rect.height), "Icon", EditorStyles.boldLabel);
            offsetH += 32;

            itemImageType.enumValueIndex = m_ImageType.enumValueIndex;

            if (m_ImageType.enumValueIndex == 0)
            {
                EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height), itemSprite, GUIContent.none);
            }
            else
            {
                if (!string.IsNullOrEmpty(itemName.stringValue))
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), IconDecoder.Decode(itemCode.stringValue), iconStyle);
                    offsetH += 16;
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), itemName.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), "No icon selected");
                }

                if (GUI.Button(new Rect(rect.width - 60, rect.y, 70, rect.height), "Pick Icon"))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImagePickerWindow.Show(optionDataListContainer.optionDataList.options[index].imageData.vectorImageData, itemData.serializedObject.targetObject);
                }

                if (GUI.Button(new Rect(rect.width + 16, rect.y, 18, rect.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                }))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImageData          data = optionDataListContainer.optionDataList.options[index].imageData.vectorImageData;
                    data.font  = null;
                    data.glyph = null;
                    EditorUtility.SetDirty(itemData.serializedObject.targetObject);
                }
            }
        }
        private void DrawIconList()
        {
            if (m_GlyphArray.Length == 0)
            {
                GUIStyle guiStyle = new GUIStyle();
                guiStyle.fontStyle = FontStyle.Bold;
                guiStyle.alignment = TextAnchor.MiddleCenter;

                EditorGUILayout.LabelField("No icon found for your search term: " + m_SearchText, guiStyle, GUILayout.Height(Screen.height - 80f));
                return;
            }

            float padded = m_PreviewSize + 5f;
            int columns = Mathf.FloorToInt((Screen.width - 25f) / padded);
            if (columns < 1) columns = 1;

            int offset = 0;
            Rect rect = new Rect(0f, 0, m_PreviewSize, m_PreviewSize);

            GUILayout.Space(5f);

            using (GUILayout.ScrollViewScope scrollViewScope = new GUILayout.ScrollViewScope(m_IconViewScrollPosition, GUILayout.Height(Screen.height - 80f)))
            {
                m_IconViewScrollPosition = scrollViewScope.scrollPosition;

                while (offset < m_GlyphArray.Length)
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        int col = 0;
                        rect.x = 0f;

                        for (; offset < m_GlyphArray.Length; ++offset)
                        {
                            // Change color of the selected VectorImage
                            if (m_VectorImageDatas[0].glyph.name == m_GlyphArray[offset].name)
                            {
                                GUI.backgroundColor = MaterialColor.iconDark;
                            }

                            if (GUI.Button(rect, new GUIContent("", m_GlyphArray[offset].name)))
                            {
                                if (Event.current.button == 0)
                                {
                                    SetGlyph(offset);

                                    if (Time.realtimeSinceStartup - m_LastClickTime < 0.3f)
                                    {
                                        Close();
                                    }

                                    m_LastClickTime = Time.realtimeSinceStartup;
                                }
                            }

                            if (Event.current.type == EventType.Repaint)
                            {
                                drawTiledTexture(rect);

                                m_GuiStyle.fontSize = m_PreviewSize;

                                string iconText = IconDecoder.Decode(@"\u" + m_GlyphArray[offset].unicode);
                                Vector2 size = m_GuiStyle.CalcSize(new GUIContent(iconText));

                                float maxSide = size.x > size.y ? size.x : size.y;
                                float scaleFactor = (m_PreviewSize / maxSide) * 0.9f;

                                m_GuiStyle.fontSize = Mathf.RoundToInt(m_PreviewSize * scaleFactor);
                                size *= scaleFactor;

                                Vector2 padding = new Vector2(rect.width - size.x, rect.height - size.y);
                                Rect iconRect = new Rect(rect.x + (padding.x / 2f), rect.y + (padding.y / 2f), rect.width - padding.x, rect.height - padding.y);

                                GUI.Label(iconRect, new GUIContent(iconText), m_GuiStyle);
                            }

                            GUI.backgroundColor = Color.white;

                            if (++col >= columns)
                            {
                                ++offset;
                                break;
                            }
                            rect.x += padded;
                        }
                    }
                    GUILayout.Space(padded);
                    rect.y += padded;
                }
            }
        }