all repos — mgba @ 2aac9da42b7514ddb3105becf46de8dee5c797f2

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