paysages3d/src/editing/terrain/mainterrainform.cpp

116 lines
3.3 KiB
C++
Raw Normal View History

#include "mainterrainform.h"
#include "ui_mainterrainform.h"
#include <QMessageBox>
#include "dialogbaseterrainnoise.h"
#include "dialogterrainpainting.h"
#include "previewterrainshape.h"
#include "tools.h"
#include "rendering/scenery.h"
MainTerrainForm::MainTerrainForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainTerrainForm)
{
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
ui->setupUi(this);
_form_helper = new FreeFormHelper(this);
_renderer_shape = new PreviewTerrainShape(_terrain);
_form_helper->addPreview(ui->preview_shape, _renderer_shape);
_form_helper->addDoubleInputSlider(ui->input_scaling, &_terrain->scaling, 0.1, 3.0, 0.03, 0.3);
_form_helper->addDoubleInputSlider(ui->input_height, &_terrain->height, 1.0, 90.0, 0.5, 5.0);
_form_helper->addDoubleInputSlider(ui->input_shadow_smoothing, &_terrain->shadow_smoothing, 0.0, 0.3, 0.003, 0.03);
_form_helper->addDoubleInputSlider(ui->input_water_height, &_terrain->water_height, -1.0, 1.0, 0.01, 0.1);
_form_helper->setApplyButton(ui->button_apply);
_form_helper->setRevertButton(ui->button_revert);
_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()));
_form_helper->startManaging();
}
MainTerrainForm::~MainTerrainForm()
{
delete _form_helper;
delete ui;
delete _renderer_shape;
TerrainDefinitionClass.destroy(_terrain);
}
void MainTerrainForm::refreshFromLocalData()
{
qint64 memused = terrainGetMemoryStats(_terrain);
if (memused > 0)
{
_form_helper->setLabelText("label_painting_info", tr("Memory used by sculpted data: %1").arg(getHumanMemory(memused)));
}
else
{
_form_helper->setLabelText("label_painting_info", tr("No manual scuplting done"));
}
ui->widget_base_noise_preview->setNoise(_terrain->_height_noise);
}
void MainTerrainForm::refreshFromFellowData()
{
// TODO Refresh texture info
}
void MainTerrainForm::updateLocalDataFromScenery()
{
sceneryGetTerrain(_terrain);
}
void MainTerrainForm::commitLocalDataToScenery()
{
scenerySetTerrain(_terrain);
}
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);
_form_helper->openDialog(&dialog);
}
void MainTerrainForm::buttonTexturesPressed()
{
// TODO Switch to textures tab
}