all repos — mgba @ b1f750e441af63b35141702ac00fd2f13313bd44

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 selectSave(bool temporary);
 63	void selectBIOS();
 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 openOverrideWindow();
 81	void openSensorWindow();
 82	void openCheatsWindow();
 83
 84	void openPaletteWindow();
 85	void openTileWindow();
 86	void openMemoryWindow();
 87	void openIOViewer();
 88
 89	void openAboutScreen();
 90	void openROMInfo();
 91
 92#ifdef USE_FFMPEG
 93	void openVideoWindow();
 94#endif
 95
 96#ifdef USE_MAGICK
 97	void openGIFWindow();
 98#endif
 99
100#ifdef USE_GDB_STUB
101	void gdbOpen();
102#endif
103
104protected:
105	virtual void keyPressEvent(QKeyEvent* event) override;
106	virtual void keyReleaseEvent(QKeyEvent* event) override;
107	virtual void resizeEvent(QResizeEvent*) override;
108	virtual void showEvent(QShowEvent*) override;
109	virtual void closeEvent(QCloseEvent*) override;
110	virtual void focusInEvent(QFocusEvent*) override;
111	virtual void focusOutEvent(QFocusEvent*) override;
112	virtual void dragEnterEvent(QDragEnterEvent*) override;
113	virtual void dropEvent(QDropEvent*) override;
114	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
115
116private slots:
117	void gameStarted(mCoreThread*, const QString&);
118	void gameStopped();
119	void gameCrashed(const QString&);
120	void gameFailed();
121	void unimplementedBiosCall(int);
122
123	void tryMakePortable();
124	void mustRestart();
125
126	void recordFrame();
127	void showFPS();
128	void focusCheck();
129
130private:
131	static const int FPS_TIMER_INTERVAL = 2000;
132	static const int FRAME_LIST_SIZE = 120;
133
134	void setupMenu(QMenuBar*);
135	void openStateWindow(LoadSave);
136
137	void attachWidget(QWidget* widget);
138	void detachWidget(QWidget* widget);
139
140	void appendMRU(const QString& fname);
141	void updateMRU();
142
143	void openView(QWidget* widget);
144
145	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
146	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
147
148	void updateTitle(float fps = -1);
149
150	QString getFilters() const;
151
152	GameController* m_controller;
153	Display* m_display;
154	// TODO: Move these to a new class
155	QList<QAction*> m_gameActions;
156	QList<QAction*> m_nonMpActions;
157	QList<QAction*> m_gbaActions;
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	QTimer m_focusCheck;
175	bool m_autoresume;
176
177	bool m_hitUnimplementedBiosCall;
178
179#ifdef USE_FFMPEG
180	VideoView* m_videoView;
181#endif
182
183#ifdef USE_MAGICK
184	GIFView* m_gifView;
185#endif
186
187#ifdef USE_GDB_STUB
188	GDBController* m_gdbController;
189#endif
190};
191
192class WindowBackground : public QLabel {
193Q_OBJECT
194
195public:
196	WindowBackground(QWidget* parent = 0);
197
198	void setSizeHint(const QSize& size);
199	virtual QSize sizeHint() const override;
200	void setLockAspectRatio(int width, int height);
201
202protected:
203	virtual void paintEvent(QPaintEvent*) override;
204
205private:
206	QSize m_sizeHint;
207	int m_aspectWidth;
208	int m_aspectHeight;
209};
210
211}
212
213#endif