all repos — mgba @ 9dfcef3f45efe580e252ec8bc3852257e9de9fd6

mGBA Game Boy Advance Emulator

src/platform/qt/DisplayQt.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 "DisplayQt.h"
 7
 8#include <QPainter>
 9
10#include <mgba/core/core.h>
11#include <mgba/core/thread.h>
12
13using namespace QGBA;
14
15DisplayQt::DisplayQt(QWidget* parent)
16	: Display(parent)
17{
18}
19
20void DisplayQt::startDrawing(mCoreThread* context) {
21	context->core->desiredVideoDimensions(context->core, &m_width, &m_height);
22	setSystemDimensions(m_width, m_height);
23	m_backing = std::move(QImage());
24	m_isDrawing = true;
25}
26
27void DisplayQt::lockAspectRatio(bool lock) {
28	Display::lockAspectRatio(lock);
29	update();
30}
31
32void DisplayQt::lockIntegerScaling(bool lock) {
33	Display::lockIntegerScaling(lock);
34	update();
35}
36
37void DisplayQt::filter(bool filter) {
38	Display::filter(filter);
39	update();
40}
41
42void DisplayQt::framePosted(const uint32_t* buffer) {
43	update();
44	if (const_cast<const QImage&>(m_backing).bits() == reinterpret_cast<const uchar*>(buffer)) {
45		return;
46	}
47#ifdef COLOR_16_BIT
48#ifdef COLOR_5_6_5
49	m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_RGB16);
50#else
51	m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_RGB555);
52#endif
53#else
54	m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_ARGB32);
55	m_backing = m_backing.convertToFormat(QImage::Format_RGB32);
56#endif
57}
58
59void DisplayQt::paintEvent(QPaintEvent*) {
60	QPainter painter(this);
61	painter.fillRect(QRect(QPoint(), size()), Qt::black);
62	if (isFiltered()) {
63		painter.setRenderHint(QPainter::SmoothPixmapTransform);
64	}
65	QSize s = size();
66	QSize ds = viewportSize();
67	QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2);
68	QRect full(origin, ds);
69
70#ifdef COLOR_5_6_5
71	painter.drawImage(full, m_backing, QRect(0, 0, m_width, m_height));
72#else
73	painter.drawImage(full, m_backing.rgbSwapped(), QRect(0, 0, m_width, m_height));
74#endif
75	messagePainter()->paint(&painter);
76}