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
11extern "C" {
12#include "gb/video.h"
13}
14
15using namespace QGBA;
16
17#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
18Display::Driver Display::s_driver = Display::Driver::OPENGL;
19#else
20Display::Driver Display::s_driver = Display::Driver::QT;
21#endif
22
23Display* Display::create(QWidget* parent) {
24#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
25 QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
26 format.setSwapInterval(1);
27#endif
28
29 switch (s_driver) {
30#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
31 case Driver::OPENGL:
32 return new DisplayGL(format, parent);
33#endif
34#ifdef BUILD_GL
35 case Driver::OPENGL1:
36 format.setVersion(1, 4);
37 return new DisplayGL(format, parent);
38#endif
39
40 case Driver::QT:
41 return new DisplayQt(parent);
42
43 default:
44#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
45 return new DisplayGL(format, parent);
46#else
47 return new DisplayQt(parent);
48#endif
49 }
50}
51
52Display::Display(QWidget* parent)
53 : QWidget(parent)
54 , m_lockAspectRatio(false)
55 , m_filter(false)
56{
57 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
58 setMinimumSize(GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
59 connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(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::filter(bool filter) {
75 m_filter = filter;
76}
77
78void Display::showMessage(const QString& message) {
79 m_messagePainter.showMessage(message);
80 if (!isDrawing()) {
81 forceDraw();
82 }
83}
84
85void Display::mouseMoveEvent(QMouseEvent*) {
86 emit showCursor();
87 m_mouseTimer.stop();
88 m_mouseTimer.start();
89}