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