From af7a2a7b63b4b3f706f3f1c9e6211b1ae4b4e369 Mon Sep 17 00:00:00 2001 From: "Stanislav Kuzmich [Art.Stea1th]" Date: Sat, 29 Apr 2017 19:22:43 +0300 Subject: [PATCH] add: #17 AppInfo, AcceptableTextBox, FormattedSlider, pixel perfect --- .../ASD.CellUniverse.Infrastructure.csproj | 15 ++- .../Algorithms/RandomMixer.cs | 4 +- .../Algorithms/TheGameOfLife.cs | 4 +- .../SettingsExtension.cs | 3 +- .../Controllers/ApplicationStateMachine.cs | 31 +++--- .../Extensions/Extensions.cs | 14 +++ .../Interfaces/IFrameSequenceGenerator.cs | 2 +- .../Interfaces/IMainController.cs | 10 +- .../Interfaces/IMatrix.cs | 15 +++ ...nerationAlgorithm.cs => IMatrixMutator.cs} | 4 +- .../Interfaces/ISeedGenerator.cs | 8 -- .../Properties/Settings.Designer.cs | 11 +- .../Properties/Settings.settings | 5 +- .../Services/FrameGenerationService.cs | 18 ++-- .../ASD.CellUniverse.Resources.csproj | 15 +++ .../Controls/AcceptableTextBox.cs | 51 ++++++++++ .../Controls/FormattedSlider.cs | 40 ++++++++ .../Converters.xaml} | 5 +- .../Extensions/Extensions.cs | 14 +++ .../Helpers/WriteableContext.cs | 7 +- .../ASD.CellUniverse.Resources/Resources.xaml | 7 ++ .../ASD.CellUniverse.Resources/Styles.xaml | 96 +++++++++++++++++- .../Themes/Generic.xaml | 57 +++++++++++ .../ASD.CellUniverse/ASD.CellUniverse.csproj | 2 +- Application/ASD.CellUniverse/App.xaml | 2 +- Application/ASD.CellUniverse/App.xaml.cs | 4 +- Application/ASD.CellUniverse/AppInfo.cs | 52 ++++++++++ Application/ASD.CellUniverse/Bootstrapper.cs | 9 -- Application/ASD.CellUniverse/Shell.xaml | 84 ++++++++++----- .../ViewModels/ShellViewModel.cs | 52 ++++++---- Screenshots/main.png | Bin 24575 -> 135518 bytes 31 files changed, 506 insertions(+), 135 deletions(-) rename Application/ASD.CellUniverse.Infrastructure/{Extensions => BindingExtensions}/SettingsExtension.cs (85%) create mode 100644 Application/ASD.CellUniverse.Infrastructure/Extensions/Extensions.cs create mode 100644 Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs rename Application/ASD.CellUniverse.Infrastructure/Interfaces/{IGenerationAlgorithm.cs => IMatrixMutator.cs} (52%) delete mode 100644 Application/ASD.CellUniverse.Infrastructure/Interfaces/ISeedGenerator.cs create mode 100644 Application/ASD.CellUniverse.Resources/Controls/AcceptableTextBox.cs create mode 100644 Application/ASD.CellUniverse.Resources/Controls/FormattedSlider.cs rename Application/{ASD.CellUniverse.Infrastructure/Resources.xaml => ASD.CellUniverse.Resources/Converters.xaml} (53%) create mode 100644 Application/ASD.CellUniverse.Resources/Resources.xaml create mode 100644 Application/ASD.CellUniverse.Resources/Themes/Generic.xaml create mode 100644 Application/ASD.CellUniverse/AppInfo.cs delete mode 100644 Application/ASD.CellUniverse/Bootstrapper.cs diff --git a/Application/ASD.CellUniverse.Infrastructure/ASD.CellUniverse.Infrastructure.csproj b/Application/ASD.CellUniverse.Infrastructure/ASD.CellUniverse.Infrastructure.csproj index 5e83939..b5d3109 100644 --- a/Application/ASD.CellUniverse.Infrastructure/ASD.CellUniverse.Infrastructure.csproj +++ b/Application/ASD.CellUniverse.Infrastructure/ASD.CellUniverse.Infrastructure.csproj @@ -79,11 +79,13 @@ - + + - + + - + @@ -94,14 +96,9 @@ True Settings.settings + - - - Designer - MSBuild:Compile - - SettingsSingleFileGenerator diff --git a/Application/ASD.CellUniverse.Infrastructure/Algorithms/RandomMixer.cs b/Application/ASD.CellUniverse.Infrastructure/Algorithms/RandomMixer.cs index 83180be..957607f 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Algorithms/RandomMixer.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Algorithms/RandomMixer.cs @@ -7,7 +7,7 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms { using Interfaces; using MVVM; - public class RandomMixer : BindableBase, IGenerationAlgorithm { + public class RandomMixer : BindableBase, IMatrixMutator { public string Name => "Random Mixer"; @@ -16,7 +16,7 @@ public class RandomMixer : BindableBase, IGenerationAlgorithm { private Random random; public RandomMixer() => random = new Random(); - public byte[,] GenerateNextBy(byte[,] prev) { + public byte[,] Mutate(byte[,] prev) { var next = new byte[prev.GetLength(0), prev.GetLength(1)]; diff --git a/Application/ASD.CellUniverse.Infrastructure/Algorithms/TheGameOfLife.cs b/Application/ASD.CellUniverse.Infrastructure/Algorithms/TheGameOfLife.cs index d69b642..5a63fff 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Algorithms/TheGameOfLife.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Algorithms/TheGameOfLife.cs @@ -9,13 +9,13 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms { using Interfaces; using MVVM; - public sealed class TheGameOfLife : BindableBase, IGenerationAlgorithm { + public sealed class TheGameOfLife : BindableBase, IMatrixMutator { public string Name => "The Game Of Life"; public override string ToString() => Name; - public byte[,] GenerateNextBy(byte[,] prev) { + public byte[,] Mutate(byte[,] prev) { return NextGeneration(prev); } diff --git a/Application/ASD.CellUniverse.Infrastructure/Extensions/SettingsExtension.cs b/Application/ASD.CellUniverse.Infrastructure/BindingExtensions/SettingsExtension.cs similarity index 85% rename from Application/ASD.CellUniverse.Infrastructure/Extensions/SettingsExtension.cs rename to Application/ASD.CellUniverse.Infrastructure/BindingExtensions/SettingsExtension.cs index 3893bb6..a8372ad 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Extensions/SettingsExtension.cs +++ b/Application/ASD.CellUniverse.Infrastructure/BindingExtensions/SettingsExtension.cs @@ -1,6 +1,7 @@ using System.Windows.Data; -namespace ASD.CellUniverse.Infrastructure.Extensions { + +namespace ASD.CellUniverse.Infrastructure.BindingExtensions { using Properties; diff --git a/Application/ASD.CellUniverse.Infrastructure/Controllers/ApplicationStateMachine.cs b/Application/ASD.CellUniverse.Infrastructure/Controllers/ApplicationStateMachine.cs index 920f6c2..012098e 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Controllers/ApplicationStateMachine.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Controllers/ApplicationStateMachine.cs @@ -6,24 +6,24 @@ namespace ASD.CellUniverse.Infrastructure.Controllers { using MVVM; using Interfaces; - public sealed class ApplicationStateMachine : BindableBase, IMainController { + public sealed class ApplicationStateMachine : BindableBase, IMainController { - private enum State { Started, Paused, Stopped } private object shared = new object(); - private State state; + public State State { get; private set; } private StateMachineCommand playCommand, pauseCommand, resumeCommand, stopCommand, resetCommand, dummyCommand; private StateMachineCommand playPauseResumeCommand, stopResetCommand; public event Action Started, Paused, Resumed, Stopped, Reseted; + public event Action StateChanged; - public ICommand PlayPauseResume { + public ICommand Start { get => playPauseResumeCommand; private set => SetProperty(ref playPauseResumeCommand, value as StateMachineCommand); } - public ICommand StopReset { + public ICommand Stop { get => stopResetCommand; private set => SetProperty(ref stopResetCommand, value as StateMachineCommand); } @@ -35,28 +35,28 @@ private void InitializeCommands() { playCommand = new StateMachineCommand( "PLAY", (o) => ChangeState(State.Started, pauseCommand, stopCommand, Started), - (o) => state == State.Stopped); + (o) => State == State.Stopped); pauseCommand = new StateMachineCommand( "PAUSE", (o) => ChangeState(State.Paused, resumeCommand, resetCommand, Paused), - (o) => state == State.Started); + (o) => State == State.Started); resumeCommand = new StateMachineCommand( "RESUME", (o) => ChangeState(State.Started, pauseCommand, stopCommand, Resumed), - (o) => state == State.Paused); + (o) => State == State.Paused); stopCommand = new StateMachineCommand( "STOP", (o) => ChangeState(State.Stopped, playCommand, dummyCommand, Stopped), - (o) => state == State.Started); + (o) => State == State.Started); resetCommand = new StateMachineCommand( "RESET", (o) => ChangeState(State.Stopped, playCommand, dummyCommand, Reseted), - (o) => state == State.Paused); + (o) => State == State.Paused); dummyCommand = new StateMachineCommand( "...", @@ -70,24 +70,25 @@ private void ChangeState( State newState, StateMachineCommand newPlayCommand, StateMachineCommand newStopCommand, Action onNewState) { lock (shared) { - state = newState; + State = newState; - PlayPauseResume = newPlayCommand; - StopReset = newStopCommand; + Start = newPlayCommand; + Stop = newStopCommand; onNewState?.Invoke(); + StateChanged?.Invoke(State); } } private class StateMachineCommand : RelayCommand { + internal string Name { get; } + public StateMachineCommand(string name, Action execute, Predicate canExecute) : base(execute, canExecute) { Name = name; } public override string ToString() => Name; - - internal string Name { get; } } } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Extensions/Extensions.cs b/Application/ASD.CellUniverse.Infrastructure/Extensions/Extensions.cs new file mode 100644 index 0000000..475d479 --- /dev/null +++ b/Application/ASD.CellUniverse.Infrastructure/Extensions/Extensions.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ASD.CellUniverse.Infrastructure.Extensions { + + public static partial class Extensions { + + + + } +} \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IFrameSequenceGenerator.cs b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IFrameSequenceGenerator.cs index 5ab31ab..346765c 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IFrameSequenceGenerator.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IFrameSequenceGenerator.cs @@ -13,7 +13,7 @@ public interface IFrameSequenceGenerator : INotifyPropertyChanged { double FPS { get; set; } DoubleCollection FPSCollection { get; } - IGenerationAlgorithm GenerationAlgorithm { get; set; } + IMatrixMutator GenerationAlgorithm { get; set; } byte[,] GeneratedData { get; set; } diff --git a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMainController.cs b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMainController.cs index 2976129..c4b618c 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMainController.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMainController.cs @@ -4,11 +4,17 @@ namespace ASD.CellUniverse.Infrastructure.Interfaces { + public enum State { Started, Paused, Stopped } + public interface IMainController : INotifyPropertyChanged { event Action Started, Paused, Resumed, Stopped, Reseted; - ICommand PlayPauseResume { get; } - ICommand StopReset { get; } + event Action StateChanged; + + State State { get; } + + ICommand Start { get; } + ICommand Stop { get; } } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs new file mode 100644 index 0000000..036099d --- /dev/null +++ b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ASD.CellUniverse.Infrastructure.Interfaces { + + interface IMatrix { + + int Width { get; } + int Height { get; } + + } +} \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IGenerationAlgorithm.cs b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrixMutator.cs similarity index 52% rename from Application/ASD.CellUniverse.Infrastructure/Interfaces/IGenerationAlgorithm.cs rename to Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrixMutator.cs index 09cb6cb..ddcbb34 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Interfaces/IGenerationAlgorithm.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrixMutator.cs @@ -1,10 +1,10 @@ namespace ASD.CellUniverse.Infrastructure.Interfaces { - public interface IGenerationAlgorithm { + public interface IMatrixMutator { string Name { get; } - byte[,] GenerateNextBy(byte[,] prev); + byte[,] Mutate(byte[,] prev); } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Interfaces/ISeedGenerator.cs b/Application/ASD.CellUniverse.Infrastructure/Interfaces/ISeedGenerator.cs deleted file mode 100644 index 7297495..0000000 --- a/Application/ASD.CellUniverse.Infrastructure/Interfaces/ISeedGenerator.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace ASD.CellUniverse.Infrastructure.Interfaces { - - public interface ISeedGenerator { // Future features: ISeed, IGenerationMode - - bool[,] Generate(int width, int height); - - } -} \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.Designer.cs b/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.Designer.cs index 30e1cc9..40c11dc 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.Designer.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.Designer.cs @@ -23,15 +23,6 @@ public static Settings Default { } } - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("CellUniverse: Space of the Cellular Machines")] - public string ShellTitle { - get { - return ((string)(this["ShellTitle"])); - } - } - [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("Normal")] @@ -46,7 +37,7 @@ public string ShellTitle { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("960")] + [global::System.Configuration.DefaultSettingValueAttribute("970")] public double ShellWidth { get { return ((double)(this["ShellWidth"])); diff --git a/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.settings b/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.settings index 5a3c68a..bd4e38f 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.settings +++ b/Application/ASD.CellUniverse.Infrastructure/Properties/Settings.settings @@ -2,14 +2,11 @@ - - CellUniverse: Space of the Cellular Machines - Normal - 960 + 970 540 diff --git a/Application/ASD.CellUniverse.Infrastructure/Services/FrameGenerationService.cs b/Application/ASD.CellUniverse.Infrastructure/Services/FrameGenerationService.cs index e9cc407..b5763d6 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Services/FrameGenerationService.cs +++ b/Application/ASD.CellUniverse.Infrastructure/Services/FrameGenerationService.cs @@ -12,13 +12,13 @@ public class FrameGenerationService : BindableBase, IFrameSequenceGenerator { private DispatcherTimer timer; - private double fps = 120.0; + private double fps; private DoubleCollection fpsCollection; - private IGenerationAlgorithm algorithm; + private IMatrixMutator algorithm; private byte[,] generatedData; - public double MinFPS => 1.0; + public double MinFPS => fpsCollection.First(); public double MaxFPS => fpsCollection.Last(); public double FPS { get => fps; @@ -29,7 +29,7 @@ public double FPS { } public DoubleCollection FPSCollection => fpsCollection; - public IGenerationAlgorithm GenerationAlgorithm { + public IMatrixMutator GenerationAlgorithm { get => algorithm; set => SetProperty(ref algorithm, value); } @@ -51,20 +51,22 @@ public IGenerationAlgorithm GenerationAlgorithm { public void Stop() { timer.Stop(); Reset(); } public void Reset() => GeneratedData = new byte[GeneratedData.GetLength(0), GeneratedData.GetLength(1)]; - public FrameGenerationService(IGenerationAlgorithm algorithm) { + public FrameGenerationService(IMatrixMutator algorithm) { fpsCollection = new DoubleCollection { 1.0, 2.0, 3.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 50.0, 60.0, 120.0 }; this.algorithm = algorithm; InitializeTimer(); + FPS = fpsCollection.Last(); } private void InitializeTimer() { timer = new DispatcherTimer(); timer.Tick += GenerateNext; - UpdateTimerInterval(); } - private void GenerateNext(object sender, EventArgs e) => GeneratedData = algorithm?.GenerateNextBy(generatedData); + private void GenerateNext(object sender, EventArgs e) => GeneratedData = algorithm?.Mutate(generatedData); private double ValidFps(double fps) => fps < MinFPS ? MinFPS : fps > MaxFPS ? MaxFPS : fps; - private void UpdateTimerInterval() => timer.Interval = TimeSpan.FromMilliseconds(1000.0 / fps); + private void UpdateTimerInterval() => timer.Interval = fps == fpsCollection.Last() + ? TimeSpan.FromTicks(1) + : TimeSpan.FromMilliseconds(1000.0 / ValidFps(fps)); } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/ASD.CellUniverse.Resources.csproj b/Application/ASD.CellUniverse.Resources/ASD.CellUniverse.Resources.csproj index 5da30f8..6caaa59 100644 --- a/Application/ASD.CellUniverse.Resources/ASD.CellUniverse.Resources.csproj +++ b/Application/ASD.CellUniverse.Resources/ASD.CellUniverse.Resources.csproj @@ -44,7 +44,10 @@ + + + @@ -55,10 +58,22 @@ + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + MSBuild:Compile Designer + + Designer + MSBuild:Compile + \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/Controls/AcceptableTextBox.cs b/Application/ASD.CellUniverse.Resources/Controls/AcceptableTextBox.cs new file mode 100644 index 0000000..84ca280 --- /dev/null +++ b/Application/ASD.CellUniverse.Resources/Controls/AcceptableTextBox.cs @@ -0,0 +1,51 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace ASD.CellUniverse.Resources.Controls { + + public sealed class AcceptableTextBox : TextBox { + + private string buffer = null; + + public object ToolTipInEdit { + get => GetValue(ToolTipInEditProperty); + set => SetValue(ToolTipInEditProperty, value); + } + + public static readonly DependencyProperty ToolTipInEditProperty = DependencyProperty.Register( + nameof(ToolTipInEdit), typeof(object), typeof(AcceptableTextBox), new FrameworkPropertyMetadata( + new object())); // { Content = "Press \"Enter\" to accept input or \"Esc\" to deny" } + + public AcceptableTextBox() { + AcceptsReturn = AcceptsTab = false; + MinLines = MaxLines = 1; + Focusable = false; + } + + static AcceptableTextBox() { + DefaultStyleKeyProperty.OverrideMetadata( + typeof(AcceptableTextBox), new FrameworkPropertyMetadata(typeof(AcceptableTextBox))); + } + + protected override sealed void OnMouseDoubleClick(MouseButtonEventArgs e) { + buffer = ((AcceptableTextBox)e.Source).Text; + Focusable = true; Focus(); SelectAll(); + } + + protected override void OnPreviewKeyDown(KeyEventArgs e) { + if (e.Key == Key.Enter) { + buffer = ((AcceptableTextBox)e.Source).Text; + } + if (e.Key == Key.Enter || e.Key == Key.Escape) { + MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); + e.Handled = true; + } + base.OnPreviewKeyDown(e); + } + + protected override sealed void OnLostFocus(RoutedEventArgs e) { + Text = buffer; Focusable = false; base.OnLostFocus(e); + } + } +} \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/Controls/FormattedSlider.cs b/Application/ASD.CellUniverse.Resources/Controls/FormattedSlider.cs new file mode 100644 index 0000000..1b1dc6c --- /dev/null +++ b/Application/ASD.CellUniverse.Resources/Controls/FormattedSlider.cs @@ -0,0 +1,40 @@ +using System.Reflection; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace ASD.CellUniverse.Resources.Controls { + + public sealed class FormattedSlider : Slider { + + private ToolTip autoToolTip; + + public string AutoToolTipFormat { get; set; } + + protected override void OnThumbDragStarted(DragStartedEventArgs e) { + base.OnThumbDragStarted(e); + FormatAutoToolTipContent(); + } + + protected override void OnThumbDragDelta(DragDeltaEventArgs e) { + base.OnThumbDragDelta(e); + FormatAutoToolTipContent(); + } + + private void FormatAutoToolTipContent() { + if (!string.IsNullOrEmpty(AutoToolTipFormat)) { + AutoToolTip.Content = string.Format(AutoToolTipFormat, AutoToolTip.Content); + } + } + + private ToolTip AutoToolTip { + get { + if (autoToolTip == null) { + FieldInfo field = typeof(Slider) + .GetField("_autoToolTip", BindingFlags.NonPublic | BindingFlags.Instance); + autoToolTip = field.GetValue(this) as ToolTip; + } + return autoToolTip; + } + } + } +} \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Infrastructure/Resources.xaml b/Application/ASD.CellUniverse.Resources/Converters.xaml similarity index 53% rename from Application/ASD.CellUniverse.Infrastructure/Resources.xaml rename to Application/ASD.CellUniverse.Resources/Converters.xaml index 825650e..97021a9 100644 --- a/Application/ASD.CellUniverse.Infrastructure/Resources.xaml +++ b/Application/ASD.CellUniverse.Resources/Converters.xaml @@ -1,4 +1,5 @@  - + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:cv="clr-namespace:ASD.CellUniverse.Resources.Converters"> + \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/Extensions/Extensions.cs b/Application/ASD.CellUniverse.Resources/Extensions/Extensions.cs index defd518..c7e14fd 100644 --- a/Application/ASD.CellUniverse.Resources/Extensions/Extensions.cs +++ b/Application/ASD.CellUniverse.Resources/Extensions/Extensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Reflection; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -50,5 +51,18 @@ public static void WriteSquares() { public static int CountX(this T[,] array2D) => array2D.GetLength(0); public static int CountY(this T[,] array2D) => array2D.GetLength(1); + + // ----- + + public static string ToReadable(this ProcessorArchitecture arch) { + switch (arch) { + case ProcessorArchitecture.MSIL: return "Any CPU"; + case ProcessorArchitecture.Amd64: return "x64"; + case ProcessorArchitecture.X86: return "x86"; + case ProcessorArchitecture.Arm: return "ARM"; + case ProcessorArchitecture.IA64: return "IA64"; + default: return "Unspecified"; + } + } } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/Helpers/WriteableContext.cs b/Application/ASD.CellUniverse.Resources/Helpers/WriteableContext.cs index 765b967..48b3209 100644 --- a/Application/ASD.CellUniverse.Resources/Helpers/WriteableContext.cs +++ b/Application/ASD.CellUniverse.Resources/Helpers/WriteableContext.cs @@ -16,9 +16,9 @@ internal WriteableContext(WriteableBitmap bitmap) { } public void Dispose() { - //if (rangeChanged) { - // bitmap.AddDirtyRect(new Int32Rect(X.min, Y.min, X.max - X.min + 1, Y.max - Y.min + 1)); - //} + if (rangeChanged) { + bitmap.AddDirtyRect(new Int32Rect(X.min, Y.min, X.max - X.min + 1, Y.max - Y.min + 1)); + } bitmap.Unlock(); } @@ -54,7 +54,6 @@ internal unsafe void WriteRect(int posX, int posY, int width, int height, Color this[x, y] = color; } } - bitmap.AddDirtyRect(new Int32Rect(posX, posY, width, height)); } internal unsafe void WriteRectSequence(IEnumerable<(int x, int y)> sequence, int rectSize, Color color) { diff --git a/Application/ASD.CellUniverse.Resources/Resources.xaml b/Application/ASD.CellUniverse.Resources/Resources.xaml new file mode 100644 index 0000000..689398a --- /dev/null +++ b/Application/ASD.CellUniverse.Resources/Resources.xaml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Application/ASD.CellUniverse.Resources/Styles.xaml b/Application/ASD.CellUniverse.Resources/Styles.xaml index 5a82e29..c5f50e7 100644 --- a/Application/ASD.CellUniverse.Resources/Styles.xaml +++ b/Application/ASD.CellUniverse.Resources/Styles.xaml @@ -1,18 +1,106 @@  + xmlns:s="clr-namespace:System;assembly=mscorlib"> - 140 + 152 28 - 8,0,8,8 - 8,8,8,0 + 6,0,6,6 + 4,0,4,4 + + 6,6,6,0 + 4,4,4,0 + + 6 + 4 + + + diff --git a/Application/ASD.CellUniverse.Resources/Themes/Generic.xaml b/Application/ASD.CellUniverse.Resources/Themes/Generic.xaml new file mode 100644 index 0000000..b4590a9 --- /dev/null +++ b/Application/ASD.CellUniverse.Resources/Themes/Generic.xaml @@ -0,0 +1,57 @@ + + + + + \ No newline at end of file diff --git a/Application/ASD.CellUniverse/ASD.CellUniverse.csproj b/Application/ASD.CellUniverse/ASD.CellUniverse.csproj index a43315b..52548f3 100644 --- a/Application/ASD.CellUniverse/ASD.CellUniverse.csproj +++ b/Application/ASD.CellUniverse/ASD.CellUniverse.csproj @@ -87,7 +87,7 @@ MSBuild:Compile Designer - + MSBuild:Compile diff --git a/Application/ASD.CellUniverse/App.xaml b/Application/ASD.CellUniverse/App.xaml index b0780c8..2ef8bca 100644 --- a/Application/ASD.CellUniverse/App.xaml +++ b/Application/ASD.CellUniverse/App.xaml @@ -5,7 +5,7 @@ - + diff --git a/Application/ASD.CellUniverse/App.xaml.cs b/Application/ASD.CellUniverse/App.xaml.cs index 138fa45..c2ce0a1 100644 --- a/Application/ASD.CellUniverse/App.xaml.cs +++ b/Application/ASD.CellUniverse/App.xaml.cs @@ -7,8 +7,6 @@ namespace ASD.CellUniverse { public partial class App : Application { - public App() { - Exit += (s, e) => Settings.Default.Save(); - } + public App() => Exit += (s, e) => Settings.Default.Save(); } } \ No newline at end of file diff --git a/Application/ASD.CellUniverse/AppInfo.cs b/Application/ASD.CellUniverse/AppInfo.cs new file mode 100644 index 0000000..c26dae2 --- /dev/null +++ b/Application/ASD.CellUniverse/AppInfo.cs @@ -0,0 +1,52 @@ +using System.Reflection; + +namespace ASD.CellUniverse { + + internal struct AppInfo { + + public static readonly string Name; + public static readonly string ProcessorArchitecture; + public static readonly string MajorVersion; + public static readonly string MinorVersion; + public static readonly string Build; + public static readonly string Revision; + + static AppInfo() { + + var assembly = Assembly.GetExecutingAssembly(); + var name = assembly.GetName(); + var version = name.Version; + + Name = assembly.GetCustomAttribute().Title; + + ProcessorArchitecture = name.ProcessorArchitecture.ToReadable(); + + MajorVersion = version.Major.ToString(); + MinorVersion = version.Minor.ToString(); + Build = version.Build.ToString(); + Revision = version.Revision.ToString(); + } + + public static string ToString(string format = null) { + if (string.IsNullOrWhiteSpace(format)) { + return $"{Name} ({ProcessorArchitecture}) - v.{MajorVersion}.{MinorVersion}, build {Build}, rev. {Revision}"; + } + return string.Format(format, Name, ProcessorArchitecture, MajorVersion, MinorVersion, Build, Revision); + } + } + + internal static partial class Extensions { + + public static string ToReadable(this ProcessorArchitecture arch) { + + switch (arch) { + case ProcessorArchitecture.MSIL: return "Any CPU"; + case ProcessorArchitecture.Amd64: return "x64"; + case ProcessorArchitecture.X86: return "x86"; + case ProcessorArchitecture.Arm: return "ARM"; + case ProcessorArchitecture.IA64: return "IA64"; + default: return "Unspecified"; + } + } + } +} \ No newline at end of file diff --git a/Application/ASD.CellUniverse/Bootstrapper.cs b/Application/ASD.CellUniverse/Bootstrapper.cs deleted file mode 100644 index 1673ceb..0000000 --- a/Application/ASD.CellUniverse/Bootstrapper.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Configuration; -using System.Windows; - -namespace ASD.CellUniverse { - - internal sealed class Bootstrapper { - - } -} \ No newline at end of file diff --git a/Application/ASD.CellUniverse/Shell.xaml b/Application/ASD.CellUniverse/Shell.xaml index f4e5bc0..3dfec74 100644 --- a/Application/ASD.CellUniverse/Shell.xaml +++ b/Application/ASD.CellUniverse/Shell.xaml @@ -3,8 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:ASD.CellUniverse.Resources.Controls;assembly=ASD.CellUniverse.Resources" xmlns:vm="clr-namespace:ASD.CellUniverse.ViewModels" - xmlns:app="clr-namespace:ASD.CellUniverse.Infrastructure.Extensions;assembly=ASD.CellUniverse.Infrastructure" - Title="{app:Settings ShellTitle, Mode=OneWay}" + xmlns:app="clr-namespace:ASD.CellUniverse.Infrastructure.BindingExtensions;assembly=ASD.CellUniverse.Infrastructure" + Title="{Binding Title}" WindowState="{app:Settings ShellState}" Width="{app:Settings ShellWidth}" Height="{app:Settings ShellHeight}" @@ -18,7 +18,7 @@ - + @@ -36,37 +36,65 @@ - - - - - - - - + + + + - + AutoToolTipPlacement="BottomRight" + AutoToolTipFormat="{}{0} FPS"/> + + + + + + + + + + + + + +