all repos — mgba @ 4f246827a63b1874bd940f43dd8fe22dfae02ed6

mGBA Game Boy Advance Emulator

src/platform/qt/Window.h (view raw)

  1/* Copyright (c) 2013-2017 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#pragma once
  7
  8#include <QAction>
  9#include <QDateTime>
 10#include <QList>
 11#include <QMainWindow>
 12#include <QTimer>
 13
 14#include <functional>
 15#include <memory>
 16
 17#include <mgba/core/thread.h>
 18
 19#include "InputController.h"
 20#include "LoadSaveState.h"
 21#include "LogController.h"
 22struct mArguments;
 23
 24namespace QGBA {
 25
 26class AudioProcessor;
 27class ConfigController;
 28class CoreController;
 29class CoreManager;
 30class DebuggerConsoleController;
 31class Display;
 32class GDBController;
 33class GIFView;
 34class LibraryController;
 35class LogView;
 36class OverrideView;
 37class SensorView;
 38class ShaderSelector;
 39class ShortcutController;
 40class VideoView;
 41class WindowBackground;
 42
 43class Window : public QMainWindow {
 44Q_OBJECT
 45
 46public:
 47	Window(CoreManager* manager, ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 48	virtual ~Window();
 49
 50	std::shared_ptr<CoreController> controller() { return m_controller; }
 51
 52	void setConfig(ConfigController*);
 53	void argumentsPassed(mArguments*);
 54
 55	void resizeFrame(const QSize& size);
 56
 57	void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
 58
 59signals:
 60	void startDrawing();
 61	void shutdown();
 62	void paused(bool);
 63
 64public slots:
 65	void setController(CoreController* controller, const QString& fname);
 66	void selectROM();
 67#ifdef USE_SQLITE3
 68	void selectROMInArchive();
 69	void addDirToLibrary();
 70#endif
 71	void selectSave(bool temporary);
 72	void selectPatch();
 73	void enterFullScreen();
 74	void exitFullScreen();
 75	void toggleFullScreen();
 76	void loadConfig();
 77	void reloadConfig();
 78	void saveConfig();
 79
 80	void loadCamImage();
 81
 82	void replaceROM();
 83
 84	void multiplayerChanged();
 85
 86	void importSharkport();
 87	void exportSharkport();
 88
 89	void openSettingsWindow();
 90
 91	void startVideoLog();
 92
 93#ifdef USE_DEBUGGERS
 94	void consoleOpen();
 95#endif
 96
 97#ifdef USE_FFMPEG
 98	void openVideoWindow();
 99#endif
100
101#ifdef USE_MAGICK
102	void openGIFWindow();
103#endif
104
105#ifdef USE_GDB_STUB
106	void gdbOpen();
107#endif
108
109protected:
110	virtual void keyPressEvent(QKeyEvent* event) override;
111	virtual void keyReleaseEvent(QKeyEvent* event) override;
112	virtual void resizeEvent(QResizeEvent*) override;
113	virtual void showEvent(QShowEvent*) override;
114	virtual void closeEvent(QCloseEvent*) override;
115	virtual void focusInEvent(QFocusEvent*) override;
116	virtual void focusOutEvent(QFocusEvent*) override;
117	virtual void dragEnterEvent(QDragEnterEvent*) override;
118	virtual void dropEvent(QDropEvent*) override;
119	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
120
121private slots:
122	void gameStarted();
123	void gameStopped();
124	void gameCrashed(const QString&);
125	void gameFailed();
126	void unimplementedBiosCall(int);
127
128	void reloadAudioDriver();
129	void reloadDisplayDriver();
130
131	void tryMakePortable();
132	void mustRestart();
133
134	void recordFrame();
135	void delimitFrames();
136	void showFPS();
137	void focusCheck();
138
139	void updateFrame();
140
141private:
142	static const int FPS_TIMER_INTERVAL = 2000;
143	static const int FRAME_LIST_INTERVAL = 100;
144	static const int FRAME_LIST_SIZE = 40;
145
146	void setupMenu(QMenuBar*);
147	void openStateWindow(LoadSave);
148
149	void attachWidget(QWidget* widget);
150	void detachWidget(QWidget* widget);
151
152	void appendMRU(const QString& fname);
153	void updateMRU();
154
155	void openView(QWidget* widget);
156
157	template <typename T, typename... A> std::function<void()> openTView(A... arg);
158	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
159
160	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
161	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
162
163	void updateTitle(float fps = -1);
164
165	QString getFilters() const;
166	QString getFiltersArchive() const;
167
168	CoreManager* m_manager;
169	std::shared_ptr<CoreController> m_controller;
170	std::unique_ptr<AudioProcessor> m_audioProcessor;
171
172	std::unique_ptr<Display> m_display;
173	int m_savedScale;
174	// TODO: Move these to a new class
175	QList<QAction*> m_gameActions;
176	QList<QAction*> m_nonMpActions;
177#ifdef M_CORE_GBA
178	QList<QAction*> m_gbaActions;
179#endif
180	QAction* m_multiWindow;
181	QMap<int, QAction*> m_frameSizes;
182	LogController m_log{0};
183	LogView* m_logView;
184#ifdef USE_DEBUGGERS
185	DebuggerConsoleController* m_console = nullptr;
186#endif
187	LoadSaveState* m_stateWindow = nullptr;
188	WindowBackground* m_screenWidget;
189	QPixmap m_logo{":/res/mgba-1024.png"};
190	ConfigController* m_config;
191	InputController m_inputController;
192	QList<int> m_frameList;
193	int m_frameCounter = 0;
194	QTimer m_fpsTimer;
195	QTimer m_frameTimer;
196	QList<QString> m_mruFiles;
197	QMenu* m_mruMenu = nullptr;
198	QMenu* m_videoLayers;
199	QMenu* m_audioChannels;
200	ShortcutController* m_shortcutController;
201#if defined(BUILD_GL) || defined(BUILD_GLES2)
202	std::unique_ptr<ShaderSelector> m_shaderView;
203#endif
204	bool m_fullscreenOnStart = false;
205	QTimer m_focusCheck;
206	bool m_autoresume = false;
207	bool m_wasOpened = false;
208	QString m_pendingPatch;
209	QString m_pendingState;
210
211	bool m_hitUnimplementedBiosCall;
212
213	std::unique_ptr<OverrideView> m_overrideView;
214	std::unique_ptr<SensorView> m_sensorView;
215
216#ifdef USE_FFMPEG
217	VideoView* m_videoView = nullptr;
218#endif
219
220#ifdef USE_MAGICK
221	GIFView* m_gifView = nullptr;
222#endif
223
224#ifdef USE_GDB_STUB
225	GDBController* m_gdbController = nullptr;
226#endif
227
228#ifdef USE_SQLITE3
229	LibraryController* m_libraryView;
230#endif
231};
232
233class WindowBackground : public QWidget {
234Q_OBJECT
235
236public:
237	WindowBackground(QWidget* parent = 0);
238
239	void setPixmap(const QPixmap& pixmap);
240	void setSizeHint(const QSize& size);
241	virtual QSize sizeHint() const override;
242	void setDimensions(int width, int height);
243	void setLockIntegerScaling(bool lock);
244	void setLockAspectRatio(bool lock);
245
246	const QPixmap& pixmap() const { return m_pixmap; }
247
248protected:
249	virtual void paintEvent(QPaintEvent*) override;
250
251private:
252	QPixmap m_pixmap;
253	QSize m_sizeHint;
254	int m_aspectWidth;
255	int m_aspectHeight;
256	bool m_lockAspectRatio;
257	bool m_lockIntegerScaling;
258};
259
260}