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 void filter(bool filter);
32#ifdef USE_PNG
33 void screenshot();
34#endif
35
36protected:
37 virtual void initializeGL() override;
38 virtual void paintEvent(QPaintEvent*) override {};
39 virtual void resizeEvent(QResizeEvent*) override;
40
41private:
42 Painter* m_painter;
43 bool m_started;
44 GBAThread* m_context;
45 bool m_lockAspectRatio;
46 bool m_filter;
47};
48
49class Painter : public QObject {
50Q_OBJECT
51
52public:
53 Painter(Display* parent);
54
55 void setContext(GBAThread*);
56 void setBacking(const uint32_t*);
57
58public slots:
59 void forceDraw();
60 void draw();
61 void start();
62 void stop();
63 void pause();
64 void unpause();
65 void resize(const QSize& size);
66 void lockAspectRatio(bool lock);
67 void filter(bool filter);
68
69private:
70 void performDraw();
71
72 QTimer* m_drawTimer;
73 GBAThread* m_context;
74 const uint32_t* m_backing;
75 GLuint m_tex;
76 QGLWidget* m_gl;
77 QSize m_size;
78 bool m_lockAspectRatio;
79 bool m_filter;
80};
81
82}
83
84#endif