all repos — mgba @ e2b964a8be5efb850368c52ee08c785eba26c6d7

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
 24struct GBAOptions;
 25struct GBAArguments;
 26
 27namespace QGBA {
 28
 29class ConfigController;
 30class Display;
 31class GameController;
 32class GIFView;
 33class LogView;
 34class ShortcutController;
 35class VideoView;
 36class WindowBackground;
 37
 38class Window : public QMainWindow {
 39Q_OBJECT
 40
 41public:
 42	Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 43	virtual ~Window();
 44
 45	GameController* controller() { return m_controller; }
 46
 47	void setConfig(ConfigController*);
 48	void argumentsPassed(GBAArguments*);
 49
 50	void resizeFrame(int width, int height);
 51
 52signals:
 53	void startDrawing(GBAThread*);
 54	void shutdown();
 55	void audioBufferSamplesChanged(int samples);
 56	void fpsTargetChanged(float target);
 57
 58public slots:
 59	void selectROM();
 60	void selectBIOS();
 61	void selectPatch();
 62	void enterFullScreen();
 63	void exitFullScreen();
 64	void toggleFullScreen();
 65	void loadConfig();
 66	void saveConfig();
 67
 68	void importSharkport();
 69	void exportSharkport();
 70
 71	void openKeymapWindow();
 72	void openSettingsWindow();
 73	void openShortcutWindow();
 74
 75	void openOverrideWindow();
 76	void openSensorWindow();
 77	void openCheatsWindow();
 78
 79	void openPaletteWindow();
 80	void openMemoryWindow();
 81
 82#ifdef BUILD_SDL
 83	void openGamepadWindow();
 84#endif
 85
 86#ifdef USE_FFMPEG
 87	void openVideoWindow();
 88#endif
 89
 90#ifdef USE_MAGICK
 91	void openGIFWindow();
 92#endif
 93
 94#ifdef USE_GDB_STUB
 95	void gdbOpen();
 96#endif
 97
 98protected:
 99	virtual void keyPressEvent(QKeyEvent* event) override;
100	virtual void keyReleaseEvent(QKeyEvent* event) override;
101	virtual void resizeEvent(QResizeEvent*) override;
102	virtual void closeEvent(QCloseEvent*) override;
103	virtual void focusOutEvent(QFocusEvent*) override;
104	virtual void dragEnterEvent(QDragEnterEvent*) override;
105	virtual void dropEvent(QDropEvent*) override;
106	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
107
108private slots:
109	void gameStarted(GBAThread*);
110	void gameStopped();
111	void gameCrashed(const QString&);
112	void gameFailed();
113	void unimplementedBiosCall(int);
114
115	void recordFrame();
116	void showFPS();
117
118private:
119	static const int FPS_TIMER_INTERVAL = 2000;
120	static const int FRAME_LIST_SIZE = 120;
121
122	void setupMenu(QMenuBar*);
123	void openStateWindow(LoadSave);
124
125	void attachWidget(QWidget* widget);
126	void detachWidget(QWidget* widget);
127
128	void appendMRU(const QString& fname);
129	void updateMRU();
130
131	void openView(QWidget* widget);
132
133	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
134	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
135
136	void updateTitle(float fps = NAN);
137
138	GameController* m_controller;
139	Display* m_display;
140	QList<QAction*> m_gameActions;
141	LogView* m_logView;
142	LoadSaveState* m_stateWindow;
143	WindowBackground* m_screenWidget;
144	QPixmap m_logo;
145	ConfigController* m_config;
146	InputController m_inputController;
147	QList<QDateTime> m_frameList;
148	QTimer m_fpsTimer;
149	QList<QString> m_mruFiles;
150	QMenu* m_mruMenu;
151	ShortcutController* m_shortcutController;
152	int m_playerId;
153
154	bool m_hitUnimplementedBiosCall;
155
156#ifdef USE_FFMPEG
157	VideoView* m_videoView;
158#endif
159
160#ifdef USE_MAGICK
161	GIFView* m_gifView;
162#endif
163
164#ifdef USE_GDB_STUB
165	GDBController* m_gdbController;
166#endif
167};
168
169class WindowBackground : public QLabel {
170Q_OBJECT
171
172public:
173	WindowBackground(QWidget* parent = 0);
174
175	void setSizeHint(const QSize& size);
176	virtual QSize sizeHint() const override;
177	void setLockAspectRatio(int width, int height);
178
179protected:
180	virtual void paintEvent(QPaintEvent*) override;
181
182private:
183	QSize m_sizeHint;
184	int m_aspectWidth;
185	int m_aspectHeight;
186};
187
188}
189
190#endif