From d8dbf199d44f01f702f7453c5df28f700d5d2433 Mon Sep 17 00:00:00 2001 From: Robert Beekman Date: Tue, 19 Jan 2016 17:00:01 +0100 Subject: [PATCH] Added missing files --- .gitignore | 5 - .../Modules/Effects/Debug/DebugEffectModel.cs | 64 +++++++++ .../Effects/Debug/DebugEffectSettings.cs | 37 +++++ .../Effects/Debug/DebugEffectView.xaml | 113 ++++++++++++++++ .../Effects/Debug/DebugEffectView.xaml.cs | 15 +++ .../Effects/Debug/DebugEffectViewModel.cs | 127 ++++++++++++++++++ 6 files changed, 356 insertions(+), 5 deletions(-) create mode 100644 Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs create mode 100644 Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs create mode 100644 Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml create mode 100644 Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml.cs create mode 100644 Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs diff --git a/.gitignore b/.gitignore index 57a1574c4..5115c12d8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,6 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ @@ -33,8 +30,6 @@ bld/ *.VisualState.xml TestResult.xml -# Build Results of an ATL Project -[Dd]ebugPS/ [Rr]eleasePS/ dlldata.c diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs new file mode 100644 index 000000000..002707de5 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using Artemis.Models; +using Artemis.Utilities.Keyboard; + +namespace Artemis.Modules.Effects.Debug +{ + internal class DebugEffectModel : EffectModel + { + public DebugEffectModel(DebugEffectSettings settings) + { + Name = "Debug Effect"; + Settings = settings; + Scale = 4; + + KeyboardRectangle = new KeyboardRectangle(Scale, 0, 0, 21, 6, + new List + { + Color.Red, + Color.OrangeRed, + Color.Yellow, + Color.Green, + Color.Blue, + Color.Purple, + Color.DeepPink + }, LinearGradientMode.Horizontal); + } + + public int Scale { get; set; } + + public DebugEffectSettings Settings { get; set; } + + public KeyboardRectangle KeyboardRectangle { get; set; } + + public override void Dispose() + { + } + + public override void Enable() + { + } + + public override void Update() + { + KeyboardRectangle.Height = Settings.Height; + KeyboardRectangle.Width = Settings.Width; + //KeyboardRectangle.GradientMode = Settings.Type; + KeyboardRectangle.Rotate = Settings.Rotate; + } + + public override Bitmap GenerateBitmap() + { + var bitmap = new Bitmap(21*Scale, 6*Scale); + + using (var g = Graphics.FromImage(bitmap)) + { + g.Clear(Color.Transparent); + KeyboardRectangle.Draw(g); + } + return bitmap; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs new file mode 100644 index 000000000..668c2ad76 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs @@ -0,0 +1,37 @@ +using System.Drawing.Drawing2D; +using Artemis.Models; + +namespace Artemis.Modules.Effects.Debug +{ + internal class DebugEffectSettings : EffectSettings + { + public DebugEffectSettings() + { + Load(); + } + + public int Width { get; set; } + public int Height { get; set; } + public int Spread { get; set; } + public bool Rotate { get; set; } + public LinearGradientMode Type { get; set; } + + public override sealed void Load() + { + ToDefault(); + } + + public override sealed void Save() + { + } + + public override sealed void ToDefault() + { + Width = 6; + Height = 100; + Spread = 0; + Type = LinearGradientMode.Horizontal; + Rotate = false; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml new file mode 100644 index 000000000..9c8dbad20 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml.cs new file mode 100644 index 000000000..289ffdcd2 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace Artemis.Modules.Effects.Debug +{ + /// + /// Interaction logic for DebugEffectView.xaml + /// + public partial class DebugEffectView : UserControl + { + public DebugEffectView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs new file mode 100644 index 000000000..cdcfdbfcd --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectViewModel.cs @@ -0,0 +1,127 @@ +using System; +using System.Drawing.Drawing2D; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Artemis.Events; +using Artemis.Models; +using Caliburn.Micro; + +namespace Artemis.Modules.Effects.Debug +{ + internal class DebugEffectViewModel : Screen, IHandle, IHandle + { + private DebugEffectSettings _debugEffectSettings; + private ImageSource _imageSource; + private string _selectedRectangleType; + + public DebugEffectViewModel(MainModel mainModel) + { + // Subscribe to main model + MainModel = mainModel; + MainModel.Events.Subscribe(this); + + // Settings are loaded from file by class + DebugEffectSettings = new DebugEffectSettings(); + + // Create effect model and add it to MainModel + DebugEffectModel = new DebugEffectModel(DebugEffectSettings); + MainModel.EffectModels.Add(DebugEffectModel); + } + + public MainModel MainModel { get; set; } + public DebugEffectModel DebugEffectModel { get; set; } + + public static string Name => "Type Waves"; + public bool EffectEnabled => MainModel.IsEnabled(DebugEffectModel); + + public DebugEffectSettings DebugEffectSettings + { + get { return _debugEffectSettings; } + set + { + if (Equals(value, _debugEffectSettings)) return; + _debugEffectSettings = value; + NotifyOfPropertyChange(() => DebugEffectSettings); + + SelectedRectangleType = value.Type.ToString(); + } + } + + public BindableCollection RectangleTypes + => new BindableCollection(Enum.GetNames(typeof (LinearGradientMode))); + + public string SelectedRectangleType + { + get { return _selectedRectangleType; } + set + { + if (value == _selectedRectangleType) return; + _selectedRectangleType = value; + NotifyOfPropertyChange(() => SelectedRectangleType); + + DebugEffectSettings.Type = (LinearGradientMode) Enum.Parse(typeof (LinearGradientMode), value); + } + } + + public ImageSource ImageSource + { + get { return _imageSource; } + set + { + _imageSource = value; + NotifyOfPropertyChange(() => ImageSource); + } + } + + public void Handle(ChangeActiveEffect message) + { + NotifyOfPropertyChange(() => EffectEnabled); + } + + public void Handle(ChangeBitmap message) + { + //// Doesn't show transparancy + //using (var memory = new MemoryStream()) + //{ + // message.Bitmap.Save(memory, ImageFormat.Bmp); + // memory.Position = 0; + + // var bitmapImage = new BitmapImage(); + // bitmapImage.BeginInit(); + // bitmapImage.StreamSource = memory; + // bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + // bitmapImage.EndInit(); + + // ImageSource = bitmapImage; + //} + + // Causes "Generic GDI+ Exception" after a while + try + { + ImageSource = Imaging.CreateBitmapSourceFromHBitmap( + message.Bitmap.GetHbitmap(), + IntPtr.Zero, + Int32Rect.Empty, + BitmapSizeOptions.FromEmptyOptions()); + } + catch (Exception) + { + // ignored + } + } + + public void ToggleEffect() + { + MainModel.EnableEffect(DebugEffectModel); + } + + public void ResetSettings() + { + // TODO: Confirmation dialog (Generic MVVM approach) + DebugEffectSettings.ToDefault(); + NotifyOfPropertyChange(() => DebugEffectSettings); + } + } +} \ No newline at end of file