From 6ea7c4beba05865bc65ed6b93e6da86dd767233c Mon Sep 17 00:00:00 2001 From: Nico Jeske Date: Fri, 15 Mar 2019 18:05:04 +0100 Subject: [PATCH] Added a real Ambilight mode. --- Ambilight/App.config | 3 ++ Ambilight/GUI/TraySettings.cs | 14 +++++ Ambilight/Logic/KeyboardLogic.cs | 30 ++++++----- Ambilight/Logic/MouseLogic.cs | 13 ++++- Ambilight/Logic/MousePadLogic.cs | 66 +++++++++++++++++------ Ambilight/Properties/AssemblyInfo.cs | 4 +- Ambilight/Properties/Settings.Designer.cs | 22 ++++++-- Ambilight/Properties/Settings.settings | 3 ++ 8 files changed, 119 insertions(+), 36 deletions(-) diff --git a/Ambilight/App.config b/Ambilight/App.config index 074f1d6..17fc9a1 100644 --- a/Ambilight/App.config +++ b/Ambilight/App.config @@ -31,6 +31,9 @@ -1 + + False + diff --git a/Ambilight/GUI/TraySettings.cs b/Ambilight/GUI/TraySettings.cs index 6cca910..494ffdf 100644 --- a/Ambilight/GUI/TraySettings.cs +++ b/Ambilight/GUI/TraySettings.cs @@ -24,6 +24,8 @@ public class TraySettings public bool KeyboardEnabledBool { get; private set; } public bool MouseEnabledBool { get; private set; } public bool PadEnabledBool { get; private set; } + + public bool AmbiModeBool { get; private set; } private readonly Logger logger = LogManager.GetCurrentClassLogger(); @@ -110,12 +112,22 @@ private void InitializeTray() Properties.Settings.Default.Save(); }); + MenuItem _ambiModeEnabled = new MenuItem("'Real' Ambilight mode", (sender, args) => + { + EnableMenuItemOnClick(sender, args); + Properties.Settings.Default.ambiEnabled = (sender as MenuItem).Checked; + AmbiModeBool = (sender as MenuItem).Checked; + Properties.Settings.Default.Save(); + }); + _keyboardEnabled.Checked = Properties.Settings.Default.keyboardEnabled; KeyboardEnabledBool = Properties.Settings.Default.keyboardEnabled; _mouseEnabled.Checked = Properties.Settings.Default.mouseEnabled; MouseEnabledBool = Properties.Settings.Default.mouseEnabled; _mousematEnabled.Checked = Properties.Settings.Default.mousematEnabled; PadEnabledBool = Properties.Settings.Default.mousematEnabled; + _ambiModeEnabled.Checked = Properties.Settings.Default.ambiEnabled; + AmbiModeBool = Properties.Settings.Default.ambiEnabled; var components = new System.ComponentModel.Container(); @@ -125,6 +137,8 @@ private void InitializeTray() contextMenu.MenuItems.Add("Change Saturation", ChangeSaturationHandler); contextMenu.MenuItems.Add("Set Manual keyboard size", changeKeyboardSizeHandler); contextMenu.MenuItems.Add("-"); + contextMenu.MenuItems.Add(_ambiModeEnabled); + contextMenu.MenuItems.Add("-"); contextMenu.MenuItems.Add(_keyboardEnabled); contextMenu.MenuItems.Add(_mouseEnabled); diff --git a/Ambilight/Logic/KeyboardLogic.cs b/Ambilight/Logic/KeyboardLogic.cs index 2120e64..b82453a 100644 --- a/Ambilight/Logic/KeyboardLogic.cs +++ b/Ambilight/Logic/KeyboardLogic.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; +using Corale.Colore.Core; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Corale; -using Corale.Colore.Core; -using KeyboardCustom = Corale.Colore.Razer.Keyboard.Effects.Custom; using ColoreColor = Corale.Colore.Core.Color; +using KeyboardCustom = Corale.Colore.Razer.Keyboard.Effects.Custom; namespace Ambilight.Logic @@ -47,16 +41,26 @@ internal void Process(Bitmap newImage) /// EffectGrid private KeyboardCustom GenerateKeyboardGrid(Bitmap map, KeyboardCustom keyboardGrid) { + + //Iterating over each key and set it to the corrosponding color of the resized Screenshot + for (var r = 0; r < settings.KeyboardHeight; r++) - { - for (var c = 0; c < settings.KeyboardWidth; c++) { - System.Drawing.Color color = map.GetPixel(c, r); + for (var c = 0; c < settings.KeyboardWidth; c++) + { + System.Drawing.Color color; + + if (settings.AmbiModeBool) + color = map.GetPixel(c, settings.KeyboardHeight - 1); + else + color = map.GetPixel(c, r); - keyboardGrid[r, c] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + keyboardGrid[r, c] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } } - } + + return keyboardGrid; } diff --git a/Ambilight/Logic/MouseLogic.cs b/Ambilight/Logic/MouseLogic.cs index e1ff944..e106e89 100644 --- a/Ambilight/Logic/MouseLogic.cs +++ b/Ambilight/Logic/MouseLogic.cs @@ -33,6 +33,9 @@ internal void Process(Bitmap newImage) var mouseGrid = Corale.Colore.Razer.Mouse.Effects.CustomGrid.Create(); Bitmap mapMouse = ImageManipulation.ResizeImage(newImage, Corale.Colore.Razer.Mouse.Constants.MaxColumns, Corale.Colore.Razer.Mouse.Constants.MaxRows); + + + mouseGrid = GenerateMouseGrid(mapMouse, mouseGrid); Chroma.Instance.Mouse.SetGrid(mouseGrid); mapMouse.Dispose(); @@ -46,11 +49,19 @@ internal void Process(Bitmap newImage) /// EffectGrid private CustomGrid GenerateMouseGrid(Bitmap mapMouse, CustomGrid mouseGrid) { + for (var r = 0; r < Corale.Colore.Razer.Mouse.Constants.MaxRows; r++) { for (var c = 0; c < Corale.Colore.Razer.Mouse.Constants.MaxColumns; c++) { - System.Drawing.Color color = mapMouse.GetPixel(c, r); + System.Drawing.Color color; + + if (settings.AmbiModeBool) + color = mapMouse.GetPixel(6, 8); + else + color = mapMouse.GetPixel(c, r); + + mouseGrid[r, c] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); } } diff --git a/Ambilight/Logic/MousePadLogic.cs b/Ambilight/Logic/MousePadLogic.cs index 66573cc..2017df2 100644 --- a/Ambilight/Logic/MousePadLogic.cs +++ b/Ambilight/Logic/MousePadLogic.cs @@ -42,34 +42,70 @@ internal void Process(Bitmap newImage) /// /// From a given resized screenshot, an ambilight effect will be created for the mousepad + ///^->>i + ///^ V + ///^ V + ///<<< /// resized screenshot /// effect grid /// private Custom GenerateMousePadGrid(Bitmap mapMousePad, Custom mousePadGrid) { - - for (int i = 0; i < 4; i++) + + if (!settings.AmbiModeBool) { - Color color = mapMousePad.GetPixel(6, i); - mousePadGrid[i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); - } + for (int i = 0; i < 4; i++) + { + Color color = mapMousePad.GetPixel(6, i); + mousePadGrid[i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } - Color colorC = mapMousePad.GetPixel(6, 4); - mousePadGrid[4] = new ColoreColor((byte)colorC.R, (byte)colorC.G, (byte)colorC.B); + Color colorC = mapMousePad.GetPixel(6, 4); + mousePadGrid[4] = new ColoreColor((byte)colorC.R, (byte)colorC.G, (byte)colorC.B); - for (int i = 5; i >= 0; i--) - { - Color color = mapMousePad.GetPixel(i, 5); - mousePadGrid[10 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); - } + for (int i = 5; i >= 0; i--) + { + Color color = mapMousePad.GetPixel(i, 5); + mousePadGrid[10 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } - for (int i = 3; i >= 0; i--) + for (int i = 3; i >= 0; i--) + { + Color color = mapMousePad.GetPixel(0, i); + mousePadGrid[14 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } + } else { - Color color = mapMousePad.GetPixel(0, i); - mousePadGrid[14 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + //RIGHT + for (int i = 0; i < 4; i++) + { + Color color = mapMousePad.GetPixel(6, 5); + mousePadGrid[i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } + + //RIGHT DOWN CORNOR + Color colorC = mapMousePad.GetPixel(6, 5); + mousePadGrid[4] = new ColoreColor((byte)colorC.R, (byte)colorC.G, (byte)colorC.B); + + //BOTTOM + for (int i = 5; i >= 0; i--) + { + Color color = mapMousePad.GetPixel(5, 5); + mousePadGrid[10 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } + + ///CORNER + LEFT + for (int i = 3; i >= 0; i--) + { + Color color = mapMousePad.GetPixel(4, 5); + mousePadGrid[14 - i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B); + } } + + return mousePadGrid; diff --git a/Ambilight/Properties/AssemblyInfo.cs b/Ambilight/Properties/AssemblyInfo.cs index a320e8c..97f6cf8 100644 --- a/Ambilight/Properties/AssemblyInfo.cs +++ b/Ambilight/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] [assembly: NeutralResourcesLanguage("")] \ No newline at end of file diff --git a/Ambilight/Properties/Settings.Designer.cs b/Ambilight/Properties/Settings.Designer.cs index 4068ab2..ddcf8f0 100644 --- a/Ambilight/Properties/Settings.Designer.cs +++ b/Ambilight/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace Ambilight.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -106,5 +106,17 @@ public int keyboardHeight { this["keyboardHeight"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ambiEnabled { + get { + return ((bool)(this["ambiEnabled"])); + } + set { + this["ambiEnabled"] = value; + } + } } } diff --git a/Ambilight/Properties/Settings.settings b/Ambilight/Properties/Settings.settings index 228b6fe..425ca54 100644 --- a/Ambilight/Properties/Settings.settings +++ b/Ambilight/Properties/Settings.settings @@ -23,5 +23,8 @@ -1 + + False + \ No newline at end of file