all repos — mgba @ ce0ad004e4acb88b3f1a0716caccf5eb1ac743db

mGBA Game Boy Advance Emulator

src/platform/qt/Display.h (view raw)

 1/* Copyright (c) 2013-2014 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_DISPLAY
 7#define QGBA_DISPLAY
 8
 9#include <QGLWidget>
10#include <QThread>
11#include <QTimer>
12
13struct GBAThread;
14
15namespace QGBA {
16
17class Painter;
18class Display : public QGLWidget {
19Q_OBJECT
20
21public:
22	Display(QGLFormat format, QWidget* parent = nullptr);
23
24public slots:
25	void startDrawing(const uint32_t* buffer, GBAThread* context);
26	void stopDrawing();
27	void pauseDrawing();
28	void unpauseDrawing();
29	void forceDraw();
30	void lockAspectRatio(bool lock);
31#ifdef USE_PNG
32	void screenshot();
33#endif
34
35protected:
36	virtual void initializeGL() override;
37	virtual void paintEvent(QPaintEvent*) override {};
38	virtual void resizeEvent(QResizeEvent*) override;
39
40private:
41	Painter* m_painter;
42	QThread* m_drawThread;
43	GBAThread* m_context;
44	bool m_lockAspectRatio;
45};
46
47class Painter : public QObject {
48Q_OBJECT
49
50public:
51	Painter(Display* parent);
52
53	void setContext(GBAThread*);
54	void setBacking(const uint32_t*);
55
56public slots:
57	void forceDraw();
58	void draw();
59	void start();
60	void stop();
61	void pause();
62	void unpause();
63	void resize(const QSize& size);
64	void lockAspectRatio(bool lock);
65
66private:
67	void performDraw();
68
69	QTimer* m_drawTimer;
70	GBAThread* m_context;
71	const uint32_t* m_backing;
72	GLuint m_tex;
73	QGLWidget* m_gl;
74	QSize m_size;
75	bool m_lockAspectRatio;
76};
77
78}
79
80#endif