Skip to content

Commit

Permalink
Added a real Ambilight mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojeske committed Mar 15, 2019
1 parent 1119b40 commit 6ea7c4b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Ambilight/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<setting name="keyboardHeight" serializeAs="String">
<value>-1</value>
</setting>
<setting name="ambiEnabled" serializeAs="String">
<value>False</value>
</setting>
</Ambilight.Properties.Settings>
</userSettings>
<runtime>
Expand Down
14 changes: 14 additions & 0 deletions Ambilight/GUI/TraySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
30 changes: 17 additions & 13 deletions Ambilight/Logic/KeyboardLogic.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,16 +41,26 @@ internal void Process(Bitmap newImage)
/// <returns>EffectGrid</returns>
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;
}
Expand Down
13 changes: 12 additions & 1 deletion Ambilight/Logic/MouseLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -46,11 +49,19 @@ internal void Process(Bitmap newImage)
/// <returns>EffectGrid</returns>
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);
}
}
Expand Down
66 changes: 51 additions & 15 deletions Ambilight/Logic/MousePadLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,70 @@ internal void Process(Bitmap newImage)

/// <summary>
/// From a given resized screenshot, an ambilight effect will be created for the mousepad
///^->>i
///^ V
///^ V
///<<<<V
///
/// </summary>
/// <param name="mapMousePad">resized screenshot</param>
/// <param name="mousePadGrid">effect grid</param>
/// <returns></returns>
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;

Expand Down
4 changes: 2 additions & 2 deletions Ambilight/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]
22 changes: 17 additions & 5 deletions Ambilight/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Ambilight/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<Setting Name="keyboardHeight" Type="System.Int32" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="ambiEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 6ea7c4b

Please sign in to comment.