all repos — mgba @ e6aa23f19cdfe97161f3696fbb3dbc4e3794edd5

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