public Pair </*repaint*/ bool, /*width*/ float> HandleWidth()
        {
            float result  = 0;
            bool  repaint = false;

            if (Event.current != null)
            {
                switch (Event.current.rawType)
                {
                case EventType.MouseDown:
                    if (LastRect.Contains(Event.current.mousePosition))
                    {
                        dragging = true;
                    }
                    break;

                case EventType.MouseDrag:
                    if (dragging)
                    {
                        result  = Event.current.delta.x;
                        repaint = true;
                    }
                    break;

                case EventType.MouseUp:
                    if (dragging)
                    {
                        dragging = false;
                    }
                    break;
                }
            }

            return(PairUtils.MakePair(repaint, result));
        }
Ejemplo n.º 2
0
        internal override Control CreateWinFormsControl()
        {
            Type propertyControlType = controlTypeToPropertyControlType[PairUtils.Create(
                                                                            Property.GetType(), (PropertyControlType)this.controlType.Value)];

            PropertyControl propertyControl = (PropertyControl)Activator.CreateInstance(propertyControlType, this);

            return(propertyControl);
        }
Ejemplo n.º 3
0
        private void ControlType_ValueChanged(object sender, EventArgs e)
        {
            PropertyCollection newProps = controlTypeToProperties[PairUtils.Create(this.Property.GetType(),
                                                                                   (PropertyControlType)this.controlType.Value)].Clone();

            newProps.CopyCompatibleValuesFrom(this.ControlProperties);

            this.ControlProperties = newProps;
        }
Ejemplo n.º 4
0
        private PropertyControlInfo(Property property)
            : base()
        {
            this.property = property;
            PropertyControlType defaultControlType = propertyTypeToDefaultControlType[this.property.GetType()];

            this.controlType = StaticListChoiceProperty.CreateForEnum <PropertyControlType>(ControlInfoPropertyNames.ControlType, defaultControlType, false);
            this.controlType.ValueChanged += new EventHandler(ControlType_ValueChanged);
            this.ControlProperties         = controlTypeToProperties[PairUtils.Create(property.GetType(), (PropertyControlType)this.controlType.Value)].Clone();
        }
Ejemplo n.º 5
0
        private void PanControl_PositionChanged(object sender, EventArgs e)
        {
            PointF pos = this.panControl.Position;

            PointF clampedPos = new PointF(
                Utility.Clamp(pos.X, (float)this.Property.MinValueX, (float)this.Property.MaxValueX),
                Utility.Clamp(pos.Y, (float)this.Property.MinValueY, (float)this.Property.MaxValueY));

            this.panControl.Position = clampedPos;

            Pair <double, double> pairValue = PairUtils.Create((double)clampedPos.X, (double)clampedPos.Y);

            this.Property.Value = pairValue;
        }
Ejemplo n.º 6
0
        public static Pair <bool, ReorderableList> GetList(SerializedProperty property, ReorderableAttribute attrib, int id)
        {
            if (property == null)
            {
                return(new Pair <bool, ReorderableList>(false, null));
            }

            ReorderableList    list  = null;
            SerializedProperty array = property.isArray ? property : property.FindPropertyRelative("array");

            bool justCreated = false;

            if (array != null && array.isArray)
            {
                if (!lists.TryGetValue(id, out list))
                {
                    if (attrib != null)
                    {
                        Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null;

                        ReorderableList.ElementDisplayType displayType = attrib.singleLine ? ReorderableList.ElementDisplayType.SingleLine : ReorderableList.ElementDisplayType.Auto;

                        list          = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon);
                        list.paginate = attrib.paginate;
                        list.pageSize = attrib.pageSize;
                    }
                    else
                    {
                        list = new ReorderableList(array, true, true, true);
                    }

                    justCreated = true;
                    lists.Add(id, list);
                }
                else
                {
                    list.List = array;
                }
            }

            return(PairUtils.MakePair(justCreated, list));
        }
Ejemplo n.º 7
0
 public DoubleVectorProperty(object name, Pair <double, double> defaultValues)
     : this(name, defaultValues, PairUtils.Create(double.MinValue, double.MinValue), PairUtils.Create(double.MaxValue, double.MaxValue))
 {
 }
Ejemplo n.º 8
0
 public DoubleVectorProperty(object name)
     : this(name, PairUtils.Create(0.0, 0.0))
 {
 }
Ejemplo n.º 9
0
        public static Property Create(Type valueType, object name, object defaultValue)
        {
            // TODO: find some way to do this better, using attributes+reflection or something, yes?

            if (valueType == typeof(bool))
            {
                return(new BooleanProperty(name, (bool)(defaultValue ?? (object)false)));
            }
            else if (valueType == typeof(double))
            {
                return(new DoubleProperty(name, (double)(defaultValue ?? (object)0.0)));
            }
            else if (valueType == typeof(Pair <double, double>))
            {
                return(new DoubleVectorProperty(name, (Pair <double, double>)(defaultValue ?? (object)PairUtils.Create(0.0, 0.0))));
            }
            else if (valueType == typeof(int))
            {
                return(new Int32Property(name, (int)(defaultValue ?? (object)0)));
            }
            else if (valueType == typeof(string))
            {
                return(new StringProperty(name, (string)defaultValue));
            }
            else if (typeof(ImageResource).IsAssignableFrom(valueType))
            {
                return(new ImageProperty(name, (ImageResource)defaultValue));
            }
            else if (valueType.IsEnum)
            {
                return(StaticListChoiceProperty.CreateForEnum(
                           valueType,
                           name,
                           defaultValue ?? ((object[])Enum.GetValues(valueType))[0],
                           false));
            }

            throw new ArgumentException(string.Format("Not a valid type: {0}", valueType.FullName));
        }
Ejemplo n.º 10
0
        private static void BuildStaticMaps()
        {
            propertyTypeToControlType        = new Dictionary <Type, Set <PropertyControlType> >();
            propertyTypeToDefaultControlType = new Dictionary <Type, PropertyControlType>();
            controlTypeToPropertyControlType = new Dictionary <Pair <Type, PropertyControlType>, Type>();
            controlTypeToProperties          = new Dictionary <Pair <Type, PropertyControlType>, PropertyCollection>();

            Assembly thisAssembly = Assembly.GetExecutingAssembly();

            Type[] types = thisAssembly.GetTypes();

            foreach (Type propertyControlType in types)
            {
                if (propertyControlType.IsAbstract)
                {
                    continue;
                }

                if (!propertyControlType.IsSubclassOf(typeof(PropertyControl)))
                {
                    continue;
                }

                object[] infoAttributes = propertyControlType.GetCustomAttributes(typeof(PropertyControlInfoAttribute), false);
                PropertyControlInfoAttribute infoAttribute;

                if (infoAttributes.Length == 1)
                {
                    infoAttribute = (PropertyControlInfoAttribute)infoAttributes[0];

                    if (!propertyTypeToControlType.ContainsKey(infoAttribute.PropertyType))
                    {
                        propertyTypeToControlType.Add(infoAttribute.PropertyType, new Set <PropertyControlType>());
                    }

                    propertyTypeToControlType[infoAttribute.PropertyType].Add(infoAttribute.ControlType);
                    controlTypeToPropertyControlType[PairUtils.Create(infoAttribute.PropertyType, infoAttribute.ControlType)] = propertyControlType;

                    if (!propertyTypeToDefaultControlType.ContainsKey(infoAttribute.PropertyType) ||
                        infoAttribute.IsDefault)
                    {
                        propertyTypeToDefaultControlType[infoAttribute.PropertyType] = infoAttribute.ControlType;
                    }

                    List <Property> controlProps = new List <Property>();
                    PropertyInfo[]  props        = propertyControlType.GetProperties();

                    foreach (PropertyInfo prop in props)
                    {
                        object[] propAttributes = prop.GetCustomAttributes(typeof(PropertyControlPropertyAttribute), true);

                        if (propAttributes.Length == 1)
                        {
                            string   propName    = prop.Name;
                            Type     propType    = prop.PropertyType;
                            object   propDefault = ((PropertyControlPropertyAttribute)propAttributes[0]).DefaultValue;
                            Property propProp    = Property.Create(propType, propName, propDefault);
                            controlProps.Add(propProp);
                        }
                    }

                    PropertyCollection controlProps2 = new PropertyCollection(controlProps);
                    controlTypeToProperties[PairUtils.Create(infoAttribute.PropertyType, infoAttribute.ControlType)] = controlProps2;
                }
            }
        }
Ejemplo n.º 11
0
 public Pair <T, T> ClampPotentialValue(Pair <T, T> newValue)
 {
     return(PairUtils.Create(ClampPotentialValueX(newValue.First), ClampPotentialValueY(newValue.Second)));
 }