all repos — mgba @ 742296b8b9e3bec29ff16c0c1553d7e5c337ca2d

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 fpsTargetChanged(float target);
 58
 59public slots:
 60	void selectROM();
 61	void selectBIOS();
 62	void selectPatch();
 63	void enterFullScreen();
 64	void exitFullScreen();
 65	void toggleFullScreen();
 66	void loadConfig();
 67	void saveConfig();
 68
 69	void replaceROM();
 70
 71	void importSharkport();
 72	void exportSharkport();
 73
 74	void openKeymapWindow();
 75	void openSettingsWindow();
 76	void openShortcutWindow();
 77
 78	void openOverrideWindow();
 79	void openSensorWindow();
 80	void openCheatsWindow();
 81
 82	void openPaletteWindow();
 83	void openMemoryWindow();
 84
 85	void openAboutScreen();
 86
 87#ifdef BUILD_SDL
 88	void openGamepadWindow();
 89#endif
 90
 91#ifdef USE_FFMPEG
 92	void openVideoWindow();
 93#endif
 94
 95#ifdef USE_MAGICK
 96	void openGIFWindow();
 97#endif
 98
 99#ifdef USE_GDB_STUB
100	void gdbOpen();
101#endif
102
103protected:
104	virtual void keyPressEvent(QKeyEvent* event) override;
105	virtual void keyReleaseEvent(QKeyEvent* event) override;
106	virtual void resizeEvent(QResizeEvent*) override;
107	virtual void showEvent(QShowEvent*) override;
108	virtual void closeEvent(QCloseEvent*) override;
109	virtual void focusInEvent(QFocusEvent*) override;
110	virtual void focusOutEvent(QFocusEvent*) override;
111	virtual void dragEnterEvent(QDragEnterEvent*) override;
112	virtual void dropEvent(QDropEvent*) override;
113	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
114
115private slots:
116	void gameStarted(GBAThread*);
117	void gameStopped();
118	void gameCrashed(const QString&);
119	void gameFailed();
120	void unimplementedBiosCall(int);
121
122	void tryMakePortable();
123	void mustRestart();
124
125	void recordFrame();
126	void showFPS();
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 = NAN);
147
148	GameController* m_controller;
149	Display* m_display;
150	QList<QAction*> m_gameActions;
151	LogController m_log;
152	LogView* m_logView;
153	LoadSaveState* m_stateWindow;
154	WindowBackground* m_screenWidget;
155	QPixmap m_logo;
156	ConfigController* m_config;
157	InputController m_inputController;
158	QList<QDateTime> m_frameList;
159	QTimer m_fpsTimer;
160	QList<QString> m_mruFiles;
161	QMenu* m_mruMenu;
162	ShortcutController* m_shortcutController;
163	int m_playerId;
164
165	bool m_hitUnimplementedBiosCall;
166
167#ifdef USE_FFMPEG
168	VideoView* m_videoView;
169#endif
170
171#ifdef USE_MAGICK
172	GIFView* m_gifView;
173#endif
174
175#ifdef USE_GDB_STUB
176	GDBController* m_gdbController;
177#endif
178};
179
180class WindowBackground : public QLabel {
181Q_OBJECT
182
183public:
184	WindowBackground(QWidget* parent = 0);
185
186	void setSizeHint(const QSize& size);
187	virtual QSize sizeHint() const override;
188	void setLockAspectRatio(int width, int height);
189
190protected:
191	virtual void paintEvent(QPaintEvent*) override;
192
193private:
194	QSize m_sizeHint;
195	int m_aspectWidth;
196	int m_aspectHeight;
197};
198
199}
200
201#endif