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
10using namespace QGBA;
11
12DisplayQt::DisplayQt(QWidget* parent)
13 : Display(parent)
14 , m_lockAspectRatio(false)
15 , m_filter(false)
16{
17}
18
19void DisplayQt::startDrawing(const uint32_t* buffer, GBAThread* context) {
20 m_context = context;
21#ifdef COLOR_16_BIT
22#ifdef COLOR_5_6_5
23 m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB16);
24#else
25 m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB555);
26#endif
27#else
28 m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB32);
29#endif
30}
31
32void DisplayQt::lockAspectRatio(bool lock) {
33 m_lockAspectRatio = lock;
34 update();
35}
36
37void DisplayQt::filter(bool filter) {
38 m_filter = filter;
39 update();
40}
41
42void DisplayQt::paintEvent(QPaintEvent*) {
43 QPainter painter(this);
44 painter.fillRect(QRect(QPoint(), size()), Qt::black);
45 if (m_filter) {
46 painter.setRenderHint(QPainter::SmoothPixmapTransform);
47 }
48 QSize s = size();
49 QSize ds = s;
50 if (s.width() * 2 > s.height() * 3) {
51 ds.setWidth(s.height() * 3 / 2);
52 } else if (s.width() * 2 < s.height() * 3) {
53 ds.setHeight(s.width() * 2 / 3);
54 }
55 QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2);
56 QRect full(origin, ds);
57
58#ifdef COLOR_5_6_5
59 painter.drawImage(full, m_backing, QRect(0, 0, 240, 160));
60#else
61 painter.drawImage(full, m_backing.rgbSwapped(), QRect(0, 0, 240, 160));
62#endif
63}