src/platform/qt/Display.cpp (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#include "Display.h"
7
8#include "DisplayGL.h"
9#include "DisplayQt.h"
10
11using namespace QGBA;
12
13#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
14Display::Driver Display::s_driver = Display::Driver::OPENGL;
15#else
16Display::Driver Display::s_driver = Display::Driver::QT;
17#endif
18
19Display* Display::create(QWidget* parent) {
20#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
21 QSurfaceFormat format;
22 format.setSwapInterval(1);
23 format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
24#endif
25
26 switch (s_driver) {
27#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
28 case Driver::OPENGL:
29 if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
30 format.setVersion(3, 0);
31 } else {
32 format.setVersion(3, 2);
33 }
34 format.setProfile(QSurfaceFormat::CoreProfile);
35 return new DisplayGL(format, parent);
36#endif
37#ifdef BUILD_GL
38 case Driver::OPENGL1:
39 format.setVersion(1, 4);
40 return new DisplayGL(format, parent);
41#endif
42
43 case Driver::QT:
44 return new DisplayQt(parent);
45
46 default:
47#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
48 return new DisplayGL(format, parent);
49#else
50 return new DisplayQt(parent);
51#endif
52 }
53}
54
55Display::Display(QWidget* parent)
56 : QWidget(parent)
57{
58 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
59 connect(&m_mouseTimer, &QTimer::timeout, this, &Display::hideCursor);
60 m_mouseTimer.setSingleShot(true);
61 m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
62 setMouseTracking(true);
63}
64
65void Display::resizeEvent(QResizeEvent*) {
66 m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
67}
68
69void Display::lockAspectRatio(bool lock) {
70 m_lockAspectRatio = lock;
71 m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
72}
73
74void Display::lockIntegerScaling(bool lock) {
75 m_lockIntegerScaling = lock;
76}
77
78void Display::interframeBlending(bool lock) {
79 m_interframeBlending = lock;
80}
81
82void Display::showOSDMessages(bool enable) {
83 m_showOSD = enable;
84}
85
86void Display::filter(bool filter) {
87 m_filter = filter;
88}
89
90void Display::showMessage(const QString& message) {
91 m_messagePainter.showMessage(message);
92 if (!isDrawing()) {
93 forceDraw();
94 }
95}
96
97void Display::mouseMoveEvent(QMouseEvent*) {
98 emit showCursor();
99 m_mouseTimer.stop();
100 m_mouseTimer.start();
101}