all repos — mgba @ 73947766defe48d122796c602b553af507cdb6d5

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 LibraryView;
 32class LogView;
 33class ShaderSelector;
 34class ShortcutController;
 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
 52signals:
 53	void startDrawing(mCoreThread*);
 54	void shutdown();
 55	void audioBufferSamplesChanged(int samples);
 56	void sampleRateChanged(unsigned samples);
 57	void fpsTargetChanged(float target);
 58
 59public slots:
 60	void selectROM();
 61#ifdef USE_SQLITE3
 62	void selectROMInArchive();
 63	void addDirToLibrary();
 64#endif
 65	void selectSave(bool temporary);
 66	void selectPatch();
 67	void enterFullScreen();
 68	void exitFullScreen();
 69	void toggleFullScreen();
 70	void loadConfig();
 71	void reloadConfig();
 72	void saveConfig();
 73
 74	void replaceROM();
 75
 76	void multiplayerChanged();
 77
 78	void importSharkport();
 79	void exportSharkport();
 80
 81	void openSettingsWindow();
 82	void openAboutScreen();
 83
 84	void startVideoLog();
 85
 86#ifdef USE_DEBUGGERS
 87	void consoleOpen();
 88#endif
 89
 90#ifdef USE_FFMPEG
 91	void openVideoWindow();
 92#endif
 93
 94#ifdef USE_MAGICK
 95	void openGIFWindow();
 96#endif
 97
 98#ifdef USE_GDB_STUB
 99	void gdbOpen();
100#endif
101
102protected:
103	virtual void keyPressEvent(QKeyEvent* event) override;
104	virtual void keyReleaseEvent(QKeyEvent* event) override;
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	QMap<int, QAction*> m_frameSizes;
164	LogController m_log;
165	LogView* m_logView;
166#ifdef USE_DEBUGGERS
167	DebuggerConsoleController* m_console;
168#endif
169	LoadSaveState* m_stateWindow;
170	WindowBackground* m_screenWidget;
171	QPixmap m_logo;
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;
178	QMenu* m_videoLayers;
179	QMenu* m_audioChannels;
180	ShortcutController* m_shortcutController;
181	ShaderSelector* m_shaderView;
182	bool m_fullscreenOnStart;
183	QTimer m_focusCheck;
184	bool m_autoresume;
185	bool m_wasOpened;
186
187	bool m_hitUnimplementedBiosCall;
188
189#ifdef USE_FFMPEG
190	VideoView* m_videoView;
191#endif
192
193#ifdef USE_MAGICK
194	GIFView* m_gifView;
195#endif
196
197#ifdef USE_GDB_STUB
198	GDBController* m_gdbController;
199#endif
200
201#ifdef USE_SQLITE3
202	LibraryView* m_libraryView;
203#endif
204};
205
206class WindowBackground : public QLabel {
207Q_OBJECT
208
209public:
210	WindowBackground(QWidget* parent = 0);
211
212	void setSizeHint(const QSize& size);
213	virtual QSize sizeHint() const override;
214	void setLockAspectRatio(int width, int height);
215	void setLockIntegerScaling(bool lock);
216
217protected:
218	virtual void paintEvent(QPaintEvent*) override;
219
220private:
221	QSize m_sizeHint;
222	int m_aspectWidth;
223	int m_aspectHeight;
224	bool m_lockIntegerScaling;
225};
226
227}
228
229#endif