1 /* 2 * changeevents.h 3 * Copyright 2019, 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 "map.h" 24 #include "mapobject.h" 25 #include "wangset.h" 26 27 #include <QList> 28 29 namespace Tiled { 30 31 class Layer; 32 class WangSet; 33 34 class ChangeEvent 35 { 36 public: 37 enum Type { 38 MapChanged, 39 LayerChanged, 40 TileLayerChanged, 41 MapObjectAboutToBeAdded, 42 MapObjectAboutToBeRemoved, 43 MapObjectAdded, 44 MapObjectRemoved, 45 MapObjectsAboutToBeRemoved, 46 MapObjectsAdded, 47 MapObjectsChanged, 48 MapObjectsRemoved, 49 ObjectGroupChanged, 50 TilesAboutToBeRemoved, 51 WangSetAboutToBeAdded, 52 WangSetAboutToBeRemoved, 53 WangSetAdded, 54 WangSetRemoved, 55 WangSetChanged, 56 WangColorAboutToBeRemoved, 57 } type; 58 59 protected: ChangeEvent(Type type)60 ChangeEvent(Type type) 61 : type(type) 62 {} 63 64 // not virtual, but protected to avoid calling at this level ~ChangeEvent()65 ~ChangeEvent() 66 {} 67 }; 68 69 class MapChangeEvent : public ChangeEvent 70 { 71 public: MapChangeEvent(Map::Property property)72 MapChangeEvent(Map::Property property) 73 : ChangeEvent(MapChanged) 74 , property(property) 75 {} 76 77 Map::Property property; 78 }; 79 80 class LayerChangeEvent : public ChangeEvent 81 { 82 public: 83 enum LayerProperty { 84 NameProperty = 1 << 0, 85 OpacityProperty = 1 << 1, 86 VisibleProperty = 1 << 2, 87 LockedProperty = 1 << 3, 88 OffsetProperty = 1 << 4, 89 ParallaxFactorProperty = 1 << 5, 90 TintColorProperty = 1 << 6, 91 PositionProperties = OffsetProperty | ParallaxFactorProperty, 92 AllProperties = 0xFF 93 }; 94 95 LayerChangeEvent(Layer *layer, int properties = AllProperties) LayerChangeEvent(LayerChanged,layer,properties)96 : LayerChangeEvent(LayerChanged, layer, properties) 97 {} 98 99 Layer *layer; 100 int properties; 101 102 protected: 103 LayerChangeEvent(Type type, Layer *layer, int properties = AllProperties) ChangeEvent(type)104 : ChangeEvent(type) 105 , layer(layer) 106 , properties(properties) 107 {} 108 }; 109 110 class TileLayerChangeEvent : public LayerChangeEvent 111 { 112 public: 113 enum TileLayerProperty { 114 SizeProperty = 1 << 5, 115 }; 116 TileLayerChangeEvent(TileLayer * tileLayer,int properties)117 TileLayerChangeEvent(TileLayer *tileLayer, int properties) 118 : LayerChangeEvent(TileLayerChanged, tileLayer, properties) 119 {} 120 tileLayer()121 TileLayer *tileLayer() { return static_cast<TileLayer*>(layer); } 122 }; 123 124 class ObjectGroupChangeEvent : public ChangeEvent 125 { 126 public: 127 enum ObjectGroupProperty { 128 ColorProperty = 1 << 0, 129 DrawOrderProperty = 1 << 1, 130 }; 131 ObjectGroupChangeEvent(ObjectGroup * objectGroup,int properties)132 ObjectGroupChangeEvent(ObjectGroup *objectGroup, int properties) 133 : ChangeEvent(ObjectGroupChanged) 134 , objectGroup(objectGroup) 135 , properties(properties) 136 {} 137 138 ObjectGroup *objectGroup; 139 int properties; 140 }; 141 142 class MapObjectsEvent : public ChangeEvent 143 { 144 public: MapObjectsEvent(Type type,QList<MapObject * > mapObjects)145 MapObjectsEvent(Type type, QList<MapObject *> mapObjects) 146 : ChangeEvent(type) 147 , mapObjects(std::move(mapObjects)) 148 {} 149 150 QList<MapObject *> mapObjects; 151 }; 152 153 class MapObjectsChangeEvent : public MapObjectsEvent 154 { 155 public: 156 MapObjectsChangeEvent(MapObject *mapObject, 157 MapObject::ChangedProperties properties = MapObject::AllProperties) MapObjectsChangeEvent(QList<MapObject * >{ mapObject },properties)158 : MapObjectsChangeEvent(QList<MapObject *> { mapObject }, properties) 159 {} 160 161 MapObjectsChangeEvent(QList<MapObject *> mapObjects, 162 MapObject::ChangedProperties properties = MapObject::AllProperties) MapObjectsEvent(MapObjectsChanged,std::move (mapObjects))163 : MapObjectsEvent(MapObjectsChanged, std::move(mapObjects)) 164 , properties(properties) 165 {} 166 167 MapObject::ChangedProperties properties; 168 }; 169 170 class MapObjectEvent : public ChangeEvent 171 { 172 public: MapObjectEvent(Type type,ObjectGroup * objectGroup,int index)173 MapObjectEvent(Type type, ObjectGroup *objectGroup, int index) 174 : ChangeEvent(type) 175 , objectGroup(objectGroup) 176 , index(index) 177 {} 178 179 ObjectGroup *objectGroup; 180 int index; 181 }; 182 183 class TilesEvent : public ChangeEvent 184 { 185 public: TilesEvent(Type type,QList<Tile * > tiles)186 TilesEvent(Type type, QList<Tile *> tiles) 187 : ChangeEvent(type) 188 , tiles(std::move(tiles)) 189 {} 190 191 QList<Tile *> tiles; 192 }; 193 194 class WangSetEvent : public ChangeEvent 195 { 196 public: WangSetEvent(Type type,Tileset * tileset,int index)197 WangSetEvent(Type type, Tileset *tileset, int index) 198 : ChangeEvent(type) 199 , tileset(tileset) 200 , index(index) 201 {} 202 203 Tileset *tileset; 204 int index; 205 }; 206 207 class WangSetChangeEvent : public ChangeEvent 208 { 209 public: 210 enum WangSetProperty { 211 TypeProperty = 1 << 0, 212 }; 213 WangSetChangeEvent(WangSet * wangSet,int properties)214 WangSetChangeEvent(WangSet *wangSet, int properties) 215 : ChangeEvent(WangSetChanged) 216 , wangSet(wangSet) 217 , properties(properties) 218 {} 219 220 WangSet *wangSet; 221 int properties; 222 }; 223 224 class WangColorEvent : public ChangeEvent 225 { 226 public: WangColorEvent(Type type,WangSet * wangSet,int color)227 WangColorEvent(Type type, WangSet *wangSet, int color) 228 : ChangeEvent(type) 229 , wangSet(wangSet) 230 , color(color) 231 {} 232 233 WangSet *wangSet; 234 int color; 235 }; 236 237 } // namespace Tiled 238