all repos — mgba @ daaa2fa5236df5e8976e7e0ba7ac39e0d9233422

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#ifdef M_CORE_GB
13#include "gb/video.h"
14#elif defined(M_CORE_GBA)
15#include "gba/video.h"
16#endif
17}
18
19using namespace QGBA;
20
21#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
22Display::Driver Display::s_driver = Display::Driver::OPENGL;
23#else
24Display::Driver Display::s_driver = Display::Driver::QT;
25#endif
26
27Display* Display::create(QWidget* parent) {
28#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
29	QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
30	format.setSwapInterval(1);
31#endif
32
33	switch (s_driver) {
34#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
35	case Driver::OPENGL:
36		return new DisplayGL(format, parent);
37#endif
38#ifdef BUILD_GL
39	case Driver::OPENGL1:
40		format.setVersion(1, 4);
41		return new DisplayGL(format, parent);
42#endif
43
44	case Driver::QT:
45		return new DisplayQt(parent);
46
47	default:
48#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
49		return new DisplayGL(format, parent);
50#else
51		return new DisplayQt(parent);
52#endif
53	}
54}
55
56Display::Display(QWidget* parent)
57	: QWidget(parent)
58	, m_lockAspectRatio(false)
59	, m_filter(false)
60{
61	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
62#ifdef M_CORE_GB
63	setMinimumSize(GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
64#elif defined(M_CORE_GBA)
65	setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
66#endif
67	connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(hideCursor()));
68	m_mouseTimer.setSingleShot(true);
69	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
70	setMouseTracking(true);
71}
72
73void Display::resizeEvent(QResizeEvent*) {
74	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
75}
76
77void Display::lockAspectRatio(bool lock) {
78	m_lockAspectRatio = lock;
79	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
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}