all repos — mgba @ c7b6c4412d772011f4e1b9ee63dd830975e30972

mGBA Game Boy Advance Emulator

src/platform/qt/FrameView.h (view raw)

  1/* Copyright (c) 2013-2019 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 "ui_FrameView.h"
  9
 10#include <QBitmap>
 11#include <QImage>
 12#include <QList>
 13#include <QMutex>
 14#include <QPixmap>
 15#include <QSet>
 16#include <QTimer>
 17
 18#include "AssetView.h"
 19
 20#include <mgba-util/vfs.h>
 21
 22#include <memory>
 23
 24struct VFile;
 25
 26namespace QGBA {
 27
 28class CoreController;
 29
 30class FrameView : public AssetView {
 31Q_OBJECT
 32
 33public:
 34	FrameView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
 35	~FrameView();
 36
 37public slots:
 38	void selectLayer(const QPointF& coord);
 39	void disableLayer(const QPointF& coord);
 40	void exportFrame();
 41
 42protected:
 43#ifdef M_CORE_GBA
 44	void updateTilesGBA(bool force) override;
 45	void injectGBA();
 46#endif
 47#ifdef M_CORE_GB
 48	void updateTilesGB(bool force) override;
 49	void injectGB();
 50#endif
 51
 52	bool eventFilter(QObject* obj, QEvent* event) override;
 53
 54private slots:
 55	void invalidateQueue(const QSize& = {});
 56	void updateRendered();
 57	void refreshVl();
 58	void newVl();
 59
 60private:
 61	struct LayerId {
 62		enum {
 63			NONE = 0,
 64			BACKGROUND,
 65			WINDOW,
 66			SPRITE,
 67			BACKDROP
 68		} type = NONE;
 69		int index = -1;
 70
 71		bool operator!=(const LayerId& other) const { return other.type != type || other.index != index; }
 72		operator uint() const { return (type << 8) | index; }
 73		QString readable() const;
 74	};
 75
 76	struct Layer {
 77		LayerId id;
 78		bool enabled;
 79		QPixmap image;
 80		QRegion mask;
 81		QPointF location;
 82		bool repeats;
 83	};
 84
 85	bool lookupLayer(const QPointF& coord, Layer*&);
 86
 87	static void frameCallback(FrameView*, std::shared_ptr<bool>);
 88
 89	Ui::FrameView m_ui;
 90
 91	LayerId m_active{};
 92
 93	int m_glowFrame;
 94	QTimer m_glowTimer;
 95
 96	QMutex m_mutex{QMutex::Recursive};
 97	VFile* m_currentFrame = nullptr;
 98	VFile* m_nextFrame = nullptr;
 99	mCore* m_vl = nullptr;
100	QImage m_framebuffer;
101
102	QSize m_dims;
103	QList<Layer> m_queue;
104	QSet<LayerId> m_disabled;
105	QPixmap m_composited;
106	QPixmap m_rendered;
107	mMapCacheEntry m_mapStatus[4][128 * 128] = {}; // TODO: Correct size
108
109#ifdef M_CORE_GBA
110	uint16_t m_gbaDispcnt;
111#endif
112
113	std::shared_ptr<bool> m_callbackLocker{std::make_shared<bool>(true)};
114};
115
116}