Beispiel #1
0
        private BaseDrawer ResolveDrawerFromTypes(Type objectType, Type drawerType, Type drawerGenArgType)
        {
            if (objectType.IsArray)             // TODO: remove concrete dependency
            {
                return(BaseDrawer.Create(typeof(ArrayDrawer <>).MakeGenericType(objectType.GetElementType())));
            }

            if (objectType.IsA(drawerGenArgType))
            {
                return(BaseDrawer.Create(drawerType));
            }

            if (drawerGenArgType.IsGenericType)
            {
                if (objectType.IsSubTypeOfRawGeneric(drawerGenArgType.GetGenericTypeDefinition()))
                {
                    return(BaseDrawer.Create(drawerType.MakeGenericType(objectType.IsArray ? new[] { objectType.GetElementType() } : objectType.GetGenericArguments())));
                }
            }
            else if (!drawerGenArgType.IsConstructedGenType())
            {
                var args = drawerType.GetGenericArguments();
                if (args.Length == 1 && args[0].IsGenericTypeDefinition)
                {
                    return(BaseDrawer.Create(drawerType.MakeGenericType(objectType)));
                }
            }

            return(null);
        }
Beispiel #2
0
        static BaseDrawer GetDrawerForType(Type objectType, Type[] typeCache, Type baseDrawerType)
        {
            for (int i = 0; i < typeCache.Length; i++)
            {
                var drawerType = typeCache[i];

                var ignoreFor = drawerType.GetCustomAttribute <IgnoreOnTypes>();
                if (ignoreFor != null)
                {
                    var forTypes = ignoreFor.types;
                    if (forTypes.Any(x => objectType.IsSubclassOfRawGeneric(x)))
                    {
                        continue;
                    }
                }

                var firstGen = drawerType.GetParentGenericArguments(baseDrawerType)[0];
                var drawer   = ResolveDrawerFromTypes(objectType, drawerType, firstGen);
                if (drawer != null)
                {
                    return(drawer);
                }
            }

            return(BaseDrawer.Create(fallbackDrawerType));
        }
Beispiel #3
0
    public static void SetDrawerToOut(DrawerDirection whichDirection)
    {
        switch (whichDirection)
        {
        case DrawerDirection.Right:
        {
            isARightDrawerIn  = false;
            ActiveRightDrawer = null;
            break;
        }

        case DrawerDirection.Left:
        {
            isALeftDrawerIn  = false;
            ActiveLeftDrawer = null;
            break;
        }

        case DrawerDirection.Top:
        {
            isATopDrawerIn  = false;
            ActiveTopDrawer = null;
            break;
        }

        case DrawerDirection.Buttom:
        {
            isAButtomDrawerIn  = false;
            ActiveButtomDrawer = null;
            break;
        }
        }
    }
Beispiel #4
0
    public static void SetDrawerToIn(DrawerDirection whichDirection, BaseDrawer whichDrawer)
    {
        switch (whichDirection)
        {
        case DrawerDirection.Right:
        {
            isARightDrawerIn  = true;
            ActiveRightDrawer = whichDrawer;
            break;
        }

        case DrawerDirection.Left:
        {
            isALeftDrawerIn  = true;
            ActiveLeftDrawer = whichDrawer;
            break;
        }

        case DrawerDirection.Top:
        {
            isATopDrawerIn  = true;
            ActiveTopDrawer = whichDrawer;
            break;
        }

        case DrawerDirection.Buttom:
        {
            isAButtomDrawerIn  = true;
            ActiveButtomDrawer = whichDrawer;
            break;
        }
        }
    }
Beispiel #5
0
 void Start()
 {
     isALeftDrawerIn    = false;
     ActiveRightDrawer  = null;
     isARightDrawerIn   = false;
     ActiveLeftDrawer   = null;
     isAButtomDrawerIn  = false;
     ActiveButtomDrawer = null;
     isATopDrawerIn     = false;
     ActiveTopDrawer    = null;
 }
Beispiel #6
0
        public override void DrawView(Graphics g)
        {
            //画通信区域的图像
            EthArea.DrawView(g);
            BaseDrawer.AddDirctionSentence(g, _infoAreaRects[0], "EtherNet", false);

            RioArea.DrawView(g);
            BaseDrawer.AddDirctionSentence(g, _infoAreaRects[1], "RapidIO", false);

            GtxArea.DrawView(g);
            BaseDrawer.AddDirctionSentence(g, _infoAreaRects[2], "GTX", false);

            LvdsArea.DrawView(g);
            BaseDrawer.AddDirctionSentence(g, _infoAreaRects[3], "LVDS", false);
        }
Beispiel #7
0
        private BaseDrawer GetDrawerForType(Type objectType, Type[] typeCache, Type baseDrawerType)
        {
            for (int i = 0; i < typeCache.Length; i++)
            {
                var drawerType = typeCache[i];
                var firstGen   = drawerType.GetParentGenericArguments(baseDrawerType)[0];
                var drawer     = ResolveDrawerFromTypes(objectType, drawerType, firstGen);
                if (drawer != null)
                {
                    return(drawer);
                }
            }

            return(BaseDrawer.Create(fallbackDrawerType));
        }
Beispiel #8
0
        static BaseDrawer ResolveDrawerFromTypes(Type objectType, Type drawerType, Type drawerGenArgType)
        {
            if (objectType.IsSubTypeOfRawGeneric(typeof(IDictionary <,>)))
            {
                var args = new List <Type>(objectType.GetGenericArgsInThisOrAbove());
                args.Insert(0, objectType);
                return(BaseDrawer.Create(typeof(DictionaryDrawer <, ,>).MakeGenericType(args.ToArray())));
            }

            if (objectType.IsSubTypeOfRawGeneric(typeof(List <>)))
            {
                var elementType = objectType.GetGenericArgsInThisOrAbove()[0];
                return(BaseDrawer.Create(typeof(ListDrawer <>).MakeGenericType(elementType)));
            }

            if (objectType.IsArray)
            {
                var elementType = objectType.GetElementType();
                return(BaseDrawer.Create(typeof(ArrayDrawer <>).MakeGenericType(elementType)));
            }

            if (objectType.IsA(drawerGenArgType))
            {
                return(BaseDrawer.Create(drawerType));
            }

            if (drawerGenArgType.IsGenericType)
            {
                if (objectType.IsSubTypeOfRawGeneric(drawerGenArgType.GetGenericTypeDefinition()))
                {
                    var args = objectType.GetGenericArgsInThisOrAbove();
                    return(BaseDrawer.Create(drawerType.MakeGenericType(args)));
                }
            }
            else if (!drawerGenArgType.IsConstructedGenType())
            {
                var args = drawerType.GetGenericArguments();
                if (args.Length == 1 && args[0].IsGenericTypeDefinition)
                {
                    return(BaseDrawer.Create(drawerType.MakeGenericType(objectType)));
                }
            }

            return(null);
        }
Beispiel #9
0
        static BaseDrawer GetDrawerForPair(Type objectType, Type attributeType, Type[] typeCache, Type baseDrawerType)
        {
            for (int i = 0; i < typeCache.Length; i++)
            {
                var drawerType = typeCache[i];

                var ignoreFor = drawerType.GetCustomAttribute <IgnoreOnTypes>();
                if (ignoreFor != null)
                {
                    var forTypes = ignoreFor.types;
                    if (forTypes.Any(x => objectType.IsSubclassOfRawGeneric(x)))
                    {
                        continue;
                    }
                }

                var args = drawerType.GetParentGenericArguments(baseDrawerType);

                if (attributeType == args[1])
                {
                    var drawer = ResolveDrawerFromTypes(objectType, drawerType, args[0]);
                    if (drawer != null)
                    {
                        return(drawer);
                    }
                }
                else if (args[1].IsGenericParameter)
                {
                    var constraints = args[1].GetGenericParameterConstraints();
                    if (constraints.Length == 1 && attributeType.IsA(constraints[0]))
                    {
                        return(BaseDrawer.Create(drawerType.MakeGenericType(attributeType)));
                    }
                }
            }

            return(null);
        }
Beispiel #10
0
        public bool Member(EditorMember member, Attribute[] attributes, BaseDrawer memberDrawer, bool ignoreComposition)
        {
            List <BaseDrawer> composites = null;

            if (!ignoreComposition)
            {
                composites = MemberDrawersHandler.GetCompositeDrawers(member, attributes, this);
            }

            #if DBG
            Label(member.Id);
            Debug.Log("Got drawer " + memberDrawer.GetType().Name + " for member " + member.Name + " Key: " + handlerKey);
            #endif

            if (composites == null || composites.Count == 0)
            {
                #if PROFILE
                Profiler.BeginSample(memberDrawer.GetType().Name + " OnGUI (C)");
                #endif

                BeginCheck();
                {
                    memberDrawer.OnGUI();
                }
                #if PROFILE
                Profiler.EndSample();
                #endif
                return(HasChanged());
            }

            for (int i = 0; i < composites.Count; i++)
            {
                composites[i].Initialize(member, attributes, this);
            }

            bool changed = false;

            #if PROFILE
            Profiler.BeginSample("OnUpperGUI " + member.Name);
            #endif
            for (int i = 0; i < composites.Count; i++)
            {
                composites[i].OnUpperGUI();
            }
            #if PROFILE
            Profiler.EndSample();
            #endif
            using (Horizontal())
            {
                #if PROFILE
                Profiler.BeginSample("OnLeftGUI " + member.Name);
                #endif
                for (int i = 0; i < composites.Count; i++)
                {
                    composites[i].OnLeftGUI();
                }
                #if PROFILE
                Profiler.EndSample();
                #endif
                using (Vertical())
                {
                    #if PROFILE
                    Profiler.BeginSample(memberDrawer.GetType().Name + " OnGUI");
                    #endif
                    BeginCheck();
                    {
                        memberDrawer.OnGUI();
                    }
                    #if PROFILE
                    Profiler.EndSample();
                    #endif
                    changed = HasChanged();

                    #if PROFILE
                    Profiler.BeginSample("OnMemberDrawn" + member.Name);
                    #endif
                    for (int i = 0; i < composites.Count; i++)
                    {
                        composites[i].OnMemberDrawn(LastRect);
                    }
                    #if PROFILE
                    Profiler.EndSample();
                    #endif
                }

                #if PROFILE
                Profiler.BeginSample("OnRightGUI " + member.Name);
                #endif
                for (int i = 0; i < composites.Count; i++)
                {
                    composites[i].OnRightGUI();
                }
                #if PROFILE
                Profiler.EndSample();
                #endif
            }

            #if PROFILE
            Profiler.BeginSample("OnLowerGUI " + member.Name);
            #endif
            for (int i = 0; i < composites.Count; i++)
            {
                composites[i].OnLowerGUI();
            }
            #if PROFILE
            Profiler.EndSample();
            #endif
            return(changed);
        }
Beispiel #11
0
 public bool Member(EditorMember member, BaseDrawer memberDrawer)
 {
     return(Member(member, member.Attributes, memberDrawer, false));
 }