Ejemplo n.º 1
0
        public override void Recalculate()
        {
            base.Recalculate();
            _controls.Sort(ZIndexComparer.Instance);
            _captionBarRect =
                new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize, CleanRect.Width, Ui.CaptionHeight);
            _mainRect = new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize + Ui.CaptionHeight, CleanRect.Width,
                                      CleanRect.Height - Ui.CaptionHeight - BorderSize);
            _closeButton.Dirty();
            for (int i = 0; i < _controls.Count; i++)
            {
                _controls[i].Dirty();
            }

            _topLeft     = new Vector2(CleanRect.Left, CleanRect.Top);
            _topRight    = new Vector2(CleanRect.Left + Width - BorderSize, CleanRect.Top);
            _bottomLeft  = new Vector2(CleanRect.Left, CleanRect.Top + Height - BorderSize);
            _bottomRight = new Vector2(CleanRect.Left + Width - BorderSize, CleanRect.Top + Height - BorderSize);

            _middleTop = new Rectangle(CleanRect.Left + BorderSize, CleanRect.Top, Width - (BorderSize * 2),
                                       BorderSize);
            _middleLeft = new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize, BorderSize,
                                        Height - (BorderSize * 2));
            _middleRight = new Rectangle(CleanRect.Left + Width - BorderSize, CleanRect.Top + BorderSize, BorderSize,
                                         Height - (BorderSize * 2));
            _middleBottom = new Rectangle(CleanRect.Left + BorderSize, CleanRect.Top + Height - BorderSize,
                                          Width - (BorderSize * 2), BorderSize);

            _captionPos = new Vector2(CleanRect.Left + (_captionBarRect.Width / 2) - (_caption.MeasuredSize.X / 2),
                                      CleanRect.Top + BorderSize + 2);
            //_closeButton.SetRect(new Rectangle(CleanRect.Right - Ui.CaptionHeight - BorderSize, CleanRect.Top, Ui.CaptionHeight + BorderSize, Ui.CaptionHeight + BorderSize));

            _backgroundRects =
                Parts.CreateRectangular(CleanRect.Size, CleanRect.Left, CleanRect.Top, Ui.Background.Size);
            _captionBackgroundRects = Parts.CreateHorizontal(_captionBarRect.Width,
                                                             Ui.CaptionBackground.Width, _captionBarRect.Top, _captionBarRect.Left, Ui.CaptionHeight);
            _draggable.SetRect(new Rectangle(_captionBarRect.Left, _captionBarRect.Top, _captionBarRect.Width - Ui.CaptionHeight - BorderSize, _captionBarRect.Height));
            IsDirty = false;
        }
        public override void Recalculate()
        {
            base.Recalculate();
            _mBoxCaptionBarRect =
                new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize, CleanRect.Width, CaptionHeight);
            _mBoxMainRect = new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize + CaptionHeight, CleanRect.Width,
                                          CleanRect.Height - CaptionHeight - BorderSize);
            _topLeft     = new Vector2(CleanRect.Left, CleanRect.Top);
            _topRight    = new Vector2(CleanRect.Left + Width - BorderSize, CleanRect.Top);
            _bottomLeft  = new Vector2(CleanRect.Left, CleanRect.Top + Height - BorderSize);
            _bottomRight = new Vector2(CleanRect.Left + Width - BorderSize, CleanRect.Top + Height - BorderSize);

            _middleTop = new Rectangle(CleanRect.Left + BorderSize, CleanRect.Top, Width - (BorderSize * 2),
                                       BorderSize);
            _middleLeft = new Rectangle(CleanRect.Left, CleanRect.Top + BorderSize, BorderSize,
                                        Height - (BorderSize * 2));
            _middleRight = new Rectangle(CleanRect.Left + Width - BorderSize, CleanRect.Top + BorderSize, BorderSize,
                                         Height - (BorderSize * 2));
            _middleBottom = new Rectangle(CleanRect.Left + BorderSize, CleanRect.Top + Height - BorderSize,
                                          Width - (BorderSize * 2), BorderSize);

            _captionPos = new Vector2(CleanRect.Left + (_mBoxCaptionBarRect.Width / 2) - (_caption.MeasuredSize.X / 2),
                                      CleanRect.Top + BorderSize + 2);
            _textPos = new Vector2(
                _mBoxMainRect.Left + (_mBoxMainRect.Width / 2) - (_text.MeasuredSize.X / 2),
                _mBoxMainRect.Top + ((_mBoxMainRect.Height - ButtonHeight) / 2) - (_text.MeasuredSize.Y / 2)
                );
            _backgroundRects =
                Parts.CreateRectangular(CleanRect.Size, CleanRect.Left, CleanRect.Top, Ui.Background.Size);
            _captionBackgroundRects = Parts.CreateHorizontal(_mBoxCaptionBarRect.Width,
                                                             Ui.CaptionBackground.Width, _mBoxCaptionBarRect.Top, _mBoxCaptionBarRect.Left, CaptionHeight);
            _buttonYes.X = _mBoxMainRect.Left + _mBoxMainRect.Width - _buttonYes.Width - _buttonNo.Width - (ButtonMargin * 3);
            _buttonYes.Y = _mBoxMainRect.Top + _mBoxMainRect.Height - ButtonHeight - BorderSize;
            _buttonNo.X  = _mBoxMainRect.Left + _mBoxMainRect.Width - _buttonNo.Width - (ButtonMargin * 2);
            _buttonNo.Y  = _mBoxMainRect.Top + _mBoxMainRect.Height - ButtonHeight - BorderSize;
            IsDirty      = false;
        }
        public override void Recalculate()
        {
            base.Recalculate();
            // TODO: clean up this mess
            var leftX   = Parent.Bounds.Left + Parent.BorderSize;
            var rightX  = Parent.Bounds.Left + Parent.Width - Ui.ScrollBar.LeftArrow.Width - BorderSize;
            var bgWidth = rightX - leftX - Ui.ScrollBar.LeftArrow.Width;

            var y = _border switch
            {
                Border.Top => Parent.Bounds.Top + Parent.BorderSize + _verticalOffset,
                Border.Bottom => Parent.Bounds.Top + Parent.Height - Ui.ScrollBar.LeftArrow.Height -
                Parent.BorderSize + _verticalOffset,
                _ => throw new ArgumentOutOfRangeException()
            };

            var scrollPartWidth = Ui.ScrollBar.LeftArrow.Width;

            var leftArrowRect = new Rectangle(leftX, y, scrollPartWidth, Scroll.Height);

            _leftArrow.SetRect(leftArrowRect);
            var rightArrowRect = new Rectangle(rightX, y, scrollPartWidth, Scroll.Height);

            _rightArrow.SetRect(rightArrowRect);

            var staticBgWidth = Ui.ScrollBar.HorizontalBackground.Width;

            _backgroundRects = Parts.CreateHorizontal(bgWidth, staticBgWidth, y,
                                                      leftX + Ui.ScrollBar.LeftArrow.Width,
                                                      Scroll.Height);

            var parent   = (ICanHaveHorizontalScrollBar)Parent;
            var midWidth = CalculateHeightOfMiddlePartOfScrollBar(parent, bgWidth);

            var fullMidBarWidth = midWidth + BarEndsWidth * 2;

            var oneScrollWidth =
                parent.HorizontalItemCount <= parent.HorizontalMaxVisibleItems
                    ? 0
                    : (float)(bgWidth - fullMidBarWidth) / parent.HorizontalMaxScrollIndex;

            _draggable.SetMinimumDragDistance((int)oneScrollWidth);
            _dragMultiplier = (float)Math.Max(Math.Ceiling(1 / oneScrollWidth), 1);
            var barOffset = (int)Math.Ceiling(oneScrollWidth * parent.HorizontalScrollIndex);

            var barStartX = barOffset + leftX + Ui.ScrollBar.LeftArrow.Width;

            _barLeftRect = new Rectangle(barStartX, y,
                                         Ui.ScrollBar.HorizontalForegroundStart.Width,
                                         Scroll.Height);
            var midPos = barStartX +
                         Ui.ScrollBar.HorizontalForegroundStart.Width;

            _barMiddleRects = Parts.CreateHorizontal(midWidth,
                                                     Ui.ScrollBar.HorizontalForegroundMiddle.Width, y, midPos, Scroll.Height);
            _barRightRect = new Rectangle(midPos + midWidth, y, Ui.ScrollBar.HorizontalForegroundEnd.Width,
                                          Scroll.Height);
            _barHitBox = new Rectangle(barStartX, y, fullMidBarWidth, Scroll.Height);
            _bgHitBox  = new Rectangle(
                leftX + scrollPartWidth, y, bgWidth, Scroll.Height);
            _draggable.SetRect(_barHitBox);
        }