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 16 struct mMapCacheEntry; 17 18 namespace QGBA { 19 20 class CoreController; 21 22 class AssetView : public QWidget { 23 Q_OBJECT 24 25 public: 26 AssetView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr); 27 28 protected slots: 29 void updateTiles(); 30 void updateTiles(bool force); 31 32 protected: 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 46 protected: 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 int x : 10; 59 int y : 10; 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 73 private: 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 } 85