Exemplo n.º 1
0
        public override ResourceData FromFileToAdd(Stream stream,
                                                   string extension,
                                                   ushort langId,
                                                   ResourceSource currentSource)
        {
            if (!IsExtension(extension, "ICO"))
            {
                throw new ArgumentException("ico is the only supported extension");
            }

            var group = new IconGroup(stream);

            group.BindToSource(currentSource, langId);

            return(new IconDirectoryResourceData(group, null));
        }
        void OnEnable()
        {
            _editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
            _scrollPos  = Vector2.zero;
            SetSelectedIcon(null);

            iconGroups = new List <IconGroup>();

            for (int i = 0; i < kIconGroupNames.Length; ++i)
            {
                IconGroup group = new IconGroup();
                group.name = kIconGroupNames[i];

                float minHeight = kIconThresholds[i];
                float maxHeight = kIconThresholds[i + 1];

                group.iconData = _editorSkin.customStyles
                                 .Where(style =>
                {
                    if (style.normal.background == null)
                    {
                        return(false);
                    }
                    if (style.normal.background.height <= minHeight || style.normal.background.height > maxHeight)
                    {
                        return(false);
                    }
                    if (kHideBlacklistedIcons && kIconBlacklist.Contains(style.name))
                    {
                        return(false);
                    }

                    return(true);
                })
                                 .OrderBy(style => style.normal.background.height).ToArray();

                float maxWidth = 0;
                foreach (GUIStyle style in group.iconData)
                {
                    maxWidth = (style.normal.background.width > maxWidth) ? style.normal.background.width : maxWidth;
                }
                group.maxWidth = maxWidth;

                iconGroups.Add(group);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// On Windows, SDL will use the same image for both large and small icons (scaled as necessary).
        /// This can look bad if scaling down a large image, so we use the Windows API directly so as
        /// to get a cleaner icon set than SDL can provide.
        /// If called before the window has been created, or we do not find two separate icon sizes, we fall back to the base method.
        /// </summary>
        internal override void SetIconFromGroup(IconGroup iconGroup)
        {
            smallIcon = iconGroup.CreateIcon(small_icon_size, small_icon_size);
            largeIcon = iconGroup.CreateIcon(large_icon_size, large_icon_size);

            var windowHandle = WindowHandle;

            if (windowHandle == IntPtr.Zero || largeIcon == null || smallIcon == null)
            {
                base.SetIconFromGroup(iconGroup);
            }
            else
            {
                SendMessage(windowHandle, seticon_message, (IntPtr)icon_small, smallIcon.Handle);
                SendMessage(windowHandle, seticon_message, (IntPtr)icon_big, largeIcon.Handle);
            }
        }
Exemplo n.º 4
0
        public virtual void SetIconFromStream(Stream stream)
        {
            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                ms.Position = 0;

                var imageInfo = Image.Identify(ms);

                if (imageInfo != null)
                {
                    SetIconFromImage(Image.Load <Rgba32>(ms.GetBuffer()));
                }
                else if (IconGroup.TryParse(ms.GetBuffer(), out var iconGroup))
                {
                    SetIconFromGroup(iconGroup);
                }
            }
        }
Exemplo n.º 5
0
        public override ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang)
        {
            if (!IsExtension(extension, "ICO"))
            {
                throw new ArgumentException("ico is the only supported extension");
            }

            if (!(currentLang.Data is IconDirectoryResourceData originalData))
            {
                throw new ResourceDataException("Unexpected original data subclass");
            }

            var newGroup = new IconGroup(stream);

            var canonicalGroup = originalData.IconGroup;

            canonicalGroup.Merge(newGroup, GetMergeOptions());

            return(new IconDirectoryResourceData(canonicalGroup, null));
        }
Exemplo n.º 6
0
        public override ResourceData FromFileToUpdate(Stream stream, String extension, ResourceLang currentLang)
        {
            if (!IsExtension(extension, "CUR"))
            {
                throw new ArgumentException("cur is the only supported extension");
            }

            CursorDirectoryResourceData originalData = currentLang.Data as CursorDirectoryResourceData;

            if (originalData == null)
            {
                throw new ResourceDataException("Unexpected original data subclass");
            }

            IconGroup newGroup = new IconGroup(stream);

            IconGroup canonicalGroup = originalData.IconGroup;

            canonicalGroup.Merge(newGroup, GetMergeOptions());

            return(new CursorDirectoryResourceData(canonicalGroup, null));
        }
        void OnGUI()
        {
            float sidePanelWidth = CalculateSidePanelWidth();

            GUILayout.BeginArea(new Rect(0, 0, sidePanelWidth, position.height), GUI.skin.box);
            DrawIconDisplay(_selectedIcon);
            GUILayout.EndArea();

            GUI.BeginGroup(new Rect(sidePanelWidth, 0, position.width - sidePanelWidth, position.height));
            _scrollPos = GUILayout.BeginScrollView(_scrollPos, true, true, GUILayout.MaxWidth(position.width - sidePanelWidth));

            for (int i = 0; i < iconGroups.Count; ++i)
            {
                IconGroup group = iconGroups[i];
                EditorGUILayout.LabelField(group.name);
                DrawIconSelectionGrid(group.iconData, group.maxWidth);

                GUILayout.Space(15);
            }

            GUILayout.EndScrollView();
            GUI.EndGroup();
        }
Exemplo n.º 8
0
        public override void SetIconFromStream(Stream stream)
        {
            if (WindowInfo.Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Window must be created before an icon can be set.");
            }

            iconGroup = new IconGroup(stream);

            smallIcon = iconGroup.CreateIcon(24, 24);
            largeIcon = iconGroup.CreateIcon(256, 256);

            // CreateIcon was changed to return null rather than throwing exceptions
            // Since we have no fallback method of generating icons, we skip if the icon can't be found
            if (smallIcon != null)
            {
                SendMessage(WindowInfo.Handle, seticon_message, (IntPtr)0, smallIcon.Handle);
            }

            if (largeIcon != null)
            {
                SendMessage(WindowInfo.Handle, seticon_message, (IntPtr)1, largeIcon.Handle);
            }
        }
Exemplo n.º 9
0
        public override ResourceData FromResource(ResourceLang lang, Byte[] data)
        {
            IconGroup group = new IconGroup(lang, data);

            return(new CursorDirectoryResourceData(group, lang));
        }
Exemplo n.º 10
0
 internal IconDirectoryResourceData(IconGroup icon, ResourceLang lang) : base(lang, icon.GetResDirectoryData())
 {
     IconGroup = icon;
 }
Exemplo n.º 11
0
        void OnEnable()
        {
            _editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
            _scrollPos = Vector2.zero;
            SetSelectedIcon(null);

            iconGroups = new List<IconGroup>();

            for (int i = 0; i < kIconGroupNames.Length; ++i)
            {
                IconGroup group = new IconGroup();
                group.name = kIconGroupNames[i];

                float minHeight = kIconThresholds[i];
                float maxHeight = kIconThresholds[i + 1];

                group.iconData = _editorSkin.customStyles
                .Where(style =>
                {
                    if (style.normal.background == null)
                        return false;
                    if (style.normal.background.height <= minHeight || style.normal.background.height > maxHeight)
                        return false;
                    if (kHideBlacklistedIcons && kIconBlacklist.Contains(style.name))
                        return false;

                    return true;
                })
                .OrderBy(style => style.normal.background.height).ToArray();

                float maxWidth = 0;
                foreach (GUIStyle style in group.iconData)
                    maxWidth = (style.normal.background.width > maxWidth) ? style.normal.background.width : maxWidth;
                group.maxWidth = maxWidth;

                iconGroups.Add(group);
            }
        }
Exemplo n.º 12
0
        public override ResourceData FromResource(ResourceLang lang, byte[] data)
        {
            var group = new IconGroup(lang, data);

            return(new IconDirectoryResourceData(group, lang));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Parses through the Icon File looking for a match on type and icon filename
        /// </summary>
        /// <param name="groupName">Group of icons to look for</param>
        /// <returns>Icon Fully Qualified Path</returns>
        private string GetIconFilename(string groupName)
        {
            string    iconFilename = "";
            IconSet   niemIcons    = null;
            IconGroup group        = null;

            //sanity check
            if (IconConfig.Icons != null)
            {
                foreach (IconSet iset in IconConfig.Icons.Sets)
                {
                    if (iset.KindofSet.Equals("NIEM", StringComparison.InvariantCultureIgnoreCase))
                    {
                        niemIcons = iset;
                        break;
                    }
                }

                if (niemIcons != null)
                {
                    foreach (IconGroup iGroup in niemIcons.Groups)
                    {
                        if (iGroup.KindofGroup.Equals(groupName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            group = iGroup;
                            break;
                        }
                    }

                    if (group != null)
                    {
                        string   resourceType = myEvent.EventTypeDescriptor.CodeValue.ToString();
                        string[] splitType    = resourceType.Split('_');

                        string temp = "";
                        //TODO:assumes file extension is .png, need to fix later

                        //this loop strips off the right most subtype when looking for a match
                        //on file name
                        //For Exmample: ALS Ambulance type is
                        //ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS_AMBULANCE_ALS
                        //each pass removes the right most subtype until either a match is found
                        //or beginning of the string is hit (which isn't good)
                        //ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS_AMBULANCE_ALS
                        //ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS_AMBULANCE
                        //ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM_EMS
                        //ATOM_GRDTRK_EQT_GRDVEH_CVLVEH_EM
                        //...
                        for (int i = splitType.Length; i >= 0; i--)
                        {
                            temp = String.Join("_", splitType, 0, i) + ".png";

                            DEUtilities.LogMessage("Searching for icon filename: " + temp + " in NIEM group: " + groupName, DEUtilities.LogLevel.Debug);

                            if (group.Filenames.Contains(temp))
                            {
                                iconFilename = group.RootFolder + @"/" + temp;
                                break;
                            }
                        }

                        if (string.IsNullOrWhiteSpace(iconFilename))
                        {
                            DEUtilities.LogMessage("Icon filename not found for: " + resourceType, DEUtilities.LogLevel.Error);
                        }
                    }
                }
            }
            return(iconFilename);
        }