Linux multi-monitor fullscreen support
[ryzomcore.git] / studio / src / plugins / landscape_editor / landscape_actions.cpp
blobf0e1834555d6a08579909196df0b9601cd33f318
1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // Project includes
21 #include "landscape_actions.h"
22 #include "builder_zone.h"
24 // NeL includes
25 #include <nel/misc/debug.h>
27 // Qt includes
29 namespace LandscapeEditor
32 LigoTileCommand::LigoTileCommand(const LigoData &data, const ZonePosition &zonePos,
33 ZoneBuilder *zoneBuilder, LandscapeScene *scene,
34 QUndoCommand *parent)
35 : QUndoCommand(parent),
36 m_zoneBuilder(zoneBuilder),
37 m_scene(scene)
39 // Backup position
40 m_zonePos = zonePos;
42 // Backup new data
43 m_newLigoData = data;
45 // Backup old data
46 m_zoneBuilder->ligoData(m_oldLigoData, m_zonePos);
49 LigoTileCommand::~LigoTileCommand()
53 void LigoTileCommand::undo ()
55 m_zoneBuilder->setLigoData(m_oldLigoData, m_zonePos);
58 void LigoTileCommand::redo ()
60 m_zoneBuilder->setLigoData(m_newLigoData, m_zonePos);
63 UndoScanRegionCommand::UndoScanRegionCommand(bool direction, ZoneBuilder *zoneBuilder, LandscapeScene *scene, QUndoCommand *parent)
64 : QUndoCommand(parent),
65 m_direction(direction),
66 m_zoneBuilder(zoneBuilder),
67 m_scene(scene)
71 UndoScanRegionCommand::~UndoScanRegionCommand()
73 m_zonePositionList.clear();
76 void UndoScanRegionCommand::setScanList(const QList<ZonePosition> &zonePositionList)
78 m_zonePositionList = zonePositionList;
81 void UndoScanRegionCommand::undo()
83 if (m_direction)
84 applyChanges();
87 void UndoScanRegionCommand::redo()
89 if (!m_direction)
90 applyChanges();
93 void UndoScanRegionCommand::applyChanges()
95 for (int i = 0; i < m_zonePositionList.size(); ++i)
96 m_scene->deleteItemZone(m_zonePositionList.at(i));
98 for (int i = 0; i < m_zonePositionList.size(); ++i)
100 LigoData data;
101 m_zoneBuilder->ligoData(data, m_zonePositionList.at(i));
102 m_scene->createItemZone(data, m_zonePositionList.at(i));
106 LigoResizeCommand::LigoResizeCommand(int index, sint32 newMinX, sint32 newMaxX,
107 sint32 newMinY, sint32 newMaxY, ZoneBuilder *zoneBuilder,
108 QUndoCommand *parent)
109 : QUndoCommand(parent),
110 m_zoneBuilder(zoneBuilder)
112 m_index = index;
113 m_newMinX = newMinX;
114 m_newMaxX = newMaxX;
115 m_newMinY = newMinY;
116 m_newMaxY = newMaxY;
118 // Backup old region zone
119 m_oldZoneRegion = m_zoneBuilder->zoneRegion(m_index)->ligoZoneRegion();
122 LigoResizeCommand::~LigoResizeCommand()
126 void LigoResizeCommand::undo ()
128 // Restore old region zone
129 m_zoneBuilder->zoneRegion(m_index)->setLigoZoneRegion(m_oldZoneRegion);
132 void LigoResizeCommand::redo ()
134 // Get the zone region
135 NLLIGO::CZoneRegion &region = m_zoneBuilder->zoneRegion(m_index)->ligoZoneRegion();
137 sint32 i, j;
138 std::vector<LigoData> newZones;
139 newZones.resize((1 + m_newMaxX - m_newMinX) * (1 + m_newMaxY - m_newMinY));
141 sint32 newStride = 1 + m_newMaxX - m_newMinX;
142 sint32 Stride = 1 + region.getMaxX() - region.getMinX();
144 for (j = m_newMinY; j <= m_newMaxY; ++j)
145 for (i = m_newMinX; i <= m_newMaxX; ++i)
147 // Ref on the new value
148 LigoData &data = newZones[(i - m_newMinX) + (j - m_newMinY) * newStride];
150 // In the old array ?
151 if ((i >= region.getMinX()) && (i <= region.getMaxX()) &&
152 (j >= region.getMinY()) && (j <= region.getMaxY()))
154 // Backup values
155 m_zoneBuilder->ligoData(data, ZonePosition(i, j, m_index));
158 region.resize(m_newMinX, m_newMaxX, m_newMinY, m_newMaxY);
160 for (j = m_newMinY; j <= m_newMaxY; ++j)
161 for (i = m_newMinX; i <= m_newMaxX; ++i)
163 // Ref on the new value
164 const LigoData &data = newZones[(i - m_newMinX) + (j - m_newMinY) * newStride];
166 region.setName(i, j, data.zoneName);
167 region.setPosX(i, j, data.posX);
168 region.setPosY(i, j, data.posY);
169 region.setRot(i, j, data.rot);
170 region.setFlip(i, j, data.flip);
171 uint k;
172 for (k = 0; k < 4; k++)
174 region.setSharingMatNames(i, j, k, data.sharingMatNames[k]);
175 region.setSharingCutEdges(i, j, k, data.sharingCutEdges[k]);
180 } /* namespace LandscapeEditor */