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 FRAME
71 } type = NONE;
72 int index = -1;
73
74 bool operator!=(const LayerId& other) const { return other.type != type || other.index != index; }
75 operator uint() const { return (type << 12) | (index & 0xFFF); }
76 QString readable() const;
77 };
78
79 struct Layer {
80 LayerId id;
81 bool enabled;
82 QPixmap image;
83 QRegion mask;
84 QPointF location;
85 bool repeats;
86 bool fixed;
87 };
88
89 bool lookupLayer(const QPointF& coord, Layer*&);
90
91 static void frameCallback(FrameView*, std::shared_ptr<bool>);
92
93 Ui::FrameView m_ui;
94
95 LayerId m_active{};
96
97 int m_glowFrame;
98 QTimer m_glowTimer;
99
100 QMutex m_mutex{QMutex::Recursive};
101 VFile* m_currentFrame = nullptr;
102 VFile* m_nextFrame = nullptr;
103 mCore* m_vl = nullptr;
104 QImage m_framebuffer;
105
106 QSize m_dims;
107 QList<Layer> m_queue;
108 QSet<LayerId> m_disabled;
109 QPixmap m_composited;
110 QPixmap m_rendered;
111 mMapCacheEntry m_mapStatus[4][128 * 128] = {}; // TODO: Correct size
112 ColorPicker m_backdropPicker;
113 QColor m_overrideBackdrop;
114
115#ifdef M_CORE_GBA
116 uint16_t m_gbaDispcnt;
117#endif
118
119 std::shared_ptr<bool> m_callbackLocker{std::make_shared<bool>(true)};
120};
121
122}