Esempio n. 1
0
            /// <summary>
            /// Rounds unit value to nearest pixel.
            /// </summary>
            /// <returns>
            /// Rounded value in units.
            /// </returns>
            public static double RoundToPixel(double units, double unitsPerPixel)
            {
                double pixels      = units / unitsPerPixel;
                double floorPixels = (double)Math.Floor(pixels);

                pixels = Tolerances.LessThan(pixels, floorPixels + 0.5) ?
                         floorPixels : (double)Math.Ceiling(pixels);
                return(pixels * unitsPerPixel);
            }
        private static bool IsNextElementStartOfNewLine(Rect currentElementLayoutBounds, Rect nextElementLayoutBounds, Orientation orientation)
        {
            switch (orientation)
            {
            case Orientation.Horizontal:
                return(Tolerances.LessThan(nextElementLayoutBounds.Left, currentElementLayoutBounds.Right));

            case Orientation.Vertical:
                return(Tolerances.LessThan(nextElementLayoutBounds.Top, currentElementLayoutBounds.Bottom));

            default:
                throw new NotImplementedException(ExceptionStringTable.StackPanelUnrecognizedOrientation);
            }
        }
Esempio n. 3
0
        private LayoutConstraintMode GetHeightConstraintModeCore(IViewVisual parent, IViewVisual child, SceneView view, bool allowGridAutoChecks)
        {
            if (parent == null)
            {
                return(LayoutConstraintMode.CanvasLike);
            }
            LayoutConstraintMode layoutConstraintMode = LayoutConstraintMode.NonOverlappingGridlike;
            IType itype = parent.GetIType((ITypeResolver)view.ProjectContext);

            if (PlatformTypes.Grid.IsAssignableFrom((ITypeId)itype) || PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype))
            {
                layoutConstraintMode |= LayoutConstraintMode.Overlapping;
            }
            IViewVisual viewVisual = parent.VisualParent as IViewVisual;

            if (viewVisual != null && PlatformTypes.IsInstance(viewVisual.PlatformSpecificObject, ProjectNeutralTypes.Viewbox, (ITypeResolver)view.ProjectContext))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)itype) || PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)itype)) || (PlatformTypes.ScrollContentPresenter.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.Viewbox.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.Popup.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.PathPanel.IsAssignableFrom((ITypeId)itype))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.StackPanel.IsAssignableFrom((ITypeId)itype) && ((IViewPanel)parent).Orientation == Orientation.Vertical)
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (ProjectNeutralTypes.DockPanel.IsAssignableFrom((ITypeId)itype) && child != null)
            {
                switch ((Dock)view.ConvertToWpfValue(child.GetCurrentValue(view.ProjectContext.ResolveProperty(DockPanelElement.DockProperty))))
                {
                case Dock.Top:
                case Dock.Bottom:
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    break;
                }
            }
            if (ProjectNeutralTypes.WrapPanel.IsAssignableFrom((ITypeId)itype) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(WrapPanelElement.ItemHeightProperty))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if ((layoutConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty))) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(DesignTimeProperties.DesignHeightProperty))))
            {
                IViewGrid viewGrid = parent as IViewGrid;
                if (viewGrid != null)
                {
                    if (!allowGridAutoChecks)
                    {
                        return(layoutConstraintMode);
                    }
                    IType type = child == null ? (IType)null : child.GetIType((ITypeResolver)view.ProjectContext);
                    if (child != null && (!PlatformTypes.Path.IsAssignableFrom((ITypeId)type) || !double.IsNaN((double)child.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty)))))
                    {
                        int    val2_1 = (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowProperty));
                        int    val2_2 = val2_1 + (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowSpanProperty));
                        int    num1   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount - 1, val2_1));
                        int    num2   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount, val2_2));
                        double num3   = 0.0;
                        bool   flag1  = true;
                        bool   flag2  = true;
                        if (num2 == 0)
                        {
                            flag1 = false;
                            flag2 = false;
                            num3  = viewGrid.RenderSize.Height;
                        }
                        else
                        {
                            for (int index = num1; index < num2; ++index)
                            {
                                IViewRowDefinition rowDefinition = viewGrid.GetRowDefinition(index);
                                flag1 &= rowDefinition.Height.IsAuto;
                                flag2 &= rowDefinition.Height.IsAbsolute;
                                num3  += rowDefinition.ActualHeight;
                            }
                        }
                        double    height      = child.DesiredSize.Height;
                        IProperty propertyKey = view.Platform.Metadata.ResolveProperty(Base2DElement.UseLayoutRoundingProperty);
                        if (propertyKey != null && child.GetCurrentValue(propertyKey) != parent.GetCurrentValue(propertyKey))
                        {
                            height += 0.999;
                        }
                        if (Tolerances.LessThan(height, num3) || flag2)
                        {
                            return(layoutConstraintMode);
                        }
                        if (flag1)
                        {
                            layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                        }
                    }
                }
                if ((VerticalAlignment)view.ConvertToWpfValue(parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.VerticalAlignmentProperty))) != VerticalAlignment.Stretch)
                {
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                }
                else
                {
                    if (PlatformTypes.Control.IsAssignableFrom((ITypeId)itype) || PlatformTypes.ContentPresenter.IsAssignableFrom((ITypeId)itype))
                    {
                        allowGridAutoChecks = true;
                    }
                    if ((this.GetHeightConstraintModeCore(parent.VisualParent as IViewVisual, parent, view, allowGridAutoChecks) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike)
                    {
                        layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    }
                }
            }
            return(layoutConstraintMode);
        }
Esempio n. 4
0
        public void MoveToTime(double time)
        {
            if (time < 0.0)
            {
                throw new ArgumentException("negative times are not valid");
            }
            if (Tolerances.LessThan(time, this.lastEvaluatedTime))
            {
                throw new ArgumentException("Evaluating backward in time is not supported. Call Reset() first");
            }
            this.lastEvaluatedTime = time;
            if (time >= this.curSegmentStartTime && time < this.curSegmentEndTime)
            {
                return;
            }
            while (time > this.curSegmentEndTime)
            {
                this.curSegmentStartTime  = this.curSegmentStartTime == -1.0 ? 0.0 : this.curSegmentEndTime;
                this.curSegmentStartValue = this.curSegmentEndValue;
                if (this.keyFrameEnumerator.MoveNext())
                {
                    this.easingFunction = (IEasingFunctionDefinition)null;
                    this.keySpline      = (KeySpline)null;
                    switch (this.keyFrameEnumerator.Current.InterpolationType)
                    {
                    case KeyFrameInterpolationType.Discrete:
                        this.keySpline = (KeySpline)null;
                        break;

                    case KeyFrameInterpolationType.Spline:
                        this.keySpline = this.keyFrameEnumerator.Current.KeySpline;
                        if (this.keySpline == null)
                        {
                            this.keySpline = ForwardAnimationEvaluator.linearKeySpline;
                            break;
                        }
                        break;

                    case KeyFrameInterpolationType.Linear:
                        this.keySpline = ForwardAnimationEvaluator.linearKeySpline;
                        break;

                    case KeyFrameInterpolationType.Easing:
                        this.easingFunction = this.keyFrameEnumerator.Current.EasingFunction;
                        if (this.easingFunction == null)
                        {
                            this.keySpline = ForwardAnimationEvaluator.linearKeySpline;
                            break;
                        }
                        break;

                    default:
                        this.keySpline = (KeySpline)null;
                        break;
                    }
                    this.curSegmentEndTime  = this.keyFrameEnumerator.Current.Time;
                    this.curSegmentEndValue = new double?(MotionPath.GetKeyframeValue(this.keyFrameEnumerator.Current));
                }
                else
                {
                    this.keySpline          = (KeySpline)null;
                    this.curSegmentEndTime  = double.PositiveInfinity;
                    this.curSegmentEndValue = new double?();
                }
            }
            if (this.curSegmentStartValue.HasValue && this.curSegmentEndValue.HasValue)
            {
                this.valueInterpolator = (DoubleInterpolator) new LinearDoubleInterpolator(this.curSegmentStartValue.Value, this.curSegmentEndValue.Value);
            }
            else
            {
                this.valueInterpolator = (DoubleInterpolator)null;
            }
        }