예제 #1
0
        private IconStyle CompileStyle(object asset, PvIconAttribute attr, Rect fullRect)
        {
            IconSizeType sizeType = PvCustomizerUtility.GetSizeType(fullRect);
            Rect         iconRect = PvCustomizerUtility.ItemRectToIconRect(fullRect, sizeType == IconSizeType.TreeView);
            IconStyle    style    = new IconStyle
            {
                IsSet        = true,
                Tint         = attr.Tint,
                CustomValues = attr.CustomData,
                FontStyle    = attr.FontStyle,
                SizeType     = PvCustomizerUtility.GetSizeType(iconRect),
                MaxSize      = attr.MaxSize,
                ScaleMode    = attr.ScaleMode
            };

            //----------complex assignments

            #region Material

            if (string.IsNullOrEmpty(attr.Material))
            {
                style.Material = null;
            }
            else
            {
                ValueableMemberCache.Pair matMember = ValueableMemberCache.GetValueables(asset.GetType()).
                                                      Find(v => v.Member.Name == attr.Material &&
                                                           v.ValueType == typeof(Material));

                style.Material = matMember.Member?.GetMemberValue(asset) as Material;
            }

            #endregion

            if (PvCustomizerUtility.TryParseGridRect(attr.Grid, out int rows, out int cols, out int pos))
            {
                float width  = iconRect.width / cols;
                float height = iconRect.height / rows;

                float x = width * (pos % cols);
                float y = height * (pos / rows);

                style.DrawRect = new Rect(iconRect.x + x, iconRect.y + y, width, height);
            }
예제 #2
0
        private bool TryDrawFromValue(object asset, object value, Rect fullRect,
                                      PvIconAttribute attr, bool selected)
        {
            if (!CanDisplay(attr.Display, PvCustomizerUtility.GetSizeType(fullRect)))
            {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }
            if (!TryGetDrawer(value.GetType(), out var drawer))
            {
                return(false);
            }

            //compile the style from attribute into something we can pass along to drawer
            IconStyle style = CompileStyle(asset, attr, fullRect);

            try
            {
                if (selected)
                {
                    style.Tint *= PvCustomizerGUI.ICON_SELECTED_TINT;
                }
                drawer.Draw(value, fullRect, selected, style);
            }
            catch
            {
                //ignore
            }

            return(true);

            bool TryGetDrawer(Type valueType, out IDrawer d)
            {
                //get proper drawer for this member's value type
                d = Registry.GetIconDrawer(valueType);
                return(d != null);
            }
        }
 public void Deconstruct(out MemberInfo m, out PvIconAttribute attr, out Type type)
 {
     m    = Member;
     attr = Attr;
     type = ValueType;
 }