all repos — mgba @ cd6b6862ff51b3d9435ba0546f7129b515da6b72

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"
 24
 25struct GBAOptions;
 26struct GBAArguments;
 27
 28namespace QGBA {
 29
 30class ConfigController;
 31class Display;
 32class GameController;
 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(GBAArguments*);
 51
 52	void resizeFrame(int width, int height);
 53
 54signals:
 55	void startDrawing(GBAThread*);
 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 selectBIOS();
 64	void selectPatch();
 65	void enterFullScreen();
 66	void exitFullScreen();
 67	void toggleFullScreen();
 68	void loadConfig();
 69	void saveConfig();
 70
 71	void replaceROM();
 72
 73	void multiplayerChanged();
 74
 75	void importSharkport();
 76	void exportSharkport();
 77
 78	void openKeymapWindow();
 79	void openSettingsWindow();
 80	void openShortcutWindow();
 81
 82	void openOverrideWindow();
 83	void openSensorWindow();
 84	void openCheatsWindow();
 85
 86	void openPaletteWindow();
 87	void openMemoryWindow();
 88	void openIOViewer();
 89
 90	void openAboutScreen();
 91	void openROMInfo();
 92
 93#ifdef BUILD_SDL
 94	void openGamepadWindow();
 95#endif
 96
 97#ifdef USE_FFMPEG
 98	void openVideoWindow();
 99#endif
100
101#ifdef USE_MAGICK
102	void openGIFWindow();
103#endif
104
105#ifdef USE_GDB_STUB
106	void gdbOpen();
107#endif
108
109protected:
110	virtual void keyPressEvent(QKeyEvent* event) override;
111	virtual void keyReleaseEvent(QKeyEvent* event) override;
112	virtual void resizeEvent(QResizeEvent*) override;
113	virtual void showEvent(QShowEvent*) override;
114	virtual void closeEvent(QCloseEvent*) override;
115	virtual void focusInEvent(QFocusEvent*) override;
116	virtual void focusOutEvent(QFocusEvent*) override;
117	virtual void dragEnterEvent(QDragEnterEvent*) override;
118	virtual void dropEvent(QDropEvent*) override;
119	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
120
121private slots:
122	void gameStarted(GBAThread*);
123	void gameStopped();
124	void gameCrashed(const QString&);
125	void gameFailed();
126	void unimplementedBiosCall(int);
127
128	void tryMakePortable();
129	void mustRestart();
130
131	void recordFrame();
132	void showFPS();
133
134private:
135	static const int FPS_TIMER_INTERVAL = 2000;
136	static const int FRAME_LIST_SIZE = 120;
137
138	void setupMenu(QMenuBar*);
139	void openStateWindow(LoadSave);
140
141	void attachWidget(QWidget* widget);
142	void detachWidget(QWidget* widget);
143
144	void appendMRU(const QString& fname);
145	void updateMRU();
146
147	void openView(QWidget* widget);
148
149	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
150	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
151
152	void updateTitle(float fps = NAN);
153
154	GameController* m_controller;
155	Display* m_display;
156	QList<QAction*> m_gameActions;
157	QList<QAction*> m_nonMpActions;
158	QMap<int, QAction*> m_frameSizes;
159	LogController m_log;
160	LogView* m_logView;
161	LoadSaveState* m_stateWindow;
162	WindowBackground* m_screenWidget;
163	QPixmap m_logo;
164	ConfigController* m_config;
165	InputController m_inputController;
166	QList<QDateTime> m_frameList;
167	QTimer m_fpsTimer;
168	QList<QString> m_mruFiles;
169	QMenu* m_mruMenu;
170	ShortcutController* m_shortcutController;
171	ShaderSelector* m_shaderView;
172	int m_playerId;
173	bool m_fullscreenOnStart;
174
175	bool m_hitUnimplementedBiosCall;
176
177#ifdef USE_FFMPEG
178	VideoView* m_videoView;
179#endif
180
181#ifdef USE_MAGICK
182	GIFView* m_gifView;
183#endif
184
185#ifdef USE_GDB_STUB
186	GDBController* m_gdbController;
187#endif
188};
189
190class WindowBackground : public QLabel {
191Q_OBJECT
192
193public:
194	WindowBackground(QWidget* parent = 0);
195
196	void setSizeHint(const QSize& size);
197	virtual QSize sizeHint() const override;
198	void setLockAspectRatio(int width, int height);
199
200protected:
201	virtual void paintEvent(QPaintEvent*) override;
202
203private:
204	QSize m_sizeHint;
205	int m_aspectWidth;
206	int m_aspectHeight;
207};
208
209}
210
211#endif