all repos — mgba @ 9dc49df0bca23925cfcc8193a1770463fd9916cf

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