all repos — mgba @ 9c5852e89ea26959c7a1872c7cee8d02e11d2317

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 importSharkport();
 73	void exportSharkport();
 74
 75	void openKeymapWindow();
 76	void openSettingsWindow();
 77	void openShortcutWindow();
 78
 79	void openOverrideWindow();
 80	void openSensorWindow();
 81	void openCheatsWindow();
 82
 83	void openPaletteWindow();
 84	void openMemoryWindow();
 85
 86	void openAboutScreen();
 87
 88#ifdef BUILD_SDL
 89	void openGamepadWindow();
 90#endif
 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(GBAThread*);
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
129private:
130	static const int FPS_TIMER_INTERVAL = 2000;
131	static const int FRAME_LIST_SIZE = 120;
132
133	void setupMenu(QMenuBar*);
134	void openStateWindow(LoadSave);
135
136	void attachWidget(QWidget* widget);
137	void detachWidget(QWidget* widget);
138
139	void appendMRU(const QString& fname);
140	void updateMRU();
141
142	void openView(QWidget* widget);
143
144	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
145	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
146
147	void updateTitle(float fps = NAN);
148
149	GameController* m_controller;
150	Display* m_display;
151	QList<QAction*> m_gameActions;
152	QMap<int, QAction*> m_frameSizes;
153	LogController m_log;
154	LogView* m_logView;
155	LoadSaveState* m_stateWindow;
156	WindowBackground* m_screenWidget;
157	QPixmap m_logo;
158	ConfigController* m_config;
159	InputController m_inputController;
160	QList<QDateTime> m_frameList;
161	QTimer m_fpsTimer;
162	QList<QString> m_mruFiles;
163	QMenu* m_mruMenu;
164	ShortcutController* m_shortcutController;
165	int m_playerId;
166
167	bool m_hitUnimplementedBiosCall;
168
169#ifdef USE_FFMPEG
170	VideoView* m_videoView;
171#endif
172
173#ifdef USE_MAGICK
174	GIFView* m_gifView;
175#endif
176
177#ifdef USE_GDB_STUB
178	GDBController* m_gdbController;
179#endif
180};
181
182class WindowBackground : public QLabel {
183Q_OBJECT
184
185public:
186	WindowBackground(QWidget* parent = 0);
187
188	void setSizeHint(const QSize& size);
189	virtual QSize sizeHint() const override;
190	void setLockAspectRatio(int width, int height);
191
192protected:
193	virtual void paintEvent(QPaintEvent*) override;
194
195private:
196	QSize m_sizeHint;
197	int m_aspectWidth;
198	int m_aspectHeight;
199};
200
201}
202
203#endif