public MainForm() { this.FormBorderStyle = FormBorderStyle.None; InitializeComponent(); ControllerData = new ControllerData(); state = new SteamController.SteamControllerState(); // 5s lookback for smoothing sensorData = new SensorCollector(5, true); LoadThemes(); LoadSettings(); if (File.Exists("ctrl.last")) { settings.Theme = File.ReadAllText("ctrl.last"); File.Delete("ctrl.last"); } if (!string.IsNullOrWhiteSpace(settings.Theme) && File.Exists(settings.Theme)) { LoadTheme(settings.Theme, false); // we'll just let this task spool off on its own and pray } if (!string.IsNullOrWhiteSpace(settings.Background)) { try { this.BackColor = ColorTranslator.FromHtml(settings.Background); } catch { } } LoadControllers(true); }
public override void Paint(Graphics graphics) { Matrix preserve = graphics.Transform; graphics.TranslateTransform(X, Y); var sensorData = MainForm.sensorData.Data; // use the cache! if (sensorData != null) { switch (DisplayType) { case "accel": { float transformX = 1.0f - Math.Abs(sensorData.GyroTiltFactorY * 0.5f); float transformY = 1.0f - Math.Abs(sensorData.GyroTiltFactorX * 0.5f); Draw2dAs3d( cache, graphics, DisplayImage, ShadowLName, ShadowL, ShadowRName, ShadowR, ShadowUName, ShadowU, ShadowDName, ShadowD, transformX, transformY, sensorData.GyroTiltFactorZ, sensorData.GyroTiltFactorX, sensorData.GyroTiltFactorY, Width, Height, TiltTranslateX, TiltTranslateY ); graphics.ResetTransform(); } break; case "gyro": { int SignY = -Math.Sign((2 * SensorCollector.Mod(Math.Floor((sensorData.Roll - 1) * 0.5f) + 1, 2)) - 1); float transformX = SignY * Math.Max(1.0f - Math.Abs(sensorData.QuatTiltFactorY), 0.15f); float transformY = Math.Max(1.0f - Math.Abs(sensorData.QuatTiltFactorX), 0.15f); #if DEBUG //Debug.WriteLine($"{TiltFactorY}\t{Roll}\t{(2 * mod(Math.Floor((Roll - 1) * 0.5f) + 1, 2)) - 1}"); //Debug.WriteLine($"qW={qw},{qx},{qy},{qz}"); //Debug.WriteLine($"gX={_gx},{_gy},{_gz}\taX={_ax},{_ay},{_az}"); //Debug.WriteLine($"{sensorData.Yaw},{sensorData.Pitch},{sensorData.Roll}\r\n"); #endif Draw2dAs3d( cache, graphics, DisplayImage, ShadowLName, ShadowL, ShadowRName, ShadowR, ShadowUName, ShadowU, ShadowDName, ShadowD, transformX, transformY, sensorData.QuatTiltFactorZ, sensorData.QuatTiltFactorX, sensorData.QuatTiltFactorY, Width, Height, TiltTranslateX, TiltTranslateY ); graphics.ResetTransform(); } break; default: break; } } graphics.Transform = preserve; }
public MainForm(int instanceNumber = 0) { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; // no borders this.SetStyle(ControlStyles.ResizeRedraw, true); // this is to avoid visual artifacts RegistryKey winLogonKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian", false); if (winLogonKey != null) { hIDGuardianWhitelistToolStripMenuItem.Visible = true; RegistryKey whitelistKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist\" + Process.GetCurrentProcess().Id, false); hIDGuardianWhitelistToolStripMenuItem.Checked = whitelistKey != null; } IconManager = new IconImageManager(); DeviceManager = new DeviceManager(); ControllerData = new ControllerData(); state = new ControllerState(); // 5s lookback for smoothing sensorData = new SensorCollector(5, true); this.instanceNumber = instanceNumber; if (this.instanceNumber > 0) { this.Text = $"{this.Text} #{(instanceNumber + 1)}"; } LoadThemes(); LoadSettings(); if (File.Exists("ctrl.last")) { settings.Theme = File.ReadAllText("ctrl.last"); File.Delete("ctrl.last"); } if (settings.CustomSize) { this.Width = settings.Width ?? this.Width; this.Height = settings.Height ?? this.Height; } if (!string.IsNullOrWhiteSpace(settings.Theme) && File.Exists(settings.Theme)) { LoadTheme(settings.Theme, true); // we'll just let this task spool off on its own and pray } if (!string.IsNullOrWhiteSpace(settings.Background)) { try { this.BackColor = ColorTranslator.FromHtml(settings.Background); } catch { } } tsmiAutoSelectOnlyController.Checked = settings.AutoSelectOnlyController; DeviceManager.ControllerAdded += DeviceManager_ControllerAdded; DeviceManager.ControllerRemoved += DeviceManager_ControllerRemoved; // foreach(IDeviceProvider provider in DeviceManager.GetManualDeviceProviders()) // { // ToolStripItem itm = tsmiManualControllers.DropDownItems.Add(provider.ToString(), null, LoadManualDevice); // itm.Tag = provider; // } }