all repos — mgba @ adf20bea09a3fe39273bf2ffaf0f12a4dcf83163

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
11extern "C" {
12#include "gba/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, false, parent);
33#endif
34#ifdef BUILD_GL
35	case Driver::OPENGL1:
36		return new DisplayGL(format, true, 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, false, parent);
45#else
46		return new DisplayQt(parent);
47#endif
48	}
49}
50
51Display::Display(QWidget* parent)
52	: QWidget(parent)
53	, m_lockAspectRatio(false)
54	, m_filter(false)
55{
56	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
57	setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
58	connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(hideCursor()));
59	m_mouseTimer.setSingleShot(true);
60	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
61	setMouseTracking(true);
62}
63
64void Display::resizeEvent(QResizeEvent*) {
65	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
66}
67
68void Display::lockAspectRatio(bool lock) {
69	m_lockAspectRatio = lock;
70	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
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}