Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
0
 public DoubleVectorProperty(object name)
     : this(name, PairUtils.Create(0.0, 0.0))
 {
 }
Ejemplo n.º 7
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.º 8
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.º 9
0
 public Pair <T, T> ClampPotentialValue(Pair <T, T> newValue)
 {
     return(PairUtils.Create(ClampPotentialValueX(newValue.First), ClampPotentialValueY(newValue.Second)));
 }