#include "mappixmapitem.h" #include "metatile.h" #include "log.h" #include "editcommands.h" #define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0) void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { if (map) { if (event->type() == QEvent::GraphicsSceneMouseRelease) { actionId_++; } else { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); // Set straight paths on/off and snap to the dominant axis when on if (event->modifiers() & Qt::ControlModifier) { this->lockNondominantAxis(event); pos = this->adjustCoords(pos); } else { this->prevStraightPathState = false; this->lockedAxis = MapPixmapItem::Axis::None; } // Paint onto the map. bool shiftPressed = event->modifiers() & Qt::ShiftModifier; QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); if (settings->smartPathsEnabled) { if (!shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) { paintSmartPath(pos.x(), pos.y()); } else { paintNormal(pos.x(), pos.y()); } } else { if (shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) { paintSmartPath(pos.x(), pos.y()); } else { paintNormal(pos.x(), pos.y()); } } } } } void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) { if (map) { if (event->type() == QEvent::GraphicsSceneMouseRelease) { actionId_++; } else { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); // Set straight paths on/off and snap to the dominant axis when on if (event->modifiers() & Qt::ControlModifier) { this->lockNondominantAxis(event); pos = this->adjustCoords(pos); } else { this->prevStraightPathState = false; this->lockedAxis = MapPixmapItem::Axis::None; } if (event->type() == QEvent::GraphicsSceneMousePress) { selection_origin = QPoint(pos.x(), pos.y()); selection.clear(); } else if (event->type() == QEvent::GraphicsSceneMouseMove) { if (pos.x() != selection_origin.x() || pos.y() != selection_origin.y()) { int xDelta = pos.x() - selection_origin.x(); int yDelta = pos.y() - selection_origin.y(); this->shift(xDelta, yDelta); selection_origin = QPoint(pos.x(), pos.y()); selection.clear(); draw(); } } } } } void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) { Blockdata oldMetatiles = map->layout->blockdata; for (int i = 0; i < map->getWidth(); i++) for (int j = 0; j < map->getHeight(); j++) { int destX = i + xDelta; int destY = j + yDelta; if (destX < 0) do { destX += map->getWidth(); } while (destX < 0); if (destY < 0) do { destY += map->getHeight(); } while (destY < 0); destX %= map->getWidth(); destY %= map->getHeight(); int blockIndex = j * map->getWidth() + i; Block srcBlock = oldMetatiles.at(blockIndex); map->setBlock(destX, destY, srcBlock); } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new ShiftMetatiles(map, oldMetatiles, map->layout->blockdata, actionId_)); } } void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) { QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QList> *selectedCollisions = this->metatileSelector->getSelectedCollisions(); int initialX = fromScriptCall ? x : this->paint_tile_initial_x; int initialY = fromScriptCall ? y : this->paint_tile_initial_y; // Snap the selected position to the top-left of the block boundary. // This allows painting via dragging the mouse to tile the painted region. int xDiff = x - initialX; int yDiff = y - initialY; if (xDiff < 0 && xDiff % selectionDimensions.x() != 0) xDiff -= selectionDimensions.x(); if (yDiff < 0 && yDiff % selectionDimensions.y() != 0) yDiff -= selectionDimensions.y(); x = initialX + (xDiff / selectionDimensions.x()) * selectionDimensions.x(); y = initialY + (yDiff / selectionDimensions.y()) * selectionDimensions.y(); // for edit history Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata(); for (int i = 0; i < selectionDimensions.x() && i + x < map->getWidth(); i++) for (int j = 0; j < selectionDimensions.y() && j + y < map->getHeight(); j++) { int actualX = i + x; int actualY = j + y; Block block; if (map->getBlock(actualX, actualY, &block)) { int index = j * selectionDimensions.x() + i; block.tile = selectedMetatiles->at(index); if (selectedCollisions && selectedCollisions->length() == selectedMetatiles->length()) { block.collision = selectedCollisions->at(index).first; block.elevation = selectedCollisions->at(index).second; } map->setBlock(actualX, actualY, block, !fromScriptCall); } } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_)); } } // These are tile offsets from the top-left tile in the 3x3 smart path selection. // Each entry is for one possibility from the marching squares value for a tile. // (Marching Squares: https://en.wikipedia.org/wiki/Marching_squares) QList MapPixmapItem::smartPathTable = QList({ 4, // 0000 4, // 0001 4, // 0010 6, // 0011 4, // 0100 4, // 0101 0, // 0110 3, // 0111 4, // 1000 8, // 1001 4, // 1010 7, // 1011 2, // 1100 5, // 1101 1, // 1110 4, // 1111 }); #define IS_SMART_PATH_TILE(block) (selectedMetatiles->contains(block.tile)) void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) { QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QList> *selectedCollisions = this->metatileSelector->getSelectedCollisions(); // Smart path should never be enabled without a 3x3 block selection. if (selectionDimensions.x() != 3 || selectionDimensions.y() != 3) return; // Shift to the middle tile of the smart path selection. uint16_t openTile = selectedMetatiles->at(4); uint16_t openTileCollision = 0; uint16_t openTileElevation = 0; bool setCollisions = false; if (selectedCollisions && selectedCollisions->length() == selectedMetatiles->length()) { openTileCollision = selectedCollisions->at(4).first; openTileElevation = selectedCollisions->at(4).second; setCollisions = true; } // for edit history Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata(); // Fill the region with the open tile. for (int i = 0; i <= 1; i++) for (int j = 0; j <= 1; j++) { // Check if in map bounds. if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0)) continue; int actualX = i + x; int actualY = j + y; Block block; if (map->getBlock(actualX, actualY, &block)) { block.tile = openTile; if (setCollisions) { block.collision = openTileCollision; block.elevation = openTileElevation; } map->setBlock(actualX, actualY, block, !fromScriptCall); } } // Go back and resolve the edge tiles for (int i = -1; i <= 2; i++) for (int j = -1; j <= 2; j++) { // Check if in map bounds. if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0)) continue; // Ignore the corners, which can't possible be affected by the smart path. if ((i == -1 && j == -1) || (i == 2 && j == -1) || (i == -1 && j == 2) || (i == 2 && j == 2)) continue; // Ignore tiles that aren't part of the smart path set. int actualX = i + x; int actualY = j + y; Block block; if (!map->getBlock(actualX, actualY, &block) || !IS_SMART_PATH_TILE(block)) { continue; } int id = 0; Block top; Block right; Block bottom; Block left; // Get marching squares value, to determine which tile to use. if (map->getBlock(actualX, actualY - 1, &top) && IS_SMART_PATH_TILE(top)) id += 1; if (map->getBlock(actualX + 1, actualY, &right) && IS_SMART_PATH_TILE(right)) id += 2; if (map->getBlock(actualX, actualY + 1, &bottom) && IS_SMART_PATH_TILE(bottom)) id += 4; if (map->getBlock(actualX - 1, actualY, &left) && IS_SMART_PATH_TILE(left)) id += 8; block.tile = selectedMetatiles->at(smartPathTable[id]); if (setCollisions) { block.collision = selectedCollisions->at(smartPathTable[id]).first; block.elevation = selectedCollisions->at(smartPathTable[id]).second; } map->setBlock(actualX, actualY, block, !fromScriptCall); } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_)); } } void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) { /* Return if an axis is already locked, or if the mouse has been released. The mouse release check is necessary * because MapPixmapItem::mouseReleaseEvent seems to get called before this function, which would unlock the axis * and then get immediately re-locked here until the next ctrl-click. */ if (this->lockedAxis != MapPixmapItem::Axis::None || event->type() == QEvent::GraphicsSceneMouseRelease) return; QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); if (!this->prevStraightPathState) { this->prevStraightPathState = true; this->straight_path_initial_x = pos.x(); this->straight_path_initial_y = pos.y(); } // Only lock an axis when the current position != initial int xDiff = pos.x() - this->straight_path_initial_x; int yDiff = pos.y() - this->straight_path_initial_y; if (xDiff || yDiff) { if (abs(xDiff) < abs(yDiff)) { this->lockedAxis = MapPixmapItem::Axis::X; } else { this->lockedAxis = MapPixmapItem::Axis::Y; } } } // Adjust the cooresponding coordinate when it is locked QPoint MapPixmapItem::adjustCoords(QPoint pos) { if (this->lockedAxis == MapPixmapItem::Axis::X) { pos.setX(this->straight_path_initial_x); } else if (this->lockedAxis == MapPixmapItem::Axis::Y) { pos.setY(this->straight_path_initial_y); } return pos; } void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); // Snap point to within map bounds. if (pos.x() < 0) pos.setX(0); if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1); if (pos.y() < 0) pos.setY(0); if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1); // Update/apply copied metatiles. if (event->type() == QEvent::GraphicsSceneMousePress) { selection_origin = QPoint(pos.x(), pos.y()); selection.clear(); selection.append(QPoint(pos.x(), pos.y())); Block block; if (map->getBlock(pos.x(), pos.y(), &block)) { this->metatileSelector->selectFromMap(block.tile, block.collision, block.elevation); } } else if (event->type() == QEvent::GraphicsSceneMouseMove) { int x1 = selection_origin.x(); int y1 = selection_origin.y(); int x2 = pos.x(); int y2 = pos.y(); if (x1 > x2) SWAP(x1, x2); if (y1 > y2) SWAP(y1, y2); selection.clear(); for (int y = y1; y <= y2; y++) { for (int x = x1; x <= x2; x++) { selection.append(QPoint(x, y)); } } QList metatiles; QList> collisions; for (QPoint point : selection) { int x = point.x(); int y = point.y(); Block block; if (map->getBlock(x, y, &block)) { metatiles.append(block.tile); } int blockIndex = y * map->getWidth() + x; block = map->layout->blockdata.at(blockIndex); auto collision = block.collision; auto elevation = block.elevation; collisions.append(QPair(collision, elevation)); } this->metatileSelector->setExternalSelection(x2 - x1 + 1, y2 - y1 + 1, metatiles, collisions); } } void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { if (map) { if (event->type() == QEvent::GraphicsSceneMouseRelease) { actionId_++; } else { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); Block block; QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); int tile = selectedMetatiles->first(); if (selectedMetatiles->count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.tile != tile)) { bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier; if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) this->floodFillSmartPath(pos.x(), pos.y()); else this->floodFill(pos.x(), pos.y()); } } } } void MapPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { if (map) { if (event->type() == QEvent::GraphicsSceneMouseRelease) { actionId_++; } else { QPoint initialPos = Metatile::coordFromPixmapCoord(event->pos()); this->magicFill(initialPos.x(), initialPos.y()); } } } void MapPixmapItem::magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall) { QPoint selectionDimensions(1, 1); QList *selectedMetatiles = new QList({ metatileId }); this->magicFill(x, y, selectionDimensions, selectedMetatiles, nullptr, fromScriptCall); delete selectedMetatiles; } void MapPixmapItem::magicFill(int x, int y, bool fromScriptCall) { QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QList> *selectedCollisions = this->metatileSelector->getSelectedCollisions(); this->magicFill(x, y, selectionDimensions, selectedMetatiles, selectedCollisions, fromScriptCall); } void MapPixmapItem::magicFill( int initialX, int initialY, QPoint selectionDimensions, QList *selectedMetatiles, QList> *selectedCollisions, bool fromScriptCall) { Block block; if (map->getBlock(initialX, initialY, &block)) { if (selectedMetatiles->length() == 1 && selectedMetatiles->value(0) == block.tile) { return; } Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata(); bool setCollisions = selectedCollisions && selectedCollisions->length() == selectedMetatiles->length(); uint16_t tile = block.tile; for (int y = 0; y < map->getHeight(); y++) { for (int x = 0; x < map->getWidth(); x++) { if (map->getBlock(x, y, &block) && block.tile == tile) { int xDiff = x - initialX; int yDiff = y - initialY; int i = xDiff % selectionDimensions.x(); int j = yDiff % selectionDimensions.y(); if (i < 0) i = selectionDimensions.x() + i; if (j < 0) j = selectionDimensions.y() + j; int index = j * selectionDimensions.x() + i; block.tile = selectedMetatiles->at(index); if (setCollisions) { block.collision = selectedCollisions->at(index).first; block.elevation = selectedCollisions->at(index).second; } map->setBlock(x, y, block, !fromScriptCall); } } } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_)); } } } void MapPixmapItem::floodFill(int initialX, int initialY, bool fromScriptCall) { QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QList> *selectedCollisions = this->metatileSelector->getSelectedCollisions(); this->floodFill(initialX, initialY, selectionDimensions, selectedMetatiles, selectedCollisions, fromScriptCall); } void MapPixmapItem::floodFill(int initialX, int initialY, uint16_t metatileId, bool fromScriptCall) { QPoint selectionDimensions(1, 1); QList *selectedMetatiles = new QList({ metatileId }); this->floodFill(initialX, initialY, selectionDimensions, selectedMetatiles, nullptr, fromScriptCall); delete selectedMetatiles; } void MapPixmapItem::floodFill( int initialX, int initialY, QPoint selectionDimensions, QList *selectedMetatiles, QList> *selectedCollisions, bool fromScriptCall) { bool setCollisions = selectedCollisions && selectedCollisions->length() == selectedMetatiles->length(); Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata(); QSet visited; QList todo; todo.append(QPoint(initialX, initialY)); while (todo.length()) { QPoint point = todo.takeAt(0); int x = point.x(); int y = point.y(); Block block; if (!map->getBlock(x, y, &block)) { continue; } visited.insert(x + y * map->getWidth()); int xDiff = x - initialX; int yDiff = y - initialY; int i = xDiff % selectionDimensions.x(); int j = yDiff % selectionDimensions.y(); if (i < 0) i = selectionDimensions.x() + i; if (j < 0) j = selectionDimensions.y() + j; int index = j * selectionDimensions.x() + i; uint16_t tile = selectedMetatiles->at(index); uint16_t old_tile = block.tile; if (selectedMetatiles->count() != 1 || old_tile != tile) { block.tile = tile; if (setCollisions) { block.collision = selectedCollisions->at(index).first; block.elevation = selectedCollisions->at(index).second; } map->setBlock(x, y, block, !fromScriptCall); } if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && block.tile == old_tile) { todo.append(QPoint(x + 1, y)); visited.insert(x + 1 + y * map->getWidth()); } if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && block.tile == old_tile) { todo.append(QPoint(x - 1, y)); visited.insert(x - 1 + y * map->getWidth()); } if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && block.tile == old_tile) { todo.append(QPoint(x, y + 1)); visited.insert(x + (y + 1) * map->getWidth()); } if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && block.tile == old_tile) { todo.append(QPoint(x, y - 1)); visited.insert(x + (y - 1) * map->getWidth()); } } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_)); } } void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScriptCall) { QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions(); QList *selectedMetatiles = this->metatileSelector->getSelectedMetatiles(); QList> *selectedCollisions = this->metatileSelector->getSelectedCollisions(); // Smart path should never be enabled without a 3x3 block selection. if (selectionDimensions.x() != 3 || selectionDimensions.y() != 3) return; // Shift to the middle tile of the smart path selection. uint16_t openTile = selectedMetatiles->at(4); uint16_t openTileCollision = 0; uint16_t openTileElevation = 0; bool setCollisions = false; if (selectedCollisions && selectedCollisions->length() == selectedMetatiles->length()) { openTileCollision = selectedCollisions->at(4).first; openTileElevation = selectedCollisions->at(4).second; setCollisions = true; } Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata(); // Flood fill the region with the open tile. QList todo; todo.append(QPoint(initialX, initialY)); while (todo.length()) { QPoint point = todo.takeAt(0); int x = point.x(); int y = point.y(); Block block; if (!map->getBlock(x, y, &block)) { continue; } uint16_t old_tile = block.tile; if (old_tile == openTile) { continue; } block.tile = openTile; if (setCollisions) { block.collision = openTileCollision; block.elevation = openTileElevation; } map->setBlock(x, y, block, !fromScriptCall); if (map->getBlock(x + 1, y, &block) && block.tile == old_tile) { todo.append(QPoint(x + 1, y)); } if (map->getBlock(x - 1, y, &block) && block.tile == old_tile) { todo.append(QPoint(x - 1, y)); } if (map->getBlock(x, y + 1, &block) && block.tile == old_tile) { todo.append(QPoint(x, y + 1)); } if (map->getBlock(x, y - 1, &block) && block.tile == old_tile) { todo.append(QPoint(x, y - 1)); } } // Go back and resolve the flood-filled edge tiles. // Mark tiles as visited while we go. QSet visited; todo.append(QPoint(initialX, initialY)); while (todo.length()) { QPoint point = todo.takeAt(0); int x = point.x(); int y = point.y(); Block block; if (!map->getBlock(x, y, &block)) { continue; } visited.insert(x + y * map->getWidth()); int id = 0; Block top; Block right; Block bottom; Block left; // Get marching squares value, to determine which tile to use. if (map->getBlock(x, y - 1, &top) && IS_SMART_PATH_TILE(top)) id += 1; if (map->getBlock(x + 1, y, &right) && IS_SMART_PATH_TILE(right)) id += 2; if (map->getBlock(x, y + 1, &bottom) && IS_SMART_PATH_TILE(bottom)) id += 4; if (map->getBlock(x - 1, y, &left) && IS_SMART_PATH_TILE(left)) id += 8; block.tile = selectedMetatiles->at(smartPathTable[id]); if (setCollisions) { block.collision = selectedCollisions->at(smartPathTable[id]).first; block.elevation = selectedCollisions->at(smartPathTable[id]).second; } map->setBlock(x, y, block, !fromScriptCall); // Visit neighbors if they are smart-path tiles, and don't revisit any. if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && IS_SMART_PATH_TILE(block)) { todo.append(QPoint(x + 1, y)); visited.insert(x + 1 + y * map->getWidth()); } if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && IS_SMART_PATH_TILE(block)) { todo.append(QPoint(x - 1, y)); visited.insert(x - 1 + y * map->getWidth()); } if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && IS_SMART_PATH_TILE(block)) { todo.append(QPoint(x, y + 1)); visited.insert(x + (y + 1) * map->getWidth()); } if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && IS_SMART_PATH_TILE(block)) { todo.append(QPoint(x, y - 1)); visited.insert(x + (y - 1) * map->getWidth()); } } if (!fromScriptCall && map->layout->blockdata != oldMetatiles) { map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_)); } } void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); Block block; if (map->getBlock(pos.x(), pos.y(), &block)) { this->metatileSelector->selectFromMap(block.tile, block.collision, block.elevation); } } void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); if (event->type() == QEvent::GraphicsSceneMousePress) { selection_origin = QPoint(pos.x(), pos.y()); selection.clear(); } else if (event->type() == QEvent::GraphicsSceneMouseMove) { if (event->buttons() & Qt::LeftButton) { selection.clear(); selection.append(QPoint(pos.x(), pos.y())); } } else if (event->type() == QEvent::GraphicsSceneMouseRelease) { if (!selection.isEmpty()) { QPoint pos = selection.last(); int x1 = selection_origin.x(); int y1 = selection_origin.y(); int x2 = pos.x(); int y2 = pos.y(); if (x1 > x2) SWAP(x1, x2); if (y1 > y2) SWAP(y1, y2); selection.clear(); for (int y = y1; y <= y2; y++) { for (int x = x1; x <= x2; x++) { selection.append(QPoint(x, y)); } } logInfo(QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2)); } } } void MapPixmapItem::draw(bool ignoreCache) { if (map) { map->setMapItem(this); setPixmap(map->render(ignoreCache)); } } void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); emit this->hoveredMapMetatileChanged(pos); if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) { setCursor(this->settings->mapCursor); } } void MapPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) { this->has_mouse = true; } void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { emit this->hoveredMapMetatileCleared(); if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) { unsetCursor(); } this->has_mouse = false; } void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); this->paint_tile_initial_x = this->straight_path_initial_x = pos.x(); this->paint_tile_initial_y = this->straight_path_initial_y = pos.y(); emit startPaint(event, this); emit mouseEvent(event, this); } void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); emit this->hoveredMapMetatileChanged(pos); emit mouseEvent(event, this); } void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { this->lockedAxis = MapPixmapItem::Axis::None; emit endPaint(event, this); emit mouseEvent(event, this); }