private static IDestination ShowVirtualDmd(IVirtualDmdConfig config) { var dmd = new VirtualDmd { AlwaysOnTop = config.StayOnTop, Left = config.Left, Top = config.Top, Width = config.Width, Height = config.Height, IgnoreAspectRatio = config.IgnoreAr, DotSize = config.DotSize }; var thread = new Thread(() => { // Create our context, and install it: SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher)); dmd.Dispatcher.Invoke(() => { dmd.Dmd.Init(); dmd.Show(); }); // Start the Dispatcher Processing Run(); }); // On closing the window, shut down the dispatcher associated with the thread. // This will allow the thread to exit after the window is closed and all of // the events resulting from the window close have been processed. dmd.Closed += (s, e) => Dispatcher.FromThread(thread).BeginInvokeShutdown(DispatcherPriority.Background); // run the thread thread.SetApartmentState(ApartmentState.STA); thread.Start(); return(dmd.VirtualControl); }
/// <summary> /// Sets the virtual DMD's parameters, initializes it and shows it. /// </summary> private void SetupVirtualDmd() { _dmd.IgnoreAspectRatio = _config.VirtualDmd.IgnoreAr; _dmd.AlwaysOnTop = _config.VirtualDmd.StayOnTop; _dmd.GripColor = _config.VirtualDmd.HideGrip ? Brushes.Transparent : Brushes.White; _dmd.DotSize = _config.VirtualDmd.DotSize; // find the game's dmd position in VPM's registry if (_config.VirtualDmd.UseRegistryPosition) { try { var regPath = @"Software\Freeware\Visual PinMame\" + _gameName; var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32); key = key.OpenSubKey(regPath); if (key == null) { // couldn't find the value in the 32-bit view so grab the 64-bit view key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); key = key.OpenSubKey(regPath); } if (key != null) { var values = key.GetValueNames(); if (values.Contains("dmd_pos_x") && values.Contains("dmd_pos_y") && values.Contains("dmd_width") && values.Contains("dmd_height")) { SetVirtualDmdDefaultPosition( Convert.ToInt64(key.GetValue("dmd_pos_x").ToString()), Convert.ToInt64(key.GetValue("dmd_pos_y").ToString()), Convert.ToInt64(key.GetValue("dmd_width").ToString()), Convert.ToInt64(key.GetValue("dmd_height").ToString()) ); } else { Logger.Warn("Ignoring VPM registry for DMD position because not all values were found at HKEY_CURRENT_USER\\{0}. Found keys: [ {1} ]", regPath, string.Join(", ", values)); SetVirtualDmdDefaultPosition(); } } else { Logger.Warn("Ignoring VPM registry for DMD position because key was not found at HKEY_CURRENT_USER\\{0}", regPath); SetVirtualDmdDefaultPosition(); } key?.Dispose(); } catch (Exception ex) { Logger.Warn(ex, "Could not retrieve registry values for DMD position for game \"" + _gameName + "\"."); SetVirtualDmdDefaultPosition(); } } else { Logger.Debug("DMD position: No registry because it's ignored."); SetVirtualDmdDefaultPosition(); } _dmd.Dmd.Init(); _dmd.Show(); }
private static IFrameDestination ShowVirtualDmd(BaseOptions options) { if (options.VirtualDmdPosition.Length != 3) { throw new InvalidOptionException("Argument --virtual-position must have three values: \"<Left> <Top> <Width>\"."); } var dmd = new VirtualDmd { AlwaysOnTop = options.VirtualDmdOnTop, GripColor = options.VirtualDmdHideGrip ? Brushes.Transparent : Brushes.White, Left = options.VirtualDmdPosition[0], Top = options.VirtualDmdPosition[1], Width = options.VirtualDmdPosition[2], Height = (int)((double)options.VirtualDmdPosition[2] / 4), }; var thread = new Thread(() => { // Create our context, and install it: SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher)); // When the window closes, shut down the dispatcher dmd.Closed += (s, e) => CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background); dmd.Dispatcher.Invoke(() => { dmd.Show(); }); // Start the Dispatcher Processing Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); return(dmd.Dmd); }
private static IDestination ShowVirtualDmd(IConfiguration config) { var dmd = new VirtualDmd { Left = config.VirtualDmd.Left, Top = config.VirtualDmd.Top, Width = config.VirtualDmd.Width, Height = config.VirtualDmd.Height }; dmd.Setup(config as Configuration, config is Configuration iniConfig ? iniConfig.GameName : null); var thread = new Thread(() => { // Create our context, and install it: SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher)); dmd.Dispatcher.Invoke(() => { dmd.Dmd.Init(); dmd.Show(); }); // Start the Dispatcher Processing Run(); }); // On closing the window, shut down the dispatcher associated with the thread. // This will allow the thread to exit after the window is closed and all of // the events resulting from the window close have been processed. dmd.Closed += (s, e) => Dispatcher.FromThread(thread).BeginInvokeShutdown(DispatcherPriority.Background); // run the thread thread.SetApartmentState(ApartmentState.STA); thread.Start(); return(dmd.VirtualControl); }
private static IDestination ShowVirtualDmd(BaseOptions options) { if (options.VirtualDmdPosition.Length != 3 && options.VirtualDmdPosition.Length != 4) { throw new InvalidOptionException("Argument --virtual-position must have three or four values: \"<Left> <Top> <Width> [<Height>]\"."); } if (options.VirtualDmdDotSize <= 0 || options.VirtualDmdDotSize > 2) { throw new InvalidOptionException("Argument --virtual-dotsize must be larger than 0 and smaller than 10."); } int height; bool ignoreAr; if (options.VirtualDmdPosition.Length == 4) { height = options.VirtualDmdPosition[3]; ignoreAr = true; } else { height = (int)((double)options.VirtualDmdPosition[2] / 4); ignoreAr = false; } var dmd = new VirtualDmd { AlwaysOnTop = options.VirtualDmdOnTop, GripColor = options.VirtualDmdHideGrip ? Brushes.Transparent : Brushes.White, Left = options.VirtualDmdPosition[0], Top = options.VirtualDmdPosition[1], Width = options.VirtualDmdPosition[2], Height = height, IgnoreAspectRatio = ignoreAr, DotSize = options.VirtualDmdDotSize }; var thread = new Thread(() => { // Create our context, and install it: SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher)); // create the window dmd.Dispatcher.Invoke(() => { dmd.Dmd.Init(); dmd.Show(); }); // Start the Dispatcher Processing Run(); }); // On closing the window, shut down the dispatcher associated with the thread. // This will allow the thread to exit after the window is closed and all of // the events resulting from the window close have been processed. dmd.Closed += (s, e) => Dispatcher.FromThread(thread).BeginInvokeShutdown(DispatcherPriority.Background); // run the thread thread.SetApartmentState(ApartmentState.STA); thread.Start(); return(dmd.Dmd); }
/// <summary> /// Sets the virtual DMD's parameters, initializes it and shows it. /// </summary> private void SetupVirtualDmd() { _dmd.IgnoreAspectRatio = _config.VirtualDmd.IgnoreAr; _dmd.Left = _config.VirtualDmd.Left; _dmd.Top = _config.VirtualDmd.Top; _dmd.Width = _config.VirtualDmd.Width; _dmd.Height = _config.VirtualDmd.Height; _dmd.AlwaysOnTop = _config.VirtualDmd.StayOnTop; _dmd.GripColor = _config.VirtualDmd.HideGrip ? Brushes.Transparent : Brushes.White; _dmd.Dmd.Init(); _dmd.Show(); }
/// <summary> /// Sets the virtual DMD's parameters, initializes it and shows it. /// </summary> private void SetupVirtualDmd() { _virtualDmd.Setup(_config, _gameName); if (_config.VirtualDmd.UseRegistryPosition) { try { var regPath = @"Software\Freeware\Visual PinMame\" + (_gameName.Length > 0 ? _gameName : "default"); var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32); key = key.OpenSubKey(regPath); if (key == null) { // couldn't find the value in the 32-bit view so grab the 64-bit view key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); key = key.OpenSubKey(regPath); } if (key != null) { var values = key.GetValueNames(); if (!values.Contains("dmd_pos_x") && values.Contains("dmd_pos_y") && values.Contains("dmd_width") && values.Contains("dmd_height")) { Logger.Warn("Not all values were found at HKEY_CURRENT_USER\\{0}. Trying default.", regPath); key?.Dispose(); regPath = @"Software\Freeware\Visual PinMame\default"; key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32); key = key.OpenSubKey(regPath); } } // still null? if (key != null) { var values = key.GetValueNames(); if (values.Contains("dmd_pos_x") && values.Contains("dmd_pos_y") && values.Contains("dmd_width") && values.Contains("dmd_height")) { SetVirtualDmdDefaultPosition( Convert.ToInt64(key.GetValue("dmd_pos_x").ToString()), Convert.ToInt64(key.GetValue("dmd_pos_y").ToString()), Convert.ToInt64(key.GetValue("dmd_width").ToString()), Convert.ToInt64(key.GetValue("dmd_height").ToString()) ); } else { Logger.Warn("Ignoring VPM registry for DMD position because not all values were found at HKEY_CURRENT_USER\\{0}. Found keys: [ {1} ]", regPath, string.Join(", ", values)); SetVirtualDmdDefaultPosition(); } } else { Logger.Warn("Ignoring VPM registry for DMD position because key was not found at HKEY_CURRENT_USER\\{0}", regPath); SetVirtualDmdDefaultPosition(); } key?.Dispose(); } catch (Exception ex) { Logger.Warn(ex, "Could not retrieve registry values for DMD position for game \"" + _gameName + "\"."); SetVirtualDmdDefaultPosition(); } } else { Logger.Debug("DMD position: No registry because it's ignored."); SetVirtualDmdDefaultPosition(); } _virtualDmd.Dmd.Init(); _virtualDmd.Show(); }