1 /*
2 * editabletilelayer.h
3 * Copyright 2018, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
4 *
5 * This file is part of Tiled.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include "editablelayer.h"
24 #include "regionvaluetype.h"
25 #include "tilelayer.h"
26
27 namespace Tiled {
28
29 class EditableTile;
30 class TileLayerEdit;
31
32 class EditableTileLayer : public EditableLayer
33 {
34 Q_OBJECT
35
36 Q_PROPERTY(int width READ width WRITE setWidth)
37 Q_PROPERTY(int height READ height WRITE setHeight)
38 Q_PROPERTY(QSize size READ size WRITE setSize)
39
40 public:
41 Q_INVOKABLE explicit EditableTileLayer(const QString &name = QString(),
42 QSize size = QSize(0, 0),
43 QObject *parent = nullptr);
44
45 explicit EditableTileLayer(EditableMap *map,
46 TileLayer *layer,
47 QObject *parent = nullptr);
48 ~EditableTileLayer() override;
49
50 int width() const;
51 int height() const;
52 QSize size() const;
53
54 void setWidth(int width);
55 void setHeight(int height);
56 void setSize(QSize size);
57
58 Q_INVOKABLE void resize(QSize size, QPoint offset = QPoint());
59
60 Q_INVOKABLE Tiled::RegionValueType region() const;
61
62 Q_INVOKABLE Tiled::Cell cellAt(int x, int y) const;
63 Q_INVOKABLE int flagsAt(int x, int y) const;
64 Q_INVOKABLE Tiled::EditableTile *tileAt(int x, int y) const;
65
66 Q_INVOKABLE Tiled::TileLayerEdit *edit();
67
68 TileLayer *tileLayer() const;
69
70 private:
71 friend TileLayerEdit;
72
73 QList<TileLayerEdit*> mActiveEdits;
74 };
75
76
width()77 inline int EditableTileLayer::width() const
78 {
79 return tileLayer()->width();
80 }
81
height()82 inline int EditableTileLayer::height() const
83 {
84 return tileLayer()->height();
85 }
86
size()87 inline QSize EditableTileLayer::size() const
88 {
89 return tileLayer()->size();
90 }
91
setWidth(int width)92 inline void EditableTileLayer::setWidth(int width)
93 {
94 setSize(QSize(width, height()));
95 }
96
setHeight(int height)97 inline void EditableTileLayer::setHeight(int height)
98 {
99 setSize(QSize(width(), height));
100 }
101
tileLayer()102 inline TileLayer *EditableTileLayer::tileLayer() const
103 {
104 return static_cast<TileLayer*>(layer());
105 }
106
107 } // namespace Tiled
108
109 Q_DECLARE_METATYPE(Tiled::EditableTileLayer*)
110