Exemple #1
0
        private void UpdateBoundingBoxState(BoundingBoxState newState, DetectionMessage newBoundingBox = null)
        {
            switch (newState)
            {
            case BoundingBoxState.Initial:
                throw new InvalidOperationException(
                          $"{nameof(BoundingBoxState.Initial)} state can be set just at the beginning.");

            case BoundingBoxState.Missing:
                canvasView.InvalidateSurface();
                boundingBox = DetectionMessage.FullScreen;
                break;

            case BoundingBoxState.Framing:
                DisposeFadeOutTimer();

                elapsedTimeSinceLastDetection = DateTime.UtcNow - lastDetectionDate;
                lastDetectionDate             = DateTime.UtcNow;

                previousBoundingBox = boundingBox;
                boundingBox         = newBoundingBox;

                if (!this.AnimationIsRunning(nameof(framingAnimation)))
                {
                    framingAnimation.Commit(
                        this,
                        nameof(framingAnimation),
                        length: AnimationLengthMilliseconds,
                        finished: (_, __) => InitializeFadeOutTimer());
                }

                break;

            case BoundingBoxState.Disappearing:
                break;

            default:
                throw new InvalidOperationException();
            }

            currentBoundingBoxState = newState;
        }