mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-09 18:40:14 +00:00
Merge pull request #2586 from unelsson/allowselectionalledges
Allow selecting cell edges everywhere
This commit is contained in:
commit
b5992b380e
@ -1038,6 +1038,28 @@ bool CSVRender::TerrainShapeMode::isInCellSelection(int globalSelectionX, int gl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVRender::TerrainShapeMode::handleSelection(int globalSelectionX, int globalSelectionY, std::vector<std::pair<int, int>>* selections)
|
||||||
|
{
|
||||||
|
if (isInCellSelection(globalSelectionX, globalSelectionY)) selections->emplace_back(globalSelectionX, globalSelectionY);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int moduloX = globalSelectionX % (ESM::Land::LAND_SIZE - 1);
|
||||||
|
int moduloY = globalSelectionY % (ESM::Land::LAND_SIZE - 1);
|
||||||
|
bool xIsAtCellBorder = moduloX == 0;
|
||||||
|
bool yIsAtCellBorder = moduloY == 0;
|
||||||
|
if (!xIsAtCellBorder && !yIsAtCellBorder)
|
||||||
|
return;
|
||||||
|
int selectionX = globalSelectionX;
|
||||||
|
int selectionY = globalSelectionY;
|
||||||
|
if (xIsAtCellBorder)
|
||||||
|
selectionX--;
|
||||||
|
if (yIsAtCellBorder)
|
||||||
|
selectionY--;
|
||||||
|
if (isInCellSelection(selectionX, selectionY))
|
||||||
|
selections->emplace_back(globalSelectionX, globalSelectionY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation)
|
void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation)
|
||||||
{
|
{
|
||||||
int r = mBrushSize / 2;
|
int r = mBrushSize / 2;
|
||||||
@ -1045,7 +1067,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>&
|
|||||||
|
|
||||||
if (mBrushShape == CSVWidget::BrushShape_Point)
|
if (mBrushShape == CSVWidget::BrushShape_Point)
|
||||||
{
|
{
|
||||||
if (isInCellSelection(vertexCoords.first, vertexCoords.second)) selections.emplace_back(vertexCoords.first, vertexCoords.second);
|
handleSelection(vertexCoords.first, vertexCoords.second, &selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mBrushShape == CSVWidget::BrushShape_Square)
|
if (mBrushShape == CSVWidget::BrushShape_Square)
|
||||||
@ -1054,7 +1076,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>&
|
|||||||
{
|
{
|
||||||
for(int j = vertexCoords.second - r; j <= vertexCoords.second + r; ++j)
|
for(int j = vertexCoords.second - r; j <= vertexCoords.second + r; ++j)
|
||||||
{
|
{
|
||||||
if (isInCellSelection(i, j)) selections.emplace_back(i, j);
|
handleSelection(i, j, &selections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1068,7 +1090,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>&
|
|||||||
int distanceX = abs(i - vertexCoords.first);
|
int distanceX = abs(i - vertexCoords.first);
|
||||||
int distanceY = abs(j - vertexCoords.second);
|
int distanceY = abs(j - vertexCoords.second);
|
||||||
int distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2)));
|
int distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2)));
|
||||||
if (isInCellSelection(i, j) && distance <= r) selections.emplace_back(i, j);
|
if (distance <= r) handleSelection(i, j, &selections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1080,8 +1102,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>&
|
|||||||
for(auto const& value: mCustomBrushShape)
|
for(auto const& value: mCustomBrushShape)
|
||||||
{
|
{
|
||||||
std::pair<int, int> localVertexCoords (vertexCoords.first + value.first, vertexCoords.second + value.second);
|
std::pair<int, int> localVertexCoords (vertexCoords.first + value.first, vertexCoords.second + value.second);
|
||||||
std::string cellId (CSMWorld::CellCoordinates::vertexGlobalToCellId(localVertexCoords));
|
handleSelection(localVertexCoords.first, localVertexCoords.second, &selections);
|
||||||
if (isInCellSelection(localVertexCoords.first, localVertexCoords.second)) selections.emplace_back(localVertexCoords);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,9 @@ namespace CSVRender
|
|||||||
/// Check if global selection coordinate belongs to cell in view
|
/// Check if global selection coordinate belongs to cell in view
|
||||||
bool isInCellSelection(int globalSelectionX, int globalSelectionY);
|
bool isInCellSelection(int globalSelectionX, int globalSelectionY);
|
||||||
|
|
||||||
|
/// Select vertex at global selection coordinate
|
||||||
|
void handleSelection(int globalSelectionX, int globalSelectionY, std::vector<std::pair<int, int>>* selections);
|
||||||
|
|
||||||
/// Handle brush mechanics for terrain shape selection
|
/// Handle brush mechanics for terrain shape selection
|
||||||
void selectTerrainShapes (const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation);
|
void selectTerrainShapes (const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user