all repos — mgba @ fe2f67e2aa2246e8ec2c2599a480d6ff7557f3f7

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	, m_lockAspectRatio(false)
 57	, m_lockIntegerScaling(false)
 58	, m_filter(false)
 59{
 60	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 61#ifdef M_CORE_GB
 62	setMinimumSize(GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
 63#elif defined(M_CORE_GBA)
 64	setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
 65#endif
 66	connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(hideCursor()));
 67	m_mouseTimer.setSingleShot(true);
 68	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
 69	setMouseTracking(true);
 70}
 71
 72QSize Display::viewportSize() {
 73	QSize s = size();
 74	QSize ds = s;
 75	if (isAspectRatioLocked()) {
 76		if (s.width() * m_coreHeight > s.height() * m_coreWidth) {
 77			ds.setWidth(s.height() * m_coreWidth / m_coreHeight);
 78		} else if (s.width() * m_coreHeight < s.height() * m_coreWidth) {
 79			ds.setHeight(s.width() * m_coreHeight / m_coreWidth);
 80		}
 81	}
 82	if (isIntegerScalingLocked()) {
 83		ds.setWidth(ds.width() - ds.width() % m_coreWidth);
 84		ds.setHeight(ds.height() - ds.height() % m_coreHeight);
 85	}
 86	return ds;
 87}
 88
 89void Display::resizeEvent(QResizeEvent*) {
 90	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 91}
 92
 93void Display::lockAspectRatio(bool lock) {
 94	m_lockAspectRatio = lock;
 95	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 96}
 97
 98void Display::lockIntegerScaling(bool lock) {
 99	m_lockIntegerScaling = lock;
100}
101
102void Display::filter(bool filter) {
103	m_filter = filter;
104}
105
106void Display::showMessage(const QString& message) {
107	m_messagePainter.showMessage(message);
108	if (!isDrawing()) {
109		forceDraw();
110	}
111}
112
113void Display::mouseMoveEvent(QMouseEvent* event) {
114	emit showCursor();
115	m_mouseTimer.stop();
116	m_mouseTimer.start();
117	event->ignore();
118}
119
120void Display::setSystemDimensions(int width, int height) {
121	m_coreWidth = width;
122	m_coreHeight = height;
123}