all repos — mgba @ 534c9ca8f87ebf948404c6ad514c99e2deb1bac1

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#ifdef BUILD_GL
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#ifdef BUILD_GL
25	QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
26	format.setSwapInterval(1);
27#endif
28
29	switch (s_driver) {
30#ifdef BUILD_GL
31	case Driver::OPENGL:
32		return new DisplayGL(format, parent);
33#endif
34
35	case Driver::QT:
36		return new DisplayQt(parent);
37
38	default:
39#ifdef BUILD_GL
40		return new DisplayGL(format, parent);
41#else
42		return new DisplayQt(parent);
43#endif
44	}
45}
46
47Display::Display(QWidget* parent)
48	: QWidget(parent)
49	, m_lockAspectRatio(false)
50	, m_filter(false)
51{
52	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
53	setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
54	connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(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::filter(bool filter) {
70	m_filter = filter;
71}
72
73void Display::showMessage(const QString& message) {
74	m_messagePainter.showMessage(message);
75	if (!isDrawing()) {
76		forceDraw();
77	}
78}
79
80void Display::mouseMoveEvent(QMouseEvent*) {
81	emit showCursor();
82	m_mouseTimer.stop();
83	m_mouseTimer.start();
84}