all repos — mgba @ 9d80089194c43a509ebc68270d131c6a0f2d2265

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