all repos — mgba @ fc905657adeba406a2c280bbb94b09533a89e3f8

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