diff --git a/WallpaperMaker.Avalonia/MainWindow.axaml b/WallpaperMaker.Avalonia/MainWindow.axaml index ae2e390..6a89dbe 100644 --- a/WallpaperMaker.Avalonia/MainWindow.axaml +++ b/WallpaperMaker.Avalonia/MainWindow.axaml @@ -39,6 +39,20 @@ + + + + + + + + + + + + + diff --git a/WallpaperMaker.Avalonia/MainWindow.axaml.cs b/WallpaperMaker.Avalonia/MainWindow.axaml.cs index 14afbc7..1429ef7 100644 --- a/WallpaperMaker.Avalonia/MainWindow.axaml.cs +++ b/WallpaperMaker.Avalonia/MainWindow.axaml.cs @@ -25,6 +25,8 @@ public partial class MainWindow : Window private Pallet? _activePalette; private SKBitmap? _lastBitmap; private WallpaperConfig _config = WallpaperConfig.CreateDefault(); + private Pallet? _presetGeneratedPalette; // Cached preset-matched palette + private bool _usePresetColors = false; // Toggle state private const string DefaultPalletJson = """ { @@ -92,10 +94,21 @@ private void InitFormElements() _pallets.AddRange(Utilities.UnpackExternalColorPallets()); RefreshPaletteComboBox(); + RefreshStylePresetComboBox(); DetectResolution(); UpdateMultisamplingList(); } + private void RefreshStylePresetComboBox() + { + CbStyle.Items.Clear(); + foreach (var preset in StylePresets.All) + CbStyle.Items.Add(preset); + + if (StylePresets.All.Count > 0) + CbStyle.SelectedIndex = 0; + } + private void DetectResolution() { var screen = Screens.ScreenFromWindow(this) ?? Screens.Primary; @@ -182,12 +195,31 @@ private async void BtnGenerate_Click(object? sender, RoutedEventArgs e) _lastBitmap?.Dispose(); _lastBitmap = await Task.Run(() => { - using var gen = new Generator(_activePalette, w, h, ms, _config); + // Select the appropriate palette based on toggle state + Pallet paletteToUse = (_usePresetColors && _presetGeneratedPalette != null) + ? _presetGeneratedPalette + : _activePalette!; + + using var gen = new Generator(paletteToUse, w, h, ms, _config); return gen.Generate(_config); }); ImgPreview.Source = SKBitmapToAvaloniaBitmap(_lastBitmap); - TxtStatus.Text = $"Generated {w}x{h} wallpaper."; + + // Score the generated wallpaper + int qualityScore = QualityScorer.ScoreWallpaper(_lastBitmap, _activePalette, _config); + var report = QualityScorer.GenerateReport(_lastBitmap, _activePalette, _config); + + // Format status with quality score + string scoreIndicator = qualityScore switch + { + >= 75 => "Excellent", + >= 60 => "Good", + >= 50 => "Fair", + _ => "Below Average" + }; + + TxtStatus.Text = $"Generated {w}x{h} wallpaper. Quality: {scoreIndicator} ({qualityScore}/100)"; } catch (Exception ex) { @@ -296,6 +328,67 @@ private void CbPalette_SelectionChanged(object? sender, SelectionChangedEventArg _activePalette = item.Pallet; } + private void CbStyle_SelectionChanged(object? sender, SelectionChangedEventArgs e) + { + if (CbStyle.SelectedItem is StylePreset preset) + { + // Apply the preset's configuration + _config = new WallpaperConfig + { + Background = preset.Config.Background, + ShapeFill = preset.Config.ShapeFill, + MinOpacity = preset.Config.MinOpacity, + MaxOpacity = preset.Config.MaxOpacity, + EnableStrokes = preset.Config.EnableStrokes, + StrokeWidth = preset.Config.StrokeWidth, + SaturationLevel = preset.RecommendedSaturation, + ApplyQualityConstraints = preset.Config.ApplyQualityConstraints, + MinimumBackgroundShapeContrast = preset.Config.MinimumBackgroundShapeContrast, + BackgroundTone = preset.Config.BackgroundTone, + Shapes = new List(preset.Config.Shapes) + }; + + // Auto-generate a harmonically appropriate palette + _presetGeneratedPalette = preset.Config.BackgroundTone == BackgroundTone.PreferDark + ? ColorTheory.GenerateDarkAccentPalette($"Auto: {preset.Name}") + : ColorTheory.GeneratePaletteWithConstraints( + preset.RecommendedHarmony, + $"Auto: {preset.Name}", + preset.RecommendedSaturation); + + // Set default to use preset colors + _activePalette = _presetGeneratedPalette; + _usePresetColors = true; + + // Enable and check the toggle + if (ChkUsePresetColors != null) + { + ChkUsePresetColors.IsEnabled = true; + ChkUsePresetColors.IsChecked = true; + } + + TxtStatus.Text = $"Loaded style: {preset.Name} — using preset-matched colors"; + } + else + { + // No preset selected, disable the toggle + if (ChkUsePresetColors != null) + ChkUsePresetColors.IsEnabled = false; + } + } + + private void ChkUsePresetColors_Checked(object? sender, RoutedEventArgs e) + { + _usePresetColors = true; + TxtStatus.Text = "Using preset-matched colors for generation"; + } + + private void ChkUsePresetColors_Unchecked(object? sender, RoutedEventArgs e) + { + _usePresetColors = false; + TxtStatus.Text = "Using selected palette (preset shapes only)"; + } + private static Bitmap SKBitmapToAvaloniaBitmap(SKBitmap skBitmap) { using var image = SKImage.FromBitmap(skBitmap); diff --git a/WallpaperMaker.Avalonia/SettingsWindow.axaml b/WallpaperMaker.Avalonia/SettingsWindow.axaml index 1a57bc5..bd48bab 100644 --- a/WallpaperMaker.Avalonia/SettingsWindow.axaml +++ b/WallpaperMaker.Avalonia/SettingsWindow.axaml @@ -49,12 +49,6 @@ - - - - - -