Skip to content

Commit

Permalink
Merge pull request #31 from atticus-lv/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
atticus-lv authored Dec 8, 2024
2 parents 932f35b + 099432e commit c03f7b0
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/VirtualStreetSnap/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
<StyleInclude Source="avares://VirtualStreetSnap/Assets/Icons.axaml" />
</Application.Styles>
</Application>
6 changes: 5 additions & 1 deletion src/VirtualStreetSnap/Assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@
"InvalidFileFormat": "Invalid File Format",
"LoadingImage": "Loading Image...",
"LoadingView": "Loading View...",
"Curve": "Curve"
"Curve": "Curve",
"BorderColor": "Border Color",
"CommonSettings": "Common Settings",
"BorderThickness": "Border Thickness",
"BorderSettings": "Border Settings"
}
6 changes: 5 additions & 1 deletion src/VirtualStreetSnap/Assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@
"InvalidFileFormat": "无效的文件格式",
"LoadingImage": "加载图像...",
"LoadingView": "加载视图...",
"Curve": "曲线"
"Curve": "曲线",
"BorderColor": "边框颜色",
"CommonSettings": "常规设置",
"BorderThickness": "边框厚度",
"BorderSettings": "边框设置"
}
32 changes: 32 additions & 0 deletions src/VirtualStreetSnap/Controls/SettingsCard.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:VirtualStreetSnap.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="VirtualStreetSnap.Controls.SettingsCard">
<ContentControl.Styles>
<Style Selector="controls|SettingsCard">
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="4" Opacity="1" OffsetX="0" OffsetY="0" />
</Border.Effect>
<Grid ColumnDefinitions="150,*,Auto">
<TextBlock Margin="10 5 0 5"
VerticalAlignment="Center"
Text="{TemplateBinding SettingName}"
FontSize="{TemplateBinding FontSize}">
</TextBlock>
<ContentPresenter Grid.Column="2" Margin="0 5 10 5"
VerticalContentAlignment="Center" VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>
</ContentControl.Styles>
</UserControl>
27 changes: 27 additions & 0 deletions src/VirtualStreetSnap/Controls/SettingsCard.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace VirtualStreetSnap.Controls;

public partial class SettingsCard : ContentControl
{
public static readonly StyledProperty<string> SettingNameProperty =
AvaloniaProperty.Register<SettingsCard, string>(nameof(SettingName));

public string SettingName
{
get { return GetValue(SettingNameProperty); }
set { SetValue(SettingNameProperty, value); }
}

public SettingsCard()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
35 changes: 34 additions & 1 deletion src/VirtualStreetSnap/Models/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Avalonia.Media;

namespace VirtualStreetSnap.Models;

Expand Down Expand Up @@ -30,7 +31,39 @@ protected virtual void OnPropertyChanged(string propertyName)
public class Overlays
{
public required Guides Guides { get; set; }
public bool Focus { get; set; } = true;
public bool ShowFocusBorder { get; set; } = true;
private int _focusBorderThickness = 10;

public int FocusBorderThickness
{
get => _focusBorderThickness;
set
{
if (_focusBorderThickness == value) return;
_focusBorderThickness = value;
OnPropertyChanged(nameof(FocusBorderThickness));
}
}

private Color _focusBorderColor = Colors.Brown;

public Color FocusBorderColor
{
get => _focusBorderColor;
set
{
if (_focusBorderColor == value) return;
_focusBorderColor = value;
OnPropertyChanged(nameof(FocusBorderColor));
}
}

public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

public class Guides
Expand Down
57 changes: 55 additions & 2 deletions src/VirtualStreetSnap/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Avalonia;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace VirtualStreetSnap;

Expand All @@ -9,13 +12,63 @@ sealed class Program
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static void Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener("VirtualStreetSnap.log"));
Trace.AutoFlush = true;
TextWriter originalConsoleOutput = Console.Out;
MultiTextWriter multiTextWriter = new MultiTextWriter(originalConsoleOutput, new TraceTextWriter());
Console.SetOut(multiTextWriter);

BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}

public class MultiTextWriter : TextWriter
{
private readonly TextWriter _consoleWriter;
private readonly TextWriter _traceWriter;

public MultiTextWriter(TextWriter consoleWriter, TextWriter traceWriter)
{
_consoleWriter = consoleWriter;
_traceWriter = traceWriter;
}

public override Encoding Encoding => Encoding.UTF8;

public override void WriteLine(string value)
{
_consoleWriter.WriteLine(value);
_traceWriter.WriteLine(value);
}

public override void Write(string value)
{
_consoleWriter.Write(value);
_traceWriter.Write(value);
}
}

public class TraceTextWriter : TextWriter
{
public override Encoding Encoding => Encoding.UTF8;

public override void WriteLine(string value)
{
Trace.WriteLine(value);
}

public override void Write(string value)
{
Trace.Write(value);
}
}
2 changes: 1 addition & 1 deletion src/VirtualStreetSnap/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static AppConfig NewDefaultConfig()
Ratio = false,
Opacity = 0.5f
},
Focus = true
ShowFocusBorder = true
}
};
}
Expand Down
18 changes: 16 additions & 2 deletions src/VirtualStreetSnap/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using VirtualStreetSnap.Models;
using VirtualStreetSnap.Services;
Expand All @@ -14,14 +15,20 @@ public partial class SettingsViewModel : ViewModelBase
{
[ObservableProperty]
private AppConfig _config = ConfigService.Instance;

[ObservableProperty]
private string _appVersion = "Unknown";


[ObservableProperty]
private string _filePrefix = "IMG";

[ObservableProperty]
private Color _focusBorderColor = Colors.Brown;

[ObservableProperty]
private int _focusBorderThickness = 10;

[ObservableProperty]
private LanguageModel _selectedLanguage;

Expand All @@ -41,11 +48,14 @@ public SettingsViewModel()
FilePrefix = Config.Settings.FilePrefix;
SelectedLanguage = LanguageModels.FirstOrDefault(x => x.Identifier == Config.Settings.Language) ??
LanguageModels.First();
FocusBorderColor = Config.Overlays.FocusBorderColor;
FocusBorderThickness = Config.Overlays.FocusBorderThickness;
// Set the default values if the config is not existing
ConfigService.SaveConfig();
GetFileVersion();
}



public void GetFileVersion()
{
var exeDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
Expand All @@ -56,6 +66,10 @@ public void GetFileVersion()
if (version == null) return;
AppVersion = version;
}

partial void OnFocusBorderColorChanged(Color value) => Config.Overlays.FocusBorderColor = value;

partial void OnFocusBorderThicknessChanged(int value) => Config.Overlays.FocusBorderThickness = value;

partial void OnSelectedLanguageChanged(LanguageModel value)
{
Expand Down
36 changes: 33 additions & 3 deletions src/VirtualStreetSnap/ViewModels/SnapShotViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using CommunityToolkit.Mvvm.ComponentModel;
using VirtualStreetSnap.Models;
using VirtualStreetSnap.Services;
Expand All @@ -24,8 +27,22 @@ public partial class SnapShotViewModel : ViewModelBase
[ObservableProperty]
private float _guideLinesOpacity = 0.5f;

[ObservableProperty]
private Color _borderColor = Colors.Brown;

private Thickness _focusBorderThickness;

public Thickness FocusBorderThickness
{
get => _focusBorderThickness;
private set => SetProperty(ref _focusBorderThickness, value);
}

private IImmutableSolidColorBrush _focusFocusBorderBrush;

public IImmutableSolidColorBrush FocusBorderBrush
{
get => _focusFocusBorderBrush;
private set => SetProperty(ref _focusFocusBorderBrush, value);
}

[ObservableProperty]
private SizeRatio? _selectedSizeRatio;
Expand Down Expand Up @@ -64,6 +81,19 @@ public SnapShotViewModel()
ShowGuideLinesGrid = Config.Overlays.Guides.Grid;
ShowGuideLinesCenter = Config.Overlays.Guides.Center;
ShowGuideLinesRatio = Config.Overlays.Guides.Ratio;
ShowFocusBorder = Config.Overlays.Focus;
ShowFocusBorder = Config.Overlays.ShowFocusBorder;
var thickness = Config.Overlays.FocusBorderThickness;
FocusBorderThickness = new Thickness(thickness);
FocusBorderBrush = new ImmutableSolidColorBrush(Config.Overlays.FocusBorderColor);

Config.Overlays.PropertyChanged += OnOverlaysPropertyChanged;
}

private void OnOverlaysPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Config.Overlays.FocusBorderColor))
FocusBorderBrush = new ImmutableSolidColorBrush(Config.Overlays.FocusBorderColor);
else if (e.PropertyName == nameof(Config.Overlays.FocusBorderThickness))
FocusBorderThickness = new Thickness(Config.Overlays.FocusBorderThickness);
}
}
Loading

0 comments on commit c03f7b0

Please sign in to comment.