コード例 #1
0
        private Size CalculateSize()
        {
            var size = (Size)_sizeConverter
                       .ConvertFromInvariantString(_formattedMultiplierString);
            double multiplier = GetFinalLengthMultiplier();

            return(new Size(size.Width * multiplier, size.Height * multiplier));
        }
コード例 #2
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }
            string strValue = value as string;

            if (strValue != null)
            {
                try
                {
                    return(_sizeConverter.ConvertFromInvariantString(strValue));
                }
                catch
                {
                }
            }

            return(Binding.DoNothing);
        }
コード例 #3
0
ファイル: GorgonFontContent.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to load a dependency file.
        /// </summary>
        /// <param name="dependency">The dependency to load.</param>
        /// <param name="stream">Stream containing the dependency file.</param>
        /// <returns>
        /// The result of the load operation.  If the dependency loaded correctly, then the developer should return NoError.  If the dependency
        /// is not vital to the content, then the developer can return CanContinue, otherwise the developer should return FatalError and the content will
        /// not continue loading.
        /// </returns>
        protected override DependencyLoadResult OnLoadDependencyFile(Dependency dependency, Stream stream)
        {
            if (ImageEditor == null)
            {
                return(new DependencyLoadResult(DependencyLoadState.ErrorContinue, Resources.GORFNT_ERR_EXTERN_IMAGE_EDITOR_MISSING));
            }

            if ((!string.Equals(dependency.Type, TextureBrushTextureType, StringComparison.OrdinalIgnoreCase)) &&
                (!string.Equals(dependency.Type, GlyphTextureType, StringComparison.OrdinalIgnoreCase)))
            {
                return(new DependencyLoadResult(DependencyLoadState.ErrorContinue,
                                                string.Format(Resources.GORFNT_ERR_DEPENDENCY_UNKNOWN_TYPE, dependency.Type)));
            }

            IImageEditorContent imageContent = null;

            try
            {
                Size newSize = Size.Empty;

                // We need to load the image as transformed (either clipped or stretched).
                if (string.Equals(dependency.Type, GlyphTextureType, StringComparison.OrdinalIgnoreCase))
                {
                    var converter  = new SizeConverter();
                    var sizeObject = converter.ConvertFromInvariantString(dependency.Properties[GlyphTextureSizeProp].Value);

                    if (!(sizeObject is Size))
                    {
                        return(new DependencyLoadResult(DependencyLoadState.ErrorContinue,
                                                        Resources.GORFNT_ERR_DEPENDENCY_GLYPH_TEXTURE_BAD_TRANSFORM));
                    }

                    newSize = (Size)sizeObject;
                }

                imageContent = ImageEditor.ImportContent(dependency.EditorFile, stream);

                if (newSize.Width == 0)
                {
                    newSize.Width = imageContent.Image.Settings.Width;
                }

                if (newSize.Height == 0)
                {
                    newSize.Height = imageContent.Image.Settings.Height;
                }

                // Clip the image to a new size if necessary.
                if ((newSize.Width != imageContent.Image.Settings.Width) ||
                    (newSize.Height != imageContent.Image.Settings.Height))
                {
                    imageContent.Image.Resize(newSize.Width, newSize.Height, true);
                }

                if (imageContent.Image == null)
                {
                    return(new DependencyLoadResult(DependencyLoadState.ErrorContinue, Resources.GORFNT_ERR_EXTERN_IMAGE_MISSING));
                }

                if (imageContent.Image.Settings.ImageType != ImageType.Image2D)
                {
                    return(new DependencyLoadResult(DependencyLoadState.ErrorContinue,
                                                    string.Format(Resources.GORFNT_ERR_IMAGE_NOT_2D, dependency.EditorFile.FilePath)));
                }

                if (!Dependencies.Contains(dependency.EditorFile, dependency.Type))
                {
                    Dependencies[dependency.EditorFile, dependency.Type] = dependency.Clone();
                }

                Dependencies.CacheDependencyObject(dependency.EditorFile,
                                                   dependency.Type,
                                                   Graphics.Textures.CreateTexture <GorgonTexture2D>(dependency.EditorFile.FilePath, imageContent.Image));

                return(new DependencyLoadResult(DependencyLoadState.Successful, null));
            }
            finally
            {
                if (imageContent != null)
                {
                    imageContent.Dispose();
                }
            }
        }
コード例 #4
0
        private bool ProcessSetValue(Type type, string name, string newvalue)
        {
            if (type == typeof(string))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { newvalue });
                return(true);
            }

            if (type == typeof(bool))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { bool.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(int))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { int.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(long))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { long.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(decimal))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { decimal.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(float))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { float.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(double))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { double.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(char))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { char.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Enum) || type.BaseType == typeof(Enum))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Enum.Parse(type, newvalue) });
                return(true);
            }

            if (type == typeof(Single))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Single.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Byte))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Byte.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(SByte))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { SByte.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int16))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int16.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int32))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int32.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Int64))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { Int64.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt16))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt16.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt32))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt32.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(UInt64))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { UInt64.Parse(newvalue) });
                return(true);
            }

            // 20080827 : DateTimeConvertor.ConvertToInvariantString(DateTime.MinValue) return empty string ""
            //            which cannot be parsed by following culture specific method.

            //if( type == typeof( DateTime ) )
            //{
            //    this.GetType().InvokeMember( name,
            //        /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
            //        BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField ,
            //        null, this, new object[]{ DateTime.Parse(newvalue) } );
            //    return true;
            //}

            if (type == typeof(TimeSpan))
            {
                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { TimeSpan.Parse(newvalue) });
                return(true);
            }

            if (type == typeof(Color))
            {
                ColorConverter cc = new ColorConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Font))
            {
                FontConverter cc = new FontConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Point))
            {
                PointConverter cc = new PointConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Rectangle))
            {
                RectangleConverter cc = new RectangleConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            if (type == typeof(Size))
            {
                SizeConverter cc = new SizeConverter();

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { cc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            //if (type == typeof(Type))
            //{
            //    Type newType = null;
            //    if (newvalue != null && newvalue.Length > 0)
            //    {
            //        newType = Type.GetType(newvalue, true);
            //    }

            //    this.GetType().InvokeMember(name,
            //        /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
            //        BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
            //        null, this, new object[] { newType });
            //    return true;
            //}

            if (!XObjectHelper.IsXBaseType(type))
            {
                TypeConverter tc = TypeDescriptor.GetConverter(type);
                if (tc == null)
                {
                    return(true);
                }

                this.GetType().InvokeMember(name,
                                            /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField,
                                            null, this, new object[] { tc.ConvertFromInvariantString(newvalue) });
                return(true);
            }

            return(true);
        }
コード例 #5
0
        private void SetProperty(PropertyInfo p, object val)
        {
            if (p == null)
            {
                return;
            }

            if (val == null)
            {
                this.GetType().InvokeMember(p.Name,
                                            BindingFlags.DeclaredOnly | BindingFlags.Public |
                                            BindingFlags.Instance | BindingFlags.SetProperty,
                                            null, this, new object[] { null });
            }
            else
            {
                string str = val.ToString();

                if (p.PropertyType == typeof(string))
                {
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { str });
                    return;
                }

                if (p.PropertyType == typeof(DateTime))
                {
                    DateTime v = DateTime.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(decimal))
                {
                    decimal v = decimal.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(int))
                {
                    int v = int.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(long))
                {
                    long v = long.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(float))
                {
                    float v = float.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(double))
                {
                    double v = double.Parse(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Color))
                {
                    ColorConverter cc = new ColorConverter();
                    Color          v  = (Color)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Font))
                {
                    FontConverter cc = new FontConverter();
                    Font          v  = (Font)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Point))
                {
                    PointConverter cc = new PointConverter();
                    Point          v  = (Point)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Size))
                {
                    SizeConverter cc = new SizeConverter();
                    Size          v  = (Size)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }

                if (p.PropertyType == typeof(Rectangle))
                {
                    RectangleConverter cc = new RectangleConverter();
                    Rectangle          v  = (Rectangle)cc.ConvertFromInvariantString(str);
                    this.GetType().InvokeMember(p.Name,
                                                BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                BindingFlags.Instance | BindingFlags.SetProperty,
                                                null, this, new object[] { v });
                    return;
                }
            }
        }
コード例 #6
0
ファイル: ConversionHelper.cs プロジェクト: vpalodic/Holodeck
 public static Size StringToSize(string str)
 {
     return((Size)_sc.ConvertFromInvariantString(str));
 }