2018-09-27 00:30:05 +01:00
|
|
|
#include "graphicsview.h"
|
2021-12-12 17:19:59 +00:00
|
|
|
#include "mapview.h"
|
2018-09-27 00:30:05 +01:00
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
void GraphicsView::mousePressEvent(QMouseEvent *event) {
|
|
|
|
QGraphicsView::mousePressEvent(event);
|
|
|
|
if (editor) {
|
|
|
|
editor->objectsView_onMousePress(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsView::mouseMoveEvent(QMouseEvent *event) {
|
|
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsView::mouseReleaseEvent(QMouseEvent *event) {
|
|
|
|
QGraphicsView::mouseReleaseEvent(event);
|
|
|
|
}
|
2020-05-02 22:25:35 +01:00
|
|
|
|
2021-12-12 17:19:59 +00:00
|
|
|
void GraphicsView::moveEvent(QMoveEvent *event) {
|
|
|
|
QGraphicsView::moveEvent(event);
|
|
|
|
QLabel *label_MapRulerStatus = findChild<QLabel *>("label_MapRulerStatus", Qt::FindDirectChildrenOnly);
|
|
|
|
if (label_MapRulerStatus && label_MapRulerStatus->isVisible())
|
|
|
|
label_MapRulerStatus->move(mapToGlobal(QPoint(6, 6)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::drawForeground(QPainter *painter, const QRectF&) {
|
2021-11-30 17:58:39 +00:00
|
|
|
foreach (Overlay * overlay, this->overlayMap)
|
|
|
|
overlay->renderItems(painter);
|
2021-12-12 17:19:59 +00:00
|
|
|
|
|
|
|
if (!editor) return;
|
|
|
|
|
|
|
|
QStyleOptionGraphicsItem option;
|
2024-09-29 21:10:48 +01:00
|
|
|
|
|
|
|
// Draw elements of the map view that should always render on top of anything added by the user with the scripting API.
|
|
|
|
|
|
|
|
// Draw map grid
|
|
|
|
if (editor->mapGrid && editor->mapGrid->isVisible()) {
|
|
|
|
painter->save();
|
|
|
|
if (editor->map) {
|
|
|
|
// We're clipping here to hide parts of the grid that are outside the map.
|
|
|
|
const QRectF mapRect(-0.5, -0.5, editor->map->getWidth() * 16 + 1.5, editor->map->getHeight() * 16 + 1.5);
|
|
|
|
painter->setClipping(true);
|
|
|
|
painter->setClipRect(mapRect);
|
2024-09-27 16:31:55 +01:00
|
|
|
}
|
2024-09-29 21:10:48 +01:00
|
|
|
for (auto item : editor->mapGrid->childItems())
|
|
|
|
item->paint(painter, &option, this);
|
|
|
|
painter->restore();
|
2021-12-12 17:19:59 +00:00
|
|
|
}
|
2024-09-29 21:10:48 +01:00
|
|
|
|
|
|
|
// Draw cursor rectangles
|
2021-12-12 17:19:59 +00:00
|
|
|
if (editor->playerViewRect && editor->playerViewRect->isVisible())
|
|
|
|
editor->playerViewRect->paint(painter, &option, this);
|
|
|
|
if (editor->cursorMapTileRect && editor->cursorMapTileRect->isVisible())
|
|
|
|
editor->cursorMapTileRect->paint(painter, &option, this);
|
2021-11-30 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 02:17:50 +01:00
|
|
|
void MapView::clearOverlayMap() {
|
2022-09-05 16:53:30 +01:00
|
|
|
foreach (Overlay * overlay, this->overlayMap) {
|
|
|
|
overlay->clearItems();
|
|
|
|
delete overlay;
|
2021-12-08 14:20:17 +00:00
|
|
|
}
|
|
|
|
this->overlayMap.clear();
|
2021-11-30 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-12 17:19:59 +00:00
|
|
|
Overlay * MapView::getOverlay(int layer) {
|
2021-11-30 17:58:39 +00:00
|
|
|
Overlay * overlay = this->overlayMap.value(layer, nullptr);
|
|
|
|
if (!overlay) {
|
|
|
|
overlay = new Overlay();
|
|
|
|
this->overlayMap.insert(layer, overlay);
|
2020-05-02 22:25:35 +01:00
|
|
|
}
|
2021-11-30 17:58:39 +00:00
|
|
|
return overlay;
|
2020-05-02 22:25:35 +01:00
|
|
|
}
|