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