src/platform/qt/ObjView.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 "ObjView.h"
7
8#include "GBAApp.h"
9
10#include <QFontDatabase>
11#include <QTimer>
12
13extern "C" {
14#include "gba/gba.h"
15}
16
17using namespace QGBA;
18
19ObjView::ObjView(GameController* controller, QWidget* parent)
20 : AssetView(controller, parent)
21 , m_controller(controller)
22 , m_tileStatus{}
23 , m_objId(0)
24{
25 m_ui.setupUi(this);
26 m_ui.tile->setController(controller);
27
28 const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
29
30 m_ui.x->setFont(font);
31 m_ui.y->setFont(font);
32 m_ui.w->setFont(font);
33 m_ui.h->setFont(font);
34 m_ui.address->setFont(font);
35
36 connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(translateIndex(int)));
37 connect(m_ui.objId, SIGNAL(valueChanged(int)), this, SLOT(selectObj(int)));
38 connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
39 updateTiles(true);
40 });
41}
42
43void ObjView::selectObj(int obj) {
44 m_objId = obj;
45 updateTiles(true);
46}
47
48void ObjView::translateIndex(int index) {
49 m_ui.tile->selectIndex(index + m_tileOffset);
50}
51
52#ifdef M_CORE_GBA
53void ObjView::updateTilesGBA(bool force) {
54 const GBA* gba = static_cast<const GBA*>(m_controller->thread()->core->board);
55 const GBAObj* obj = &gba->video.oam.obj[m_objId];
56
57 unsigned shape = GBAObjAttributesAGetShape(obj->a);
58 unsigned size = GBAObjAttributesBGetSize(obj->b);
59 unsigned width = GBAVideoObjSizes[shape * 4 + size][0];
60 unsigned height = GBAVideoObjSizes[shape * 4 + size][1];
61 m_ui.tiles->setTileCount(width * height / 64);
62 m_ui.tiles->resize(QSize(width, height) * m_ui.magnification->value());
63 unsigned palette = GBAObjAttributesCGetPalette(obj->c);
64 unsigned tile = GBAObjAttributesCGetTile(obj->c);
65 int i = 0;
66 // TODO: Tile stride
67 if (GBAObjAttributesAIs256Color(obj->a)) {
68 mTileCacheSetPalette(m_tileCache.get(), 1);
69 m_ui.tile->setPalette(0);
70 m_ui.tile->setPaletteSet(1, 1024, 1536);
71 tile /= 2;
72 for (int y = 0; y < height / 8; ++y) {
73 for (int x = 0; x < width / 8; ++x, ++i) {
74 unsigned t = tile + i;
75 const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[32 * t], t + 1024, 1);
76 if (data) {
77 m_ui.tiles->setTile(i, data);
78 } else if (force) {
79 m_ui.tiles->setTile(i, mTileCacheGetTile(m_tileCache.get(), t + 1024, 1));
80 }
81 }
82 }
83 tile += 1024;
84 } else {
85 mTileCacheSetPalette(m_tileCache.get(), 0);
86 m_ui.tile->setPalette(palette);
87 m_ui.tile->setPaletteSet(0, 2048, 3072);
88 for (int y = 0; y < height / 8; ++y) {
89 for (int x = 0; x < width / 8; ++x, ++i) {
90 unsigned t = tile + i;
91 const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[32 * t], t + 2048, palette + 16);
92 if (data) {
93 m_ui.tiles->setTile(i, data);
94 } else if (force) {
95 m_ui.tiles->setTile(i, mTileCacheGetTile(m_tileCache.get(), t + 2048, palette + 16));
96 }
97 }
98 }
99 tile += 2048;
100 }
101 m_tileOffset = tile;
102
103 m_ui.x->setText(QString::number(GBAObjAttributesBGetX(obj->b)));
104 m_ui.y->setText(QString::number(GBAObjAttributesAGetY(obj->a)));
105 m_ui.w->setText(QString::number(width));
106 m_ui.h->setText(QString::number(height));
107
108 // TODO: Flags
109}
110#endif
111
112#ifdef M_CORE_GB
113void ObjView::updateTilesGB(bool force) {
114}
115#endif