src/platform/qt/AssetView.h (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#pragma once
7
8#include <QTimer>
9#include <QTransform>
10#include <QWidget>
11
12#include <mgba/core/cache-set.h>
13
14#include <memory>
15
16struct mMapCacheEntry;
17
18namespace QGBA {
19
20class CoreController;
21
22class AssetView : public QWidget {
23Q_OBJECT
24
25public:
26 AssetView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
27
28protected slots:
29 void updateTiles();
30 void updateTiles(bool force);
31
32protected:
33#ifdef M_CORE_GBA
34 virtual void updateTilesGBA(bool force) = 0;
35#endif
36#ifdef M_CORE_GB
37 virtual void updateTilesGB(bool force) = 0;
38#endif
39
40 void resizeEvent(QResizeEvent*) override;
41 void showEvent(QShowEvent*) override;
42
43 mCacheSet* const m_cacheSet;
44 std::shared_ptr<CoreController> m_controller;
45
46protected:
47 struct ObjInfo {
48 unsigned tile;
49 unsigned width;
50 unsigned height;
51 unsigned stride;
52 unsigned paletteId;
53 unsigned paletteSet;
54 unsigned bits;
55
56 bool enabled : 1;
57 unsigned priority : 2;
58 unsigned x : 9;
59 unsigned y : 9;
60 bool hflip : 1;
61 bool vflip : 1;
62 QTransform xform;
63
64 bool operator!=(const ObjInfo&) const;
65 };
66
67 static void compositeTile(const void* tile, void* image, size_t stride, size_t x, size_t y, int depth = 8);
68 QImage compositeMap(int map, mMapCacheEntry*);
69 QImage compositeObj(const ObjInfo&);
70
71 bool lookupObj(int id, struct ObjInfo*);
72
73private:
74#ifdef M_CORE_GBA
75 bool lookupObjGBA(int id, struct ObjInfo*);
76#endif
77#ifdef M_CORE_GB
78 bool lookupObjGB(int id, struct ObjInfo*);
79#endif
80
81 QTimer m_updateTimer;
82};
83
84}