all repos — mgba @ f836a67863e66499c812c8d963d37ff56ad10638

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