diff --git a/src/editing/paysages-qt.pro b/src/editing/paysages-qt.pro index 86093c6..1169b91 100644 --- a/src/editing/paysages-qt.pro +++ b/src/editing/paysages-qt.pro @@ -71,7 +71,8 @@ HEADERS += \ common/widgetsliderdecimal.h \ common/previewrenderer.h \ terrain/widgetterrainbasenoisepreview.h \ - common/mainwindow.h + common/mainwindow.h \ + terrain/dialogbaseterrainnoise.h SOURCES += \ terrain/widgetheightmap.cpp \ @@ -121,13 +122,15 @@ SOURCES += \ common/widgetsliderdecimal.cpp \ common/previewrenderer.cpp \ terrain/widgetterrainbasenoisepreview.cpp \ - common/mainwindow.cpp + common/mainwindow.cpp \ + terrain/dialogbaseterrainnoise.cpp FORMS += \ terrain/dialogterrainpainting.ui \ common/widgetglobalformbuttons.ui \ terrain/mainterrainform.ui \ - common/mainwindow.ui + common/mainwindow.ui \ + terrain/dialogbaseterrainnoise.ui RESOURCES += \ ../../data/ui_pictures.qrc diff --git a/src/editing/terrain/dialogbaseterrainnoise.cpp b/src/editing/terrain/dialogbaseterrainnoise.cpp new file mode 100644 index 0000000..5b139c8 --- /dev/null +++ b/src/editing/terrain/dialogbaseterrainnoise.cpp @@ -0,0 +1,31 @@ +#include "dialogbaseterrainnoise.h" +#include "ui_dialogbaseterrainnoise.h" + +DialogBaseTerrainNoise::DialogBaseTerrainNoise(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogBaseTerrainNoise) +{ + ui->setupUi(this); + + _original = 0; + _modified = noiseCreateGenerator(); +} + +DialogBaseTerrainNoise::~DialogBaseTerrainNoise() +{ + delete ui; + noiseDeleteGenerator(_modified); +} + +void DialogBaseTerrainNoise::setNoise(NoiseGenerator* noise) +{ + _original = noise; + noiseCopy(noise, _modified); +} + +int DialogBaseTerrainNoise::editNoise(QWidget* parent, NoiseGenerator* noise) +{ + DialogBaseTerrainNoise dialog(parent); + dialog.setNoise(noise); + return dialog.exec(); +} diff --git a/src/editing/terrain/dialogbaseterrainnoise.h b/src/editing/terrain/dialogbaseterrainnoise.h new file mode 100644 index 0000000..a38292c --- /dev/null +++ b/src/editing/terrain/dialogbaseterrainnoise.h @@ -0,0 +1,29 @@ +#ifndef DIALOGBASETERRAINNOISE_H +#define DIALOGBASETERRAINNOISE_H + +#include +#include "rendering/noise.h" + +namespace Ui { +class DialogBaseTerrainNoise; +} + +class DialogBaseTerrainNoise : public QDialog +{ + Q_OBJECT + +public: + explicit DialogBaseTerrainNoise(QWidget *parent = 0); + ~DialogBaseTerrainNoise(); + + void setNoise(NoiseGenerator* noise); + + static int editNoise(QWidget* parent, NoiseGenerator* noise); + +private: + Ui::DialogBaseTerrainNoise *ui; + NoiseGenerator* _original; + NoiseGenerator* _modified; +}; + +#endif // DIALOGBASETERRAINNOISE_H diff --git a/src/editing/terrain/dialogbaseterrainnoise.ui b/src/editing/terrain/dialogbaseterrainnoise.ui new file mode 100644 index 0000000..57b1add --- /dev/null +++ b/src/editing/terrain/dialogbaseterrainnoise.ui @@ -0,0 +1,43 @@ + + + DialogBaseTerrainNoise + + + Qt::ApplicationModal + + + + 0 + 0 + 400 + 300 + + + + Paysages 3D - Base terrain noise + + + true + + + + + + + + + + WidgetGlobalFormButtons + QWidget +
common/widgetglobalformbuttons.h
+ 1 + + okClicked() + revertClicked() + cancelClicked() + +
+
+ + +
diff --git a/src/editing/terrain/mainterrainform.cpp b/src/editing/terrain/mainterrainform.cpp index c383327..0c659ed 100644 --- a/src/editing/terrain/mainterrainform.cpp +++ b/src/editing/terrain/mainterrainform.cpp @@ -1,6 +1,8 @@ #include "mainterrainform.h" #include "ui_mainterrainform.h" +#include +#include "dialogbaseterrainnoise.h" #include "dialogterrainpainting.h" #include "previewterrainshape.h" #include "tools.h" @@ -29,6 +31,7 @@ MainTerrainForm::MainTerrainForm(QWidget *parent) : _form_helper->setExploreButton(ui->button_explore); _form_helper->setRenderButton(ui->button_render); + connect(ui->button_dialog_basenoise, SIGNAL(clicked()), this, SLOT(buttonBaseNoisePressed())); connect(ui->button_dialog_painting, SIGNAL(clicked()), this, SLOT(buttonPaintingPressed())); connect(ui->button_goto_textures, SIGNAL(clicked()), this, SLOT(buttonTexturesPressed())); @@ -79,6 +82,27 @@ void MainTerrainForm::alterRenderer(Renderer* renderer) TerrainRendererClass.bind(renderer, _terrain); } +void MainTerrainForm::buttonBaseNoisePressed() +{ + int erase; + if (terrainGetMemoryStats(_terrain) > 0) + { + erase = QMessageBox::question(this, tr("Paysages 3D - Base noise edition"), tr("You have manual modifications on this terrain, regenerating base noise may produce weird results."), tr("Keep my changes anyway"), tr("Erase my changes")); + } + else + { + erase = 0; + } + + if (DialogBaseTerrainNoise::editNoise(this, _terrain->_height_noise)) + { + if (erase) + { + terrainClearPainting(_terrain->height_map); + } + } +} + void MainTerrainForm::buttonPaintingPressed() { DialogTerrainPainting dialog(this, _terrain); diff --git a/src/editing/terrain/mainterrainform.h b/src/editing/terrain/mainterrainform.h index 712197a..5cf5bb9 100644 --- a/src/editing/terrain/mainterrainform.h +++ b/src/editing/terrain/mainterrainform.h @@ -26,6 +26,7 @@ public slots: void commitLocalDataToScenery(); void alterRenderer(Renderer* renderer); + void buttonBaseNoisePressed(); void buttonPaintingPressed(); void buttonTexturesPressed(); diff --git a/src/editing/terrain/mainterrainform.ui b/src/editing/terrain/mainterrainform.ui index 12fbb1b..dac4f2f 100644 --- a/src/editing/terrain/mainterrainform.ui +++ b/src/editing/terrain/mainterrainform.ui @@ -44,7 +44,7 @@ - + Generate base noise diff --git a/src/rendering/terrain/public.h b/src/rendering/terrain/public.h index ca83821..905e626 100644 --- a/src/rendering/terrain/public.h +++ b/src/rendering/terrain/public.h @@ -81,6 +81,7 @@ typedef struct /* Heightmap manipulation */ int terrainIsPainted(TerrainHeightMap* heightmap, int x, int z); +void terrainClearPainting(TerrainHeightMap* heightmap); void terrainBrushElevation(TerrainHeightMap* heightmap, TerrainBrush* brush, double value); void terrainBrushSmooth(TerrainHeightMap* heightmap, TerrainBrush* brush, double value); void terrainBrushAddNoise(TerrainHeightMap* heightmap, TerrainBrush* brush, NoiseGenerator* generator, double value); diff --git a/src/rendering/terrain/ter_painting.c b/src/rendering/terrain/ter_painting.c index 3d60890..b94ab59 100644 --- a/src/rendering/terrain/ter_painting.c +++ b/src/rendering/terrain/ter_painting.c @@ -454,6 +454,12 @@ int terrainIsPainted(TerrainHeightMap* heightmap, int x, int z) return _getDataPointer(&heightmap->brush_data, x, z, NULL, NULL, 0) || _getDataPointer(&heightmap->merged_data, x, z, NULL, NULL, 0); } +void terrainClearPainting(TerrainHeightMap* heightmap) +{ + _clearData(&heightmap->merged_data); + _clearData(&heightmap->brush_data); +} + typedef double (*BrushCallback)(TerrainHeightMap* heightmap, TerrainBrush* brush, double x, double z, double basevalue, double influence, double force, void* data); static inline void _applyBrush(TerrainHeightMap* heightmap, TerrainBrush* brush, double force, void* data, BrushCallback callback)