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::SingleBuffer);
24#endif
25
26 switch (s_driver) {
27#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
28 case Driver::OPENGL:
29 format.setVersion(3, 0);
30 return new DisplayGL(format, parent);
31#endif
32#ifdef BUILD_GL
33 case Driver::OPENGL1:
34 format.setVersion(1, 4);
35 return new DisplayGL(format, parent);
36#endif
37
38 case Driver::QT:
39 return new DisplayQt(parent);
40
41 default:
42#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
43 return new DisplayGL(format, parent);
44#else
45 return new DisplayQt(parent);
46#endif
47 }
48}
49
50Display::Display(QWidget* parent)
51 : QWidget(parent)
52{
53 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
54 connect(&m_mouseTimer, &QTimer::timeout, this, &Display::hideCursor);
55 m_mouseTimer.setSingleShot(true);
56 m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
57 setMouseTracking(true);
58}
59
60void Display::resizeEvent(QResizeEvent*) {
61 m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
62}
63
64void Display::lockAspectRatio(bool lock) {
65 m_lockAspectRatio = lock;
66 m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
67}
68
69void Display::lockIntegerScaling(bool lock) {
70 m_lockIntegerScaling = lock;
71}
72
73void Display::filter(bool filter) {
74 m_filter = filter;
75}
76
77void Display::showMessage(const QString& message) {
78 m_messagePainter.showMessage(message);
79 if (!isDrawing()) {
80 forceDraw();
81 }
82}
83
84void Display::mouseMoveEvent(QMouseEvent*) {
85 emit showCursor();
86 m_mouseTimer.stop();
87 m_mouseTimer.start();
88}