all repos — mgba @ 87758b274cb45e575ca34240cddc684e3fe03aa5

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