all repos — mgba @ fa36a3da812701bbf163db20507c5253c9fb3c22

mGBA Game Boy Advance Emulator

src/platform/qt/Window.h (view raw)

  1/* Copyright (c) 2013-2015 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 "GDBController.h"
 22#include "InputController.h"
 23#include "LoadSaveState.h"
 24#include "LogController.h"
 25struct mArguments;
 26
 27namespace QGBA {
 28
 29class ConfigController;
 30class Display;
 31class GameController;
 32class GIFView;
 33class LogView;
 34class ShaderSelector;
 35class ShortcutController;
 36class VideoView;
 37class WindowBackground;
 38
 39class Window : public QMainWindow {
 40Q_OBJECT
 41
 42public:
 43	Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 44	virtual ~Window();
 45
 46	GameController* controller() { return m_controller; }
 47
 48	void setConfig(ConfigController*);
 49	void argumentsPassed(mArguments*);
 50
 51	void resizeFrame(const QSize& size);
 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	void selectROMInArchive();
 63	void selectSave(bool temporary);
 64	void selectBIOS();
 65	void selectPatch();
 66	void enterFullScreen();
 67	void exitFullScreen();
 68	void toggleFullScreen();
 69	void loadConfig();
 70	void reloadConfig();
 71	void saveConfig();
 72
 73	void replaceROM();
 74
 75	void multiplayerChanged();
 76
 77	void importSharkport();
 78	void exportSharkport();
 79
 80	void openSettingsWindow();
 81	void openOverrideWindow();
 82	void openSensorWindow();
 83	void openCheatsWindow();
 84
 85	void openPaletteWindow();
 86	void openTileWindow();
 87	void openMemoryWindow();
 88	void openIOViewer();
 89
 90	void openAboutScreen();
 91	void openROMInfo();
 92
 93#ifdef USE_FFMPEG
 94	void openVideoWindow();
 95#endif
 96
 97#ifdef USE_MAGICK
 98	void openGIFWindow();
 99#endif
100
101#ifdef USE_GDB_STUB
102	void gdbOpen();
103#endif
104
105protected:
106	virtual void keyPressEvent(QKeyEvent* event) override;
107	virtual void keyReleaseEvent(QKeyEvent* event) override;
108	virtual void resizeEvent(QResizeEvent*) override;
109	virtual void showEvent(QShowEvent*) override;
110	virtual void closeEvent(QCloseEvent*) override;
111	virtual void focusInEvent(QFocusEvent*) override;
112	virtual void focusOutEvent(QFocusEvent*) override;
113	virtual void dragEnterEvent(QDragEnterEvent*) override;
114	virtual void dropEvent(QDropEvent*) override;
115	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
116
117private slots:
118	void gameStarted(mCoreThread*, const QString&);
119	void gameStopped();
120	void gameCrashed(const QString&);
121	void gameFailed();
122	void unimplementedBiosCall(int);
123
124	void tryMakePortable();
125	void mustRestart();
126
127	void recordFrame();
128	void showFPS();
129	void focusCheck();
130
131private:
132	static const int FPS_TIMER_INTERVAL = 2000;
133	static const int FRAME_LIST_SIZE = 120;
134
135	void setupMenu(QMenuBar*);
136	void openStateWindow(LoadSave);
137
138	void attachWidget(QWidget* widget);
139	void detachWidget(QWidget* widget);
140
141	void appendMRU(const QString& fname);
142	void updateMRU();
143
144	void openView(QWidget* widget);
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	// TODO: Move these to a new class
157	QList<QAction*> m_gameActions;
158	QList<QAction*> m_nonMpActions;
159	QList<QAction*> m_gbaActions;
160	QMap<int, QAction*> m_frameSizes;
161	LogController m_log;
162	LogView* m_logView;
163	LoadSaveState* m_stateWindow;
164	WindowBackground* m_screenWidget;
165	QPixmap m_logo;
166	ConfigController* m_config;
167	InputController m_inputController;
168	QList<QDateTime> m_frameList;
169	QTimer m_fpsTimer;
170	QList<QString> m_mruFiles;
171	QMenu* m_mruMenu;
172	ShortcutController* m_shortcutController;
173	ShaderSelector* m_shaderView;
174	int m_playerId;
175	bool m_fullscreenOnStart;
176	QTimer m_focusCheck;
177	bool m_autoresume;
178
179	bool m_hitUnimplementedBiosCall;
180
181#ifdef USE_FFMPEG
182	VideoView* m_videoView;
183#endif
184
185#ifdef USE_MAGICK
186	GIFView* m_gifView;
187#endif
188
189#ifdef USE_GDB_STUB
190	GDBController* m_gdbController;
191#endif
192};
193
194class WindowBackground : public QLabel {
195Q_OBJECT
196
197public:
198	WindowBackground(QWidget* parent = 0);
199
200	void setSizeHint(const QSize& size);
201	virtual QSize sizeHint() const override;
202	void setLockAspectRatio(int width, int height);
203
204protected:
205	virtual void paintEvent(QPaintEvent*) override;
206
207private:
208	QSize m_sizeHint;
209	int m_aspectWidth;
210	int m_aspectHeight;
211};
212
213}
214
215#endif