all repos — mgba @ 609d5314ec8090c5ede27cb07d0d1569463a570a

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