all repos — mgba @ 27a178fe3ce47f50ee5460a0ce7efb0bc523d60c

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