Пример #1
0
        private void ExportConfigOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(ExportConfigModel.UseCropping):
                OnPropertyChanged(nameof(UseCropping));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportConfigModel.CropStart):
            case nameof(ExportConfigModel.CropEnd):
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportConfigModel.Layer):
                if (models.ExportConfig.Layer < 0)
                {
                    selectedLayer = AvailableLayers.Last();
                }
                else
                {
                    selectedLayer = AvailableLayers[models.ExportConfig.Layer];
                }
                OnPropertyChanged(nameof(SelectedLayer));

                // preview layer
                if (models.ExportConfig.Layer >= 0)
                {
                    models.Display.ActiveLayer = models.ExportConfig.Layer;
                }
                break;

            case nameof(ExportConfigModel.Mipmap):
                if (models.ExportConfig.Mipmap < 0)
                {
                    selectedMipmap = AvailableMipmaps.Last();
                }
                else
                {
                    selectedMipmap = AvailableMipmaps[models.ExportConfig.Mipmap];
                }
                OnPropertyChanged(nameof(SelectedMipmap));

                Crop.Mipmap = selectedMipmap.Cargo;

                // preview mipmap
                models.Display.ActiveMipmap = Math.Max(models.ExportConfig.Mipmap, 0);
                break;
            }
        }
Пример #2
0
        public ExportViewModel(Models.Models models)
        {
            this.models = models;

            // init layers
            for (var i = 0; i < models.Images.NumLayers; ++i)
            {
                AvailableLayers.Add(new ComboBoxItem <int>("Layer " + i, i));
            }
            selectedLayer = AvailableLayers[models.Export.Layer];
            Debug.Assert(selectedLayer.Cargo == models.Export.Layer);

            // init mipmaps
            for (var i = 0; i < models.Images.NumMipmaps; ++i)
            {
                AvailableMipmaps.Add(new ComboBoxItem <int>("Mipmap " + i, i));
            }
            selectedMipmap = AvailableMipmaps[models.Export.Mipmap];
            Debug.Assert(selectedMipmap.Cargo == models.Export.Mipmap);

            // all layer option for ktx and dds
            if (models.Images.NumLayers > 1 && (models.Export.FileType == FileFormat.Ktx || models.Export.FileType == FileFormat.Ktx2 || models.Export.FileType == FileFormat.Dds))
            {
                AvailableLayers.Add(new ComboBoxItem <int>("All Layer", -1));
                selectedLayer       = AvailableLayers.Last();
                models.Export.Layer = selectedLayer.Cargo;
            }

            // all mipmaps option for ktx and dds
            if (models.Images.NumMipmaps > 1 && (models.Export.FileType == FileFormat.Ktx || models.Export.FileType == FileFormat.Ktx2 || models.Export.FileType == FileFormat.Dds))
            {
                AvailableMipmaps.Add(new ComboBoxItem <int>("All Mipmaps", -1));
                selectedMipmap       = AvailableMipmaps.Last();
                models.Export.Mipmap = selectedMipmap.Cargo;
            }

            // init formats
            foreach (var format in models.Export.SupportedFormats)
            {
                AvailableFormat.Add(new ComboBoxItem <DisplayedFormat>(format.DisplayedName, format));
                if (format == models.Export.TexFormat)
                {
                    SelectedFormat = AvailableFormat.Last();
                }
            }

            models.Export.PropertyChanged += ExportOnPropertyChanged;
        }
Пример #3
0
        public ExportViewModel(ModelsEx models, string extension, GliFormat preferredFormat, string filename, bool is3D, DefaultStatistics stats)
        {
            this.models                = models;
            this.extension             = extension;
            this.filename              = filename;
            this.is3D                  = is3D;
            this.usedFormat            = models.Export.Formats.First(fmt => fmt.Extension == extension);
            models.Display.IsExporting = true;
            Quality = models.Settings.LastQuality;

            // init layers
            for (var i = 0; i < models.Images.NumLayers; ++i)
            {
                AvailableLayers.Add(new ListItemViewModel <int>
                {
                    Cargo = i,
                    Name  = "Layer " + i
                });
            }
            selectedLayer = AvailableLayers[models.Export.Layer];
            Debug.Assert(selectedLayer.Cargo == models.Export.Layer);

            // init mipmaps
            for (var i = 0; i < models.Images.NumMipmaps; ++i)
            {
                AvailableMipmaps.Add(new ListItemViewModel <int>
                {
                    Cargo = i,
                    Name  = "Mipmap " + i
                });
            }
            selectedMipmap = AvailableMipmaps[models.Export.Mipmap];
            Debug.Assert(selectedMipmap.Cargo == models.Export.Mipmap);

            // all layer option for ktx and dds
            if (models.Images.NumLayers > 1 && (extension == "ktx" || extension == "dds"))
            {
                AvailableLayers.Add(new ListItemViewModel <int>
                {
                    Cargo = -1,
                    Name  = "All Layer"
                });
                selectedLayer       = AvailableLayers.Last();
                models.Export.Layer = selectedLayer.Cargo;
            }

            // all mipmaps option for ktx and dds
            if (models.Images.NumMipmaps > 1 && (extension == "ktx" || extension == "dds"))
            {
                AvailableMipmaps.Add(new ListItemViewModel <int>
                {
                    Cargo = -1,
                    Name  = "All Mipmaps"
                });
                selectedMipmap       = AvailableMipmaps.Last();
                models.Export.Mipmap = selectedMipmap.Cargo;
            }

            // init available pixel data types
            var usedPixelTypes = new SortedSet <PixelDataType>();

            foreach (var format in usedFormat.Formats)
            {
                // exclude some formats for 3d export
                if (is3D && format.IsExcludedFrom3DExport())
                {
                    continue;
                }

                allFormats.Add(new ListItemViewModel <GliFormat>
                {
                    Cargo   = format,
                    Name    = format.ToString(),
                    ToolTip = format.GetDescription()
                });
                formatRatings.Add(stats.GetFormatRating(format, preferredFormat));
                usedPixelTypes.Add(format.GetDataType());
            }

            if (usedPixelTypes.Count > 1)
            {
                AvailableDataTypes.Add(new ListItemViewModel <PixelDataType>
                {
                    Cargo = PixelDataType.Undefined,
                    Name  = "All"
                });
            }
            var preferredPixelType = preferredFormat.GetDataType();

            foreach (var usedPixelType in usedPixelTypes)
            {
                AvailableDataTypes.Add(new ListItemViewModel <PixelDataType>
                {
                    Cargo   = usedPixelType,
                    Name    = usedPixelType.ToString(),
                    ToolTip = usedPixelType.GetDescription()
                });
                if (usedPixelType == preferredPixelType)
                {
                    SelectedDataType = AvailableDataTypes.Last();
                }
            }

            if (SelectedDataType == null)
            {
                SelectedDataType = AvailableDataTypes[0];
            }

            // assert that those were were set by SelectedDataType
            Debug.Assert(AvailableFormats != null);
            Debug.Assert(SelectedFormat != null);

            // enable quality
            if (extension == "jpg")
            {
                hasQualityValue       = true;
                nonSrgbExportWarnings = true;
            }
            else if (extension == "bmp")
            {
                nonSrgbExportWarnings = true;
            }
            else
            {
                SetKtxDdsQuality();
            }

            models.Export.PropertyChanged += ExportOnPropertyChanged;

            if (models.Export.CropEndX == 0 && models.Export.CropEndY == 0 && models.Export.CropEndZ == 0)
            {
                // assume cropping was not set
                SetMaxCropping();
            }
        }
Пример #4
0
        private void ExportOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            switch (args.PropertyName)
            {
            case nameof(ExportModel.UseCropping):
                OnPropertyChanged(nameof(UseCropping));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropStartX):
                OnPropertyChanged(nameof(CropStartX));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropStartY):
                OnPropertyChanged(nameof(CropStartY));
                OnPropertyChanged(nameof(CropEndY));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropStartZ):
                OnPropertyChanged(nameof(CropStartZ));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropEndX):
                OnPropertyChanged(nameof(CropEndX));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropEndY):
                OnPropertyChanged(nameof(CropEndY));
                OnPropertyChanged(nameof(CropStartY));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropEndZ):
                OnPropertyChanged(nameof(CropEndZ));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.Mipmap):
                if (models.Export.Mipmap < 0)
                {
                    selectedMipmap = AvailableMipmaps.Last();
                }
                else
                {
                    selectedMipmap = AvailableMipmaps[models.Export.Mipmap];
                }
                OnPropertyChanged(nameof(SelectedMipmap));
                OnPropertyChanged(nameof(UseCropping));
                OnPropertyChanged(nameof(CropMaxX));
                OnPropertyChanged(nameof(CropMaxY));
                OnPropertyChanged(nameof(CropMaxZ));
                // refit start and end since dimensions changed
                CropStartX = CropStartX;
                CropStartY = CropStartY;
                CropStartZ = CropStartZ;
                CropEndX   = CropEndX;
                CropEndY   = CropEndY;
                CropEndZ   = CropEndZ;
                // force change on y components because coordinate flipping
                OnPropertyChanged(nameof(CropStartY));
                OnPropertyChanged(nameof(CropEndY));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.Layer):
                if (models.Export.Layer < 0)
                {
                    selectedLayer = AvailableLayers.Last();
                }
                else
                {
                    selectedLayer = AvailableLayers[models.Export.Layer];
                }
                OnPropertyChanged(nameof(SelectedLayer));
                break;

            case nameof(ExportModel.Quality):
                OnPropertyChanged(nameof(Quality));
                break;
            }
        }
Пример #5
0
        private void ExportOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            switch (args.PropertyName)
            {
            case nameof(ExportModel.UseCropping):
                OnPropertyChanged(nameof(UseCropping));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropMinX):
                OnPropertyChanged(nameof(CropMinX));
                break;

            case nameof(ExportModel.CropMinY):
                OnPropertyChanged(nameof(CropMinY));
                break;

            case nameof(ExportModel.CropMaxX):
                OnPropertyChanged(nameof(CropMaxX));
                break;

            case nameof(ExportModel.CropMaxY):
                OnPropertyChanged(nameof(CropMaxY));
                break;

            case nameof(ExportModel.CropStartX):
                OnPropertyChanged(nameof(CropStartX));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropStartY):
                OnPropertyChanged(nameof(CropStartY));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropEndX):
                OnPropertyChanged(nameof(CropEndX));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.CropEndY):
                OnPropertyChanged(nameof(CropEndY));
                OnPropertyChanged(nameof(IsValid));
                break;

            case nameof(ExportModel.Mipmap):
                if (models.Export.Mipmap < 0)
                {
                    selectedMipmap = AvailableMipmaps.Last();
                }
                else
                {
                    selectedMipmap = AvailableMipmaps[models.Export.Mipmap];
                }
                OnPropertyChanged(nameof(SelectedMipmap));
                break;

            case nameof(ExportModel.Layer):
                if (models.Export.Layer < 0)
                {
                    selectedLayer = AvailableLayers.Last();
                }
                else
                {
                    selectedLayer = AvailableLayers[models.Export.Layer];
                }
                OnPropertyChanged(nameof(SelectedLayer));
                break;

            case nameof(ExportModel.Quality):
                OnPropertyChanged(nameof(Quality));
                break;

            case nameof(ExportModel.AllowCropping):
                OnPropertyChanged(nameof(AllowCropping));
                break;
            }
        }