src/platform/qt/TilePainter.cpp (view raw)
1/* Copyright (c) 2013-2016 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 "TilePainter.h"
7
8#include <QImage>
9#include <QMouseEvent>
10#include <QPainter>
11
12using namespace QGBA;
13
14TilePainter::TilePainter(QWidget* parent)
15 : QWidget(parent)
16{
17 m_backing = QPixmap(256, 768);
18 m_backing.fill(Qt::transparent);
19}
20
21void TilePainter::paintEvent(QPaintEvent* event) {
22 QPainter painter(this);
23 painter.drawPixmap(QPoint(), m_backing);
24}
25
26void TilePainter::mousePressEvent(QMouseEvent* event) {
27 int x = event->x() / 8;
28 int y = event->y() / 8;
29 emit indexPressed(y * 32 + x);
30}
31
32void TilePainter::setTile(int index, const uint16_t* data) {
33 QPainter painter(&m_backing);
34 int x = index & 31;
35 int y = index / 32;
36 QRect r(x * 8, y * 8, 8, 8);
37 QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555);
38 painter.fillRect(r, tile.rgbSwapped());
39 update(r);
40}