Started terrain base noise edition dialog

This commit is contained in:
Michaël Lemaire 2013-06-09 19:36:30 +02:00
parent 6707998a76
commit b15ea439d2
9 changed files with 142 additions and 4 deletions

View file

@ -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

View file

@ -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();
}

View file

@ -0,0 +1,29 @@
#ifndef DIALOGBASETERRAINNOISE_H
#define DIALOGBASETERRAINNOISE_H
#include <QDialog>
#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

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogBaseTerrainNoise</class>
<widget class="QDialog" name="DialogBaseTerrainNoise">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Paysages 3D - Base terrain noise</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="WidgetGlobalFormButtons" name="widget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>WidgetGlobalFormButtons</class>
<extends>QWidget</extends>
<header>common/widgetglobalformbuttons.h</header>
<container>1</container>
<slots>
<signal>okClicked()</signal>
<signal>revertClicked()</signal>
<signal>cancelClicked()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -1,6 +1,8 @@
#include "mainterrainform.h"
#include "ui_mainterrainform.h"
#include <QMessageBox>
#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);

View file

@ -26,6 +26,7 @@ public slots:
void commitLocalDataToScenery();
void alterRenderer(Renderer* renderer);
void buttonBaseNoisePressed();
void buttonPaintingPressed();
void buttonTexturesPressed();

View file

@ -44,7 +44,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="button_dialog_basenoise">
<property name="text">
<string>Generate base noise</string>
</property>

View file

@ -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);

View file

@ -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)