main.h 4.8 KB

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