mirror of
https://github.com/vcmi/vcmi.git
synced 2026-06-19 22:57:37 +02:00
Merge pull request #1328 from Nordsoft91/editor-lasso
[MapEditor] Implement lasso brush
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
@@ -866,6 +866,22 @@ void MainWindow::on_toolArea_clicked(bool checked)
|
|||||||
ui->tabWidget->setCurrentIndex(0);
|
ui->tabWidget->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolLasso_clicked(bool checked)
|
||||||
|
{
|
||||||
|
ui->toolBrush->setChecked(false);
|
||||||
|
ui->toolBrush2->setChecked(false);
|
||||||
|
ui->toolBrush4->setChecked(false);
|
||||||
|
ui->toolArea->setChecked(false);
|
||||||
|
//ui->toolLasso->setChecked(false);
|
||||||
|
|
||||||
|
if(checked)
|
||||||
|
ui->mapView->selectionTool = MapView::SelectionTool::Lasso;
|
||||||
|
else
|
||||||
|
ui->mapView->selectionTool = MapView::SelectionTool::None;
|
||||||
|
|
||||||
|
ui->tabWidget->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionErase_triggered()
|
void MainWindow::on_actionErase_triggered()
|
||||||
{
|
{
|
||||||
on_toolErase_clicked();
|
on_toolErase_clicked();
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ private slots:
|
|||||||
void on_toolBrush2_clicked(bool checked);
|
void on_toolBrush2_clicked(bool checked);
|
||||||
|
|
||||||
void on_toolBrush4_clicked(bool checked);
|
void on_toolBrush4_clicked(bool checked);
|
||||||
|
|
||||||
|
void on_toolLasso_clicked(bool checked);
|
||||||
|
|
||||||
void on_inspectorWidget_itemChanged(QTableWidgetItem *item);
|
void on_inspectorWidget_itemChanged(QTableWidgetItem *item);
|
||||||
|
|
||||||
|
|||||||
@@ -642,7 +642,7 @@
|
|||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QPushButton" name="toolLasso">
|
<widget class="QPushButton" name="toolLasso">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
@@ -663,7 +663,11 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">O</string>
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons:brush-3.png</normaloff>icons:brush-3.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|||||||
@@ -155,6 +155,14 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
sc->selectionTerrainView.draw();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MapView::SelectionTool::Lasso:
|
||||||
|
if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
sc->selectionTerrainView.select(tile);
|
||||||
|
sc->selectionTerrainView.draw();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::None:
|
case MapView::SelectionTool::None:
|
||||||
if(mouseEvent->buttons() & Qt::RightButton)
|
if(mouseEvent->buttons() & Qt::RightButton)
|
||||||
@@ -247,6 +255,7 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Area:
|
case MapView::SelectionTool::Area:
|
||||||
|
case MapView::SelectionTool::Lasso:
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -329,6 +338,55 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
switch(selectionTool)
|
switch(selectionTool)
|
||||||
{
|
{
|
||||||
|
case MapView::SelectionTool::Lasso: {
|
||||||
|
if(event->button() == Qt::RightButton)
|
||||||
|
break;
|
||||||
|
|
||||||
|
//key: y position of tile
|
||||||
|
//value.first: x position of left tile
|
||||||
|
//value.second: x postiion of right tile
|
||||||
|
std::map<int, std::pair<int, int>> selectionRangeMapX, selectionRangeMapY;
|
||||||
|
for(auto & t : sc->selectionTerrainView.selection())
|
||||||
|
{
|
||||||
|
auto pairIter = selectionRangeMapX.find(t.y);
|
||||||
|
if(pairIter == selectionRangeMapX.end())
|
||||||
|
selectionRangeMapX[t.y] = std::make_pair(t.x, t.x);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pairIter->second.first = std::min(pairIter->second.first, t.x);
|
||||||
|
pairIter->second.second = std::max(pairIter->second.second, t.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
pairIter = selectionRangeMapY.find(t.x);
|
||||||
|
if(pairIter == selectionRangeMapY.end())
|
||||||
|
selectionRangeMapY[t.x] = std::make_pair(t.y, t.y);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pairIter->second.first = std::min(pairIter->second.first, t.y);
|
||||||
|
pairIter->second.second = std::max(pairIter->second.second, t.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<int3> selectionByX, selectionByY;
|
||||||
|
std::vector<int3> finalSelection;
|
||||||
|
for(auto & selectionRange : selectionRangeMapX)
|
||||||
|
{
|
||||||
|
for(int i = selectionRange.second.first; i < selectionRange.second.second; ++i)
|
||||||
|
selectionByX.insert(int3(i, selectionRange.first, sc->level));
|
||||||
|
}
|
||||||
|
for(auto & selectionRange : selectionRangeMapY)
|
||||||
|
{
|
||||||
|
for(int i = selectionRange.second.first; i < selectionRange.second.second; ++i)
|
||||||
|
selectionByY.insert(int3(selectionRange.first, i, sc->level));
|
||||||
|
}
|
||||||
|
std::set_intersection(selectionByX.begin(), selectionByX.end(), selectionByY.begin(), selectionByY.end(), std::back_inserter(finalSelection));
|
||||||
|
for(auto & lassoTile : finalSelection)
|
||||||
|
sc->selectionTerrainView.select(lassoTile);
|
||||||
|
|
||||||
|
sc->selectionTerrainView.draw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MapView::SelectionTool::None:
|
case MapView::SelectionTool::None:
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user