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