Ejemplo n.º 1
0
        public override bool Equals(object o)
        {
            bool result = false;

            if (o is ZoomboxView)
            {
                ZoomboxView other = ( ZoomboxView )o;
                if (this.ViewKind == other.ViewKind)
                {
                    switch (this.ViewKind)
                    {
                    case ZoomboxViewKind.Absolute:
                        result = (DoubleHelper.AreVirtuallyEqual(_scaleWidth, other._scaleWidth)) &&
                                 (DoubleHelper.AreVirtuallyEqual(Position, other.Position));
                        break;

                    case ZoomboxViewKind.Region:
                        result = DoubleHelper.AreVirtuallyEqual(Region, other.Region);
                        break;

                    default:
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public override object ConvertTo(
            ITypeDescriptorContext typeDescriptorContext,
            CultureInfo cultureInfo,
            object value,
            Type destinationType)
        {
            object      result = null;
            ZoomboxView view   = value as ZoomboxView;

            if (view != null)
            {
                if (destinationType == typeof(string))
                {
                    result = "Empty";
                    switch (view.ViewKind)
                    {
                    case ZoomboxViewKind.Absolute:
                        if (PointHelper.IsEmpty(view.Position))
                        {
                            if (!DoubleHelper.IsNaN(view.Scale))
                            {
                                result = view.Scale.ToString();
                            }
                        }
                        else if (DoubleHelper.IsNaN(view.Scale))
                        {
                            result = String.Format("{0},{1}", view.Position.X, view.Position.Y);
                        }
                        else
                        {
                            result = String.Format("{0},{1},{2}", view.Scale, view.Position.X, view.Position.Y);
                        }
                        break;

                    case ZoomboxViewKind.Center:
                        result = "Center";
                        break;

                    case ZoomboxViewKind.Fill:
                        result = "Fill";
                        break;

                    case ZoomboxViewKind.Fit:
                        result = "Fit";
                        break;

                    case ZoomboxViewKind.Region:
                        result = String.Format("{0},{1},{2},{3}", view.Region.X, view.Region.Y, view.Region.Width, view.Region.Height);
                        break;
                    }
                }
            }
            return(result == null ? base.ConvertTo(typeDescriptorContext, cultureInfo, value, destinationType) : result);
        }
Ejemplo n.º 3
0
        public override object ConvertFrom(
            ITypeDescriptorContext typeDescriptorContext,
            CultureInfo cultureInfo,
            object value)
        {
            ZoomboxView result = null;

            if (value is double)
            {
                result = new ZoomboxView(( double )value);
            }
            else if (value is Point)
            {
                result = new ZoomboxView(( Point )value);
            }
            else if (value is Rect)
            {
                result = new ZoomboxView(( Rect )value);
            }
            else if (value is string)
            {
                if (string.IsNullOrEmpty((value as string).Trim()))
                {
                    result = ZoomboxView.Empty;
                }
                else
                {
                    switch ((value as string).Trim().ToLower())
                    {
                    case "center":
                        result = ZoomboxView.Center;
                        break;

                    case "empty":
                        result = ZoomboxView.Empty;
                        break;

                    case "fill":
                        result = ZoomboxView.Fill;
                        break;

                    case "fit":
                        result = ZoomboxView.Fit;
                        break;

                    default:
                        // parse double values; respect the following separators: ' ', ';', or ','
                        List <double> values = new List <double>();
                        foreach (string token in (value as string).Split(new char[] { ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            double d;
                            if (double.TryParse(token, out d))
                            {
                                values.Add(d);
                            }
                            if (values.Count >= 4)
                            {
                                // disregard additional values
                                break;
                            }
                        }

                        switch (values.Count)
                        {
                        case 1: // scale
                            result = new ZoomboxView(values[0]);
                            break;

                        case 2: // x, y
                            result = new ZoomboxView(values[0], values[1]);
                            break;

                        case 3: // scale, x, y
                            result = new ZoomboxView(values[0], values[1], values[2]);
                            break;

                        case 4: // x, y, width, height
                            result = new ZoomboxView(values[0], values[1], values[2], values[3]);
                            break;
                        }
                        break;
                    }
                }
            }
            return(result ?? base.ConvertFrom(typeDescriptorContext, cultureInfo, value));
        }