main.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <QMainWindow>
  7. #include <QTimer>
  8. #include "core/core.h"
  9. #include "ui_main.h"
  10. class Config;
  11. class EmuThread;
  12. class GameList;
  13. class GImageInfo;
  14. class GraphicsBreakPointsWidget;
  15. class GraphicsSurfaceWidget;
  16. class GRenderWindow;
  17. class MicroProfileDialog;
  18. class ProfilerWidget;
  19. class WaitTreeWidget;
  20. namespace Tegra {
  21. class DebugContext;
  22. }
  23. class GMainWindow : public QMainWindow {
  24. Q_OBJECT
  25. /// Max number of recently loaded items to keep track of
  26. static const int max_recent_files_item = 10;
  27. // TODO: Make use of this!
  28. enum {
  29. UI_IDLE,
  30. UI_EMU_BOOTING,
  31. UI_EMU_RUNNING,
  32. UI_EMU_STOPPING,
  33. };
  34. public:
  35. void filterBarSetChecked(bool state);
  36. void UpdateUITheme();
  37. GMainWindow();
  38. ~GMainWindow();
  39. signals:
  40. /**
  41. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  42. * about to start. At this time, the core system emulation has been initialized, and all
  43. * emulation handles and memory should be valid.
  44. *
  45. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  46. * access/change emulation state).
  47. */
  48. void EmulationStarting(EmuThread* emu_thread);
  49. /**
  50. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  51. * system emulation handles and memory are still valid, but are about become invalid.
  52. */
  53. void EmulationStopping();
  54. // Signal that tells widgets to update icons to use the current theme
  55. void UpdateThemedIcons();
  56. private:
  57. void InitializeWidgets();
  58. void InitializeDebugWidgets();
  59. void InitializeRecentFileMenuActions();
  60. void InitializeHotkeys();
  61. void SetDefaultUIGeometry();
  62. void RestoreUIState();
  63. void ConnectWidgetEvents();
  64. void ConnectMenuEvents();
  65. bool SupportsRequiredGLExtensions();
  66. bool LoadROM(const QString& filename);
  67. void BootGame(const QString& filename);
  68. void ShutdownGame();
  69. void ShowCallouts();
  70. /**
  71. * Stores the filename in the recently loaded files list.
  72. * The new filename is stored at the beginning of the recently loaded files list.
  73. * After inserting the new entry, duplicates are removed meaning that if
  74. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  75. * and remove from its previous position.
  76. *
  77. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  78. *
  79. * @param filename the filename to store
  80. */
  81. void StoreRecentFile(const QString& filename);
  82. /**
  83. * Updates the recent files menu.
  84. * Menu entries are rebuilt from the configuration file.
  85. * If there is no entry in the menu, the menu is greyed out.
  86. */
  87. void UpdateRecentFiles();
  88. /**
  89. * If the emulation is running,
  90. * asks the user if he really want to close the emulator
  91. *
  92. * @return true if the user confirmed
  93. */
  94. bool ConfirmClose();
  95. bool ConfirmChangeGame();
  96. void closeEvent(QCloseEvent* event) override;
  97. private slots:
  98. void OnStartGame();
  99. void OnPauseGame();
  100. void OnStopGame();
  101. /// Called whenever a user selects a game in the game list widget.
  102. void OnGameListLoadFile(QString game_path);
  103. void OnGameListOpenSaveFolder(u64 program_id);
  104. void OnMenuLoadFile();
  105. /// Called whenever a user selects the "File->Select Game List Root" menu item
  106. void OnMenuSelectGameListRoot();
  107. void OnMenuRecentFile();
  108. void OnConfigure();
  109. void OnAbout();
  110. void OnToggleFilterBar();
  111. void OnDisplayTitleBars(bool);
  112. void ToggleFullscreen();
  113. void ShowFullscreen();
  114. void HideFullscreen();
  115. void ToggleWindowMode();
  116. void OnCoreError(Core::System::ResultStatus, std::string);
  117. private:
  118. void UpdateStatusBar();
  119. Ui::MainWindow ui;
  120. std::shared_ptr<Tegra::DebugContext> debug_context;
  121. GRenderWindow* render_window;
  122. GameList* game_list;
  123. // Status bar elements
  124. QLabel* message_label = nullptr;
  125. QLabel* emu_speed_label = nullptr;
  126. QLabel* game_fps_label = nullptr;
  127. QLabel* emu_frametime_label = nullptr;
  128. QTimer status_bar_update_timer;
  129. std::unique_ptr<Config> config;
  130. // Whether emulation is currently running in yuzu.
  131. bool emulation_running = false;
  132. std::unique_ptr<EmuThread> emu_thread;
  133. // Debugger panes
  134. ProfilerWidget* profilerWidget;
  135. MicroProfileDialog* microProfileDialog;
  136. GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
  137. GraphicsSurfaceWidget* graphicsSurfaceWidget;
  138. WaitTreeWidget* waitTreeWidget;
  139. QAction* actions_recent_files[max_recent_files_item];
  140. // stores default icon theme search paths for the platform
  141. QStringList default_theme_paths;
  142. protected:
  143. void dropEvent(QDropEvent* event) override;
  144. void dragEnterEvent(QDragEnterEvent* event) override;
  145. void dragMoveEvent(QDragMoveEvent* event) override;
  146. };