all repos — mgba @ ab07c280fe5ecad1b939a4f9f3ea10f80885206d

mGBA Game Boy Advance Emulator

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

  1/* Copyright (c) 2013-2016 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#ifndef QGBA_WINDOW
  7#define QGBA_WINDOW
  8
  9#include <QDateTime>
 10#include <QList>
 11#include <QMainWindow>
 12#include <QTimer>
 13
 14#include <functional>
 15
 16#include <mgba/core/thread.h>
 17
 18#include "InputController.h"
 19#include "LoadSaveState.h"
 20#include "LogController.h"
 21struct mArguments;
 22
 23namespace QGBA {
 24
 25class ConfigController;
 26class DebuggerConsoleController;
 27class Display;
 28class GameController;
 29class GDBController;
 30class GIFView;
 31class InputModel;
 32class LibraryController;
 33class LogView;
 34class ShaderSelector;
 35class VideoView;
 36class WindowBackground;
 37
 38class Window : public QMainWindow {
 39Q_OBJECT
 40
 41public:
 42	Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 43	virtual ~Window();
 44
 45	GameController* controller() { return m_controller; }
 46
 47	void setConfig(ConfigController*);
 48	void argumentsPassed(mArguments*);
 49
 50	void resizeFrame(const QSize& size);
 51
 52	void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
 53
 54signals:
 55	void startDrawing(mCoreThread*);
 56	void shutdown();
 57	void audioBufferSamplesChanged(int samples);
 58	void sampleRateChanged(unsigned samples);
 59	void fpsTargetChanged(float target);
 60
 61public slots:
 62	void selectROM();
 63#ifdef USE_SQLITE3
 64	void selectROMInArchive();
 65	void addDirToLibrary();
 66#endif
 67	void selectSave(bool temporary);
 68	void selectPatch();
 69	void enterFullScreen();
 70	void exitFullScreen();
 71	void toggleFullScreen();
 72	void loadConfig();
 73	void reloadConfig();
 74	void saveConfig();
 75
 76	void replaceROM();
 77
 78	void multiplayerChanged();
 79
 80	void importSharkport();
 81	void exportSharkport();
 82
 83	void openSettingsWindow();
 84	void openAboutScreen();
 85
 86	void startVideoLog();
 87
 88#ifdef USE_DEBUGGERS
 89	void consoleOpen();
 90#endif
 91
 92#ifdef USE_FFMPEG
 93	void openVideoWindow();
 94#endif
 95
 96#ifdef USE_MAGICK
 97	void openGIFWindow();
 98#endif
 99
100#ifdef USE_GDB_STUB
101	void gdbOpen();
102#endif
103
104protected:
105	virtual void resizeEvent(QResizeEvent*) override;
106	virtual void showEvent(QShowEvent*) override;
107	virtual void closeEvent(QCloseEvent*) override;
108	virtual void focusInEvent(QFocusEvent*) override;
109	virtual void focusOutEvent(QFocusEvent*) override;
110	virtual void dragEnterEvent(QDragEnterEvent*) override;
111	virtual void dropEvent(QDropEvent*) override;
112	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
113
114private slots:
115	void gameStarted(mCoreThread*, const QString&);
116	void gameStopped();
117	void gameCrashed(const QString&);
118	void gameFailed();
119	void unimplementedBiosCall(int);
120
121	void tryMakePortable();
122	void mustRestart();
123
124	void recordFrame();
125	void showFPS();
126	void focusCheck();
127
128private:
129	static const int FPS_TIMER_INTERVAL = 2000;
130	static const int FRAME_LIST_SIZE = 120;
131
132	void setupMenu(QMenuBar*);
133	void openStateWindow(LoadSave);
134
135	void attachWidget(QWidget* widget);
136	void detachWidget(QWidget* widget);
137
138	void appendMRU(const QString& fname);
139	void updateMRU();
140
141	void openView(QWidget* widget);
142
143	template <typename T, typename A> std::function<void()> openTView(A arg);
144	template <typename T> std::function<void()> openTView();
145
146	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
147	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
148
149	void updateTitle(float fps = -1);
150
151	QString getFilters() const;
152	QString getFiltersArchive() const;
153
154	GameController* m_controller;
155	Display* m_display;
156	int m_savedScale;
157	// TODO: Move these to a new class
158	QList<QAction*> m_gameActions;
159	QList<QAction*> m_nonMpActions;
160#ifdef M_CORE_GBA
161	QList<QAction*> m_gbaActions;
162#endif
163	QAction* m_multiWindow;
164	QMap<int, QAction*> m_frameSizes;
165	LogController m_log{0};
166	LogView* m_logView;
167#ifdef USE_DEBUGGERS
168	DebuggerConsoleController* m_console = nullptr;
169#endif
170	LoadSaveState* m_stateWindow = nullptr;
171	WindowBackground* m_screenWidget;
172	QPixmap m_logo{":/res/mgba-1024.png"};
173	ConfigController* m_config;
174	InputModel* m_inputModel;
175	InputController m_inputController;
176	QList<QDateTime> m_frameList;
177	QTimer m_fpsTimer;
178	QList<QString> m_mruFiles;
179	QMenu* m_mruMenu = nullptr;
180	QMenu* m_videoLayers;
181	QMenu* m_audioChannels;
182	ShaderSelector* m_shaderView;
183	bool m_fullscreenOnStart = false;
184	QTimer m_focusCheck;
185	bool m_autoresume = false;
186	bool m_wasOpened = false;
187
188	bool m_hitUnimplementedBiosCall;
189
190#ifdef USE_FFMPEG
191	VideoView* m_videoView = nullptr;
192#endif
193
194#ifdef USE_MAGICK
195	GIFView* m_gifView = nullptr;
196#endif
197
198#ifdef USE_GDB_STUB
199	GDBController* m_gdbController = nullptr;
200#endif
201
202#ifdef USE_SQLITE3
203	LibraryController* m_libraryView;
204#endif
205};
206
207class WindowBackground : public QLabel {
208Q_OBJECT
209
210public:
211	WindowBackground(QWidget* parent = 0);
212
213	void setSizeHint(const QSize& size);
214	virtual QSize sizeHint() const override;
215	void setLockAspectRatio(int width, int height);
216	void setLockIntegerScaling(bool lock);
217
218protected:
219	virtual void paintEvent(QPaintEvent*) override;
220
221private:
222	QSize m_sizeHint;
223	int m_aspectWidth;
224	int m_aspectHeight;
225	bool m_lockIntegerScaling;
226};
227
228}
229
230#endif