all repos — mgba @ e7be40e80ccb6dbeee0b79c97f349859b1b4afb8

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