Ejemplo n.º 1
0
        private TItem GetOverlapItem(TContainer rootTreeView, Point draggingPoint)
        {
            //TODO X Offset
            var result = VisualTreeHelper.HitTest(rootTreeView, new Point(rootTreeView.ActualWidth - 30, draggingPoint.Y));

            if (result == null)
            {
                return(null);
            }

            var overlapContainer = TreeUtil.FindVisualParent <TItem>(result.VisualHit);

            //overlapContainer 有可能是已经被折叠的子节点,故通过 IsVisible 来判断
            if (overlapContainer == null || !overlapContainer.IsVisible)
            {
                return(null);
            }

            TItem overlapItem = null;

            if (JustOverlapGroup)
            {
                if (overlapContainer.HasItems || IsGroup != null && IsGroup(overlapContainer))
                {
                    overlapItem = overlapContainer;
                }
                else
                {
                    overlapItem = ItemsControl.ItemsControlFromItemContainer(overlapContainer) as TItem;
                }
            }
            else
            {
                overlapItem = overlapContainer;
            }

            if (overlapItem != null)
            {
                var overlapItemPos = overlapItem.TranslatePoint(new Point(), rootTreeView);
                var checkHeight    = DoubleUtil.IsNaN(OverlapAreaCheckHeight) ? overlapItem.ActualHeight : OverlapAreaCheckHeight;

                if (DoubleUtil.GreaterThan(draggingPoint.Y, overlapItemPos.Y) && DoubleUtil.LessThanOrClose(draggingPoint.Y, overlapItemPos.Y + checkHeight / 2))
                {
                    _overDragArea  = OverlapArea.Inner;
                    _overDragArea |= OverlapArea.Up;
                }

                if (DoubleUtil.GreaterThan(draggingPoint.Y, overlapItemPos.Y + checkHeight / 2) && DoubleUtil.LessThanOrClose(draggingPoint.Y, overlapItemPos.Y + checkHeight))
                {
                    _overDragArea  = OverlapArea.Inner;
                    _overDragArea |= OverlapArea.Down;
                }
            }
            else
            {
                _overDragArea = OverlapArea.Inner;
            }

            return(overlapItem);
        }
Ejemplo n.º 2
0
        private void Move()
        {
            if ((DoubleUtil.IsZero(_draggingContainer.ActualWidth) || DoubleUtil.IsZero(_draggingContainer.ActualHeight)) &&
                _draggingContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
            {
                return;
            }

            var screenPos = new Win32.POINT();

            if (!Win32.GetCursorPos(ref screenPos))
            {
                return;
            }

            var draggingPoint = _treeView.PointFromScreen(new Point(screenPos.X, screenPos.Y));

            if (DoubleUtil.GreaterThan(draggingPoint.X, _treeView.ActualWidth) || DoubleUtil.LessThan(draggingPoint.X, 0) ||
                DoubleUtil.LessThan(draggingPoint.Y, 0) || DoubleUtil.GreaterThan(draggingPoint.Y, _treeView.ActualHeight))
            {
                _overDragArea = OverlapArea.Out;
                OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
                return;
            }

            _overlapItem = GetOverlapItem(_treeView, draggingPoint);
            OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Distributes the remaining space after step 1 equally among all the
        ///     qualified member, such that they are constrained by their min/max constraints
        ///     maintaining (but not necessarily attaining) the goal of making perstarvalue of
        ///     all the elements as equal as possible.
        /// </summary>
        private static void DistributeRemainingSpace(List <StarLayoutInfo> starInfoList,
                                                     int distributionCount,
                                                     ref double remainingSpace)
        {
            Debug.Assert(distributionCount > 0 && distributionCount <= starInfoList.Count);
            Debug.Assert(DoubleUtil.GreaterThan(remainingSpace, 0));

            double remainingStarWeight = 0;

            for (int i = 0; i < distributionCount; i++)
            {
                remainingStarWeight += starInfoList[i].RequestedStarWeight;
            }

            double impactPerStar = 0;

            for (int i = 0; i < distributionCount; i++)
            {
                StarLayoutInfo starInfo = starInfoList[i];
                if (DoubleUtil.GreaterThan(remainingSpace, 0))
                {
                    double currentContribution = starInfo.RequestedStarMaxWidth - starInfo.AllocatedStarWidth;
                    currentContribution -= (impactPerStar * starInfo.RequestedStarWeight);
                    currentContribution /= starInfo.RequestedStarWeight;
                    if (DoubleUtil.GreaterThan(currentContribution * remainingStarWeight, remainingSpace))
                    {
                        currentContribution = remainingSpace / remainingStarWeight;
                    }
                    impactPerStar  += currentContribution;
                    remainingSpace -= (currentContribution * remainingStarWeight);
                }
                starInfo.AllocatedStarWidth += (impactPerStar * starInfo.RequestedStarWeight);
                remainingStarWeight         -= starInfo.RequestedStarWeight;
            }
        }
Ejemplo n.º 4
0
        private void Move()
        {
            if (DoubleUtil.IsZero(_draggingContainer.ActualWidth) || DoubleUtil.IsZero(_draggingContainer.ActualHeight))
            {
                return;
            }

            var screenPos = new Win32.POINT();

            if (!Win32.GetCursorPos(ref screenPos))
            {
                return;
            }

            var draggingPoint = _itemsControl.PointFromScreen(new Point(screenPos.X, screenPos.Y));

            if (DoubleUtil.GreaterThan(draggingPoint.X, _itemsControl.ActualWidth) || DoubleUtil.LessThan(draggingPoint.X, 0) ||
                DoubleUtil.LessThan(draggingPoint.Y, 0) || DoubleUtil.GreaterThan(draggingPoint.Y, _itemsControl.ActualHeight))
            {
                _overDragArea = OverlapArea.Out;
                OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
                return;
            }

            _overlapItem = GetOverlapItem(_itemsControl, draggingPoint);
            OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
        }
        /// <summary>
        /// Content arrangement.
        /// </summary>
        /// <param name="arrangeBounds"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            int    firstInLine       = 0;
            Size   curLineSize       = new Size();
            double accumulatedHeight = 0d;

            _wrapWidth = Math.Min(_wrapWidth, arrangeBounds.Width);

            UIElementCollection children = this.Children;

            for (int i = 0; i < children.Count; i++)
            {
                Size sz = children[i].DesiredSize;

                if (DoubleUtil.GreaterThan(curLineSize.Width + sz.Width, _wrapWidth)) //need to switch to another line
                {
                    // Arrange the items in the current line not including the current
                    arrangeLine(accumulatedHeight, curLineSize.Height, firstInLine, i);
                    accumulatedHeight += curLineSize.Height;

                    // Current item will be first on the next line
                    firstInLine = i;
                    curLineSize = sz;
                }
                else //continue to accumulate a line
                {
                    curLineSize.Width += sz.Width;
                    curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
                }
            }

            arrangeLine(accumulatedHeight, curLineSize.Height, firstInLine, children.Count);

            return(_panelSize);
        }
Ejemplo n.º 6
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var oriValue     = (double)value;
            var compareValue = parameter == null ? 0d : double.Parse(parameter.ToString());

            return(DoubleUtil.GreaterThan(oriValue, compareValue) ? Visibility.Visible : Visibility.Collapsed);
        }
Ejemplo n.º 7
0
        private static bool ValidateRequestedStarMaxWidth(object value)
        {
            double starMaxWidth = (double)value;

            return(!double.IsNaN(starMaxWidth) &&
                   DoubleUtil.GreaterThan(starMaxWidth, 0.0));
        }
Ejemplo n.º 8
0
            /// <summary>
            /// Merge two crossings into one.
            /// </summary>
            /// <param name="crossing"></param>
            /// <returns>Return true if these two crossings are actually overlapping and merged; false otherwise</returns>
            public bool Merge(LassoCrossing crossing)
            {
                if (crossing.IsEmpty)
                {
                    return(false);
                }

                if (FIndices.IsEmpty && !crossing.IsEmpty)
                {
                    FIndices  = crossing.FIndices;
                    StartNode = crossing.StartNode;
                    EndNode   = crossing.EndNode;
                    return(true);
                }

                if (DoubleUtil.GreaterThanOrClose(crossing.FIndices.EndFIndex, FIndices.BeginFIndex) &&
                    DoubleUtil.GreaterThanOrClose(FIndices.EndFIndex, crossing.FIndices.BeginFIndex))
                {
                    if (DoubleUtil.LessThan(crossing.FIndices.BeginFIndex, FIndices.BeginFIndex))
                    {
                        FIndices.BeginFIndex = crossing.FIndices.BeginFIndex;
                        StartNode            = crossing.StartNode;
                    }

                    if (DoubleUtil.GreaterThan(crossing.FIndices.EndFIndex, FIndices.EndFIndex))
                    {
                        FIndices.EndFIndex = crossing.FIndices.EndFIndex;
                        EndNode            = crossing.EndNode;
                    }
                    return(true);
                }

                return(false);
            }
        /// <summary>Arranges and sizes the content of a <see cref="T:System.Windows.Controls.Primitives.ToolBarOverflowPanel" /> object.</summary>
        /// <param name="arrangeBounds">Size that a toolbar overflow panel assumes to position child elements.</param>
        /// <returns>The size of the <see cref="T:System.Windows.Controls.Primitives.ToolBarOverflowPanel" />.</returns>
        // Token: 0x060060FC RID: 24828 RVA: 0x001B3530 File Offset: 0x001B1730
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            int    start = 0;
            Size   size  = default(Size);
            double num   = 0.0;

            this._wrapWidth = Math.Min(this._wrapWidth, arrangeBounds.Width);
            UIElementCollection children = base.Children;

            for (int i = 0; i < children.Count; i++)
            {
                Size desiredSize = children[i].DesiredSize;
                if (DoubleUtil.GreaterThan(size.Width + desiredSize.Width, this._wrapWidth))
                {
                    this.arrangeLine(num, size.Height, start, i);
                    num  += size.Height;
                    start = i;
                    size  = desiredSize;
                }
                else
                {
                    size.Width += desiredSize.Width;
                    size.Height = Math.Max(desiredSize.Height, size.Height);
                }
            }
            this.arrangeLine(num, size.Height, start, children.Count);
            return(this._panelSize);
        }
Ejemplo n.º 10
0
        internal void OnRowResize(double changeAmount)
        {
            var cellsPresenter = CellsPresenter;

            if (cellsPresenter != null)
            {
                double newHeight = cellsPresenter.ActualHeight + changeAmount;

                // clamp the CellsPresenter size to the RowHeader size or MinHeight because the header wont shrink any smaller.
                double minHeight = Math.Max(RowHeader.DesiredSize.Height, MinHeight);
                if (DoubleUtil.LessThan(newHeight, minHeight))
                {
                    newHeight = minHeight;
                }

                // clamp the CellsPresenter size to the MaxHeight of Row, because row wouldn't grow any larger
                double maxHeight = MaxHeight;
                if (DoubleUtil.GreaterThan(newHeight, maxHeight))
                {
                    newHeight = maxHeight;
                }

                cellsPresenter.Height = newHeight;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Draw the separators if needed.
        /// </summary>
        /// <param name="drawingContext"></param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            UIElementCollection children = InternalChildren;
            int count = children.Count;

            if (!SystemParameters.HighContrast && DoubleUtil.GreaterThan(_separatorOpacity, 0))
            {
                Ribbon ribbon       = Ribbon;
                Pen    separatorPen = SeparatorPen;
                if (ribbon != null && separatorPen != null)
                {
                    double xOffset = -HorizontalOffset;
                    separatorPen.Brush.Opacity = _separatorOpacity;

                    int elementCount = ribbon.TabDisplayIndexToIndexMap.Count;
                    for (int i = 0; i < elementCount; i++)
                    {
                        Debug.Assert(ribbon.TabDisplayIndexToIndexMap.ContainsKey(i));
                        int index = ribbon.TabDisplayIndexToIndexMap[i];
                        Debug.Assert(children.Count > index && index >= 0);
                        UIElement child = children[index];
                        if (!child.IsVisible)
                        {
                            continue;
                        }
                        xOffset += child.DesiredSize.Width;
                        drawingContext.DrawLine(separatorPen, new Point(xOffset, 0), new Point(xOffset, this.ActualHeight));
                    }
                }
            }

            base.OnRender(drawingContext);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        protected override Size MeasureOverride(Size constraint)
        {
            var curLineSize   = new UvSize(this.Orientation);
            var panelSize     = new UvSize(this.Orientation);
            var uvConstraint  = new UvSize(this.Orientation, constraint.Width, constraint.Height);
            var itemWidth     = this.ItemWidth;
            var itemHeight    = this.ItemHeight;
            var itemWidthSet  = !double.IsNaN(itemWidth);
            var itemHeightSet = !double.IsNaN(itemHeight);

            var childConstraint = new Size(
                itemWidthSet ? itemWidth : constraint.Width,
                itemHeightSet ? itemHeight : constraint.Height);

            var children = this.InternalChildren;

            for (int i = 0, count = children.Count; i < count; i++)
            {
                var child = children[i];
                if (child is null)
                {
                    continue;
                }

                //Flow passes its own constrint to children
                child.Measure(childConstraint);

                //this is the size of the child in UV space
                var sz = new UvSize(
                    this.Orientation,
                    itemWidthSet ? itemWidth : child.DesiredSize.Width,
                    itemHeightSet ? itemHeight : child.DesiredSize.Height);

                if (DoubleUtil.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) //need to switch to another line
                {
                    panelSize.U  = Math.Max(curLineSize.U, panelSize.U);
                    panelSize.V += curLineSize.V;
                    curLineSize  = sz;

                    if (DoubleUtil.GreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constraint - give it a separate line
                    {
                        panelSize.U  = Math.Max(sz.U, panelSize.U);
                        panelSize.V += sz.V;
                        curLineSize  = new UvSize(this.Orientation);
                    }
                }
                else //continue to accumulate a line
                {
                    curLineSize.U += sz.U;
                    curLineSize.V  = Math.Max(sz.V, curLineSize.V);
                }
            }

            //the last line size, if any should be added
            panelSize.U  = Math.Max(curLineSize.U, panelSize.U);
            panelSize.V += curLineSize.V;

            //go from UV space to W/H space
            return(new Size(panelSize.Width, panelSize.Height));
        }
Ejemplo n.º 13
0
        private bool CheckAnchorOffset()
        {
            var result = false;

            switch (AnchorDock)
            {
            case AnchorDock.LeftTop:
            case AnchorDock.LeftCenter:
            case AnchorDock.LeftBottom:
                result = DoubleUtil.LessThan(AnchorOffset.X, 0);
                break;

            case AnchorDock.RightTop:
            case AnchorDock.RightCenter:
            case AnchorDock.RightBottom:
                result = DoubleUtil.GreaterThan(AnchorOffset.X, 0);
                break;

            case AnchorDock.TopLeft:
            case AnchorDock.TopCenter:
            case AnchorDock.TopRight:
                result = DoubleUtil.LessThan(AnchorOffset.Y, 0);
                break;

            case AnchorDock.BottomLeft:
            case AnchorDock.BottomCenter:
            case AnchorDock.BottomRight:
                result = DoubleUtil.GreaterThan(AnchorOffset.Y, 0);
                break;
            }

            return(result);
        }
Ejemplo n.º 14
0
        private void DrawYAxis()
        {
            if (_grid == null)
            {
                return;
            }

            var maxWidth = 0d;
            var disPerY  = (_imageGrid.ActualHeight - 30) / (YMax - YMin);

            var texts = new List <(SWM.FormattedText, double)>();

            for (int i = YMin; i <= YMax; i += 10)
            {
                var y = (YMax - i) * disPerY;

                if (DoubleUtil.GreaterThan(y, _imageGrid.ActualHeight))
                {
                    break;
                }

                var ft = GetFormattedText(i.ToString());
                maxWidth = Math.Max(maxWidth, ft.Width);

                texts.Add((ft, y - ft.Height / 2));
            }

            _grid.ColumnDefinitions[0].Width = new GridLength(maxWidth);

            using (var dc = _drawingGroup.Open())
            {
                texts.ForEach(t => dc.DrawText(t.Item1, new System.Windows.Point(maxWidth - t.Item1.Width, t.Item2)));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Constructor for nodes with pressure data
        /// </summary>
        /// <param name="position">position of the node</param>
        /// <param name="pressure">pressure scaling factor at the node</param>
        internal StrokeNodeData(Point position, float pressure)
        {
            System.Diagnostics.Debug.Assert(DoubleUtil.GreaterThan((double)pressure, 0d));

            _position = position;
            _pressure = pressure;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Calculate the two transforms for two-pass rendering used to draw as hollow. The resulting outerTransform will make the
        /// first-pass-rendering 1 avalon-unit wider/heigher. The resulting innerTransform will make the second-pass-rendering 1 avalon-unit
        /// narrower/shorter.
        /// </summary>
        private static void CalcHollowTransforms(DrawingAttributes originalDa, out Matrix innerTransform, out Matrix outerTransform)
        {
            System.Diagnostics.Debug.Assert(DoubleUtil.IsZero(originalDa.StylusTipTransform.OffsetX) && DoubleUtil.IsZero(originalDa.StylusTipTransform.OffsetY));

            innerTransform = outerTransform = Matrix.Identity;
            Point w = originalDa.StylusTipTransform.Transform(new Point(originalDa.Width, 0));
            Point h = originalDa.StylusTipTransform.Transform(new Point(0, originalDa.Height));

            // the newWidth and newHeight are the actual width/height of the stylus shape considering StylusTipTransform.
            // The assumption is TylusTipTransform has no translation component.
            double newWidth  = Math.Sqrt(w.X * w.X + w.Y * w.Y);
            double newHeight = Math.Sqrt(h.X * h.X + h.Y * h.Y);

            double xTransform = DoubleUtil.GreaterThan(newWidth, HollowLineSize) ?
                                (newWidth - HollowLineSize) / newWidth : 1.0f;
            double yTransform = DoubleUtil.GreaterThan(newHeight, HollowLineSize) ?
                                (newHeight - HollowLineSize) / newHeight : 1.0f;

            innerTransform.Scale(xTransform, yTransform);
            innerTransform *= originalDa.StylusTipTransform;

            outerTransform.Scale((newWidth + HollowLineSize) / newWidth,
                                 (newHeight + HollowLineSize) / newHeight);
            outerTransform *= originalDa.StylusTipTransform;
        }
        // Token: 0x06006DB6 RID: 28086 RVA: 0x001F8550 File Offset: 0x001F6750
        protected override void StylusInputBegin(StylusPointCollection stylusPoints, bool userInitiated)
        {
            this._disableLasso = false;
            bool         flag = false;
            List <Point> list = new List <Point>();

            for (int i = 0; i < stylusPoints.Count; i++)
            {
                Point point = (Point)stylusPoints[i];
                if (i == 0)
                {
                    this._startPoint = point;
                    list.Add(point);
                }
                else if (!flag)
                {
                    double lengthSquared = (point - this._startPoint).LengthSquared;
                    if (DoubleUtil.GreaterThan(lengthSquared, 49.0))
                    {
                        list.Add(point);
                        flag = true;
                    }
                }
                else
                {
                    list.Add(point);
                }
            }
            if (flag)
            {
                this.StartLasso(list);
            }
        }
Ejemplo n.º 18
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            UIElementCollection children   = InternalChildren;
            int    childCount              = children.Count;
            double remainingHeightInColumn = finalSize.Height;
            double columnWidth             = 0;
            double currentX = 0;
            double starLayoutCombinationCount = _starLayoutCombinations.Count;

            for (int i = 0; i < childCount; i++)
            {
                UIElement child            = children[i];
                Size      childDesiredSize = child.DesiredSize;
                if (DoubleUtil.GreaterThan(childDesiredSize.Height, remainingHeightInColumn))
                {
                    currentX   += columnWidth;
                    columnWidth = childDesiredSize.Width;
                    if (IsStarChild(child))
                    {
                        if (_childIndexToStarLayoutIndexMap.ContainsKey(i))
                        {
                            int starLayoutIndex = _childIndexToStarLayoutIndexMap[i];
                            if (starLayoutIndex < starLayoutCombinationCount)
                            {
                                StarLayoutInfo starLayoutInfo = _starLayoutCombinations[starLayoutIndex];
                                columnWidth = starLayoutInfo.AllocatedStarWidth;
                            }
                        }
                    }
                    child.Arrange(new Rect(currentX, 0, columnWidth, childDesiredSize.Height));
                    remainingHeightInColumn = Math.Max(0, finalSize.Height - childDesiredSize.Height);
                }
                else
                {
                    double arrangeWidth = child.DesiredSize.Width;
                    if (IsStarChild(child))
                    {
                        if (_childIndexToStarLayoutIndexMap.ContainsKey(i))
                        {
                            int starLayoutIndex = _childIndexToStarLayoutIndexMap[i];
                            if (starLayoutIndex < starLayoutCombinationCount)
                            {
                                if (CanChildStretch(child))
                                {
                                    // If the child's HorizontalAlignment is Left/Right, then
                                    // use its desired width as arrange width.
                                    StarLayoutInfo starLayoutInfo = _starLayoutCombinations[starLayoutIndex];
                                    arrangeWidth = starLayoutInfo.AllocatedStarWidth;
                                }
                            }
                        }
                    }
                    columnWidth = Math.Max(columnWidth, arrangeWidth);
                    child.Arrange(new Rect(currentX, (finalSize.Height - remainingHeightInColumn), arrangeWidth, childDesiredSize.Height));
                    remainingHeightInColumn -= childDesiredSize.Height;
                }
            }
            return(finalSize);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// This algorithm calculates the extra Padding that can be assigned to a contextual tab.
        /// </summary>
        /// <param name="spaceAvailable"></param>
        /// <returns></returns>
        private double CalculateMaxPadding(double spaceAvailable)
        {
            UIElementCollection children = InternalChildren;
            int childCount = children.Count;

            // Sort DesiredPaddings
            List <double> desiredPaddings     = new List <double>();
            double        totalDesiredPadding = 0.0;

            foreach (UIElement element in children)
            {
                if (!element.IsVisible)
                {
                    continue;
                }
                RibbonTabHeader tabHeader = element as RibbonTabHeader;
                if (tabHeader != null && tabHeader.IsContextualTab)
                {
                    RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup;
                    if (tabGroup != null && DoubleUtil.GreaterThan(tabGroup.DesiredExtraPaddingPerTab, 0.0))
                    {
                        // ContextualTabGroup requires this much more width to reach its ideal DesiredSize.
                        double desiredPaddingPerTabHeader = tabGroup.DesiredExtraPaddingPerTab;
                        desiredPaddings.Add(desiredPaddingPerTabHeader);
                        totalDesiredPadding += desiredPaddingPerTabHeader;
                    }
                }
            }
            int sizeCount = desiredPaddings.Count;

            if (sizeCount == 0)
            {
                return(0.0);
            }
            desiredPaddings.Sort();

            double delta = totalDesiredPadding - spaceAvailable;

            if (DoubleUtil.LessThanOrClose(delta, 0.0))
            {
                return(desiredPaddings[sizeCount - 1]);
            }

            // Clip the TabHeader requesting most extra Padding
            double maxDesiredPadding = desiredPaddings[sizeCount - 1] - delta;

            for (int i = 1; i < sizeCount; i++)
            {
                double currentDesiredPadding = desiredPaddings[sizeCount - 1 - i];
                if (DoubleUtil.GreaterThanOrClose(maxDesiredPadding, currentDesiredPadding))
                {
                    break;
                }
                // Include next element and calculate new average
                maxDesiredPadding = ((maxDesiredPadding * i) + currentDesiredPadding) / (i + 1);
            }
            return(maxDesiredPadding);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Converts the percent from 0 to 100 into proportional angle from 0 to 360.
        /// </summary>
        /// <param name="percent">
        ///     The percent to convert.
        /// </param>
        /// <returns>
        ///     The converted angle from 0 to 360 proportional to 0 to 100 percent.
        /// </returns>
        public static double Angle(this double percent)
        {
            if (DoubleUtil.LessThan(percent, 0) || DoubleUtil.GreaterThan(percent, 100))
            {
                throw new ArgumentOutOfRangeException($"Percent '{percent}' must be between 0 to 100");
            }

            return(FullCircleInDegrees / 100 * percent);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// StylusInputContinue
        /// </summary>
        /// <param name="stylusPoints">stylusPoints</param>
        /// <param name="userInitiated">true if the source eventArgs.UserInitiated flag was set to true</param>
        protected override void StylusInputContinue(StylusPointCollection stylusPoints, bool userInitiated)
        {
            // Check whether Lasso has started.
            if (_lassoHelper != null)
            {
                //
                // pump packets to the LassoHelper, it will convert them into an array of equidistant
                // lasso points, render those lasso point and return them to hit test against.
                //
                List <Point> points = new List <Point>();
                for (int x = 0; x < stylusPoints.Count; x++)
                {
                    points.Add((Point)stylusPoints[x]);
                }
                Point[] lassoPoints = _lassoHelper.AddPoints(points);
                if (0 != lassoPoints.Length)
                {
                    _incrementalLassoHitTester.AddPoints(lassoPoints);
                }
            }
            else if (!_disableLasso)
            {
                // If Lasso hasn't start and been disabled, we should try to start it when it is needed.
                bool startLasso = false;

                List <Point> points = new List <Point>();
                for (int x = 0; x < stylusPoints.Count; x++)
                {
                    Point point = (Point)(stylusPoints[x]);

                    if (!startLasso)
                    {
                        // If startLasso hasn't be flagged, we should check if the distance between two points is greater than
                        // our tolerance. If so, we should flag startLasso.
                        Vector vector          = point - _startPoint;
                        double distanceSquared = vector.LengthSquared;

                        if (DoubleUtil.GreaterThan(distanceSquared, LassoHelper.MinDistanceSquared))
                        {
                            points.Add(point);
                            startLasso = true;
                        }
                    }
                    else
                    {
                        // The flag is set. We just add the point.
                        points.Add(point);
                    }
                }

                // Start Lasso if it isn't a tap selection.
                if (startLasso)
                {
                    StartLasso(points);
                }
            }
        }
Ejemplo n.º 22
0
        protected override System.Drawing.SizeF MeasureOverride(System.Drawing.SizeF constraint)
        {
            UVSize size          = new UVSize(this.Orientation);
            UVSize size2         = new UVSize(this.Orientation);
            UVSize size3         = new UVSize(this.Orientation, constraint.Width, constraint.Height);
            float  itemWidth     = this.ItemWidth;
            float  itemHeight    = this.ItemHeight;
            bool   flag          = !float.IsNaN(itemWidth);
            bool   flag2         = !float.IsNaN(itemHeight);
            SizeF  availableSize = new SizeF(flag ? itemWidth : constraint.Width, flag2 ? itemHeight : constraint.Height);
            RadElementCollection internalChildren = base.Children;
            int num3  = 0;
            int count = internalChildren.Count;

            while (num3 < count)
            {
                RadCommandBarBaseItem element = internalChildren[num3] as RadCommandBarBaseItem;
                if (element != null)
                {
                    if (!element.VisibleInStrip)
                    {
                        element.Measure(SizeF.Empty);
                    }
                    else
                    {
                        element.Measure(availableSize);
                    }

                    UVSize size5 = new UVSize(this.Orientation, flag ? itemWidth : element.DesiredSize.Width, flag2 ? itemHeight : element.DesiredSize.Height);
                    if (DoubleUtil.GreaterThan(size.U + size5.U, size3.U))
                    {
                        size2.U  = Math.Max(size.U, size2.U);
                        size2.V += size.V;
                        size     = size5;
                        if (DoubleUtil.GreaterThan(size5.U, size3.U))
                        {
                            size2.U  = Math.Max(size5.U, size2.U);
                            size2.V += size5.V;
                            size     = new UVSize(this.Orientation);
                        }
                    }
                    else
                    {
                        size.U += size5.U;
                        size.V  = Math.Max(size5.V, size.V);
                    }
                }
                num3++;
            }
            size2.U  = Math.Max(size.U, size2.U);
            size2.V += size.V;


            return(new SizeF(size2.Width, size2.Height));
        }
Ejemplo n.º 23
0
        public PageOrientation AutoComputePageOrientation(Size elementSize, Size pageSize)
        {
            var elementRatio = elementSize.Width / elementSize.Height;
            var pageRatio    = pageSize.Width / pageSize.Height;

            if (DoubleUtil.GreaterThan(elementRatio, 1) && DoubleUtil.LessThan(pageRatio, 1) ||
                DoubleUtil.LessThan(elementRatio, 1) && DoubleUtil.GreaterThan(pageRatio, 1))
            {
                return(PageOrientation.Landscape);
            }

            return(PageOrientation.Portrait);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Snap the input 'value' to the closest tick.
        /// If input value is exactly in the middle of 2 surrounding ticks, it will be snapped to the tick that has greater value.
        /// </summary>
        /// <param name="value">Value that want to snap to closest Tick.</param>
        /// <returns>Snapped value if IsSnapToTickEnabled is 'true'. Otherwise, returns un-snaped value.</returns>
        private double SnapToTick(double value)
        {
            if (IsSnapToTickEnabled)
            {
                double previous = Minimum;
                double next     = Maximum;

                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;

                if (GetValue(TicksProperty)
                    != null)
                {
                    ticks = Ticks;
                }

                // If ticks collection is available, use it.
                // Note that ticks may be unsorted.
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++)
                    {
                        double tick = ticks[i];
                        if (DoubleUtil.AreClose(tick, value))
                        {
                            return(value);
                        }

                        if (DoubleUtil.LessThan(tick, value) && DoubleUtil.GreaterThan(tick, previous))
                        {
                            previous = tick;
                        }
                        else if (DoubleUtil.GreaterThan(tick, value) && DoubleUtil.LessThan(tick, next))
                        {
                            next = tick;
                        }
                    }
                }
                else if (DoubleUtil.GreaterThan(TickFrequency, 0.0))
                {
                    previous = Minimum + (Math.Round(((value - Minimum) / TickFrequency)) * TickFrequency);
                    next     = Math.Min(Maximum, previous + TickFrequency);
                }

                // Choose the closest value between previous and next. If tie, snap to 'next'.
                value = DoubleUtil.GreaterThanOrClose(value, (previous + next) * 0.5) ? next : previous;
            }

            return(value);
        }
Ejemplo n.º 25
0
        protected override SizeF MeasureOverride(SizeF constraint)
        {
            RadCommandBarOverflowPanel.UVSize uvSize1 = new RadCommandBarOverflowPanel.UVSize(this.Orientation);
            RadCommandBarOverflowPanel.UVSize uvSize2 = new RadCommandBarOverflowPanel.UVSize(this.Orientation);
            RadCommandBarOverflowPanel.UVSize uvSize3 = new RadCommandBarOverflowPanel.UVSize(this.Orientation, constraint.Width, constraint.Height);
            float itemWidth               = this.ItemWidth;
            float itemHeight              = this.ItemHeight;
            bool  flag1                   = !float.IsNaN(itemWidth);
            bool  flag2                   = !float.IsNaN(itemHeight);
            SizeF availableSize           = new SizeF(flag1 ? itemWidth : constraint.Width, flag2 ? itemHeight : constraint.Height);
            RadElementCollection children = this.Children;
            int index = 0;

            for (int count = children.Count; index < count; ++index)
            {
                RadCommandBarBaseItem commandBarBaseItem = children[index] as RadCommandBarBaseItem;
                if (commandBarBaseItem != null)
                {
                    if (!commandBarBaseItem.VisibleInStrip)
                    {
                        commandBarBaseItem.Measure(SizeF.Empty);
                    }
                    else
                    {
                        commandBarBaseItem.Measure(availableSize);
                    }
                    RadCommandBarOverflowPanel.UVSize uvSize4 = new RadCommandBarOverflowPanel.UVSize(this.Orientation, flag1 ? itemWidth : commandBarBaseItem.DesiredSize.Width, flag2 ? itemHeight : commandBarBaseItem.DesiredSize.Height);
                    if (DoubleUtil.GreaterThan(uvSize1.U + uvSize4.U, uvSize3.U))
                    {
                        uvSize2.U  = Math.Max(uvSize1.U, uvSize2.U);
                        uvSize2.V += uvSize1.V;
                        uvSize1    = uvSize4;
                        if (DoubleUtil.GreaterThan(uvSize4.U, uvSize3.U))
                        {
                            uvSize2.U  = Math.Max(uvSize4.U, uvSize2.U);
                            uvSize2.V += uvSize4.V;
                            uvSize1    = new RadCommandBarOverflowPanel.UVSize(this.Orientation);
                        }
                    }
                    else
                    {
                        uvSize1.U += uvSize4.U;
                        uvSize1.V  = Math.Max(uvSize4.V, uvSize1.V);
                    }
                }
            }
            uvSize2.U  = Math.Max(uvSize1.U, uvSize2.U);
            uvSize2.V += uvSize1.V;
            return(new SizeF(uvSize2.Width, uvSize2.Height));
        }
Ejemplo n.º 26
0
        public int Compare(double x, double y)
        {
            if (DoubleUtil.AreClose(x, y))
            {
                return(0);
            }

            if (DoubleUtil.GreaterThan(x, y))
            {
                return(1);
            }

            return(-1);
        }
Ejemplo n.º 27
0
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            int    start      = 0;
            float  itemWidth  = this.ItemWidth;
            float  itemHeight = this.ItemHeight;
            float  v          = 0;
            float  itemU      = (this.Orientation == Orientation.Horizontal) ? itemWidth : itemHeight;
            float  totalSize  = (this.Orientation == Orientation.Horizontal) ? finalSize.Width : finalSize.Height;
            UVSize size       = new UVSize(this.Orientation);
            UVSize size2      = new UVSize(this.Orientation, finalSize.Width, finalSize.Height);
            bool   flag       = !float.IsNaN(itemWidth);
            bool   flag2      = !float.IsNaN(itemHeight);
            bool   useItemU   = (this.Orientation == Orientation.Horizontal) ? flag : flag2;
            RadElementCollection internalChildren = base.Children;
            int end   = 0;
            int count = internalChildren.Count;

            while (end < count)
            {
                RadElement element = internalChildren[end];
                if (element != null)
                {
                    UVSize size3 = new UVSize(this.Orientation, flag ? itemWidth : element.DesiredSize.Width, flag2 ? itemHeight : element.DesiredSize.Height);
                    if (DoubleUtil.GreaterThan(size.U + size3.U, size2.U))
                    {
                        this.ArrangeLine(v, size.V, start, end, useItemU, itemU, totalSize);
                        v   += size.V;
                        size = size3;
                        if (DoubleUtil.GreaterThan(size3.U, size2.U))
                        {
                            this.ArrangeLine(v, size3.V, end, ++end, useItemU, itemU, totalSize);
                            v   += size3.V;
                            size = new UVSize(this.Orientation);
                        }
                        start = end;
                    }
                    else
                    {
                        size.U += size3.U;
                        size.V  = Math.Max(size3.V, size.V);
                    }
                }
                end++;
            }
            if (start < internalChildren.Count)
            {
                this.ArrangeLine(v, size.V, start, internalChildren.Count, useItemU, itemU, totalSize);
            }
            return(finalSize);
        }
Ejemplo n.º 28
0
        private double CalculateInterval(bool isContinue = true)
        {
            if (!Speedup || !isContinue)
            {
                return(Interval);
            }

            if (DoubleUtil.GreaterThan((_intervalValueSinceReset += _internalLargeChange), _internalLargeChange * 100))
            {
                _internalLargeChange *= 10;
            }

            return(_internalLargeChange);
        }
Ejemplo n.º 29
0
        // Returns an offset coerced into the [0, Extent - Viewport] range.
        // Internal because it is also used by other Avalon ISI implementations (just to avoid code duplication).
        internal static double CoerceOffset(double offset, double extent, double viewport)
        {
            if (DoubleUtil.GreaterThan(offset, extent - viewport))
            {
                offset = extent - viewport;
            }

            if (DoubleUtil.LessThan(offset, 0))
            {
                offset = 0;
            }

            return(offset);
        }
Ejemplo n.º 30
0
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            int   start      = 0;
            float itemWidth  = this.ItemWidth;
            float itemHeight = this.ItemHeight;
            float VPosition  = 0.0f;
            float itemU      = this.Orientation == Orientation.Horizontal ? itemWidth : itemHeight;
            float totalU     = this.Orientation == Orientation.Horizontal ? finalSize.Width : finalSize.Height;

            WrapLayoutPanel.UVSize uvSize1 = new WrapLayoutPanel.UVSize(this.Orientation);
            WrapLayoutPanel.UVSize uvSize2 = new WrapLayoutPanel.UVSize(this.Orientation, finalSize.Width, finalSize.Height);
            bool flag1    = !float.IsNaN(itemWidth);
            bool flag2    = !float.IsNaN(itemHeight);
            bool useItemU = this.Orientation == Orientation.Horizontal ? flag1 : flag2;
            RadElementCollection children = this.Children;
            int index = 0;

            for (int count = children.Count; index < count; ++index)
            {
                RadElement radElement = children[index];
                if (radElement != null)
                {
                    WrapLayoutPanel.UVSize uvSize3 = new WrapLayoutPanel.UVSize(this.Orientation, flag1 ? itemWidth : radElement.DesiredSize.Width, flag2 ? itemHeight : radElement.DesiredSize.Height);
                    if (DoubleUtil.GreaterThan(uvSize1.U + uvSize3.U, uvSize2.U))
                    {
                        this.ArrangeLine(VPosition, uvSize1.V, start, index, useItemU, itemU, totalU);
                        VPosition += uvSize1.V;
                        uvSize1    = uvSize3;
                        if (DoubleUtil.GreaterThan(uvSize3.U, uvSize2.U))
                        {
                            this.ArrangeLine(VPosition, uvSize3.V, index, ++index, useItemU, itemU, totalU);
                            VPosition += uvSize3.V;
                            uvSize1    = new WrapLayoutPanel.UVSize(this.Orientation);
                        }
                        start = index;
                    }
                    else
                    {
                        uvSize1.U += uvSize3.U;
                        uvSize1.V  = Math.Max(uvSize3.V, uvSize1.V);
                    }
                }
            }
            if (start < children.Count)
            {
                this.ArrangeLine(VPosition, uvSize1.V, start, children.Count, useItemU, itemU, totalU);
            }
            return(finalSize);
        }