all repos — mgba @ fa884d071ecaa3e05ff20b45a67bf9500dd3d6b6

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