Exemplo n.º 1
0
        private void LoadNewImageFile(string imagePath)
        {
            try
            {
                pictureBox1.SizeMode = (PictureBoxSizeMode)_applicationSettingsService.Settings.PrimaryImageSizeMode;


                if (_applicationSettingsService.Settings.NextImageAnimation == ImageViewApplicationSettings.ChangeImageAnimation.None)
                {
                    _changeImageAnimation = ImageViewApplicationSettings.ChangeImageAnimation.None;
                }

                _pictureBoxAnimation.ImageLocation = null;

                if (pictureBox1.Image != null && _changeImageAnimation != ImageViewApplicationSettings.ChangeImageAnimation.None)
                {
                    _pictureBoxAnimation.Image = _imageCacheService.GetImageFromCache(imagePath);
                    _pictureBoxAnimation.Refresh();
                }
                else
                {
                    pictureBox1.Image = _imageCacheService.GetImageFromCache(imagePath);
                    pictureBox1.Refresh();
                }

                Text = _windowTitle + @" | " + GeneralConverters.GetFileNameFromPath(imagePath);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "FormMain.LoadNewImageFile(string imagePath) Error when trying to load file: {imagePath} : {Message}", imagePath, ex.Message);
            }
        }
Exemplo n.º 2
0
        private void SyncUserControlStateWithAppSettings()
        {
            var settings = _applicationSettingsService.Settings;

            if (TopMost != settings.AlwaysOntop)
            {
                TopMost = settings.AlwaysOntop;
            }

            topMostToolStripMenuItem.Checked = settings.AlwaysOntop;

            _changeImageAnimation = settings.NextImageAnimation;
            autoLoadPreviousFolderToolStripMenuItem.Enabled = settings.EnableAutoLoadFunctionFromMenu &&
                                                              !string.IsNullOrWhiteSpace(settings.LastFolderLocation);
            if (settings.MainWindowBackgroundColor != null)
            {
                pictureBox1.BackColor = settings.MainWindowBackgroundColor.ToColor();
                BackColor             = settings.MainWindowBackgroundColor.ToColor();
            }

            if (settings.ExtendedAppSettings.FormStateDictionary.ContainsKey(this.GetType().Name))
            {
                var formState = settings.ExtendedAppSettings.FormStateDictionary[this.GetType().Name];
                RestoreFormState.SetFormSizeAndPosition(this, formState);
            }
        }
Exemplo n.º 3
0
        private void ChangeImage(bool next)
        {
            if (_imageTransitionRunning)
            {
                return;
            }

            if (!ImageSourceDataAvailable || _imageReferenceCollection.ImageCount == 0)
            {
                return;
            }

            ImageReferenceElement imgRef;

            //Reset timer
            if (timerSlideShow.Enabled)
            {
                timerSlideShow.Stop();
                timerSlideShow.Start();
            }

            //Go Forward
            if (next)
            {
                _changeImageAnimation = ImageViewApplicationSettings.ChangeImageAnimation.SlideLeft;
                imgRef = _imageReferenceCollection.GetNextImage();
            }
            else
            {
                _changeImageAnimation = ImageViewApplicationSettings.ChangeImageAnimation.SlideRight;
                imgRef = _imageReferenceCollection.GetPreviousImage();
            }

            LoadNewImageFile(imgRef.CompletePath);
            AddNextImageToCache(_imageReferenceCollection.PeekNextImage().CompletePath);
        }
Exemplo n.º 4
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            DoubleBuffered = true;
            _applicationSettingsService.OnSettingsSaved        += Instance_OnSettingsSaved;
            _applicationSettingsService.OnRegistryAccessDenied += Instance_OnRegistryAccessDenied;
            _imageLoaderService.OnImportComplete  += Instance_OnImportComplete;
            _imageLoaderService.OnImageWasDeleted += Instance_OnImageWasDeleted;

            _pictureBoxAnimation.LoadCompleted += pictureBoxAnimation_LoadCompleted;
            bool settingsLoaded = _applicationSettingsService.LoadSettings();


            if (!settingsLoaded)
            {
                // Problem. Settings could not be loaded due to deserialization error because the decryption used an invalid key which made protobuffer try to deserialize garbage.
                _applicationSettingsService.SaveSettings();
                _applicationSettingsService.LoadSettings();
                SyncUserControlStateWithAppSettings();
            }
            else
            {
                SyncUserControlStateWithAppSettings();

                try
                {
                    var fileConfig = _applicationSettingsService.Settings.ExtendedAppSettings;
                    if (fileConfig.FormStateDictionary.ContainsKey(GetType().Name))
                    {
                        var formState = fileConfig.FormStateDictionary[GetType().Name];
                        RestoreFormState.SetFormSizeAndPosition(this, formState);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }

                _changeImageAnimation   = _applicationSettingsService.Settings.NextImageAnimation;
                timerSlideShow.Interval = _applicationSettingsService.Settings.SlideshowInterval;

                addBookmarkToolStripMenuItem.Enabled = false;
                Text = _windowTitle;
                ToggleSlideshowMenuState();
            }


            //    MessageBox.Show(Resources.Unable_To_Access_application_settings_in_registry,
            //        Resources.Faild_to_load_settings, MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    _formRestartWithAdminPrivileges = new FormRestartWithAdminPrivileges();
            //    if (_formRestartWithAdminPrivileges.ShowDialog(this) == DialogResult.OK)
            //    {
            //        return;
            //    }



            //Notification Service
            _interactionService.Initialize(this);
            _interactionService.UserInformationReceived += InteractionServiceUserInformationReceived;
            _interactionService.UserQuestionReceived    += InteractionServiceUserQuestionReceived;
        }
Exemplo n.º 5
0
        private async Task PerformImageTransition(Image currentImage, Image nextImage, ImageViewApplicationSettings.ChangeImageAnimation animation, int animationTime)
        {
            const int sleepTime = 1;

            _imageTransitionRunning = true;
            await Task.Run(() =>
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                while (stopwatch.ElapsedMilliseconds <= animationTime)
                {
                    long elapsedTime = stopwatch.ElapsedMilliseconds;

                    float factor = stopwatch.ElapsedMilliseconds / (float)animationTime;
                    Image transitionImage;
                    switch (animation)
                    {
                    case ImageViewApplicationSettings.ChangeImageAnimation.SlideLeft:
                        transitionImage = ImageTransform.OffsetImagesHorizontal(currentImage, nextImage,
                                                                                new Size(pictureBox1.Width, pictureBox1.Height), factor, false);
                        break;

                    case ImageViewApplicationSettings.ChangeImageAnimation.SlideRight:
                        transitionImage = ImageTransform.OffsetImagesHorizontal(nextImage, currentImage,
                                                                                new Size(pictureBox1.Width, pictureBox1.Height), factor, true);
                        break;

                    case ImageViewApplicationSettings.ChangeImageAnimation.SlideDown:
                        transitionImage = ImageTransform.OffsetImagesVertical(nextImage, currentImage,
                                                                              new Size(nextImage.Width, nextImage.Height), factor, true);
                        break;

                    case ImageViewApplicationSettings.ChangeImageAnimation.SlideUp:
                        transitionImage = ImageTransform.OffsetImagesVertical(currentImage, nextImage,
                                                                              new Size(Math.Max(nextImage.Width, currentImage.Width), nextImage.Height), factor, false);
                        break;

                    case ImageViewApplicationSettings.ChangeImageAnimation.FadeIn:
                        int width           = nextImage.Width;
                        int height          = nextImage.Height;
                        var nextImageBitmap = new Bitmap(nextImage, new Size(width, height));
                        transitionImage     = ImageTransform.SetImageOpacity(nextImageBitmap, factor);
                        break;

                    default:
                        return;
                    }

                    if (!Visible)
                    {
                        return;
                    }

                    try
                    {
                        pictureBox1.Image = transitionImage.Clone() as Image;
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, Resources.Failed_to_set_transition_image_over_current_image_);
                        MessageBox.Show(Resources.Failed_to_set_transition_image_over_current_image_,
                                        Resources.Error_loading_new_image, MessageBoxButtons.OK, MessageBoxIcon.Error);

                        _imageTransitionRunning = false;
                        return;
                    }
                    finally
                    {
                        transitionImage.Dispose();
                    }

                    elapsedTime = stopwatch.ElapsedMilliseconds - elapsedTime;

                    if (sleepTime - elapsedTime > 0)
                    {
                        Thread.Sleep(Convert.ToInt32(sleepTime - elapsedTime));
                    }
                }

                stopwatch.Stop();
                Log.Verbose("Image transition finished after " + stopwatch.ElapsedMilliseconds + " ms");
                Invoke(new EventHandler(OnImageLoadComplete), this, new EventArgs());
            });

            pictureBox1.Image       = nextImage.Clone() as Image;
            _imageTransitionRunning = false;
        }