Esempio n. 1
0
        private void DrawFolderIcon(string path, Rect selectionRect, PvRuleItem rule, bool selected)
        {
            string       name     = Path.GetFileName(path);
            IconSizeType sizeType = PvCustomizerUtility.GetSizeType(selectionRect);
            Rect         iconRect = PvCustomizerUtility.ItemRectToIconRect(selectionRect, sizeType == IconSizeType.TreeView);
            Color        tint     = selected ? (Color)PvCustomizerGUI.ICON_SELECTED_TINT : Color.white;

            #region Icon Drawing

            if (sizeType == IconSizeType.Small || sizeType == IconSizeType.TreeView && rule.smallIcon.sprite != null)
            {
                TryDrawIconBackground();
                iconRect = PvCustomizerUtility.ItemRectToIconRect(selectionRect, true);
                PvCustomizerGUI.DrawSprite(iconRect, rule.smallIcon.sprite, tint: tint,
                                           scaleMode: PvScaleMode.ScaleToFit);
            }
            else if (sizeType == IconSizeType.Large && rule.largeIcon.sprite != null)
            {
                TryDrawIconBackground();
                PvCustomizerGUI.DrawSprite(iconRect, rule.largeIcon.sprite, tint: tint,
                                           scaleMode: PvScaleMode.ScaleToFit);
            }

            #endregion

            #region Text Drawing

            Rect textRect = PvCustomizerUtility.ItemRectToTextRect(selectionRect);
            textRect.height++;
            PvCustomizerGUI.DrawBackground(textRect);
            if (rule.textBackground.sprite != null)
            {
                PvCustomizerGUI.DrawSprite(textRect, rule.textBackground.sprite, tint: tint,
                                           scaleMode: PvScaleMode.StretchToFill);
            }

            using (new TempFontSize(10))
            {
                PvCustomizerGUI.DrawTextDirect(textRect, name,
                                               textAnchor: sizeType == IconSizeType.Small || sizeType == IconSizeType.TreeView
                        ? PvAnchor.MiddleLeft
                        : PvAnchor.MiddleCenter,
                                               color: rule.textColor);
            }

            #endregion

            void TryDrawIconBackground()
            {
                if (rule.eraseDefaultFolder)
                {
                    PvCustomizerGUI.DrawBackground(iconRect);
                }
            }
        }
Esempio n. 2
0
        private bool FindAndDrawAttributes(Object asset, Rect fullRect, bool selected)
        {
            //get all relevant attributes and member info on which they're declared
            var          triplets = PvIconAttributeCache.GetAttributeTriplets(asset.GetType());
            IconSizeType sizeType = PvCustomizerUtility.GetSizeType(fullRect);

            if (triplets.Exists(t => CanDisplay(t.Attr.Display, sizeType) && !t.Attr.DontEraseDefault))
            {
                Rect iconRect = PvCustomizerUtility.ItemRectToIconRect(fullRect, sizeType == IconSizeType.TreeView);
                PvCustomizerGUI.DrawBackground(iconRect);
            }

            bool drewAtleastOnce = false;

            foreach (var(member, attr, valueType) in triplets)
            {
                object value = member.GetMemberValue(asset);
                drewAtleastOnce |= TryDrawFromValue(asset, value, fullRect, attr, selected);
            }

            return(drewAtleastOnce);
        }