all repos — mgba @ 4fd170ac38a9c312f3dd1d0dd912d2c761f60fdb

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		if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
 30			format.setVersion(3, 0);
 31		} else {
 32			format.setVersion(3, 2);
 33		}
 34		format.setProfile(QSurfaceFormat::CoreProfile);
 35		return new DisplayGL(format, parent);
 36#endif
 37#ifdef BUILD_GL
 38	case Driver::OPENGL1:
 39		format.setVersion(1, 4);
 40		return new DisplayGL(format, parent);
 41#endif
 42
 43	case Driver::QT:
 44		return new DisplayQt(parent);
 45
 46	default:
 47#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 48		return new DisplayGL(format, parent);
 49#else
 50		return new DisplayQt(parent);
 51#endif
 52	}
 53}
 54
 55Display::Display(QWidget* parent)
 56	: QWidget(parent)
 57{
 58	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 59	connect(&m_mouseTimer, &QTimer::timeout, this, &Display::hideCursor);
 60	m_mouseTimer.setSingleShot(true);
 61	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
 62	setMouseTracking(true);
 63}
 64
 65QSize Display::viewportSize() {
 66	QSize s = size();
 67	QSize ds = s;
 68	if (isAspectRatioLocked()) {
 69		if (s.width() * m_coreHeight > s.height() * m_coreWidth) {
 70			ds.setWidth(s.height() * m_coreWidth / m_coreHeight);
 71		} else if (s.width() * m_coreHeight < s.height() * m_coreWidth) {
 72			ds.setHeight(s.width() * m_coreHeight / m_coreWidth);
 73		}
 74	}
 75	if (isIntegerScalingLocked()) {
 76		ds.setWidth(ds.width() - ds.width() % m_coreWidth);
 77		ds.setHeight(ds.height() - ds.height() % m_coreHeight);
 78	}
 79	return ds;
 80}
 81
 82void Display::resizeEvent(QResizeEvent*) {
 83	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 84}
 85
 86void Display::lockAspectRatio(bool lock) {
 87	m_lockAspectRatio = lock;
 88	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 89}
 90
 91void Display::lockIntegerScaling(bool lock) {
 92	m_lockIntegerScaling = lock;
 93}
 94
 95void Display::interframeBlending(bool lock) {
 96	m_interframeBlending = lock;
 97}
 98
 99void Display::showOSDMessages(bool enable) {
100	m_showOSD = enable;
101}
102
103void Display::filter(bool filter) {
104	m_filter = filter;
105}
106
107void Display::showMessage(const QString& message) {
108	m_messagePainter.showMessage(message);
109	if (!isDrawing()) {
110		forceDraw();
111	}
112}
113
114void Display::mouseMoveEvent(QMouseEvent* event) {
115	emit showCursor();
116	m_mouseTimer.stop();
117	m_mouseTimer.start();
118	event->ignore();
119}
120
121void Display::setSystemDimensions(int width, int height) {
122	m_coreWidth = width;
123	m_coreHeight = height;
124}