diff --git a/apps/opencs/model/world/cellcoordinates.cpp b/apps/opencs/model/world/cellcoordinates.cpp index 1e545e38d..55adc3eff 100644 --- a/apps/opencs/model/world/cellcoordinates.cpp +++ b/apps/opencs/model/world/cellcoordinates.cpp @@ -113,6 +113,13 @@ int CSMWorld::CellCoordinates::vertexSelectionToInCellCoords(int pos) return static_cast(pos - std::floor(static_cast(pos) / (landSize - 1)) * (landSize - 1)); } +std::string CSMWorld::CellCoordinates::textureGlobalToCellId(std::pair textureGlobal) +{ + int x = std::floor(static_cast(textureGlobal.first) / landTextureSize); + int y = std::floor(static_cast(textureGlobal.second) / landTextureSize); + return generateId(x, y); +} + std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(std::pair vertexGlobal) { int x = std::floor(static_cast(vertexGlobal.first) / (landSize - 1)); diff --git a/apps/opencs/model/world/cellcoordinates.hpp b/apps/opencs/model/world/cellcoordinates.hpp index 3b2119517..c6c2c7ccd 100644 --- a/apps/opencs/model/world/cellcoordinates.hpp +++ b/apps/opencs/model/world/cellcoordinates.hpp @@ -63,6 +63,8 @@ namespace CSMWorld ///Converts local cell's heightmap coordinates from the global vertex coordinate static int vertexSelectionToInCellCoords(int); + static std::string textureGlobalToCellId(std::pair); + ///Converts global vertex coordinates to cell id static std::string vertexGlobalToCellId(std::pair); }; diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index ad13e80be..fae18f8c2 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -493,6 +493,21 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } +bool CSVRender::TerrainTextureMode::isInCellSelection(const int& globalSelectionX, const int& globalSelectionY) +{ + if (CSVRender::PagedWorldspaceWidget *paged = dynamic_cast (&getWorldspaceWidget())) + { + CSMWorld::CellSelection selection = paged->getCellSelection(); + if (selection.has (CSMWorld::CellCoordinates::fromId( + CSMWorld::CellCoordinates::textureGlobalToCellId(std::make_pair(globalSelectionX, globalSelectionY))).first)) + { + return true; + } + } + return false; +} + + void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair& texCoords, unsigned char selectMode, bool dragOperation) { int r = mBrushSize / 2; @@ -500,7 +515,7 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair& texCoords, unsigned char selectMode, bool dragOperation);