void Tile::press(MapEditor& editor, QMouseEvent* pEvent) { if (pEvent->button() == Qt::RightButton || pEvent->button() == Qt::LeftButton) { // create brush auto brush = brushIndexFromMouseButton(pEvent->button()); auto pos = editor.mapToScene(pEvent->pos()).toPoint(); // if there is an old brush, release it _finishBrush(); try { m_pCurrentBrush = MAP::BRUSH::BrushFactory::createBrush(m_BrushInfos.at(static_cast<std::size_t>(brush)), m_DBMgr, editor.getMapData().getMapLayer(), editor.getLayerType(), editor.getLayerIndex() - 1); GEOMETRY::Point<uint32> tilePos(pos.x() / MAP::TILE_SIZE, pos.y() / MAP::TILE_SIZE); // if tileSet mapping, set brush size equal tileSet size if (m_BrushInfos.at(static_cast<std::size_t>(brush)).getType() == MAP::BRUSH::BrushInfo::Type::TILE_SET) { if (auto pTileSet = m_DBMgr.getTileSetDatabase().getPrototype(m_BrushInfos.at(static_cast<std::size_t>(brush)).getID())) m_pCurrentBrush->setBrushSize(pTileSet->getSize()); } m_pCurrentBrush->start(tilePos); editor.scene()->update(); m_pCurrentEditor = &editor; } catch (const MAP::EXCEPTION::LayerOutOfRangeException&) {} } }
void MAPPING_MODE::ScriptArea::press(MapEditor& editor, QMouseEvent* pEvent) { if (pEvent->button() != Qt::LeftButton) return; auto pos = editor.mapToScene(pEvent->pos()).toPoint(); if (auto pItem = editor.scene()->itemAt(pos, QTransform())) { if (pItem->type() == MAPPING_MODE::ITEM_MOVE_POINT) return; } auto pItem = editor.addScriptArea(AREA::Data(GEOMETRY::Rectangle<int32>(GEOMETRY::Point<int32>(pos.x(), pos.y()), GEOMETRY::Size<int32>())), ACTION::Data("test")); editor.addRevert(new MAPPING_MODE::SCRIPT_AREA::REVERT::Add(pItem->getScriptArea()->getGUID(), editor)); }
void Tile::move(MapEditor& editor, QMouseEvent* pEvent) { if (m_pCurrentEditor && &editor == m_pCurrentEditor) { try { auto pos = editor.mapToScene(pEvent->pos()).toPoint(); GEOMETRY::Point<uint32> tilePos(pos.x() / MAP::TILE_SIZE, pos.y() / MAP::TILE_SIZE); m_pCurrentBrush->start(tilePos); m_pCurrentEditor->scene()->update(); } catch (const MAP::EXCEPTION::LayerOutOfRangeException&) {} } else _finishBrush(); }