all repos — mgba @ 080c97532803811f1eb18898d55de37fc05190b7

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