diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 54e236c9..895d6994 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -2,7 +2,9 @@ using NAudio.Wave; using Starlight.AnimeMatrix; using System.Diagnostics; +using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using System.IO; using System.Timers; namespace GHelper.AnimeMatrix @@ -14,30 +16,32 @@ namespace GHelper.AnimeMatrix SettingsForm settings; System.Timers.Timer matrixTimer = default!; - AnimeMatrixDevice? mat; + public AnimeMatrixDevice? device; double[]? AudioValues; WasapiCapture? AudioDevice; - public bool IsValid => mat != null; + public bool IsValid => device != null; private long lastPresent; private List maxes = new List(); + private MemoryStream ms = new MemoryStream(); + public AniMatrixControl(SettingsForm settingsForm) { settings = settingsForm; try { - mat = new AnimeMatrixDevice(); - Task.Run(mat.WakeUp); + device = new AnimeMatrixDevice(); + Task.Run(device.WakeUp); matrixTimer = new System.Timers.Timer(100); matrixTimer.Elapsed += MatrixTimer_Elapsed; } catch { - mat = null; + device = null; } } @@ -67,24 +71,26 @@ namespace GHelper.AnimeMatrix try { - mat.SetProvider(); - } catch (Exception ex) { + device.SetProvider(); + } + catch (Exception ex) + { Logger.WriteLine(ex.Message); return; } - if (wakeUp && AppConfig.ContainsModel("401")) mat.WakeUp(); + if (wakeUp && AppConfig.ContainsModel("401")) device.WakeUp(); if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)) { - mat.SetDisplayState(false); - mat.SetDisplayState(false); // some devices are dumb + device.SetDisplayState(false); + device.SetDisplayState(false); // some devices are dumb Logger.WriteLine("Matrix Off"); } else { - mat.SetDisplayState(true); - mat.SetBrightness((BrightnessMode)brightness); + device.SetDisplayState(true); + device.SetBrightness((BrightnessMode)brightness); switch (running) { @@ -98,7 +104,7 @@ namespace GHelper.AnimeMatrix SetMatrixAudio(); break; default: - mat.SetBuiltInAnimation(true, animation); + device.SetBuiltInAnimation(true, animation); Logger.WriteLine("Matrix builtin " + animation.AsByte); break; @@ -127,10 +133,10 @@ namespace GHelper.AnimeMatrix switch (AppConfig.Get("matrix_running")) { case 2: - mat.PresentNextFrame(); + device.PresentNextFrame(); break; case 3: - mat.PresentClock(); + device.PresentClock(); break; } @@ -139,7 +145,7 @@ namespace GHelper.AnimeMatrix public void SetMatrixClock() { - mat.SetBuiltInAnimation(false); + device.SetBuiltInAnimation(false); StartMatrixTimer(1000); Logger.WriteLine("Matrix Clock"); } @@ -169,7 +175,7 @@ namespace GHelper.AnimeMatrix { if (!IsValid) return; - mat.SetBuiltInAnimation(false); + device.SetBuiltInAnimation(false); StopMatrixTimer(); StopMatrixAudio(); @@ -238,8 +244,8 @@ namespace GHelper.AnimeMatrix for (int x = 0; x < 2 - (y % 2); x++) { //color = (byte)(Math.Min(1,(h - y - 2)*2) * 255); - mat.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30)); - mat.SetLedPlanar(x + dx, dy - y, 255); + device.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30)); + device.SetLedPlanar(x + dx, dy - y, 255); } } @@ -249,7 +255,7 @@ namespace GHelper.AnimeMatrix if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return; lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - mat.Clear(); + device.Clear(); int size = 20; double[] bars = new double[size]; @@ -267,7 +273,7 @@ namespace GHelper.AnimeMatrix for (int i = 0; i < size; i++) DrawBar(20 - i, bars[i] * 20 / maxAverage); - mat.Present(); + device.Present(); } @@ -302,22 +308,27 @@ namespace GHelper.AnimeMatrix } - public void SetMatrixPicture(string fileName) + public void SetMatrixPicture(string fileName, bool visualise = true) { if (!IsValid) return; StopMatrixTimer(); - Image image; - try { using (var fs = new FileStream(fileName, FileMode.Open)) { - var ms = new MemoryStream(); + ms.SetLength(0); fs.CopyTo(ms); ms.Position = 0; - image = Image.FromStream(ms); + + using (Image image = Image.FromStream(ms)) + { + ProcessPicture(image); + Logger.WriteLine("Matrix " + fileName); + if (visualise) settings.VisualiseMatrix(image); + } + } } catch @@ -326,30 +337,47 @@ namespace GHelper.AnimeMatrix return; } - mat.SetBuiltInAnimation(false); - mat.ClearFrames(); + } + + protected void ProcessPicture(Image image) + { + device.SetBuiltInAnimation(false); + device.ClearFrames(); + + int matrixX = AppConfig.Get("matrix_x", 0); + int matrixY = AppConfig.Get("matrix_y", 0); + int matrixZoom = AppConfig.Get("matrix_zoom", 100); + InterpolationMode matrixQuality = (InterpolationMode)AppConfig.Get("matrix_quality", 0); + FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]); int frameCount = image.GetFrameCount(dimension); if (frameCount > 1) { + var delayPropertyBytes = image.GetPropertyItem(0x5100).Value; + var frameDelay = BitConverter.ToInt32(delayPropertyBytes) * 10; + for (int i = 0; i < frameCount; i++) { image.SelectActiveFrame(dimension, i); - mat.GenerateFrame(image); - mat.AddFrame(); + device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + device.AddFrame(); } - StartMatrixTimer(); - Logger.WriteLine("Matrix GIF " + fileName); + + Logger.WriteLine("GIF Delay:" + frameDelay); + StartMatrixTimer(Math.Max(50, frameDelay)); + + //image.SelectActiveFrame(dimension, 0); + } else { - mat.GenerateFrame(image); - mat.Present(); - Logger.WriteLine("Matrix " + fileName); + device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + device.Present(); } + } diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index ef706ccb..4e251755 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -1,11 +1,14 @@ // Source thanks to https://github.com/vddCore/Starlight with some adjustments from me +using GHelper; using GHelper.AnimeMatrix.Communication; using System.Drawing.Drawing2D; +using System.Drawing.Imaging; using System.Drawing.Text; using System.Globalization; using System.Management; using System.Text; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; namespace Starlight.AnimeMatrix { @@ -103,12 +106,10 @@ namespace Starlight.AnimeMatrix string model = GetModel(); if (model.Contains("401")) { - _model = AnimeType.GA401; MaxColumns = 33; dx = 1; - MaxRows = 55; LedCount = 1245; @@ -392,8 +393,9 @@ namespace Starlight.AnimeMatrix { g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.AntiAlias; + g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; - using (Font font = new Font("Consolas", 21F, FontStyle.Regular, GraphicsUnit.Pixel)) + using (Font font = new Font("Consolas", 22F, FontStyle.Regular, GraphicsUnit.Pixel)) { SizeF textSize = g.MeasureString(text1, font); g.DrawString(text1, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 3, -4); @@ -408,39 +410,16 @@ namespace Starlight.AnimeMatrix } - GenerateFrame(bmp, InterpolationMode.Bicubic); + GenerateFrame(bmp); Present(); } } - public void GenerateFrame(Image image, InterpolationMode interpolation = InterpolationMode.High) + public void GenerateFrame(Image image, float zoom = 1, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default) { - - int width = MaxColumns / 2 * 6; - int height = MaxRows; - - int targetWidth = MaxColumns * 2; - - float scale; - - using (Bitmap bmp = new Bitmap(targetWidth, height)) + using (Bitmap bmp = GeneratePicture(image, zoom, panX, panY, quality)) { - scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height); - - using (var graph = Graphics.FromImage(bmp)) - { - var scaleWidth = (float)(image.Width * scale); - var scaleHeight = (float)(image.Height * scale); - - graph.InterpolationMode = interpolation; - graph.CompositingQuality = CompositingQuality.HighQuality; - graph.SmoothingMode = SmoothingMode.AntiAlias; - - graph.DrawImage(image, (float)Math.Round(targetWidth - scaleWidth * targetWidth / width), 0, (float)Math.Round(scaleWidth * targetWidth / width), scaleHeight); - - } - for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) @@ -456,9 +435,40 @@ namespace Starlight.AnimeMatrix } + public Bitmap GeneratePicture(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default) + { + + int width = MaxColumns * 3; + int height = MaxRows; + + int targetWidth = MaxColumns * 2; + + float scale; + + Bitmap bmp = new Bitmap(targetWidth, height); + { + scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height) * zoom / 100; + + using (var graph = Graphics.FromImage(bmp)) + { + var scaleWidth = (float)(image.Width * scale); + var scaleHeight = (float)(image.Height * scale); + + graph.InterpolationMode = quality; + graph.CompositingQuality = CompositingQuality.HighQuality; + graph.SmoothingMode = SmoothingMode.AntiAlias; + + graph.DrawImage(image, (float)Math.Round(targetWidth - (scaleWidth + panX) * targetWidth / width), -panY, (float)Math.Round(scaleWidth * targetWidth / width), scaleHeight); + return bmp; + } + + } + } + + public void SetLedDiagonal(int x, int y, byte color, int delta = 10) { - //x+=delta; + //x += delta; y -= delta; int dx = (x - y) / 2; @@ -471,25 +481,8 @@ namespace Starlight.AnimeMatrix Clear(); - - InstalledFontCollection installedFontCollection = new InstalledFontCollection(); - - - string familyName; - string familyList = ""; - FontFamily[] fontFamilies; - // Get the array of FontFamily objects. - fontFamilies = installedFontCollection.Families; - - int count = fontFamilies.Length; - for (int j = 0; j < count; ++j) - { - familyName = fontFamilies[j].Name; - familyList = familyList + familyName; - familyList = familyList + ", "; - } - int maxX = (int)Math.Sqrt(MaxRows * MaxRows + MaxColumns * MaxColumns); + int textHeight; using (Bitmap bmp = new Bitmap(maxX, MaxRows)) { @@ -497,11 +490,13 @@ namespace Starlight.AnimeMatrix { g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.AntiAlias; + g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; - using (Font font = new Font("Consolas", 13F, FontStyle.Regular, GraphicsUnit.Pixel)) + using (Font font = new Font("Consolas", 11, FontStyle.Regular, GraphicsUnit.Pixel)) { SizeF textSize = g.MeasureString(text, font); - g.DrawString(text, font, Brushes.White, 4, 1); + textHeight = (int)textSize.Height; + g.DrawString(text, font, Brushes.White, 4, 0); } } @@ -511,7 +506,7 @@ namespace Starlight.AnimeMatrix { var pixel = bmp.GetPixel(x, y); var color = (pixel.R + pixel.G + pixel.B) / 3; - SetLedDiagonal(x, y, (byte)color); + SetLedDiagonal(x, y, (byte)color, textHeight - 8); } } } diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 0ef18dc5..6b9704e1 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -383,7 +383,7 @@ public static class AppConfig public static bool IsNoGPUModes() { - return ContainsModel("GV301RA"); + return ContainsModel("GV301RA") || ContainsModel("GV302XA"); } } diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index 0f4ce7df..ccfd754f 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -59,8 +59,11 @@ public class AsusACPI public const uint VivoBookMode = 0x00110019; // Vivobook performance modes public const uint GPUEco = 0x00090020; + + public const uint GPUXGInit = 0x00090017; public const uint GPUXGConnected = 0x00090018; public const uint GPUXG = 0x00090019; + public const uint GPUMux = 0x00090016; public const uint BatteryLimit = 0x00120057; @@ -508,8 +511,9 @@ public class AsusACPI public void TUFKeyboardRGB(int mode, Color color, int speed) { - byte[] setting = new byte[12]; - setting[0] = (byte)0xB4; + byte[] setting = new byte[6]; + + setting[0] = (byte)0xb4; setting[1] = (byte)mode; setting[2] = color.R; setting[3] = color.G; @@ -517,6 +521,12 @@ public class AsusACPI setting[5] = (byte)speed; DeviceSet(TUF_KB, setting, "TUF RGB"); + + /* + setting[0] = (byte)0xb4; + DeviceSet(TUF_KB, setting, "TUF RGB"); + */ + //Debug.WriteLine(BitConverter.ToString(setting)); } diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index bf25d65c..75b9815a 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -641,11 +641,17 @@ namespace GHelper public static void InitXGM() { - SetXGM(LED_INIT1); - SetXGM(LED_INIT2); - SetXGM(LED_INIT3); - SetXGM(LED_INIT4); - SetXGM(LED_INIT5); + byte[] ASUS_INIT = Encoding.ASCII.GetBytes("^ASUS Tech.Inc."); + + SetXGM(ASUS_INIT); + SetXGM(new byte[] { 0x5e, 0xd0, 0x02 }); + SetXGM(new byte[] { 0x5e, 0xd0, 0x03 }); + SetXGM(ASUS_INIT); + SetXGM(new byte[] { 0x5e, 0xd1, 0x02 }); // reset fan + SetXGM(ASUS_INIT); + SetXGM(new byte[] { 0x5e, 0xce, 0x03 }); + SetXGM(new byte[] { 0x5e, 0xd0, 0x04 }); + SetXGM(new byte[] { 0x5e, 0xd0, 0x01 }); } public static void ApplyXGMLight(bool status) diff --git a/app/Fans.cs b/app/Fans.cs index 83dc42a7..71a3f9c3 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -78,15 +78,19 @@ namespace GHelper chartCPU.MouseMove += (sender, e) => ChartCPU_MouseMove(sender, e, AsusFan.CPU); chartCPU.MouseUp += ChartCPU_MouseUp; + chartCPU.MouseLeave += ChartCPU_MouseLeave; chartGPU.MouseMove += (sender, e) => ChartCPU_MouseMove(sender, e, AsusFan.GPU); chartGPU.MouseUp += ChartCPU_MouseUp; + chartGPU.MouseLeave += ChartCPU_MouseLeave; chartMid.MouseMove += (sender, e) => ChartCPU_MouseMove(sender, e, AsusFan.Mid); chartMid.MouseUp += ChartCPU_MouseUp; + chartMid.MouseLeave += ChartCPU_MouseLeave; chartXGM.MouseMove += (sender, e) => ChartCPU_MouseMove(sender, e, AsusFan.XGM); chartXGM.MouseUp += ChartCPU_MouseUp; + chartXGM.MouseLeave += ChartCPU_MouseLeave; chartCPU.MouseClick += ChartCPU_MouseClick; chartGPU.MouseClick += ChartCPU_MouseClick; @@ -141,6 +145,7 @@ namespace GHelper trackGPUMemory.MouseUp += TrackGPU_MouseUp; trackGPUBoost.MouseUp += TrackGPU_MouseUp; trackGPUTemp.MouseUp += TrackGPU_MouseUp; + trackGPUClockLimit.MouseUp += TrackGPU_MouseUp; //labelInfo.MaximumSize = new Size(280, 0); @@ -201,6 +206,7 @@ namespace GHelper } + private void ChartCPU_MouseClick(object? sender, MouseEventArgs e) { if (sender is null) return; @@ -984,7 +990,7 @@ namespace GHelper } - private void ChartCPU_MouseUp(object? sender, MouseEventArgs e) + private void Chart_Save() { curPoint = null; curIndex = -1; @@ -1001,8 +1007,17 @@ namespace GHelper SaveProfile(seriesXGM, AsusFan.XGM); modeControl.AutoFans(); + } + + private void ChartCPU_MouseUp(object? sender, MouseEventArgs e) + { + Chart_Save(); + } + private void ChartCPU_MouseLeave(object? sender, EventArgs e) + { + Chart_Save(); } private void ChartCPU_MouseMove(object? sender, MouseEventArgs e, AsusFan device) diff --git a/app/GHelper.csproj b/app/GHelper.csproj index 610c47ec..e97702cf 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -15,7 +15,7 @@ AnyCPU False True - 0.118 + 0.119 diff --git a/app/Gpu/GPUModeControl.cs b/app/Gpu/GPUModeControl.cs index 18c3ebf2..d9b52edf 100644 --- a/app/Gpu/GPUModeControl.cs +++ b/app/Gpu/GPUModeControl.cs @@ -276,6 +276,16 @@ namespace GHelper.Gpu } + public void InitXGM() + { + if (Program.acpi.IsXGConnected()) + { + //Program.acpi.DeviceSet(AsusACPI.GPUXGInit, 1, "XG Init"); + AsusUSB.InitXGM(); + } + + } + public void ToggleXGM() { @@ -299,7 +309,8 @@ namespace GHelper.Gpu { Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM"); - AsusUSB.ResetXGM(); + InitXGM(); + AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light")); await Task.Delay(TimeSpan.FromSeconds(15)); diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index 71da206a..4a5871f1 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -507,6 +507,9 @@ namespace GHelper.Input case 56: // M4 / Rog button KeyProcess("m4"); return; + case 55: // Arconym + KeyProcess("m6"); + return; case 181: // FN + Numpad Enter KeyProcess("fne"); return; diff --git a/app/Matrix.Designer.cs b/app/Matrix.Designer.cs new file mode 100644 index 00000000..bdee1a76 --- /dev/null +++ b/app/Matrix.Designer.cs @@ -0,0 +1,258 @@ +namespace GHelper +{ + partial class Matrix + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureMatrix = new PictureBox(); + trackZoom = new TrackBar(); + buttonPicture = new UI.RButton(); + panelPicture = new Panel(); + panelMain = new Panel(); + panelButtons = new Panel(); + buttonReset = new UI.RButton(); + panelScaling = new Panel(); + comboScaling = new UI.RComboBox(); + labelScaling = new Label(); + panelZoom = new Panel(); + labelZoom = new Label(); + labelZoomTitle = new Label(); + ((System.ComponentModel.ISupportInitialize)pictureMatrix).BeginInit(); + ((System.ComponentModel.ISupportInitialize)trackZoom).BeginInit(); + panelPicture.SuspendLayout(); + panelMain.SuspendLayout(); + panelButtons.SuspendLayout(); + panelScaling.SuspendLayout(); + panelZoom.SuspendLayout(); + SuspendLayout(); + // + // pictureMatrix + // + pictureMatrix.BackColor = Color.Black; + pictureMatrix.Cursor = Cursors.SizeAll; + pictureMatrix.Location = new Point(731, 27); + pictureMatrix.Name = "pictureMatrix"; + pictureMatrix.Size = new Size(81, 73); + pictureMatrix.TabIndex = 0; + pictureMatrix.TabStop = false; + // + // trackZoom + // + trackZoom.LargeChange = 50; + trackZoom.Location = new Point(16, 52); + trackZoom.Maximum = 200; + trackZoom.Minimum = 10; + trackZoom.Name = "trackZoom"; + trackZoom.Size = new Size(782, 90); + trackZoom.SmallChange = 10; + trackZoom.TabIndex = 2; + trackZoom.TickFrequency = 20; + trackZoom.TickStyle = TickStyle.TopLeft; + trackZoom.Value = 100; + // + // buttonPicture + // + buttonPicture.Activated = false; + buttonPicture.BackColor = SystemColors.ControlLight; + buttonPicture.BorderColor = Color.Transparent; + buttonPicture.BorderRadius = 5; + buttonPicture.FlatAppearance.BorderSize = 0; + buttonPicture.FlatStyle = FlatStyle.Flat; + buttonPicture.Image = Properties.Resources.icons8_matrix_32; + buttonPicture.Location = new Point(16, 19); + buttonPicture.Name = "buttonPicture"; + buttonPicture.Secondary = true; + buttonPicture.Size = new Size(258, 56); + buttonPicture.TabIndex = 3; + buttonPicture.Text = "Picture / Gif"; + buttonPicture.TextAlign = ContentAlignment.MiddleRight; + buttonPicture.TextImageRelation = TextImageRelation.ImageBeforeText; + buttonPicture.UseVisualStyleBackColor = false; + // + // panelPicture + // + panelPicture.BackColor = Color.Black; + panelPicture.Controls.Add(pictureMatrix); + panelPicture.Dock = DockStyle.Top; + panelPicture.Location = new Point(0, 0); + panelPicture.Name = "panelPicture"; + panelPicture.Size = new Size(834, 419); + panelPicture.TabIndex = 4; + // + // panelMain + // + panelMain.Controls.Add(panelButtons); + panelMain.Controls.Add(panelScaling); + panelMain.Controls.Add(panelZoom); + panelMain.Controls.Add(panelPicture); + panelMain.Dock = DockStyle.Top; + panelMain.Location = new Point(20, 20); + panelMain.Name = "panelMain"; + panelMain.Size = new Size(834, 924); + panelMain.TabIndex = 5; + // + // panelButtons + // + panelButtons.Controls.Add(buttonReset); + panelButtons.Controls.Add(buttonPicture); + panelButtons.Dock = DockStyle.Top; + panelButtons.Location = new Point(0, 642); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(834, 94); + panelButtons.TabIndex = 6; + // + // buttonReset + // + buttonReset.Activated = false; + buttonReset.BackColor = SystemColors.ControlLight; + buttonReset.BorderColor = Color.Transparent; + buttonReset.BorderRadius = 5; + buttonReset.FlatAppearance.BorderSize = 0; + buttonReset.FlatStyle = FlatStyle.Flat; + buttonReset.Image = Properties.Resources.icons8_refresh_32; + buttonReset.Location = new Point(290, 19); + buttonReset.Name = "buttonReset"; + buttonReset.Secondary = true; + buttonReset.Size = new Size(258, 56); + buttonReset.TabIndex = 4; + buttonReset.Text = "Reset"; + buttonReset.TextAlign = ContentAlignment.MiddleRight; + buttonReset.TextImageRelation = TextImageRelation.ImageBeforeText; + buttonReset.UseVisualStyleBackColor = false; + // + // panelScaling + // + panelScaling.Controls.Add(comboScaling); + panelScaling.Controls.Add(labelScaling); + panelScaling.Dock = DockStyle.Top; + panelScaling.Location = new Point(0, 564); + panelScaling.Name = "panelScaling"; + panelScaling.Size = new Size(834, 78); + panelScaling.TabIndex = 7; + // + // comboScaling + // + comboScaling.BorderColor = Color.White; + comboScaling.ButtonColor = Color.FromArgb(255, 255, 255); + comboScaling.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + comboScaling.FormattingEnabled = true; + comboScaling.ItemHeight = 32; + comboScaling.Items.AddRange(new object[] { "Default", "Low", "High", "Bilinear", "Bicubic", "NearestNeighbor", "HighQualityBilinear", "HighQualityBicubic" }); + comboScaling.Location = new Point(229, 17); + comboScaling.Margin = new Padding(4, 11, 4, 8); + comboScaling.Name = "comboScaling"; + comboScaling.Size = new Size(322, 40); + comboScaling.TabIndex = 17; + // + // labelScaling + // + labelScaling.AutoSize = true; + labelScaling.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelScaling.Location = new Point(16, 20); + labelScaling.Name = "labelScaling"; + labelScaling.Size = new Size(185, 32); + labelScaling.TabIndex = 4; + labelScaling.Text = "Scaling Quality"; + // + // panelZoom + // + panelZoom.AutoSize = true; + panelZoom.Controls.Add(labelZoom); + panelZoom.Controls.Add(labelZoomTitle); + panelZoom.Controls.Add(trackZoom); + panelZoom.Dock = DockStyle.Top; + panelZoom.Location = new Point(0, 419); + panelZoom.Name = "panelZoom"; + panelZoom.Size = new Size(834, 145); + panelZoom.TabIndex = 5; + // + // labelZoom + // + labelZoom.Anchor = AnchorStyles.Top | AnchorStyles.Right; + labelZoom.AutoSize = true; + labelZoom.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + labelZoom.Location = new Point(731, 17); + labelZoom.Name = "labelZoom"; + labelZoom.Size = new Size(77, 32); + labelZoom.TabIndex = 4; + labelZoom.Text = "Zoom"; + // + // labelZoomTitle + // + labelZoomTitle.AutoSize = true; + labelZoomTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelZoomTitle.Location = new Point(16, 17); + labelZoomTitle.Name = "labelZoomTitle"; + labelZoomTitle.Size = new Size(81, 32); + labelZoomTitle.TabIndex = 3; + labelZoomTitle.Text = "Zoom"; + // + // Matrix + // + AutoScaleDimensions = new SizeF(192F, 192F); + AutoScaleMode = AutoScaleMode.Dpi; + AutoSize = true; + ClientSize = new Size(874, 978); + Controls.Add(panelMain); + MaximizeBox = false; + MinimizeBox = false; + MinimumSize = new Size(900, 0); + Name = "Matrix"; + Padding = new Padding(20); + ShowIcon = false; + ShowInTaskbar = false; + Text = "Matrix"; + ((System.ComponentModel.ISupportInitialize)pictureMatrix).EndInit(); + ((System.ComponentModel.ISupportInitialize)trackZoom).EndInit(); + panelPicture.ResumeLayout(false); + panelMain.ResumeLayout(false); + panelMain.PerformLayout(); + panelButtons.ResumeLayout(false); + panelScaling.ResumeLayout(false); + panelScaling.PerformLayout(); + panelZoom.ResumeLayout(false); + panelZoom.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureMatrix; + private TrackBar trackZoom; + private UI.RButton buttonPicture; + private Panel panelPicture; + private Panel panelMain; + private Panel panelZoom; + private Label labelZoom; + private Label labelZoomTitle; + private Panel panelButtons; + private UI.RButton buttonReset; + private Panel panelScaling; + private Label labelScaling; + private UI.RComboBox comboScaling; + } +} \ No newline at end of file diff --git a/app/Matrix.cs b/app/Matrix.cs new file mode 100644 index 00000000..a0bb298c --- /dev/null +++ b/app/Matrix.cs @@ -0,0 +1,190 @@ +using GHelper.AnimeMatrix; +using GHelper.UI; + +namespace GHelper +{ + public partial class Matrix : RForm + { + + public AniMatrixControl matrixControl = Program.settingsForm.matrixControl; + + private bool Dragging; + private int xPos; + private int yPos; + + private int baseX; + private int baseY; + + private float uiScale; + + public Matrix() + { + InitializeComponent(); + InitTheme(true); + + Shown += Matrix_Shown; + FormClosing += Matrix_FormClosed; + + buttonPicture.Click += ButtonPicture_Click; + buttonReset.Click += ButtonReset_Click; + + pictureMatrix.MouseUp += PictureMatrix_MouseUp; + pictureMatrix.MouseMove += PictureMatrix_MouseMove; + pictureMatrix.MouseDown += PictureMatrix_MouseDown; + + trackZoom.MouseUp += TrackZoom_MouseUp; + trackZoom.ValueChanged += TrackZoom_Changed; + + trackZoom.Value = Math.Min(trackZoom.Maximum, AppConfig.Get("matrix_zoom", 100)); + VisualiseZoom(); + + comboScaling.DropDownStyle = ComboBoxStyle.DropDownList; + comboScaling.SelectedIndex = AppConfig.Get("matrix_quality", 0); + comboScaling.SelectedValueChanged += ComboScaling_SelectedValueChanged; + + uiScale = panelPicture.Width / matrixControl.device.MaxColumns / 3; + panelPicture.Height = (int)(matrixControl.device.MaxRows * uiScale); + + } + + private void ComboScaling_SelectedValueChanged(object? sender, EventArgs e) + { + AppConfig.Set("matrix_quality", comboScaling.SelectedIndex); + SetMatrixPicture(false); + } + + private void Matrix_FormClosed(object? sender, FormClosingEventArgs e) + { + if (pictureMatrix.Image is not null) pictureMatrix.Image.Dispose(); + pictureMatrix.Dispose(); + Dispose(); + GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); + } + + private void VisualiseZoom() + { + labelZoom.Text = trackZoom.Value + "%"; + } + + private void ButtonReset_Click(object? sender, EventArgs e) + { + AppConfig.Set("matrix_zoom", 100); + AppConfig.Set("matrix_x", 0); + AppConfig.Set("matrix_y", 0); + + trackZoom.Value = 100; + + SetMatrixPicture(); + + } + + private void TrackZoom_MouseUp(object? sender, EventArgs e) + { + AppConfig.Set("matrix_zoom", trackZoom.Value); + SetMatrixPicture(); + } + + private void TrackZoom_Changed(object? sender, EventArgs e) + { + VisualiseZoom(); + } + + + private void PictureMatrix_MouseDown(object? sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + Dragging = true; + xPos = e.X; + yPos = e.Y; + } + } + + private void PictureMatrix_MouseMove(object? sender, MouseEventArgs e) + { + Control c = sender as Control; + if (Dragging && c != null) + { + c.Top = e.Y + c.Top - yPos; + c.Left = e.X + c.Left - xPos; + } + } + + private void PictureMatrix_MouseUp(object? sender, MouseEventArgs e) + { + + Dragging = false; + + Control c = sender as Control; + + int matrixX = (int)((baseX - c.Left) / uiScale); + int matrixY = (int)((baseY - c.Top) / uiScale); + + AppConfig.Set("matrix_x", matrixX); + AppConfig.Set("matrix_y", matrixY); + + SetMatrixPicture(false); + } + + private void Matrix_Shown(object? sender, EventArgs e) + { + FormPosition(); + SetMatrixPicture(); + } + + private void SetMatrixPicture(bool visualise = true) + { + matrixControl.SetMatrixPicture(AppConfig.GetString("matrix_picture"), visualise); + } + + private void ButtonPicture_Click(object? sender, EventArgs e) + { + matrixControl.OpenMatrixPicture(); + + } + public void FormPosition() + { + if (Height > Program.settingsForm.Height) + { + Top = Program.settingsForm.Top + Program.settingsForm.Height - Height; + } + else + { + Height = Program.settingsForm.Height; + Top = Program.settingsForm.Top; + } + + Left = Program.settingsForm.Left - Width - 5; + } + + public void VisualiseMatrix(Image picture) + { + + if (pictureMatrix.Image is not null) pictureMatrix.Image.Dispose(); + + int width = picture.Width; + int height = picture.Height; + + int matrixX = AppConfig.Get("matrix_x", 0); + int matrixY = AppConfig.Get("matrix_y", 0); + int matrixZoom = AppConfig.Get("matrix_zoom", 100); + + + float scale = Math.Min((float)panelPicture.Width / (float)width, (float)panelPicture.Height / (float)height) * matrixZoom / 100; + + pictureMatrix.Width = (int)(width * scale); + pictureMatrix.Height = (int)(height * scale); + + baseX = panelPicture.Width - pictureMatrix.Width; + baseY = 0; + + pictureMatrix.Left = baseX - (int)(matrixX * uiScale); + pictureMatrix.Top = baseY - (int)(matrixY * uiScale); + + pictureMatrix.SizeMode = PictureBoxSizeMode.Zoom; + pictureMatrix.Image = (Image)picture.Clone(); + + } + + } +} diff --git a/app/Matrix.resx b/app/Matrix.resx new file mode 100644 index 00000000..af32865e --- /dev/null +++ b/app/Matrix.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index 0cdb8410..d4c6d74c 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -134,6 +134,7 @@ namespace GHelper.Mode bool xgmFan = false; if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) { + //AsusUSB.InitXGM(); AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM)); xgmFan = true; } diff --git a/app/Program.cs b/app/Program.cs index 60dbcd7b..88c41d79 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -95,6 +95,7 @@ namespace GHelper settingsForm.InitAura(); settingsForm.InitMatrix(); + gpuControl.InitXGM(); SetAutoModes(); @@ -164,6 +165,8 @@ namespace GHelper if (settingsForm.updates is not null && settingsForm.updates.Text != "") settingsForm.updates.InitTheme(); + if (settingsForm.matrix is not null && settingsForm.matrix.Text != "") + settingsForm.matrix.InitTheme(); break; } } @@ -194,7 +197,7 @@ namespace GHelper BatteryControl.SetBatteryChargeLimit(); settingsForm.AutoKeyboard(); - settingsForm.matrix.SetMatrix(true); + settingsForm.matrixControl.SetMatrix(true); } private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) diff --git a/app/Properties/Resources.Designer.cs b/app/Properties/Resources.Designer.cs index 52eb7f23..12344ce9 100644 --- a/app/Properties/Resources.Designer.cs +++ b/app/Properties/Resources.Designer.cs @@ -629,5 +629,15 @@ namespace GHelper.Properties { return ((System.Drawing.Icon)(obj)); } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Vector_3 { + get { + object obj = ResourceManager.GetObject("Vector 3", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/app/Properties/Resources.resx b/app/Properties/Resources.resx index 0e039773..4a2934d9 100644 --- a/app/Properties/Resources.resx +++ b/app/Properties/Resources.resx @@ -130,6 +130,9 @@ ..\Resources\icons8-mute-unmute-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icons8-hibernate-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icons8-quit-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -286,7 +289,7 @@ ..\Resources\icons8-rocket-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icons8-hibernate-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Vector 3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/app/Resources/Vector 3.png b/app/Resources/Vector 3.png new file mode 100644 index 00000000..024ea3fd Binary files /dev/null and b/app/Resources/Vector 3.png differ diff --git a/app/Settings.cs b/app/Settings.cs index abe4ffce..8ace5e97 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -10,6 +10,7 @@ using GHelper.Peripherals; using GHelper.Peripherals.Mouse; using GHelper.UI; using System.Diagnostics; +using System.Drawing.Imaging; using System.Timers; namespace GHelper @@ -27,10 +28,11 @@ namespace GHelper AsusMouseSettings? mouseSettings; - public AniMatrixControl matrix; + public AniMatrixControl matrixControl; public static System.Timers.Timer sensorTimer = default!; + public Matrix? matrix; public Fans? fans; public Extra? keyb; public Updates? updates; @@ -49,7 +51,7 @@ namespace GHelper gpuControl = new GPUModeControl(this); updateControl = new AutoUpdateControl(this); - matrix = new AniMatrixControl(this); + matrixControl = new AniMatrixControl(this); buttonSilent.Text = Properties.Strings.Silent; buttonBalanced.Text = Properties.Strings.Balanced; @@ -269,6 +271,12 @@ namespace GHelper } } + public void VisualiseMatrix(Image image) + { + if (matrix == null || matrix.Text == "") return; + matrix.VisualiseMatrix(image); + } + protected override void WndProc(ref Message m) { @@ -506,14 +514,29 @@ namespace GHelper private void CheckMatrix_CheckedChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0); - matrix.SetMatrix(); + matrixControl.SetMatrix(); } private void ButtonMatrix_Click(object? sender, EventArgs e) { - matrix.OpenMatrixPicture(); + + if (matrix == null || matrix.Text == "") + { + matrix = new Matrix(); + } + + if (matrix.Visible) + { + matrix.Close(); + } + else + { + matrix.FormPosition(); + matrix.Show(); + } + } public void SetMatrixRunning(int mode) @@ -527,14 +550,14 @@ namespace GHelper private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex); - matrix.SetMatrix(); + matrixControl.SetMatrix(); } private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex); - matrix.SetMatrix(); + matrixControl.SetMatrix(); } @@ -682,7 +705,7 @@ namespace GHelper public void InitMatrix() { - if (!matrix.IsValid) + if (!matrixControl.IsValid) { panelMatrix.Visible = false; return; @@ -786,7 +809,7 @@ namespace GHelper private void ButtonQuit_Click(object? sender, EventArgs e) { - matrix.Dispose(); + matrixControl.Dispose(); Close(); Program.trayIcon.Visible = false; Application.Exit();