RendererWidgetBase.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. using ARMeilleure.Translation;
  2. using ARMeilleure.Translation.PTC;
  3. using Gdk;
  4. using Gtk;
  5. using Ryujinx.Common;
  6. using Ryujinx.Common.Configuration;
  7. using Ryujinx.Common.Logging;
  8. using Ryujinx.Ui.Common.Configuration;
  9. using Ryujinx.Graphics.Gpu;
  10. using Ryujinx.Graphics.GAL;
  11. using Ryujinx.Graphics.GAL.Multithreading;
  12. using Ryujinx.Input;
  13. using Ryujinx.Input.GTK3;
  14. using Ryujinx.Input.HLE;
  15. using Ryujinx.Ui.Widgets;
  16. using SixLabors.ImageSharp;
  17. using SixLabors.ImageSharp.Formats.Png;
  18. using SixLabors.ImageSharp.PixelFormats;
  19. using SixLabors.ImageSharp.Processing;
  20. using System;
  21. using System.Diagnostics;
  22. using System.IO;
  23. using System.Threading;
  24. using System.Threading.Tasks;
  25. namespace Ryujinx.Ui
  26. {
  27. using Image = SixLabors.ImageSharp.Image;
  28. using Key = Input.Key;
  29. using Switch = HLE.Switch;
  30. public abstract class RendererWidgetBase : DrawingArea
  31. {
  32. private const int SwitchPanelWidth = 1280;
  33. private const int SwitchPanelHeight = 720;
  34. private const int TargetFps = 60;
  35. private const float MaxResolutionScale = 4.0f; // Max resolution hotkeys can scale to before wrapping.
  36. public ManualResetEvent WaitEvent { get; set; }
  37. public NpadManager NpadManager { get; }
  38. public TouchScreenManager TouchScreenManager { get; }
  39. public Switch Device { get; private set; }
  40. public IRenderer Renderer { get; private set; }
  41. public bool ScreenshotRequested { get; set; }
  42. protected int WindowWidth { get; private set; }
  43. protected int WindowHeight { get; private set; }
  44. public static event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
  45. private bool _isActive;
  46. private bool _isStopped;
  47. private bool _toggleFullscreen;
  48. private bool _toggleDockedMode;
  49. private readonly long _ticksPerFrame;
  50. private long _ticks = 0;
  51. private readonly Stopwatch _chrono;
  52. private KeyboardHotkeyState _prevHotkeyState;
  53. private readonly ManualResetEvent _exitEvent;
  54. private readonly CancellationTokenSource _gpuCancellationTokenSource;
  55. // Hide Cursor
  56. const int CursorHideIdleTime = 8; // seconds
  57. private static readonly Cursor _invisibleCursor = new Cursor(Display.Default, CursorType.BlankCursor);
  58. private long _lastCursorMoveTime;
  59. private bool _hideCursorOnIdle;
  60. private InputManager _inputManager;
  61. private IKeyboard _keyboardInterface;
  62. private GraphicsDebugLevel _glLogLevel;
  63. private string _gpuVendorName;
  64. private bool _isMouseInClient;
  65. public RendererWidgetBase(InputManager inputManager, GraphicsDebugLevel glLogLevel)
  66. {
  67. var mouseDriver = new GTK3MouseDriver(this);
  68. _inputManager = inputManager;
  69. _inputManager.SetMouseDriver(mouseDriver);
  70. NpadManager = _inputManager.CreateNpadManager();
  71. TouchScreenManager = _inputManager.CreateTouchScreenManager();
  72. _keyboardInterface = (IKeyboard)_inputManager.KeyboardDriver.GetGamepad("0");
  73. WaitEvent = new ManualResetEvent(false);
  74. _glLogLevel = glLogLevel;
  75. Destroyed += Renderer_Destroyed;
  76. _chrono = new Stopwatch();
  77. _ticksPerFrame = Stopwatch.Frequency / TargetFps;
  78. AddEvents((int)(EventMask.ButtonPressMask
  79. | EventMask.ButtonReleaseMask
  80. | EventMask.PointerMotionMask
  81. | EventMask.ScrollMask
  82. | EventMask.EnterNotifyMask
  83. | EventMask.LeaveNotifyMask
  84. | EventMask.KeyPressMask
  85. | EventMask.KeyReleaseMask));
  86. _exitEvent = new ManualResetEvent(false);
  87. _gpuCancellationTokenSource = new CancellationTokenSource();
  88. _hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle;
  89. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  90. ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged;
  91. }
  92. public abstract void InitializeRenderer();
  93. public abstract void SwapBuffers(object image);
  94. public abstract string GetGpuVendorName();
  95. private void HideCursorStateChanged(object sender, ReactiveEventArgs<bool> state)
  96. {
  97. Gtk.Application.Invoke(delegate
  98. {
  99. _hideCursorOnIdle = state.NewValue;
  100. if (_hideCursorOnIdle)
  101. {
  102. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  103. }
  104. else
  105. {
  106. Window.Cursor = null;
  107. }
  108. });
  109. }
  110. private void Renderer_Destroyed(object sender, EventArgs e)
  111. {
  112. ConfigurationState.Instance.HideCursorOnIdle.Event -= HideCursorStateChanged;
  113. NpadManager.Dispose();
  114. Dispose();
  115. }
  116. protected override bool OnMotionNotifyEvent(EventMotion evnt)
  117. {
  118. if (_hideCursorOnIdle)
  119. {
  120. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  121. }
  122. if (ConfigurationState.Instance.Hid.EnableMouse)
  123. {
  124. Window.Cursor = _invisibleCursor;
  125. }
  126. _isMouseInClient = true;
  127. return false;
  128. }
  129. protected override bool OnEnterNotifyEvent(EventCrossing evnt)
  130. {
  131. Window.Cursor = ConfigurationState.Instance.Hid.EnableMouse ? _invisibleCursor : null;
  132. _isMouseInClient = true;
  133. return base.OnEnterNotifyEvent(evnt);
  134. }
  135. protected override bool OnLeaveNotifyEvent(EventCrossing evnt)
  136. {
  137. Window.Cursor = null;
  138. _isMouseInClient = false;
  139. return base.OnLeaveNotifyEvent(evnt);
  140. }
  141. protected override void OnGetPreferredHeight(out int minimumHeight, out int naturalHeight)
  142. {
  143. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  144. // If the monitor is at least 1080p, use the Switch panel size as minimal size.
  145. if (monitor.Geometry.Height >= 1080)
  146. {
  147. minimumHeight = SwitchPanelHeight;
  148. }
  149. // Otherwise, we default minimal size to 480p 16:9.
  150. else
  151. {
  152. minimumHeight = 480;
  153. }
  154. naturalHeight = minimumHeight;
  155. }
  156. protected override void OnGetPreferredWidth(out int minimumWidth, out int naturalWidth)
  157. {
  158. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  159. // If the monitor is at least 1080p, use the Switch panel size as minimal size.
  160. if (monitor.Geometry.Height >= 1080)
  161. {
  162. minimumWidth = SwitchPanelWidth;
  163. }
  164. // Otherwise, we default minimal size to 480p 16:9.
  165. else
  166. {
  167. minimumWidth = 854;
  168. }
  169. naturalWidth = minimumWidth;
  170. }
  171. protected override bool OnConfigureEvent(EventConfigure evnt)
  172. {
  173. bool result = base.OnConfigureEvent(evnt);
  174. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  175. WindowWidth = evnt.Width * monitor.ScaleFactor;
  176. WindowHeight = evnt.Height * monitor.ScaleFactor;
  177. Renderer?.Window.SetSize(WindowWidth, WindowHeight);
  178. return result;
  179. }
  180. private void HandleScreenState(KeyboardStateSnapshot keyboard)
  181. {
  182. bool toggleFullscreen = keyboard.IsPressed(Key.F11)
  183. || ((keyboard.IsPressed(Key.AltLeft)
  184. || keyboard.IsPressed(Key.AltRight))
  185. && keyboard.IsPressed(Key.Enter))
  186. || keyboard.IsPressed(Key.Escape);
  187. bool fullScreenToggled = ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen);
  188. if (toggleFullscreen != _toggleFullscreen)
  189. {
  190. if (toggleFullscreen)
  191. {
  192. if (fullScreenToggled)
  193. {
  194. ParentWindow.Unfullscreen();
  195. (Toplevel as MainWindow)?.ToggleExtraWidgets(true);
  196. }
  197. else
  198. {
  199. if (keyboard.IsPressed(Key.Escape))
  200. {
  201. if (!ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  202. {
  203. Exit();
  204. }
  205. }
  206. else
  207. {
  208. ParentWindow.Fullscreen();
  209. (Toplevel as MainWindow)?.ToggleExtraWidgets(false);
  210. }
  211. }
  212. }
  213. }
  214. _toggleFullscreen = toggleFullscreen;
  215. bool toggleDockedMode = keyboard.IsPressed(Key.F9);
  216. if (toggleDockedMode != _toggleDockedMode)
  217. {
  218. if (toggleDockedMode)
  219. {
  220. ConfigurationState.Instance.System.EnableDockedMode.Value =
  221. !ConfigurationState.Instance.System.EnableDockedMode.Value;
  222. }
  223. }
  224. _toggleDockedMode = toggleDockedMode;
  225. if (_hideCursorOnIdle && !ConfigurationState.Instance.Hid.EnableMouse)
  226. {
  227. long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime;
  228. Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null;
  229. }
  230. if(ConfigurationState.Instance.Hid.EnableMouse && _isMouseInClient)
  231. {
  232. Window.Cursor = _invisibleCursor;
  233. }
  234. }
  235. public void Initialize(Switch device)
  236. {
  237. Device = device;
  238. IRenderer renderer = Device.Gpu.Renderer;
  239. if (renderer is ThreadedRenderer tr)
  240. {
  241. renderer = tr.BaseRenderer;
  242. }
  243. Renderer = renderer;
  244. Renderer?.Window.SetSize(WindowWidth, WindowHeight);
  245. if (Renderer != null)
  246. {
  247. Renderer.ScreenCaptured += Renderer_ScreenCaptured;
  248. }
  249. NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse);
  250. TouchScreenManager.Initialize(device);
  251. }
  252. private unsafe void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e)
  253. {
  254. if (e.Data.Length > 0 && e.Height > 0 && e.Width > 0)
  255. {
  256. Task.Run(() =>
  257. {
  258. lock (this)
  259. {
  260. var currentTime = DateTime.Now;
  261. string filename = $"ryujinx_capture_{currentTime.Year}-{currentTime.Month:D2}-{currentTime.Day:D2}_{currentTime.Hour:D2}-{currentTime.Minute:D2}-{currentTime.Second:D2}.png";
  262. string directory = AppDataManager.Mode switch
  263. {
  264. AppDataManager.LaunchMode.Portable => System.IO.Path.Combine(AppDataManager.BaseDirPath, "screenshots"),
  265. _ => System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "Ryujinx")
  266. };
  267. string path = System.IO.Path.Combine(directory, filename);
  268. try
  269. {
  270. Directory.CreateDirectory(directory);
  271. }
  272. catch (Exception ex)
  273. {
  274. Logger.Error?.Print(LogClass.Application, $"Failed to create directory at path {directory}. Error : {ex.GetType().Name}", "Screenshot");
  275. return;
  276. }
  277. Image image = e.IsBgra ? Image.LoadPixelData<Bgra32>(e.Data, e.Width, e.Height)
  278. : Image.LoadPixelData<Rgba32>(e.Data, e.Width, e.Height);
  279. if (e.FlipX)
  280. {
  281. image.Mutate(x => x.Flip(FlipMode.Horizontal));
  282. }
  283. if (e.FlipY)
  284. {
  285. image.Mutate(x => x.Flip(FlipMode.Vertical));
  286. }
  287. image.SaveAsPng(path, new PngEncoder()
  288. {
  289. ColorType = PngColorType.Rgb
  290. });
  291. image.Dispose();
  292. Logger.Notice.Print(LogClass.Application, $"Screenshot saved to {path}", "Screenshot");
  293. }
  294. });
  295. }
  296. else
  297. {
  298. Logger.Error?.Print(LogClass.Application, $"Screenshot is empty. Size : {e.Data.Length} bytes. Resolution : {e.Width}x{e.Height}", "Screenshot");
  299. }
  300. }
  301. public void Render()
  302. {
  303. Gtk.Window parent = Toplevel as Gtk.Window;
  304. parent.Present();
  305. InitializeRenderer();
  306. Device.Gpu.Renderer.Initialize(_glLogLevel);
  307. _gpuVendorName = GetGpuVendorName();
  308. Device.Gpu.Renderer.RunLoop(() =>
  309. {
  310. Device.Gpu.SetGpuThread();
  311. Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
  312. Translator.IsReadyForTranslation.Set();
  313. (Toplevel as MainWindow)?.ActivatePauseMenu();
  314. while (_isActive)
  315. {
  316. if (_isStopped)
  317. {
  318. return;
  319. }
  320. _ticks += _chrono.ElapsedTicks;
  321. _chrono.Restart();
  322. if (Device.WaitFifo())
  323. {
  324. Device.Statistics.RecordFifoStart();
  325. Device.ProcessFrame();
  326. Device.Statistics.RecordFifoEnd();
  327. }
  328. while (Device.ConsumeFrameAvailable())
  329. {
  330. Device.PresentFrame((texture) => { SwapBuffers(texture);});
  331. }
  332. if (_ticks >= _ticksPerFrame)
  333. {
  334. string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? "Docked" : "Handheld";
  335. float scale = Graphics.Gpu.GraphicsConfig.ResScale;
  336. if (scale != 1)
  337. {
  338. dockedMode += $" ({scale}x)";
  339. }
  340. StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
  341. Device.EnableDeviceVsync,
  342. Device.GetVolume(),
  343. dockedMode,
  344. ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
  345. $"Game: {Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
  346. $"FIFO: {Device.Statistics.GetFifoPercent():0.00} %",
  347. $"GPU: {_gpuVendorName}"));
  348. _ticks = Math.Min(_ticks - _ticksPerFrame, _ticksPerFrame);
  349. }
  350. }
  351. });
  352. }
  353. public void Start()
  354. {
  355. _chrono.Restart();
  356. _isActive = true;
  357. Gtk.Window parent = Toplevel as Gtk.Window;
  358. Application.Invoke(delegate
  359. {
  360. parent.Present();
  361. string titleNameSection = string.IsNullOrWhiteSpace(Device.Application.TitleName) ? string.Empty
  362. : $" - {Device.Application.TitleName}";
  363. string titleVersionSection = string.IsNullOrWhiteSpace(Device.Application.DisplayVersion) ? string.Empty
  364. : $" v{Device.Application.DisplayVersion}";
  365. string titleIdSection = string.IsNullOrWhiteSpace(Device.Application.TitleIdText) ? string.Empty
  366. : $" ({Device.Application.TitleIdText.ToUpper()})";
  367. string titleArchSection = Device.Application.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
  368. parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
  369. });
  370. Thread renderLoopThread = new Thread(Render)
  371. {
  372. Name = "GUI.RenderLoop"
  373. };
  374. renderLoopThread.Start();
  375. Thread nvStutterWorkaround = null;
  376. if (Renderer is Graphics.OpenGL.Renderer)
  377. {
  378. nvStutterWorkaround = new Thread(NVStutterWorkaround)
  379. {
  380. Name = "GUI.NVStutterWorkaround"
  381. };
  382. nvStutterWorkaround.Start();
  383. }
  384. MainLoop();
  385. renderLoopThread.Join();
  386. nvStutterWorkaround?.Join();
  387. Exit();
  388. }
  389. public void Exit()
  390. {
  391. TouchScreenManager?.Dispose();
  392. NpadManager?.Dispose();
  393. if (_isStopped)
  394. {
  395. return;
  396. }
  397. _gpuCancellationTokenSource.Cancel();
  398. _isStopped = true;
  399. _isActive = false;
  400. _exitEvent.WaitOne();
  401. _exitEvent.Dispose();
  402. }
  403. private void NVStutterWorkaround()
  404. {
  405. while (_isActive)
  406. {
  407. // When NVIDIA Threaded Optimization is on, the driver will snapshot all threads in the system whenever the application creates any new ones.
  408. // The ThreadPool has something called a "GateThread" which terminates itself after some inactivity.
  409. // However, it immediately starts up again, since the rules regarding when to terminate and when to start differ.
  410. // This creates a new thread every second or so.
  411. // The main problem with this is that the thread snapshot can take 70ms, is on the OpenGL thread and will delay rendering any graphics.
  412. // This is a little over budget on a frame time of 16ms, so creates a large stutter.
  413. // The solution is to keep the ThreadPool active so that it never has a reason to terminate the GateThread.
  414. // TODO: This should be removed when the issue with the GateThread is resolved.
  415. ThreadPool.QueueUserWorkItem((state) => { });
  416. Thread.Sleep(300);
  417. }
  418. }
  419. public void MainLoop()
  420. {
  421. while (_isActive)
  422. {
  423. UpdateFrame();
  424. // Polling becomes expensive if it's not slept
  425. Thread.Sleep(1);
  426. }
  427. _exitEvent.Set();
  428. }
  429. private bool UpdateFrame()
  430. {
  431. if (!_isActive)
  432. {
  433. return true;
  434. }
  435. if (_isStopped)
  436. {
  437. return false;
  438. }
  439. if ((Toplevel as MainWindow).IsFocused)
  440. {
  441. Application.Invoke(delegate
  442. {
  443. KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot();
  444. HandleScreenState(keyboard);
  445. if (keyboard.IsPressed(Key.Delete))
  446. {
  447. if (!ParentWindow.State.HasFlag(WindowState.Fullscreen))
  448. {
  449. Ptc.Continue();
  450. }
  451. }
  452. });
  453. }
  454. NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
  455. if ((Toplevel as MainWindow).IsFocused)
  456. {
  457. KeyboardHotkeyState currentHotkeyState = GetHotkeyState();
  458. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) &&
  459. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync))
  460. {
  461. Device.EnableDeviceVsync = !Device.EnableDeviceVsync;
  462. }
  463. if ((currentHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot) &&
  464. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot)) || ScreenshotRequested)
  465. {
  466. ScreenshotRequested = false;
  467. Renderer.Screenshot();
  468. }
  469. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi) &&
  470. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi))
  471. {
  472. (Toplevel as MainWindow).ToggleExtraWidgets(true);
  473. }
  474. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.Pause) &&
  475. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Pause))
  476. {
  477. (Toplevel as MainWindow)?.TogglePause();
  478. }
  479. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute) &&
  480. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute))
  481. {
  482. if (Device.IsAudioMuted())
  483. {
  484. Device.SetVolume(ConfigurationState.Instance.System.AudioVolume);
  485. }
  486. else
  487. {
  488. Device.SetVolume(0);
  489. }
  490. }
  491. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleUp) &&
  492. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleUp))
  493. {
  494. GraphicsConfig.ResScale = GraphicsConfig.ResScale % MaxResolutionScale + 1;
  495. }
  496. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleDown) &&
  497. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleDown))
  498. {
  499. GraphicsConfig.ResScale =
  500. (MaxResolutionScale + GraphicsConfig.ResScale - 2) % MaxResolutionScale + 1;
  501. }
  502. _prevHotkeyState = currentHotkeyState;
  503. }
  504. // Touchscreen
  505. bool hasTouch = false;
  506. // Get screen touch position
  507. if ((Toplevel as MainWindow).IsFocused && !ConfigurationState.Instance.Hid.EnableMouse)
  508. {
  509. hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as GTK3MouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
  510. }
  511. if (!hasTouch)
  512. {
  513. TouchScreenManager.Update(false);
  514. }
  515. Device.Hid.DebugPad.Update();
  516. return true;
  517. }
  518. [Flags]
  519. private enum KeyboardHotkeyState
  520. {
  521. None = 0,
  522. ToggleVSync = 1 << 0,
  523. Screenshot = 1 << 1,
  524. ShowUi = 1 << 2,
  525. Pause = 1 << 3,
  526. ToggleMute = 1 << 4,
  527. ResScaleUp = 1 << 5,
  528. ResScaleDown = 1 << 6
  529. }
  530. private KeyboardHotkeyState GetHotkeyState()
  531. {
  532. KeyboardHotkeyState state = KeyboardHotkeyState.None;
  533. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleVsync))
  534. {
  535. state |= KeyboardHotkeyState.ToggleVSync;
  536. }
  537. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot))
  538. {
  539. state |= KeyboardHotkeyState.Screenshot;
  540. }
  541. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi))
  542. {
  543. state |= KeyboardHotkeyState.ShowUi;
  544. }
  545. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause))
  546. {
  547. state |= KeyboardHotkeyState.Pause;
  548. }
  549. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleMute))
  550. {
  551. state |= KeyboardHotkeyState.ToggleMute;
  552. }
  553. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ResScaleUp))
  554. {
  555. state |= KeyboardHotkeyState.ResScaleUp;
  556. }
  557. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ResScaleDown))
  558. {
  559. state |= KeyboardHotkeyState.ResScaleDown;
  560. }
  561. return state;
  562. }
  563. }
  564. }