all repos — mgba @ daaa2fa5236df5e8976e7e0ba7ac39e0d9233422

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
 16extern "C" {
 17#include "core/thread.h"
 18#include "gba/gba.h"
 19}
 20
 21#include "InputController.h"
 22#include "LoadSaveState.h"
 23#include "LogController.h"
 24struct mArguments;
 25
 26namespace QGBA {
 27
 28class ConfigController;
 29class DebuggerConsoleController;
 30class Display;
 31class GameController;
 32class GDBController;
 33class GIFView;
 34class LogView;
 35class ShaderSelector;
 36class ShortcutController;
 37class VideoView;
 38class WindowBackground;
 39
 40class Window : public QMainWindow {
 41Q_OBJECT
 42
 43public:
 44	Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 45	virtual ~Window();
 46
 47	GameController* controller() { return m_controller; }
 48
 49	void setConfig(ConfigController*);
 50	void argumentsPassed(mArguments*);
 51
 52	void resizeFrame(const QSize& size);
 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	void selectROMInArchive();
 64	void selectSave(bool temporary);
 65	void selectBIOS();
 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#ifdef USE_DEBUGGERS
 85	void consoleOpen();
 86#endif
 87
 88#ifdef USE_FFMPEG
 89	void openVideoWindow();
 90#endif
 91
 92#ifdef USE_MAGICK
 93	void openGIFWindow();
 94#endif
 95
 96#ifdef USE_GDB_STUB
 97	void gdbOpen();
 98#endif
 99
100protected:
101	virtual void keyPressEvent(QKeyEvent* event) override;
102	virtual void keyReleaseEvent(QKeyEvent* event) override;
103	virtual void resizeEvent(QResizeEvent*) override;
104	virtual void showEvent(QShowEvent*) override;
105	virtual void closeEvent(QCloseEvent*) override;
106	virtual void focusInEvent(QFocusEvent*) override;
107	virtual void focusOutEvent(QFocusEvent*) override;
108	virtual void dragEnterEvent(QDragEnterEvent*) override;
109	virtual void dropEvent(QDropEvent*) override;
110	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
111
112private slots:
113	void gameStarted(mCoreThread*, const QString&);
114	void gameStopped();
115	void gameCrashed(const QString&);
116	void gameFailed();
117	void unimplementedBiosCall(int);
118
119	void tryMakePortable();
120	void mustRestart();
121
122	void recordFrame();
123	void showFPS();
124	void focusCheck();
125
126private:
127	static const int FPS_TIMER_INTERVAL = 2000;
128	static const int FRAME_LIST_SIZE = 120;
129
130	void setupMenu(QMenuBar*);
131	void openStateWindow(LoadSave);
132
133	void attachWidget(QWidget* widget);
134	void detachWidget(QWidget* widget);
135
136	void appendMRU(const QString& fname);
137	void updateMRU();
138
139	void openView(QWidget* widget);
140
141	template <typename T, typename A> std::function<void()> openTView(A arg);
142	template <typename T> std::function<void()> openTView();
143
144	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
145	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
146
147	void updateTitle(float fps = -1);
148
149	QString getFilters() const;
150	QString getFiltersArchive() const;
151
152	GameController* m_controller;
153	Display* m_display;
154	int m_savedScale;
155	// TODO: Move these to a new class
156	QList<QAction*> m_gameActions;
157	QList<QAction*> m_nonMpActions;
158#ifdef M_CORE_GBA
159	QList<QAction*> m_gbaActions;
160#endif
161	QMap<int, QAction*> m_frameSizes;
162	LogController m_log;
163	LogView* m_logView;
164#ifdef USE_DEBUGGERS
165	DebuggerConsoleController* m_console;
166#endif
167	LoadSaveState* m_stateWindow;
168	WindowBackground* m_screenWidget;
169	QPixmap m_logo;
170	ConfigController* m_config;
171	InputController m_inputController;
172	QList<QDateTime> m_frameList;
173	QTimer m_fpsTimer;
174	QList<QString> m_mruFiles;
175	QMenu* m_mruMenu;
176	ShortcutController* m_shortcutController;
177	ShaderSelector* m_shaderView;
178	bool m_fullscreenOnStart;
179	QTimer m_focusCheck;
180	bool m_autoresume;
181	bool m_wasOpened;
182
183	bool m_hitUnimplementedBiosCall;
184
185#ifdef USE_FFMPEG
186	VideoView* m_videoView;
187#endif
188
189#ifdef USE_MAGICK
190	GIFView* m_gifView;
191#endif
192
193#ifdef USE_GDB_STUB
194	GDBController* m_gdbController;
195#endif
196};
197
198class WindowBackground : public QLabel {
199Q_OBJECT
200
201public:
202	WindowBackground(QWidget* parent = 0);
203
204	void setSizeHint(const QSize& size);
205	virtual QSize sizeHint() const override;
206	void setLockAspectRatio(int width, int height);
207
208protected:
209	virtual void paintEvent(QPaintEvent*) override;
210
211private:
212	QSize m_sizeHint;
213	int m_aspectWidth;
214	int m_aspectHeight;
215};
216
217}
218
219#endif