all repos — mgba @ 480415c51e8a3f1af0535042a2dbaf35058e82c8

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