author | unC0Rr |
Mon, 17 Feb 2025 16:37:59 +0100 | |
branch | qmlrenderer |
changeset 16089 | 02304ad06381 |
permissions | -rw-r--r-- |
16089
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
1 |
#pragma once |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
2 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
3 |
#include <QImage> |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
4 |
#include <QQuickItem> |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
5 |
#include <QQuickWindow> |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
6 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
7 |
class TiledImageItem : public QQuickItem { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
8 |
Q_OBJECT |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
9 |
QML_ELEMENT |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
10 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
11 |
Q_PROPERTY( |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
12 |
int tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged FINAL) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
13 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
14 |
public: |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
15 |
explicit TiledImageItem(QQuickItem *parent = nullptr); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
16 |
~TiledImageItem(); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
17 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
18 |
void setImageData(int width, int height, uchar *pixels, |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
19 |
QImage::Format format); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
20 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
21 |
int tileSize() const; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
22 |
void setTileSize(int newTileSize); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
23 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
24 |
Q_INVOKABLE void test(const QString &fileName); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
25 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
26 |
protected: |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
27 |
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
28 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
29 |
Q_SIGNALS: |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
30 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
31 |
void tileSizeChanged(); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
32 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
33 |
private: |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
34 |
Q_DISABLE_COPY_MOVE(TiledImageItem) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
35 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
36 |
QImage m_texture; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
37 |
bool m_dirty; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
38 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
39 |
struct Tile { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
40 |
Tile() = default; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
41 |
Tile(Tile &&other) noexcept; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
42 |
~Tile() = default; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
43 |
QRectF outRect; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
44 |
QImage image; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
45 |
bool dirty = false; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
46 |
std::unique_ptr<QSGImageNode> node; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
47 |
std::unique_ptr<QSGTexture, QScopedPointerDeleteLater> texture; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
48 |
}; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
49 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
50 |
void buildTiles(); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
51 |
int m_tileSize{512}; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
52 |
std::vector<Tile> m_tiles; |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
53 |
}; |