all repos — mgba @ 0b2f8bb4dcf74ffc0bd28c7349e73450aea4010d

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#ifdef M_CORE_GBA
160	QList<QAction*> m_gbaActions;
161#endif
162	QMap<int, QAction*> m_frameSizes;
163	LogController m_log;
164	LogView* m_logView;
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
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