all repos — mgba @ 7d360d6cb893f916ecdcece999303cd6a35e952c

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
 11#ifdef M_CORE_GB
 12#include <mgba/internal/gb/video.h>
 13#elif defined(M_CORE_GBA)
 14#include <mgba/internal/gba/video.h>
 15#endif
 16
 17using namespace QGBA;
 18
 19#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 20Display::Driver Display::s_driver = Display::Driver::OPENGL;
 21#else
 22Display::Driver Display::s_driver = Display::Driver::QT;
 23#endif
 24
 25Display* Display::create(QWidget* parent) {
 26#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 27	QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
 28	format.setSwapInterval(1);
 29#endif
 30
 31	switch (s_driver) {
 32#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 33	case Driver::OPENGL:
 34		return new DisplayGL(format, parent);
 35#endif
 36#ifdef BUILD_GL
 37	case Driver::OPENGL1:
 38		format.setVersion(1, 4);
 39		return new DisplayGL(format, parent);
 40#endif
 41
 42	case Driver::QT:
 43		return new DisplayQt(parent);
 44
 45	default:
 46#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 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{
 57	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 58#ifdef M_CORE_GB
 59	setMinimumSize(GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
 60#elif defined(M_CORE_GBA)
 61	setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
 62#endif
 63	connect(&m_mouseTimer, &QTimer::timeout, this, &Display::hideCursor);
 64	m_mouseTimer.setSingleShot(true);
 65	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
 66	setMouseTracking(true);
 67}
 68
 69QSize Display::viewportSize() {
 70	QSize s = size();
 71	QSize ds = s;
 72	if (isAspectRatioLocked()) {
 73		if (s.width() * m_coreHeight > s.height() * m_coreWidth) {
 74			ds.setWidth(s.height() * m_coreWidth / m_coreHeight);
 75		} else if (s.width() * m_coreHeight < s.height() * m_coreWidth) {
 76			ds.setHeight(s.width() * m_coreHeight / m_coreWidth);
 77		}
 78	}
 79	if (isIntegerScalingLocked()) {
 80		ds.setWidth(ds.width() - ds.width() % m_coreWidth);
 81		ds.setHeight(ds.height() - ds.height() % m_coreHeight);
 82	}
 83	return ds;
 84}
 85
 86void Display::resizeEvent(QResizeEvent*) {
 87	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 88}
 89
 90void Display::lockAspectRatio(bool lock) {
 91	m_lockAspectRatio = lock;
 92	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 93}
 94
 95void Display::lockIntegerScaling(bool lock) {
 96	m_lockIntegerScaling = lock;
 97}
 98
 99void Display::filter(bool filter) {
100	m_filter = filter;
101}
102
103void Display::showMessage(const QString& message) {
104	m_messagePainter.showMessage(message);
105	if (!isDrawing()) {
106		forceDraw();
107	}
108}
109
110void Display::mouseMoveEvent(QMouseEvent* event) {
111	emit showCursor();
112	m_mouseTimer.stop();
113	m_mouseTimer.start();
114	event->ignore();
115}
116
117void Display::setSystemDimensions(int width, int height) {
118	m_coreWidth = width;
119	m_coreHeight = height;
120}