all repos — mgba @ 1baa9287f34855f9eaceab89eb7703cb928f5599

mGBA Game Boy Advance Emulator

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