Ejemplo n.º 1
0
        private void UpdateState()
        {
            if (IsDisposed)
            {
                return;
            }
            if (ClientRectangle.IsEmpty)
            {
                return;
            }

            Image refImage = BackgroundImage;

            if (Enabled)
            {
                switch (_state)
                {
                default:
                case MouseState.NONE:
                {
                    _image           = BaseImage;
                    BackgroundImage  = _image ?? BackgroundImage;
                    _textFont        = Font ?? DefaultFont;
                    _textColor       = TextColor;
                    _borderColor     = BorderColor;
                    _borderThickness = BorderThickness;
                    break;
                }

                case MouseState.HOVER:
                {
                    _image           = Cascade.Pick(null, BackgroundHoverImage, BaseImage);
                    BackgroundImage  = _image ?? BackgroundImage;
                    _textFont        = Cascade.Pick(null, HoverFont, Font) ?? DefaultFont;
                    _textColor       = Cascade.Pick(Color.Empty, TextHoverColor, TextColor);
                    _borderColor     = Cascade.Pick(Color.Empty, BorderHoverColor, BorderColor);
                    _borderThickness = Cascade.Pick(-1, BorderHoverThickness, BorderThickness);
                    break;
                }

                case MouseState.DOWN:
                {
                    _image           = Cascade.Pick(null, BackgroundClickImage, BackgroundHoverImage, BaseImage);
                    BackgroundImage  = _image ?? BackgroundImage;
                    _textFont        = Cascade.Pick(null, ClickFont, HoverFont, Font) ?? DefaultFont;
                    _textColor       = Cascade.Pick(Color.Empty, TextClickColor, TextHoverColor, TextColor);
                    _borderColor     = Cascade.Pick(Color.Empty, BorderClickColor, BorderHoverColor, BorderColor);
                    _borderThickness = Cascade.Pick(-1, BorderClickThickness, BorderHoverThickness, BorderThickness);
                    break;
                }
                }
            }
            else
            {
                _image           = Cascade.Pick(null, BackgroundDisabledImage, BaseImage);
                BackgroundImage  = _image ?? BackgroundImage;
                _textFont        = Cascade.Pick(null, DisabledFont, Font) ?? DefaultFont;
                _textColor       = Cascade.Pick(Color.Empty, TextDisabledColor, TextColor);
                _borderColor     = Cascade.Pick(Color.Empty, BorderDisabledColor, BorderColor);
                _borderThickness = Cascade.Pick(-1, BorderDisabledThickness, BorderThickness);
            }

            if (refImage != BackgroundImage)
            {
                UpdateAnimCount();
            }

            // for animation
            if (_animating && refImage != null && (refImage != BackgroundImage || _animCyclesRemaining == 0))
            {
                ImageAnimator.StopAnimate(refImage, OnFrameChanged);
                UnlockInput();
                _animating = false;
            }

            refImage = BackgroundImage;

            if (!_animating && _animCyclesRemaining != 0 && refImage != null && ImageAnimator.CanAnimate(refImage))
            {
                _animating = true;
                if (LockWhenAnimating)
                {
                    LockInput();
                }
                _animFramesRemaining = refImage.GetFrameCount(new FrameDimension(refImage.FrameDimensionsList[0]));
                ImageAnimator.Animate(refImage, OnFrameChanged);
            }

            if (!DesignMode && Size != _orgSize)
            {
                float factor = _scale.x.Clamp(MIN_SCALE, _scale.y);
                _textFont = new Font(_textFont.FontFamily, _textFont.Size * factor, _textFont.Style);
            }

            if (!string.IsNullOrWhiteSpace(Text))
            {
                // update the cache so that the PageCount is updated as early as possible
                GetOrCreateFromTextPageCache(out _);
            }

            Invalidate();
        }