diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 94f6b265..134ce6ae 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -350,6 +350,8 @@ namespace GHelper.AnimeMatrix int matrixZoom = AppConfig.Get("matrix_zoom", 100); int matrixSpeed = AppConfig.Get("matrix_speed", 50); + MatrixRotation rotation = (MatrixRotation)AppConfig.Get("matrix_rotation", 0); + InterpolationMode matrixQuality = (InterpolationMode)AppConfig.Get("matrix_quality", 0); @@ -364,7 +366,12 @@ namespace GHelper.AnimeMatrix for (int i = 0; i < frameCount; i++) { image.SelectActiveFrame(dimension, i); - device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + + if (rotation == MatrixRotation.Planar) + device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + else + device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality); + device.AddFrame(); } @@ -377,7 +384,11 @@ namespace GHelper.AnimeMatrix } else { - device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + if (rotation == MatrixRotation.Planar) + device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality); + else + device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality); + device.Present(); } diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index c39bb43e..ac6fa870 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -2,7 +2,6 @@ using GHelper.AnimeMatrix.Communication; using System.Drawing.Drawing2D; -using System.Drawing.Imaging; using System.Drawing.Text; using System.Management; using System.Text; @@ -51,6 +50,12 @@ namespace Starlight.AnimeMatrix } } + public enum MatrixRotation + { + Planar, + Diagonal + } + internal class AnimeMatrixPacket : Packet { public AnimeMatrixPacket(byte[] command) @@ -90,7 +95,7 @@ namespace Starlight.AnimeMatrix public int MaxColumns = 34; public int LedStart = 0; - public int TextShift = 8; + public int FullRows = 11; private int frameIndex = 0; @@ -114,7 +119,7 @@ namespace Starlight.AnimeMatrix UpdatePageLength = 410; - TextShift = 11; + FullRows = 5; LedStart = 1; } @@ -128,19 +133,11 @@ namespace Starlight.AnimeMatrix LedCount = 1711; UpdatePageLength = 630; - TextShift = 10; + FullRows = 9; } _displayBuffer = new byte[LedCount]; - /* - for (int i = 0; i < MaxRows; i++) - { - _model = AnimeType.GA401; - Logger.WriteLine(FirstX(i) + " " + Pitch(i)); - } - */ - LoadMFont(); } @@ -397,19 +394,49 @@ namespace Starlight.AnimeMatrix string time = DateTime.Now.ToString("HH" + second + "mm"); Clear(); - TextDiagonal(time, 15, 12, TextShift + 11); - TextDiagonal(DateTime.Now.ToString("yy'. 'MM'. 'dd"), 11.5F, 3, TextShift); + Text(time, 15, 0, 24); + Text(DateTime.Now.ToString("yy'. 'MM'. 'dd"), 11F, 0, 14); Present(); } - public void TextDiagonal(string text, float fontSize = 10, int deltaX = 0, int deltaY = 10) + private void SetBitmapDiagonal(Bitmap bmp, int deltaX = 0, int deltaY = 0) + { + for (int y = 0; y < bmp.Height; y++) + { + for (int x = 0; x < bmp.Width; x++) + { + var pixel = bmp.GetPixel(x, y); + var color = (pixel.R + pixel.G + pixel.B) / 3; + if (color > 20) + SetLedDiagonal(x, y, (byte)color, deltaX + (FullRows / 2) + 1, deltaY - (FullRows / 2) - 1); + } + } + } + + private void SetBitmapLinear(Bitmap bmp) + { + for (int y = 0; y < bmp.Height; y++) + { + for (int x = 0; x < bmp.Width; x++) + if (x % 2 == y % 2) + { + var pixel = bmp.GetPixel(x, y); + var color = (pixel.R + pixel.G + pixel.B) / 3; + if (color > 20) + SetLedPlanar(x / 2, y, (byte)color); + } + } + } + + public void Text(string text, float fontSize = 10, int x = 0, int y = 0) { - int maxX = (int)Math.Sqrt(MaxRows * MaxRows + MaxColumns * MaxColumns); - int textHeight; + int width = MaxRows - FullRows; + int height = MaxRows - FullRows; + int textHeight, textWidth; - using (Bitmap bmp = new Bitmap(maxX, MaxRows)) + using (Bitmap bmp = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(bmp)) { @@ -421,59 +448,19 @@ namespace Starlight.AnimeMatrix { SizeF textSize = g.MeasureString(text, font); textHeight = (int)textSize.Height; - g.DrawString(text, font, Brushes.White, 0, 0); + textWidth = (int)textSize.Width; + g.DrawString(text, font, Brushes.White, x, height - y); } } - for (int y = 0; y < bmp.Height; y++) - { - for (int x = 0; x < bmp.Width; x++) - { - var pixel = bmp.GetPixel(x, y); - var color = (pixel.R + pixel.G + pixel.B) / 3; - if (color > 100) SetLedDiagonal(x, y, (byte)color, deltaX, deltaY); - } - } + SetBitmapDiagonal(bmp, (width - textWidth), height); + } } - public void PresentText(string text1, string text2 = "") - { - using (Bitmap bmp = new Bitmap(MaxColumns * 3, MaxRows)) - { - using (Graphics g = Graphics.FromImage(bmp)) - { - g.CompositingQuality = CompositingQuality.HighQuality; - g.SmoothingMode = SmoothingMode.AntiAlias; - g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; - - 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); - } - - if (text2.Length > 0) - using (Font font = new Font("Consolas", 18F, GraphicsUnit.Pixel)) - { - SizeF textSize = g.MeasureString(text2, font); - g.DrawString(text2, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 1, 25); - } - - } - - bmp.Save("test.bmp", ImageFormat.Bmp); - - GenerateFrame(bmp); - Present(); - } - - } - public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default) { - int width = MaxColumns / 2 * 6; int height = MaxRows; @@ -498,22 +485,42 @@ namespace Starlight.AnimeMatrix } - for (int y = 0; y < bmp.Height; y++) + Clear(); + SetBitmapLinear(bmp); + } + } + + public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default) + { + int width = MaxRows - FullRows; + int height = MaxRows - FullRows*2; + float scale; + + using (Bitmap bmp = new Bitmap(width, height)) + { + scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height) * zoom / 100; + + using (var graph = Graphics.FromImage(bmp)) { - for (int x = 0; x < bmp.Width; x++) - if (x % 2 == y % 2) - { - var pixel = bmp.GetPixel(x, y); - var color = (pixel.R + pixel.G + pixel.B) / 3; - if (color < 10) color = 0; - SetLedPlanar(x / 2, y, (byte)color); - } + 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, width - scaleWidth, height - scaleHeight, scaleWidth, scaleHeight); + } + + Clear(); + SetBitmapDiagonal(bmp, -panX, height + panY); } } - public void SetLedDiagonal(int x, int y, byte color, int deltaX = 0, int deltaY = 10) + + public void SetLedDiagonal(int x, int y, byte color, int deltaX = 0, int deltaY = 0) { x += deltaX; y -= deltaY; diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index be136bd6..92d78e76 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -301,7 +301,7 @@ public class AsusACPI } - public int DeviceSet(uint DeviceID, byte[] Params, string logName) + public int DeviceSet(uint DeviceID, byte[] Params, string? logName) { byte[] args = new byte[4 + Params.Length]; BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0); @@ -310,7 +310,9 @@ public class AsusACPI byte[] status = CallMethod(DEVS, args); int result = BitConverter.ToInt32(status, 0); - Logger.WriteLine(logName + " = " + BitConverter.ToString(Params) + " : " + (result == 1 ? "OK" : result)); + if (logName is not null) + Logger.WriteLine(logName + " = " + BitConverter.ToString(Params) + " : " + (result == 1 ? "OK" : result)); + return BitConverter.ToInt32(status, 0); } @@ -540,7 +542,7 @@ public class AsusACPI DeviceSet(TUF_KB_BRIGHTNESS, param, "TUF Brightness"); } - public void TUFKeyboardRGB(int mode, Color color, int speed) + public void TUFKeyboardRGB(int mode, Color color, int speed, string? log = "TUF RGB") { byte[] setting = new byte[6]; @@ -552,8 +554,8 @@ public class AsusACPI setting[4] = color.B; setting[5] = (byte)speed; - int result = DeviceSet(TUF_KB, setting, "TUF RGB"); - if (result != 1) DeviceSet(TUF_KB2, setting, "TUF RGB"); + int result = DeviceSet(TUF_KB, setting, log); + if (result != 1) DeviceSet(TUF_KB2, setting, log); } diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index bea0a235..0c15553e 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -472,7 +472,7 @@ namespace GHelper if (isTuf) { - Program.acpi.TUFKeyboardRGB(0, color, 0); + Program.acpi.TUFKeyboardRGB(0, color, 0, null); return; } @@ -531,7 +531,7 @@ namespace GHelper else { - Debug.WriteLine(color.ToString()); + //Debug.WriteLine(color.ToString()); auraDevice.Write(AuraMessage(0, color, color, 0)); auraDevice.Write(MESSAGE_SET); } diff --git a/app/Display/ScreenNative.cs b/app/Display/ScreenNative.cs index 43d32b1e..37dc25fb 100644 --- a/app/Display/ScreenNative.cs +++ b/app/Display/ScreenNative.cs @@ -162,7 +162,8 @@ namespace GHelper.Display if (log) Logger.WriteLine(device.monitorDevicePath + " " + device.outputTechnology); AppConfig.Set("internal_display", device.monitorFriendlyDeviceName); var names = device.monitorDevicePath.Split("#"); - return names[1]; + if (names.Length > 0) return names[1]; + else return ""; } } } diff --git a/app/Extra.cs b/app/Extra.cs index a1ac3eb4..8cfba44f 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -16,25 +16,33 @@ namespace GHelper const string EMPTY = "--------------"; - Dictionary customActions = new Dictionary - { - {"", EMPTY}, - {"mute", Properties.Strings.VolumeMute}, - {"screenshot", Properties.Strings.PrintScreen}, - {"play", Properties.Strings.PlayPause}, - {"aura", Properties.Strings.ToggleAura}, - {"performance", Properties.Strings.PerformanceMode}, - {"screen", Properties.Strings.ToggleScreen}, - {"miniled", Properties.Strings.ToggleMiniled}, - {"fnlock", Properties.Strings.ToggleFnLock}, - {"brightness_down", Properties.Strings.BrightnessDown}, - {"brightness_up", Properties.Strings.BrightnessUp}, - {"custom", Properties.Strings.Custom} - }; private void SetKeyCombo(ComboBox combo, TextBox txbox, string name) { + Dictionary customActions = new Dictionary + { + {"", EMPTY}, + {"mute", Properties.Strings.VolumeMute}, + {"screenshot", Properties.Strings.PrintScreen}, + {"play", Properties.Strings.PlayPause}, + {"aura", Properties.Strings.ToggleAura}, + {"performance", Properties.Strings.PerformanceMode}, + {"screen", Properties.Strings.ToggleScreen}, + {"miniled", Properties.Strings.ToggleMiniled}, + {"fnlock", Properties.Strings.ToggleFnLock}, + {"brightness_down", Properties.Strings.BrightnessDown}, + {"brightness_up", Properties.Strings.BrightnessUp}, + {"ghelper", Properties.Strings.OpenGHelper}, + {"custom", Properties.Strings.Custom} + }; + + if (AppConfig.IsDUO()) + { + customActions.Add("screenpad_down", Properties.Strings.ScreenPadDown); + customActions.Add("screenpad_up", Properties.Strings.ScreenPadUp); + } + switch (name) { case "m1": @@ -48,6 +56,7 @@ namespace GHelper break; case "m4": customActions[""] = Properties.Strings.OpenGHelper; + customActions.Remove("ghelper"); break; case "fnf4": customActions[""] = Properties.Strings.ToggleAura; @@ -59,7 +68,6 @@ namespace GHelper break; case "fne": customActions[""] = "Calculator"; - customActions["ghelper"] = Properties.Strings.OpenGHelper; break; case "paddle": customActions[""] = EMPTY; @@ -131,12 +139,6 @@ namespace GHelper Text = Properties.Strings.ExtraSettings; - if (AppConfig.IsDUO()) - { - customActions.Add("screenpad_down", Properties.Strings.ScreenPadDown); - customActions.Add("screenpad_up", Properties.Strings.ScreenPadUp); - } - if (AppConfig.IsARCNM()) { labelM3.Text = "FN+F6"; diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index cf8d0d86..05f35dcb 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -80,7 +80,7 @@ public static class HardwareControl } catch (Exception ex) { - Logger.WriteLine("Discharge Reading: " + ex.Message); + Debug.WriteLine("Discharge Reading: " + ex.Message); } } @@ -102,7 +102,7 @@ public static class HardwareControl } catch (Exception ex) { - Logger.WriteLine("Full Charge Reading: " + ex.Message); + Debug.WriteLine("Full Charge Reading: " + ex.Message); } } @@ -125,7 +125,7 @@ public static class HardwareControl } catch (Exception ex) { - Logger.WriteLine("Design Capacity Reading: " + ex.Message); + Debug.WriteLine("Design Capacity Reading: " + ex.Message); } } diff --git a/app/Matrix.Designer.cs b/app/Matrix.Designer.cs index bdee1a76..8a1d708e 100644 --- a/app/Matrix.Designer.cs +++ b/app/Matrix.Designer.cs @@ -41,6 +41,9 @@ panelZoom = new Panel(); labelZoom = new Label(); labelZoomTitle = new Label(); + panelRotation = new Panel(); + comboRotation = new UI.RComboBox(); + labelRotation = new Label(); ((System.ComponentModel.ISupportInitialize)pictureMatrix).BeginInit(); ((System.ComponentModel.ISupportInitialize)trackZoom).BeginInit(); panelPicture.SuspendLayout(); @@ -48,6 +51,7 @@ panelButtons.SuspendLayout(); panelScaling.SuspendLayout(); panelZoom.SuspendLayout(); + panelRotation.SuspendLayout(); SuspendLayout(); // // pictureMatrix @@ -106,6 +110,7 @@ // panelMain // panelMain.Controls.Add(panelButtons); + panelMain.Controls.Add(panelRotation); panelMain.Controls.Add(panelScaling); panelMain.Controls.Add(panelZoom); panelMain.Controls.Add(panelPicture); @@ -120,7 +125,7 @@ panelButtons.Controls.Add(buttonReset); panelButtons.Controls.Add(buttonPicture); panelButtons.Dock = DockStyle.Top; - panelButtons.Location = new Point(0, 642); + panelButtons.Location = new Point(0, 720); panelButtons.Name = "panelButtons"; panelButtons.Size = new Size(834, 94); panelButtons.TabIndex = 6; @@ -211,6 +216,40 @@ labelZoomTitle.TabIndex = 3; labelZoomTitle.Text = "Zoom"; // + // panelRotation + // + panelRotation.Controls.Add(comboRotation); + panelRotation.Controls.Add(labelRotation); + panelRotation.Dock = DockStyle.Top; + panelRotation.Location = new Point(0, 642); + panelRotation.Name = "panelRotation"; + panelRotation.Size = new Size(834, 78); + panelRotation.TabIndex = 8; + // + // comboRotation + // + comboRotation.BorderColor = Color.White; + comboRotation.ButtonColor = Color.FromArgb(255, 255, 255); + comboRotation.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + comboRotation.FormattingEnabled = true; + comboRotation.ItemHeight = 32; + comboRotation.Items.AddRange(new object[] { "Straight", "Diagonal" }); + comboRotation.Location = new Point(229, 17); + comboRotation.Margin = new Padding(4, 11, 4, 8); + comboRotation.Name = "comboRotation"; + comboRotation.Size = new Size(322, 40); + comboRotation.TabIndex = 17; + // + // labelRotation + // + labelRotation.AutoSize = true; + labelRotation.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelRotation.Location = new Point(16, 20); + labelRotation.Name = "labelRotation"; + labelRotation.Size = new Size(190, 32); + labelRotation.TabIndex = 4; + labelRotation.Text = "Image Rotation"; + // // Matrix // AutoScaleDimensions = new SizeF(192F, 192F); @@ -236,6 +275,8 @@ panelScaling.PerformLayout(); panelZoom.ResumeLayout(false); panelZoom.PerformLayout(); + panelRotation.ResumeLayout(false); + panelRotation.PerformLayout(); ResumeLayout(false); } @@ -254,5 +295,8 @@ private Panel panelScaling; private Label labelScaling; private UI.RComboBox comboScaling; + private Panel panelRotation; + private UI.RComboBox comboRotation; + private Label labelRotation; } } \ No newline at end of file diff --git a/app/Matrix.cs b/app/Matrix.cs index 37583f74..3d21e00e 100644 --- a/app/Matrix.cs +++ b/app/Matrix.cs @@ -45,11 +45,22 @@ namespace GHelper comboScaling.SelectedIndex = AppConfig.Get("matrix_quality", 0); comboScaling.SelectedValueChanged += ComboScaling_SelectedValueChanged; + comboRotation.DropDownStyle = ComboBoxStyle.DropDownList; + comboRotation.SelectedIndex = AppConfig.Get("matrix_rotation", 0); + comboRotation.SelectedValueChanged += ComboRotation_SelectedValueChanged; ; + + uiScale = panelPicture.Width / matrixControl.device.MaxColumns / 3; panelPicture.Height = (int)(matrixControl.device.MaxRows * uiScale); } + private void ComboRotation_SelectedValueChanged(object? sender, EventArgs e) + { + AppConfig.Set("matrix_rotation", comboRotation.SelectedIndex); + SetMatrixPicture(false); + } + private void ComboScaling_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_quality", comboScaling.SelectedIndex);