Пример #1
0
        void Load(string filename)
        {
            ConvertButton.Visibility    = Visibility.Visible;
            ClosePanelButton.Visibility = Visibility.Collapsed;

            // Reset zoom etc
            SaveImageViewBox.Reset();
            LoadedImageViewBox.Reset();

            vm.LoadImage(filename);
        }
Пример #2
0
 private void ImageCloseButton_Click(object sender, RoutedEventArgs e)
 {
     // Reset scaling and position
     LoadedImageViewBox.Reset();
     SaveImageViewBox.Reset();
 }
Пример #3
0
        public NewMainWindow()
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            ProfileOptimization.SetProfileRoot(path);
            ProfileOptimization.StartProfile("Startup.Profile_ImageEngine_UI");

            vm = new NewViewModel();

            DragDropHandler = new UsefulThings.WPF.DragDropHandler <NewViewModel>(this)
            {
                DropValidator = new Predicate <string[]>(files =>
                {
                    // Check only one file - can only load one, so restrict to one.
                    if (files.Length != 1)
                    {
                        return(false);
                    }

                    // Check file extension
                    return(ImageFormats.IsExtensionSupported(files[0]));
                }),

                DropAction = new Action <NewViewModel, string[]>((viewModel, filePath) =>
                {
                    if (filePath?.Length < 1)
                    {
                        return;
                    }

                    Load(filePath[0]);
                })
            };

            vm.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(vm.IsImageLoaded) && !vm.IsImageLoaded)
                {
                    CloseSavePanel();
                }
                else if (args.PropertyName == nameof(vm.UseHighQualityScaling))
                {
                    BitmapScalingMode mode = BitmapScalingMode.HighQuality;
                    if (!vm.UseHighQualityScaling)
                    {
                        mode = BitmapScalingMode.NearestNeighbor;
                    }

                    RenderOptions.SetBitmapScalingMode(LoadedImageImage, mode);
                    RenderOptions.SetBitmapScalingMode(SaveImageImage, mode);
                }
                else if (args.PropertyName == nameof(vm.IsWindowBlurred))
                {
                    if (vm.IsWindowBlurred)
                    {
                        UsefulThings.WPF.WindowBlur.EnableBlur(this);
                    }
                    else
                    {
                        UsefulThings.WPF.WindowBlur.DisableBlur(this);
                    }
                }
                else if (args.PropertyName == nameof(vm.SettingsPanelOpen))
                {
                    SetOptionalContent(vm.SettingsPanelOpen, "SettingsPanel");
                }
                else if (args.PropertyName == nameof(vm.MergeChannelsPanelOpen))
                {
                    SetOptionalContent(vm.MergeChannelsPanelOpen, "MergeChannelsPanel");
                }
                else if (args.PropertyName == nameof(vm.InfoPanelOpen))
                {
                    SetOptionalContent(vm.InfoPanelOpen, "InfoPanel");
                }
                else if (args.PropertyName == nameof(vm.BulkConvertOpen))
                {
                    SetOptionalContent(vm.BulkConvertOpen, "BulkConvertPanel");
                }
                else if (args.PropertyName == nameof(vm.ShowHelpAbout))
                {
                    SetOptionalContent(vm.ShowHelpAbout, "HelpAboutPanel");
                }
            };

            BulkDropDragHandler = new UsefulThings.WPF.DragDropHandler <NewViewModel>(this)
            {
                DropValidator = files =>
                {
                    if (files == null || files.Length == 0)
                    {
                        return(false);
                    }

                    // Check all extensions
                    var supported = ImageFormats.GetSupportedExtensions(true);
                    foreach (string file in files)
                    {
                        if (!ImageFormats.IsExtensionSupported(file, supported))
                        {
                            return(false);
                        }
                    }

                    return(true);
                },

                DropAction = (model, files) => vm.BulkAdd(files)
            };

            MergeDropHandler = new UsefulThings.WPF.DragDropHandler <NewViewModel>(this)
            {
                DropValidator = BulkDropDragHandler.DropValidator,  // Same validator as bulk
                DropAction    = (model, files) => Task.Run(() => vm.MergeLoad(files))
            };

            InitializeComponent();
            DataContext = vm;

            optionalPanelWaitTimer.Interval = ((Duration)TOPWINDOW.FindResource("StandardDuration")).TimeSpan;
            optionalPanelWaitTimer.Tick    += (source, args) =>
            {
                // Close panel with faded content properly.
                OptionalPanelsDisplayBox.Content = null;
                optionalPanelWaitTimer.Stop();
            };

            FadeIn  = (Storyboard)TOPWINDOW.FindResource("FadeInPanel");
            FadeOut = (Storyboard)TOPWINDOW.FindResource("FadeOutPanel");

            CloseSavePanel();
            ClosePanelButton.Visibility = Visibility.Collapsed;


            // Prevent maximised window overtaking the taskbar
            this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight - 5;

            // Setup events for linking image viewbox pan and scroll
            PanZoomLinkButton.Checked   += (sender, args) => LoadedImageViewBox.Link(SaveImageViewBox);
            PanZoomLinkButton.Unchecked += (sender, args) => LoadedImageViewBox.Unlink(SaveImageViewBox);

            // Linked by default
            LoadedImageViewBox.Link(SaveImageViewBox);


            // Fix window size if on low res, < 1920x1080
            if (this.Height >= SystemParameters.WorkArea.Height)
            {
                this.Height = SystemParameters.WorkArea.Height - 100; // For a bit of space and in case of taskbar weirdness
            }
            // "Global" exception handler - kills the application if this is hit.
            if (!Debugger.IsAttached)
            {
                Application.Current.DispatcherUnhandledException += (sender, args) =>
                {
                    MessageBox.Show("Unhandled exception occured." + Environment.NewLine + args.Exception);
                    this.Close();  // Might not work I guess, but either way, it's going down.
                }
            }
            ;

            // Make sure Minimise/Maximise functionality from dragging the title bar is connected to any margin adjustments required.
            this.StateChanged += (sender, args) => WindowMinMaxButton_Click(sender, null);


            // Handle Command Line parameters
            string[] cmdLineParams = Environment.GetCommandLineArgs();

            // For now, just loading image.
            if (cmdLineParams.Length != 1)
            {
                // Since only loading, just use the first one.
                Load(cmdLineParams[2]);
            }
        }