123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863 |
- /*
- * scenelayer.cpp, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- #include "StdInc.h"
- #include "scenelayer.h"
- #include "mainwindow.h"
- #include "../lib/mapping/CMapEditManager.h"
- #include "../lib/mapping/CMap.h"
- #include "inspector/inspector.h"
- #include "mapview.h"
- #include "mapcontroller.h"
- AbstractLayer::AbstractLayer(MapSceneBase * s): scene(s)
- {
- }
- void AbstractLayer::initialize(MapController & controller)
- {
- map = controller.map();
- handler = controller.mapHandler();
- }
- void AbstractLayer::show(bool show)
- {
- isShown = show;
- redraw();
- }
- int AbstractLayer::mapWidthPx() const
- {
- return map ? map->width * tileSize : 0;
- }
- int AbstractLayer::mapHeightPx() const
- {
- return map ? map->height * tileSize : 0;
- }
- int AbstractLayer::toInt(double value) const
- {
- return static_cast<int>(std::round(value)); // is rounded explicitly in order to avoid rounding down unprecise double values
- }
- AbstractFixedLayer::AbstractFixedLayer(MapSceneBase * s): AbstractLayer(s)
- {
- }
- void AbstractFixedLayer::redraw()
- {
- if(item)
- {
- if(pixmap && isShown)
- item->setPixmap(*pixmap);
- else
- item->setPixmap(emptyPixmap);
- }
- else
- {
- if(pixmap && isShown)
- item.reset(scene->addPixmap(*pixmap));
- else
- item.reset(scene->addPixmap(emptyPixmap));
- }
- }
- AbstractViewportLayer::AbstractViewportLayer(MapSceneBase * s): AbstractLayer(s)
- {
- }
- void AbstractViewportLayer::createLayer()
- {
- QList<QGraphicsItem *>emptyList;
- items.reset(scene->createItemGroup(emptyList));
- }
- void AbstractViewportLayer::setViewport(const QRectF & viewPort)
- {
- if(!map)
- return;
- if (items->boundingRect().contains(viewPort))
- return;
- std::vector<QGraphicsItem *> outOfScreenSectors;
- for (QGraphicsItem * sector : getAllSectors())
- {
- if (!viewPort.intersects(sector->sceneBoundingRect()))
- outOfScreenSectors.push_back(sector);
- }
- for (QGraphicsItem * sector : outOfScreenSectors)
- {
- removeSector(sector);
- }
- std::vector<QRectF> newAreas;
- int left = toInt(viewPort.left());
- int right = toInt(viewPort.right());
- int top = toInt(viewPort.top());
- int bottom = toInt(viewPort.bottom());
- int startX = left - (left % sectorSize);
- int limitX = std::min(right + (sectorSize - right % sectorSize), mapWidthPx());
- int startY = top - (top % sectorSize);
- int limitY = std::min(bottom + (sectorSize - bottom % sectorSize), mapHeightPx());
- for (int x = startX; x < limitX; x += sectorSize)
- {
- for (int y = startY; y < limitY; y += sectorSize)
- {
- int width = x + sectorSize < limitX ? sectorSize : limitX - x;
- int height = y + sectorSize < limitY ? sectorSize : limitY - y;
- QRectF area(x, y, width, height);
- if (!items->boundingRect().intersects(area))
- newAreas.emplace_back(area);
- }
- }
- for(QRectF newSection : newAreas)
- {
- QGraphicsItem * sector = draw(newSection);
- if (sector)
- addSector(sector);
- }
- }
- void AbstractViewportLayer::update()
- {
- redraw();
- }
- void AbstractViewportLayer::redraw()
- {
- std::set<QGraphicsItem *> allSectors;
- for (auto * sector : getAllSectors())
- allSectors.insert(sector);
- redrawSectors(allSectors);
- }
- void AbstractViewportLayer::redraw(const std::vector<int3> & tiles)
- {
- std::set<QGraphicsItem *> sectorsToRedraw = getContainingSectors(tiles);
- redrawSectors(sectorsToRedraw);
- }
- void AbstractViewportLayer::redrawWithSurroundingTiles(const std::vector<int3> & tiles)
- {
- int maxX = 0;
- int maxY = 0;
- int minX = INT_MAX;
- int minY = INT_MAX;
- for (const int3 tile : tiles)
- {
- maxX = std::max(tile.x, maxX);
- maxY = std::max(tile.y, maxY);
- minX = std::min(tile.x, minX);
- minY = std::min(tile.y, minY);
- }
- QRectF bounds((minX - 2) * tileSize, (minY - 2) * tileSize, (maxX - minX + 4) * tileSize, (maxY - minY + 4) * tileSize); //tiles start with 1, QRectF from 0
- redraw({bounds});
- }
- void AbstractViewportLayer::redraw(const std::set<CGObjectInstance *> & objects)
- {
- std::vector<QRectF> areas(objects.size());
- for (const CGObjectInstance * object : objects)
- {
- areas.push_back(getObjectArea(object));
- }
- redraw(areas);
- }
- void AbstractViewportLayer::redraw(const std::vector<QRectF> & areas)
- {
- std::set<QGraphicsItem *> intersectingSectors;
- for (QGraphicsItem * existingSector : getAllSectors())
- {
- for (auto area : areas)
- {
- if (existingSector->sceneBoundingRect().intersects(area))
- {
- intersectingSectors.insert(existingSector);
- }
- }
- }
- redrawSectors(intersectingSectors);
- }
- QRectF AbstractViewportLayer::getObjectArea(const CGObjectInstance * object) const
- {
- auto pos = object->pos;
- int x = ((pos.x + 1) * tileSize) - (object->getWidth() * tileSize); //Qt set 0,0 point on the top right corner, CGObjectInstance on the bottom left
- int y = ((pos.y + 1) * tileSize) - (object->getHeight() * tileSize);
- QRectF objectArea(x, y, object->getWidth() * tileSize, object->getHeight() * tileSize);
- return objectArea;
- }
- void AbstractViewportLayer::addSector(QGraphicsItem * sector)
- {
- items->addToGroup(sector);
- }
- void AbstractViewportLayer::removeSector(QGraphicsItem * sector)
- {
- items->removeFromGroup(sector);
- delete sector;
- }
- void AbstractViewportLayer::redrawSectors(std::set<QGraphicsItem *> & sectors)
- {
- std::set<QGraphicsItem *> sectorsToRemove;
- for (QGraphicsItem * existingSectors : getAllSectors())
- {
- for (QGraphicsItem * sector : sectors)
- {
- if (existingSectors->sceneBoundingRect().contains(sector->sceneBoundingRect()))
- sectorsToRemove.insert(existingSectors);
- }
- }
- for (QGraphicsItem * sectorToRemove : sectorsToRemove)
- {
- addSector(draw(sectorToRemove->sceneBoundingRect()));
- removeSector(sectorToRemove);
- }
- }
- const QList<QGraphicsItem *> AbstractViewportLayer::getAllSectors() const //returning const is necessary to avoid "range-loop might detach Qt container" problem
- {
- QList<QGraphicsItem *> emptyList;
- return items ? items->childItems() : emptyList;
- }
- std::set<QGraphicsItem *> AbstractViewportLayer::getContainingSectors(const std::vector<int3> & tiles) const
- {
- std::set<QGraphicsItem *> result;
- for (QGraphicsItem * existingSector : getAllSectors()) {
- for (const int3 tile : tiles)
- {
- if (existingSector->sceneBoundingRect().contains(QPointF(tile.x * tileSize, tile.y * tileSize)))
- {
- result.insert(existingSector);
- break;
- }
- }
- }
- return result;
- }
- std::set<QGraphicsItem *> AbstractViewportLayer::getIntersectingSectors(const std::vector<QRectF> & areas) const
- {
- std::set<QGraphicsItem *> result;
- for (QGraphicsItem * existingSector : getAllSectors()) {
- for (QRectF area : areas)
- {
- if (existingSector->sceneBoundingRect().intersects(area))
- {
- result.insert(existingSector);
- }
- }
- }
- return result;
- }
- EmptyLayer::EmptyLayer(MapSceneBase * s): AbstractFixedLayer(s)
- {
- isShown = true;
- }
- void EmptyLayer::update()
- {
- if(!map)
- return;
- pixmap = std::make_unique<QPixmap>(map->width * 32, map->height * 32);
- redraw();
- }
- GridLayer::GridLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- QGraphicsItem * GridLayer::draw(const QRectF & section)
- {
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- if (isShown)
- {
- QPainter painter(&pixmap);
- painter.setPen(QColor(0, 0, 0, 190));
- for(int j = 0; j <= pixmap.height(); j += tileSize)
- {
- painter.drawLine(0, j, pixmap.width(), j);
- }
- for(int i = 0; i <= pixmap.width(); i += tileSize)
- {
- painter.drawLine(i, 0, i, pixmap.height());
- }
- }
- QGraphicsItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- PassabilityLayer::PassabilityLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- QGraphicsItem * PassabilityLayer::draw(const QRectF & section)
- {
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- if(isShown)
- {
- QPainter painter(&pixmap);
- for(int j = 0; j <= pixmap.height(); j += tileSize)
- {
- for(int i = 0; i < pixmap.width(); i += tileSize)
- {
- auto tl = map->getTile(int3(toInt(section.x())/tileSize + i/tileSize, toInt(section.y())/tileSize + j/tileSize, scene->level));
- if(tl.blocked() || tl.visitable())
- {
- painter.fillRect(i, j, 31, 31, tl.visitable() ? QColor(200, 200, 0, 64) : QColor(255, 0, 0, 64));
- }
- }
- }
- }
- QGraphicsItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- ObjectPickerLayer::ObjectPickerLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- void ObjectPickerLayer::highlight(const std::function<bool(const CGObjectInstance *)> & predicate)
- {
- if(!map)
- return;
-
- for(int j = 0; j < map->height; ++j)
- {
- for(int i = 0; i < map->width; ++i)
- {
- auto tl = map->getTile(int3(i, j, scene->level));
- ObjectInstanceID objID = tl.topVisitableObj();
- if(!objID.hasValue() && !tl.blockingObjects.empty())
- objID = tl.blockingObjects.front();
- if (objID.hasValue())
- {
- const CGObjectInstance * obj = map->getObject(objID);
-
- if(obj && predicate(obj))
- possibleObjects.insert(obj);
- }
- }
- }
-
- isActive = true;
- }
- bool ObjectPickerLayer::isVisible() const
- {
- return isShown && isActive;
- }
- void ObjectPickerLayer::clear()
- {
- possibleObjects.clear();
- isActive = false;
- }
- QGraphicsItem * ObjectPickerLayer::draw(const QRectF & section)
- {
- int offsetX = toInt(section.x());
- int offsetY = toInt(section.y());
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- if(isVisible())
- pixmap.fill(QColor(255, 255, 255, 128));
- QPainter painter(&pixmap);
- painter.setCompositionMode(QPainter::CompositionMode_Source);
- for(const auto * obj : possibleObjects)
- {
- if(obj->pos.z != scene->level)
- continue;
- for(const auto & pos : obj->getBlockedPos())
- painter.fillRect(pos.x * tileSize - offsetX, pos.y * tileSize - offsetY, tileSize, tileSize, QColor(255, 211, 0, 64));
- }
- QGraphicsItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- void ObjectPickerLayer::select(const CGObjectInstance * obj)
- {
- if(obj && possibleObjects.count(obj))
- {
- clear();
- Q_EMIT selectionMade(obj);
- }
- }
- void ObjectPickerLayer::discard()
- {
- clear();
- Q_EMIT selectionMade(nullptr);
- }
- SelectionTerrainLayer::SelectionTerrainLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- QGraphicsItem * SelectionTerrainLayer::draw(const QRectF & section)
- {
- int offsetX = toInt(section.x());
- int offsetY = toInt(section.y());
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- QPainter painter(&pixmap);
- painter.setCompositionMode(QPainter::CompositionMode_Source);
- for(const auto & t : area)
- {
- if(section.contains(t.x * tileSize, t.y * tileSize))
- painter.fillRect(t.x * tileSize - offsetX, t.y * tileSize - offsetY, 31, 31, QColor(128, 128, 128, 96));
- }
- QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- void SelectionTerrainLayer::select(const std::vector<int3> & tiles)
- {
- for (int3 tile : tiles)
- {
- if(!area.count(tile))
- {
- area.insert(tile);
- }
- }
- redraw(tiles);
- onSelection();
- }
- void SelectionTerrainLayer::erase(const std::vector<int3> & tiles)
- {
- for (int3 tile : tiles)
- {
- if(area.count(tile))
- {
- area.erase(tile);
- }
- }
- redraw(tiles);
- onSelection();
- }
- void SelectionTerrainLayer::clear()
- {
- area.clear();
- onSelection();
- redraw();
- }
- const std::set<int3> & SelectionTerrainLayer::selection() const
- {
- return area;
- }
- void SelectionTerrainLayer::onSelection()
- {
- Q_EMIT selectionMade(!area.empty());
- }
- TerrainLayer::TerrainLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- void TerrainLayer::redrawTerrain(const std::vector<int3> & tiles)
- {
- redrawWithSurroundingTiles(tiles);
- }
- QGraphicsItem * TerrainLayer::draw(const QRectF & section)
- {
- int left = toInt(section.left());
- int right = toInt(section.right());
- int top = toInt(section.top());
- int bottom = toInt(section.bottom());
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- QPainter painter(&pixmap);
- QPointF offset = section.topLeft();
- for(int x = left/tileSize; x < right/tileSize; ++x)
- {
- for(int y = top/tileSize; y < bottom/tileSize; ++y)
- {
- handler->drawTerrainTile(painter, x, y, scene->level, offset);
- handler->drawRiver(painter, x, y, scene->level, offset);
- handler->drawRoad(painter, x, y, scene->level, offset);
- }
- }
- QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- ObjectsLayer::ObjectsLayer(MapSceneBase * s): AbstractViewportLayer(s)
- {
- }
- QGraphicsItem * ObjectsLayer::draw(const QRectF & section)
- {
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- if (isShown)
- {
- QPainter painter(&pixmap);
- handler->drawObjects(painter, section, scene->level, lockedObjects);
- }
- QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- void ObjectsLayer::redrawObjects(const std::set<CGObjectInstance *> & objects)
- {
- redraw(objects);
- }
- void ObjectsLayer::setLockObject(const CGObjectInstance * object, bool lock)
- {
- if(lock)
- lockedObjects.insert(object);
- else
- lockedObjects.erase(object);
- QRectF area = getObjectArea(object);
- redraw({area});
- }
- void ObjectsLayer::unlockAll()
- {
- lockedObjects.clear();
- redraw();
- }
- SelectionObjectsLayer::SelectionObjectsLayer(MapSceneBase * s): AbstractViewportLayer(s), newObject(nullptr)
- {
- }
- QGraphicsItem * SelectionObjectsLayer::draw(const QRectF & section)
- {
- QPixmap pixmap(toInt(section.width()), toInt(section.height()));
- pixmap.fill(Qt::transparent);
- if (isShown)
- {
- QPainter painter(&pixmap);
- painter.setCompositionMode(QPainter::CompositionMode_Source);
- painter.setPen(Qt::white);
- QPointF offset = section.topLeft();
- for(auto * obj : selectedObjects)
- {
- auto objectArea = getObjectArea(obj);
- if(obj != newObject.get() && section.intersects(objectArea))
- {
- auto pos = obj->anchorPos();
- QRectF bbox(pos.x, pos.y, 1, 1);
- for(const auto & t : obj->getBlockedPos())
- {
- QPointF topLeft(std::min(t.x * 1.0, bbox.topLeft().x()), std::min(t.y * 1.0, bbox.topLeft().y()));
- bbox.setTopLeft(topLeft);
- QPointF bottomRight(std::max(t.x * 1.0, bbox.bottomRight().x()), std::max(t.y * 1.0, bbox.bottomRight().y()));
- bbox.setBottomRight(bottomRight);
- }
- //selection box's size was decreased by 1 px to get rid of a persistent bug
- //with displaying a box on a border of two sectors. Bite me.
- painter.setOpacity(1.0);
- QRectF rect((bbox.x() * tileSize + 1) - offset.x(), (bbox.y() * tileSize + 1) - offset.y(), (bbox.width() * tileSize) - 2, (bbox.height() * tileSize) - 2);
- painter.drawRect(rect);
- }
- if(selectionMode == SelectionMode::MOVEMENT && (shift.x() || shift.y()))
- {
- objectArea.moveTo(objectArea.topLeft() + (shift * tileSize));
- if (section.intersects(objectArea))
- {
- painter.setOpacity(0.7);
- auto newPos = QPoint(obj->anchorPos().x, obj->anchorPos().y) + shift;
- handler->drawObjectAt(painter, obj, newPos.x(), newPos.y(), offset);
- }
- }
- }
- }
- QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
- result->setPos(section.x(), section.y());
- return result;
- }
- CGObjectInstance * SelectionObjectsLayer::selectObjectAt(int x, int y, const CGObjectInstance * ignore) const
- {
- if(!map || !map->isInTheMap(int3(x, y, scene->level)))
- return nullptr;
-
- auto & objects = handler->getObjects(x, y, scene->level);
-
- //visitable is most important
- for(auto & object : objects)
- {
- if(!object.obj || object.obj == ignore || lockedObjects.count(object.obj))
- continue;
-
- if(object.obj->visitableAt(int3(x, y, scene->level)))
- {
- return const_cast<CGObjectInstance*>(object.obj);
- }
- }
-
- //if not visitable tile - try to get blocked
- for(auto & object : objects)
- {
- if(!object.obj || object.obj == ignore || lockedObjects.count(object.obj))
- continue;
-
- if(object.obj->blockingAt(int3(x, y, scene->level)))
- {
- return const_cast<CGObjectInstance*>(object.obj);
- }
- }
-
- //finally, we can take any object
- for(auto & object : objects)
- {
- if(!object.obj || object.obj == ignore || lockedObjects.count(object.obj))
- continue;
-
- if(object.obj->coveringAt(int3(x, y, scene->level)))
- {
- return const_cast<CGObjectInstance*>(object.obj);
- }
- }
-
- return nullptr;
- }
- void SelectionObjectsLayer::selectObjects(int x1, int y1, int x2, int y2)
- {
- if(!map)
- return;
-
- if(x1 > x2)
- std::swap(x1, x2);
-
- if(y1 > y2)
- std::swap(y1, y2);
- std::set<CGObjectInstance *> selectedObjects;
- for(int j = y1; j < y2; ++j)
- {
- for(int i = x1; i < x2; ++i)
- {
- if(map->isInTheMap(int3(i, j, scene->level)))
- {
- for(auto & o : handler->getObjects(i, j, scene->level))
- if(!lockedObjects.count(o.obj))
- {
- selectedObjects.insert(const_cast<CGObjectInstance*>(o.obj));
- }
- }
- }
- }
- selectObjects(selectedObjects);
- }
- void SelectionObjectsLayer::selectObject(CGObjectInstance * obj)
- {
- selectedObjects.insert(obj);
- onSelection();
- redraw({obj});
- }
- void SelectionObjectsLayer::selectObjects(const std::set<CGObjectInstance *> & objs)
- {
- for (CGObjectInstance * obj : objs)
- {
- selectedObjects.insert(obj);
- }
- onSelection();
- redraw(objs);
- }
- void SelectionObjectsLayer::deselectObject(CGObjectInstance * obj)
- {
- selectedObjects.erase(obj);
- redraw({obj});
- }
- bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const
- {
- return selectedObjects.count(const_cast<CGObjectInstance*>(obj));
- }
- std::set<CGObjectInstance*> SelectionObjectsLayer::getSelection() const
- {
- return selectedObjects;
- }
- void SelectionObjectsLayer::clear()
- {
- selectedObjects.clear();
- shift.setX(0);
- shift.setY(0);
- redraw();
- }
- void SelectionObjectsLayer::onSelection()
- {
- Q_EMIT selectionMade(!selectedObjects.empty());
- }
- void SelectionObjectsLayer::setShift(int x, int y)
- {
- std::vector<QRectF>areas;
- if(shift.x() || shift.y())
- {
- for (auto * selectedObject : selectedObjects)
- {
- QRectF formerArea = getObjectArea(selectedObject);
- formerArea.moveTo(formerArea.topLeft() + (shift * tileSize));
- areas.emplace_back(formerArea);
- }
- }
- shift = QPoint(x, y);
- for (auto * selectedObject : selectedObjects)
- {
- QRectF area = getObjectArea(selectedObject);
- area.moveTo(area.topLeft() + (shift * tileSize));
- areas.emplace_back(area);
- }
- redraw(areas);
- }
- void SelectionObjectsLayer::setLockObject(CGObjectInstance * object, bool lock)
- {
- if(lock)
- lockedObjects.insert(object);
- else
- lockedObjects.erase(object);
- redraw({object});
- }
- void SelectionObjectsLayer::unlockAll()
- {
- lockedObjects.clear();
- }
- MinimapLayer::MinimapLayer(MapSceneBase * s): AbstractFixedLayer(s)
- {
- }
- void MinimapLayer::update()
- {
- if(!map)
- return;
- pixmap = std::make_unique<QPixmap>(map->width, map->height);
- QPainter painter(pixmap.get());
- //coordinate transformation
- for(int j = 0; j < map->height; ++j)
- {
- for(int i = 0; i < map->width; ++i)
- {
- handler->drawMinimapTile(painter, i, j, scene->level);
- }
- }
-
- redraw();
- }
- MinimapViewLayer::MinimapViewLayer(MapSceneBase * s): AbstractFixedLayer(s)
- {
- }
- void MinimapViewLayer::update()
- {
- if(!map)
- return;
- pixmap = std::make_unique<QPixmap>(map->width, map->height);
- draw();
- }
- void MinimapViewLayer::draw()
- {
- if(!map)
- return;
-
- pixmap->fill(Qt::transparent);
-
- //maybe not optimal but ok
- QPainter painter(pixmap.get());
- painter.setPen(Qt::white);
- painter.drawRect(x, y, w, h);
-
- redraw();
- }
- void MinimapViewLayer::setViewport(int _x, int _y, int _w, int _h)
- {
- x = _x;
- y = _y;
- w = _w;
- h = _h;
- draw();
- }
|