all repos — mgba @ 546f787eb3b276f4ad2f5469f5a774dc83fbbe09

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