예제 #1
0
        private void HideImageInControl(Image imageCtrl, ImageFadeType fadeType, double fadeTime, Action completed)
        {
            var shouldFadeOut = imageCtrl.Source != null &&
                                (fadeType == ImageFadeType.FadeOut ||
                                 fadeType == ImageFadeType.FadeInOut ||
                                 fadeType == ImageFadeType.CrossFade);

            if (!shouldFadeOut)
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    completed?.Invoke();
                    imageCtrl.Source = null;
                    RemoveAnimation(imageCtrl);
                });
            }
            else
            {
                var fadeOut = new DoubleAnimation
                {
                    Duration = TimeSpan.FromSeconds(fadeTime),
                    From     = 1.0,
                    To       = 0.0
                };

                fadeOut.Completed += (sender, args) =>
                {
                    completed?.Invoke();
                    imageCtrl.Source = null;
                };

                imageCtrl.BeginAnimation(UIElement.OpacityProperty, fadeOut);
            }
        }
예제 #2
0
        private void ShowImageInControl(string imageFile, Image imageCtrl, ImageFadeType fadeType, double fadeTime, Action completed)
        {
            var shouldFadeIn =
                fadeType == ImageFadeType.FadeIn ||
                fadeType == ImageFadeType.FadeInOut ||
                fadeType == ImageFadeType.CrossFade;

            var imageSrc = _optionsService.CacheImages
                ? ImageCache.GetImage(imageFile)
                : GraphicsUtils.GetBitmapImageWithCacheOnLoad(imageFile);

            OnNewMediaSizeEvent(CreateNewMediaSizeEventArgs(imageSrc.PixelWidth, imageSrc.PixelHeight));

            if (!shouldFadeIn)
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    RemoveAnimation(imageCtrl);
                    imageCtrl.Source = imageSrc;
                    completed?.Invoke();
                });
            }
            else
            {
                imageCtrl.Opacity = 0.0;
                imageCtrl.Source  = imageSrc;

                // This delay allows us to accommodate large images without the apparent loss of fade-in animation
                // the first time an image is loaded. There must be a better way!
                Task.Delay(10).ContinueWith(t =>
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        var fadeIn = new DoubleAnimation
                        {
                            // note that the fade in time is longer than fade out - just seems to look better
                            Duration = TimeSpan.FromSeconds(fadeTime * 1.2),
                            From     = 0.0,
                            To       = 1.0,
                        };

                        if (completed != null)
                        {
                            fadeIn.Completed += (sender, args) => { completed(); };
                        }

                        imageCtrl.BeginAnimation(UIElement.OpacityProperty, fadeIn);
                    });
                }).ConfigureAwait(false);
            }
        }
예제 #3
0
        private void UnplaceImage(
            Guid mediaItemId,
            MediaClassification mediaClassification,
            ImageFadeType fadeType,
            Action <Guid, MediaClassification> stopping,
            Action <Guid, MediaClassification> stopped)
        {
            var fadeTime = _optionsService.Options.ImageFadeSpeed.GetFadeSpeedSeconds();

            stopping?.Invoke(mediaItemId, mediaClassification);

            if (_image1MediaItemId == mediaItemId)
            {
                if ((int)_image1.GetValue(Panel.ZIndexProperty) == 1)
                {
                    HideImageInControl(
                        _image1,
                        fadeType,
                        fadeTime,
                        () =>
                    {
                        stopped?.Invoke(mediaItemId, mediaClassification);
                        _image1MediaItemId    = Guid.Empty;
                        _mediaClassification1 = MediaClassification.Unknown;
                    });
                }
            }

            if (_image2MediaItemId == mediaItemId)
            {
                if ((int)_image2.GetValue(Panel.ZIndexProperty) == 1)
                {
                    HideImageInControl(
                        _image2,
                        fadeType,
                        fadeTime,
                        () =>
                    {
                        stopped?.Invoke(mediaItemId, mediaClassification);
                        _image2MediaItemId    = Guid.Empty;
                        _mediaClassification2 = MediaClassification.Unknown;
                    });
                }
            }
        }
예제 #4
0
        private void ShowImageInternal(
            bool isBlankScreenImage,
            ScreenPosition screenPosition,
            string imageFile,
            Image controlToUse,
            Image otherControl,
            ImageFadeType fadeType,
            double fadeTime,
            Action hideCompleted,
            Action showCompleted)
        {
            controlToUse.SetValue(Panel.ZIndexProperty, 1);
            otherControl.SetValue(Panel.ZIndexProperty, 0);

            controlToUse.Stretch = isBlankScreenImage
                ? Stretch.Fill
                : Stretch.Uniform;

            ScreenPositionHelper.SetScreenPosition(
                controlToUse,
                isBlankScreenImage ? new ScreenPosition() : screenPosition);

            if (fadeType == ImageFadeType.CrossFade ||
                fadeType == ImageFadeType.None)
            {
                ShowImageInControl(imageFile, controlToUse, fadeType, fadeTime, showCompleted);
                HideImageInControl(otherControl, fadeType, fadeTime, hideCompleted);
            }
            else
            {
                HideImageInControl(
                    otherControl,
                    fadeType,
                    fadeTime,
                    () =>
                {
                    hideCompleted?.Invoke();
                    ShowImageInControl(imageFile, controlToUse, fadeType, fadeTime, showCompleted);
                });
            }
        }
예제 #5
0
        public static string GetDescriptiveName(this ImageFadeType fadeType)
        {
            switch (fadeType)
            {
            case ImageFadeType.None:
                return(Resources.FADE_NONE);

            case ImageFadeType.FadeIn:
                return(Resources.FADE_IN);

            case ImageFadeType.FadeOut:
                return(Resources.FADE_OUT);

            case ImageFadeType.FadeInOut:
                return(Resources.FADE_IN_OUT);

            default:
            // ReSharper disable once RedundantCaseLabel
            case ImageFadeType.CrossFade:
                return(Resources.FADE_CROSS);
            }
        }
예제 #6
0
        private void PlaceImage(
            Guid mediaItemId,
            MediaClassification mediaClassification,
            string imageFilePath,
            bool isBlankScreenImage,
            ImageFadeType fadeType,
            Action <Guid, MediaClassification> onStarting,
            Action <Guid, MediaClassification> onStopping,
            Action <Guid, MediaClassification> onStopped,
            Action <Guid, MediaClassification> onStarted)
        {
            var fadeTime = _optionsService.Options.ImageFadeSpeed.GetFadeSpeedSeconds();

            onStarting?.Invoke(mediaItemId, mediaClassification);

            if (!Image1Populated)
            {
                onStopping?.Invoke(_image2MediaItemId, _mediaClassification2);

                ShowImageInternal(
                    isBlankScreenImage,
                    _optionsService.Options.ImageScreenPosition,
                    imageFilePath,
                    _image1,
                    _image2,
                    fadeType,
                    fadeTime,
                    () =>
                {
                    onStopped?.Invoke(_image2MediaItemId, _mediaClassification2);
                    _image2MediaItemId    = Guid.Empty;
                    _mediaClassification2 = MediaClassification.Unknown;
                },
                    () =>
                {
                    _image1MediaItemId    = mediaItemId;
                    _mediaClassification1 = mediaClassification;
                    onStarted?.Invoke(_image1MediaItemId, _mediaClassification1);
                });
            }
            else if (!Image2Populated)
            {
                onStopping?.Invoke(_image1MediaItemId, _mediaClassification1);

                ShowImageInternal(
                    isBlankScreenImage,
                    _optionsService.Options.ImageScreenPosition,
                    imageFilePath,
                    _image2,
                    _image1,
                    fadeType,
                    fadeTime,
                    () =>
                {
                    onStopped?.Invoke(_image1MediaItemId, _mediaClassification1);
                    _image1MediaItemId    = Guid.Empty;
                    _mediaClassification1 = MediaClassification.Unknown;
                },
                    () =>
                {
                    _image2MediaItemId    = mediaItemId;
                    _mediaClassification2 = mediaClassification;
                    onStarted?.Invoke(_image2MediaItemId, _mediaClassification2);
                });
            }
        }