all repos — mgba @ 9dfcef3f45efe580e252ec8bc3852257e9de9fd6

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