1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Support brush size

This commit is contained in:
nordsoft 2022-09-03 17:43:20 +04:00
parent ff6cd104cf
commit 2572744f00
4 changed files with 118 additions and 12 deletions

View File

@ -598,6 +598,10 @@ void MainWindow::on_actionGrid_triggered(bool checked)
} }
} }
void MainWindow::changeBrushState(int idx)
{
}
void MainWindow::on_toolBrush_clicked(bool checked) void MainWindow::on_toolBrush_clicked(bool checked)
{ {
@ -608,15 +612,39 @@ void MainWindow::on_toolBrush_clicked(bool checked)
ui->toolLasso->setChecked(false); ui->toolLasso->setChecked(false);
if(checked) if(checked)
{
ui->mapView->selectionTool = MapView::SelectionTool::Brush; ui->mapView->selectionTool = MapView::SelectionTool::Brush;
}
else else
{
ui->mapView->selectionTool = MapView::SelectionTool::None; ui->mapView->selectionTool = MapView::SelectionTool::None;
}
} }
void MainWindow::on_toolBrush2_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::Brush2;
else
ui->mapView->selectionTool = MapView::SelectionTool::None;
}
void MainWindow::on_toolBrush4_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::Brush4;
else
ui->mapView->selectionTool = MapView::SelectionTool::None;
}
void MainWindow::on_toolArea_clicked(bool checked) void MainWindow::on_toolArea_clicked(bool checked)
{ {
@ -627,13 +655,9 @@ void MainWindow::on_toolArea_clicked(bool checked)
ui->toolLasso->setChecked(false); ui->toolLasso->setChecked(false);
if(checked) if(checked)
{
ui->mapView->selectionTool = MapView::SelectionTool::Area; ui->mapView->selectionTool = MapView::SelectionTool::Area;
}
else else
{
ui->mapView->selectionTool = MapView::SelectionTool::None; ui->mapView->selectionTool = MapView::SelectionTool::None;
}
} }

View File

@ -72,6 +72,10 @@ private slots:
void on_actionFill_triggered(); void on_actionFill_triggered();
void on_toolBrush2_clicked(bool checked);
void on_toolBrush4_clicked(bool checked);
public slots: public slots:
void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);
@ -81,6 +85,8 @@ private:
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly); void addGroupIntoCatalog(const std::string & groupName, bool staticOnly);
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID); void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID);
void changeBrushState(int idx);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ObjectBrowser * objectBrowser = nullptr; ObjectBrowser * objectBrowser = nullptr;

View File

@ -399,7 +399,7 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QPushButton" name="toolBrush2"> <widget class="QPushButton" name="toolBrush2">
<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">
@ -433,7 +433,7 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QPushButton" name="toolBrush4"> <widget class="QPushButton" name="toolBrush4">
<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">

View File

@ -44,8 +44,41 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
sc->selectionTerrainView.draw(); sc->selectionTerrainView.draw();
break; break;
case MapView::SelectionTool::Brush2:
{
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
for(auto & e : extra)
{
if(mouseEvent->buttons() & Qt::RightButton)
sc->selectionTerrainView.erase(tile + e);
else if(mouseEvent->buttons() == Qt::LeftButton)
sc->selectionTerrainView.select(tile + e);
}
}
sc->selectionTerrainView.draw();
break;
case MapView::SelectionTool::Brush4:
{
std::array<int3, 16> extra{
int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0},
int3{-1, 0, 0}, int3{0, 0, 0}, int3{1, 0, 0}, int3{2, 0, 0},
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
};
for(auto & e : extra)
{
if(mouseEvent->buttons() & Qt::RightButton)
sc->selectionTerrainView.erase(tile + e);
else if(mouseEvent->buttons() == Qt::LeftButton)
sc->selectionTerrainView.select(tile + e);
}
}
sc->selectionTerrainView.draw();
break;
case MapView::SelectionTool::Area: case MapView::SelectionTool::Area:
if(mouseEvent->buttons() & Qt::RightButton) if(mouseEvent->buttons() & Qt::RightButton || !mouseEvent->buttons() & Qt::LeftButton)
break; break;
sc->selectionTerrainView.clear(); sc->selectionTerrainView.clear();
@ -106,6 +139,43 @@ void MapView::mousePressEvent(QMouseEvent *event)
sc->selectionTerrainView.draw(); sc->selectionTerrainView.draw();
break; break;
case MapView::SelectionTool::Brush2:
sc->selectionObjectsView.clear();
sc->selectionObjectsView.draw();
{
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
for(auto & e : extra)
{
if(event->button() == Qt::RightButton)
sc->selectionTerrainView.erase(tileStart + e);
else if(event->button() == Qt::LeftButton)
sc->selectionTerrainView.select(tileStart + e);
}
}
sc->selectionTerrainView.draw();
break;
case MapView::SelectionTool::Brush4:
sc->selectionObjectsView.clear();
sc->selectionObjectsView.draw();
{
std::array<int3, 16> extra{
int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0},
int3{-1, 0, 0}, int3{0, 0, 0}, int3{1, 0, 0}, int3{2, 0, 0},
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
};
for(auto & e : extra)
{
if(event->button() == Qt::RightButton)
sc->selectionTerrainView.erase(tileStart + e);
else if(event->button() == Qt::LeftButton)
sc->selectionTerrainView.select(tileStart + e);
}
}
sc->selectionTerrainView.draw();
break;
case MapView::SelectionTool::Area: case MapView::SelectionTool::Area:
if(event->button() == Qt::RightButton) if(event->button() == Qt::RightButton)
break; break;
@ -361,6 +431,9 @@ void SelectionTerrainView::draw()
void SelectionTerrainView::select(const int3 & tile) void SelectionTerrainView::select(const int3 & tile)
{ {
if(!main->getMap() || !main->getMap()->isInTheMap(tile))
return;
if(!area.count(tile)) if(!area.count(tile))
{ {
area.insert(tile); area.insert(tile);
@ -371,6 +444,9 @@ void SelectionTerrainView::select(const int3 & tile)
void SelectionTerrainView::erase(const int3 & tile) void SelectionTerrainView::erase(const int3 & tile)
{ {
if(!main->getMap() || !main->getMap()->isInTheMap(tile))
return;
if(area.count(tile)) if(area.count(tile))
{ {
area.erase(tile); area.erase(tile);
@ -601,7 +677,7 @@ void SelectionObjectsView::draw()
CGObjectInstance * SelectionObjectsView::selectObjectAt(int x, int y) CGObjectInstance * SelectionObjectsView::selectObjectAt(int x, int y)
{ {
if(!main->getMap() || !main->getMapHandler()) if(!main->getMap() || !main->getMapHandler() || !main->getMap()->isInTheMap(int3(x, y, scene->level)))
return nullptr; return nullptr;
auto & objects = main->getMapHandler()->getObjects(x, y, scene->level); auto & objects = main->getMapHandler()->getObjects(x, y, scene->level);