diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index b454838b..f59e202c 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -91,7 +91,7 @@ namespace Starlight.AnimeMatrix MaxColumns = 33; FullRows = 7; - FullEvenRows = 6; + FullEvenRows = 1; MaxRows = 55; LedCount = 1214; @@ -277,34 +277,32 @@ namespace Starlight.AnimeMatrix } - public void PresentText(string text, int fontSize = 8) + public void PresentText(string text, float fontSize = 8F) { - int width = MaxColumns * 3; - int height = MaxRows; - - Bitmap bmp = new Bitmap(width, height); - - using (Graphics g = Graphics.FromImage(bmp)) + using (Bitmap bmp = new Bitmap(MaxColumns * 3, MaxRows)) { - using (Font font = new Font("Arial", fontSize)) + using (Graphics g = Graphics.FromImage(bmp)) { - - g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; - g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; - SizeF textSize = g.MeasureString(text, font); - - /* - g.TranslateTransform(bmp.Width / 2, bmp.Height / 2); - g.RotateTransform(33); - g.DrawString(text, font, Brushes.White, -textSize.Width/2, -textSize.Height / 2); - */ + using (Font font = new Font("Arial", fontSize)) + { - g.DrawString(text, font, Brushes.White, bmp.Width - textSize.Width + 5, 0); + g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + SizeF textSize = g.MeasureString(text, font); + + /* + g.TranslateTransform(bmp.Width / 2, bmp.Height / 2); + g.RotateTransform(33); + g.DrawString(text, font, Brushes.White, -textSize.Width/2, -textSize.Height / 2); + */ + + g.DrawString(text, font, Brushes.White, bmp.Width - textSize.Width + 5, 0); + } } - } - GenerateFrame(bmp); - Present(); + GenerateFrame(bmp); + Present(); + } } @@ -315,34 +313,32 @@ namespace Starlight.AnimeMatrix int height = MaxRows; float scale; - Bitmap canvas = new Bitmap(width, height); - - scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height); - - var graph = Graphics.FromImage(canvas); - var scaleWidth = (int)(image.Width * scale); - var scaleHeight = (int)(image.Height * scale); - - graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; - graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; - graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; - - graph.DrawImage(image, ((int)width - scaleWidth), 0, scaleWidth, scaleHeight); - - Bitmap bmp = new Bitmap(canvas, MaxColumns * 2, MaxRows); - - for (int y = 0; y < bmp.Height; y++) + using (Bitmap canvas = new Bitmap(width, height)) { - for (int x = 0; x < bmp.Width; x++) + scale = Math.Min((float)width / (float)image.Width, (float)height / (float)image.Height); + + using (var graph = Graphics.FromImage(canvas)) { - if (x % 2 == y % 2) - { - var color = GetColor(bmp, x, y); - SetLedPlanar(x / 2, y, (byte)color); - } + var scaleWidth = (int)(image.Width * scale); + var scaleHeight = (int)(image.Height * scale); + + graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; + graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + + graph.DrawImage(image, ((int)width - scaleWidth), 0, scaleWidth, scaleHeight); + } + + using (Bitmap bmp = new Bitmap(canvas, MaxColumns * 2, MaxRows)) + { + for (int y = 0; y < bmp.Height; y++) + for (int x = 0; x < bmp.Width; x++) + if (x % 2 == y % 2) + SetLedPlanar(x / 2, y, (byte)GetColor(bmp, x, y)); } } + } private void EnsureRowInRange(int row) diff --git a/app/Program.cs b/app/Program.cs index d71b810b..180622ee 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -56,7 +56,8 @@ namespace GHelper ds = settingsForm.Handle; - trayIcon.MouseClick += TrayIcon_MouseClick; ; + trayIcon.MouseClick += TrayIcon_MouseClick; + wmi.SubscribeToEvents(WatcherEventArrived); diff --git a/app/Settings.cs b/app/Settings.cs index 5a0ebf1c..a78fe7da 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -10,7 +10,9 @@ namespace GHelper public partial class SettingsForm : RForm { - static System.Timers.Timer aTimer = default!; + public static System.Timers.Timer aTimer = default!; + public static Point trayPoint; + static System.Timers.Timer matrixTimer = default!; public string versionUrl = "http://github.com/seerge/g-helper/releases"; @@ -21,7 +23,6 @@ namespace GHelper public Keyboard keyb; static AnimeMatrixDevice mat; - static int matrixMode = 0; public SettingsForm() { @@ -115,12 +116,40 @@ namespace GHelper button120Hz.MouseMove += Button120Hz_MouseHover; button120Hz.MouseLeave += ButtonScreen_MouseLeave; + //Program.trayIcon.MouseMove += TrayIcon_MouseMove; + //buttonStandard.Image = (Image)(new Bitmap(buttonStandard.Image, new Size(16, 16))); - SetTimer(); + aTimer = new System.Timers.Timer(500); + aTimer.Elapsed += OnTimedEvent; } + private static void TrayIcon_MouseMove(object? sender, MouseEventArgs e) + { + trayPoint = Cursor.Position; + + if (!aTimer.Enabled) + { + aTimer.Interval = 100; + aTimer.Enabled = true; + } + } + + + private static void OnTimedEvent(Object? source, ElapsedEventArgs? e) + { + if (Program.settingsForm.Visible || Cursor.Position == trayPoint) + { + aTimer.Interval = 2000; + RefreshSensors(); + } else + { + Program.trayIcon.Text = ""; + aTimer.Enabled = false; + } + + } private void Button120Hz_MouseHover(object? sender, EventArgs e) { @@ -350,6 +379,8 @@ namespace GHelper if (fileName is not null) { Program.config.setConfig("matrix_picture", fileName); + Program.config.setConfig("matrix_running", 2); + SetMatrixPicture(fileName); BeginInvoke(delegate { @@ -408,8 +439,7 @@ namespace GHelper switch (running) { case 2: - string fileName = Program.config.getConfigString("matrix_picture"); - SetMatrixPicture(fileName); + SetMatrixPicture(Program.config.getConfigString("matrix_picture")); break; case 3: mat.SetBuiltInAnimation(false); @@ -762,14 +792,6 @@ namespace GHelper SetGPUMode(ASUSWmi.GPUModeEco); } - private static void SetTimer() - { - aTimer = new System.Timers.Timer(500); - aTimer.Elapsed += OnTimedEvent; - aTimer.AutoReset = true; - aTimer.Enabled = false; - } - private static string FormatFan(int fan) { @@ -811,14 +833,12 @@ namespace GHelper Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + gpuFan; if (midFan is not null) Program.settingsForm.labelMidFan.Text = "Mid" + midFan; Program.settingsForm.labelBattery.Text = battery; + + Program.trayIcon.Text = "CPU" + cpuTemp + cpuFan + "\n" + "GPU" + gpuTemp + gpuFan + ((battery.Length > 0) ? ("\n" + battery) : ""); + }); } - private static void OnTimedEvent(Object? source, ElapsedEventArgs? e) - { - RefreshSensors(); - aTimer.Interval = 2000; - } private void SettingsForm_VisibleChanged(object? sender, EventArgs e) {