all repos — mgba @ 3f142cb96a7c53d57c96aff5a07f5f19f2e3a0b8

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