paysages : Noise dialog WIP.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@229 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-20 16:25:09 +00:00 committed by ThunderK
parent 57e7341ce0
commit 6b9b813753
5 changed files with 153 additions and 43 deletions

View file

@ -16,24 +16,32 @@ class PreviewLevel:public Preview
{
public:
PreviewLevel(QWidget* parent, NoiseGenerator* noise):
Preview(parent),
_noise(noise)
Preview(parent)
{
_noise = noise;
_level = -1;
}
void setLevel(int row)
{
_level = row;
redraw();
}
protected:
QColor getColor(double x, double y)
{
/*Vector3 eye = {0.0, 0.0, 0.0};
Vector3 look;
look.x = cos(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0));
look.y = -sin(M_PI * (y / 256.0));
look.z = sin(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0));
return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL));*/
if ((_level >= 0) && (y > noiseGet1DLevel(_noise, _level, x)))
{
return QColor(255, 255, 255);
}
else
{
return QColor(0, 0, 0);
}
}
private:
NoiseGenerator* _noise;
int _level;
};
class PreviewTotal:public Preview
@ -67,14 +75,11 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
QWidget* previews;
QWidget* form;
QWidget* buttons;
QSlider* slider;
QPushButton* button;
_base = value;
_current = noiseCreateGenerator();
noiseCopy(_base, _current);
setLayout(new QHBoxLayout());
previews = new QWidget(this);
@ -84,39 +89,56 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
previewLevel = new PreviewLevel(previews, _current);
previews->layout()->addWidget(new QLabel("Level preview"));
previews->layout()->addWidget(previewLevel);
previewLevel->setScaling(1.0 / 127.0);
previewTotal = new PreviewTotal(previews, _current);
previews->layout()->addWidget(new QLabel("Total preview"));
previews->layout()->addWidget(previewTotal);
previewTotal->setScaling(1.0 / 127.0);
form = new QWidget(this);
form->setLayout(new QVBoxLayout());
layout()->addWidget(form);
form->layout()->addWidget(new QLabel("Layers"));
form->layout()->addWidget(new QLabel("Noise components"));
levels = new QListWidget(form);
form->layout()->addWidget(levels);
QObject::connect(levels, SIGNAL(currentRowChanged(int)), this, SLOT(levelChanged(int)));
form->layout()->addWidget(new QLabel("Layer height"));
slider = new QSlider(form);
slider->setOrientation(Qt::Horizontal);
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(0);
slider->setMaximum(1000);
slider->setTickInterval(100);
slider->setTickPosition(QSlider::TicksBelow);
form->layout()->addWidget(slider);
buttons = new QWidget(form);
buttons->setLayout(new QHBoxLayout());
form->layout()->addWidget(buttons);
form->layout()->addWidget(new QLabel("Layer scaling"));
slider = new QSlider(form);
slider->setOrientation(Qt::Horizontal);
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(0);
slider->setMaximum(1000);
slider->setTickInterval(100);
slider->setTickPosition(QSlider::TicksBelow);
form->layout()->addWidget(slider);
button = new QPushButton("Add component", buttons);
buttons->layout()->addWidget(button);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(addLevel()));
button = new QPushButton("Remove component", buttons);
buttons->layout()->addWidget(button);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(removeLevel()));
form->layout()->addWidget(new QLabel("Component height"));
slider_height = new QSlider(form);
slider_height->setOrientation(Qt::Horizontal);
slider_height->setMinimumWidth(150);
slider_height->setMaximumWidth(400);
slider_height->setMinimum(0);
slider_height->setMaximum(1000);
slider_height->setTickInterval(100);
slider_height->setTickPosition(QSlider::TicksBelow);
form->layout()->addWidget(slider_height);
QObject::connect(slider_height, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
form->layout()->addWidget(new QLabel("Component scaling"));
slider_scaling = new QSlider(form);
slider_scaling->setOrientation(Qt::Horizontal);
slider_scaling->setMinimumWidth(150);
slider_scaling->setMaximumWidth(400);
slider_scaling->setMinimum(1);
slider_scaling->setMaximum(1000);
slider_scaling->setTickInterval(100);
slider_scaling->setTickPosition(QSlider::TicksBelow);
form->layout()->addWidget(slider_scaling);
QObject::connect(slider_scaling, SIGNAL(valueChanged(int)), this, SLOT(scalingChanged(int)));
buttons = new QWidget(form);
buttons->setLayout(new QHBoxLayout());
@ -124,14 +146,19 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
button = new QPushButton("Validate", buttons);
buttons->layout()->addWidget(button);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
button = new QPushButton("Reset", buttons);
buttons->layout()->addWidget(button);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
button = new QPushButton("Cancel", buttons);
buttons->layout()->addWidget(button);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));
setWindowTitle("Paysages 3D - Noise editor");
revert();
}
DialogNoise::~DialogNoise()
@ -164,3 +191,73 @@ void DialogNoise::accept()
noiseCopy(_current, _base);
QDialog::accept();
}
void DialogNoise::revert()
{
noiseCopy(_base, _current);
revertToCurrent();
}
void DialogNoise::revertToCurrent()
{
int i, n;
levels->clear();
n = noiseGetLevelCount(_current);
for (i = 0; i < n; i++)
{
levels->addItem("Level");
}
previewLevel->redraw();
previewTotal->redraw();
}
void DialogNoise::addLevel()
{
NoiseLevel level;
level.height = 0.1;
level.scaling = 0.1;
level.xoffset = 0.0;
level.yoffset = 0.0;
level.zoffset = 0.0;
noiseAddLevel(_current, level);
revertToCurrent();
}
void DialogNoise::removeLevel()
{
// TODO
}
void DialogNoise::levelChanged(int row)
{
if (noiseGetLevel(_current, row, &_current_level_params))
{
_current_level = row;
((PreviewLevel*)previewLevel)->setLevel(row);
slider_height->setValue(_current_level_params.height * 1000.0);
slider_scaling->setValue(_current_level_params.scaling * 1000.0);
}
// TODO else ...
}
void DialogNoise::heightChanged(int value)
{
_current_level_params.height = ((double)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw();
previewTotal->redraw();
}
void DialogNoise::scalingChanged(int value)
{
_current_level_params.scaling = ((double)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw();
previewTotal->redraw();
}

View file

@ -18,22 +18,31 @@ public:
public slots:
virtual void accept();
void revert();
protected:
virtual void closeEvent(QCloseEvent* e);
private:
void revertToCurrent();
private slots:
void cancelClicked();
void revertClicked();
void applyClicked();
void addLevel();
void removeLevel();
void levelChanged(int row);
void heightChanged(int value);
void scalingChanged(int value);
private:
NoiseGenerator* _base;
NoiseGenerator* _current;
NoiseLevel _current_level;
int _current_level;
NoiseLevel _current_level_params;
Preview* previewLevel;
Preview* previewTotal;
QListWidget* levels;
QSlider* slider_height;
QSlider* slider_scaling;
};
#endif

View file

@ -98,6 +98,13 @@ void Preview::redraw()
//lock->unlock();
}
void Preview::setScaling(double scaling)
{
// TODO Follow conf_scale
this->scaling = scaling;
redraw();
}
void Preview::resizeEvent(QResizeEvent* event)
{
QImage* image;

View file

@ -18,6 +18,8 @@ public:
void doRender();
void redraw();
void setScaling(double scaling);
protected:
void resizeEvent(QResizeEvent* event);
void paintEvent(QPaintEvent* event);

View file

@ -172,11 +172,6 @@ void noiseClearLevels(NoiseGenerator* generator)
void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level)
{
if (level.scaling < 0.0000001 || level.height < 0.0000001)
{
return;
}
generator->levels = realloc(generator->levels, sizeof(NoiseLevel) * (generator->level_count + 1));
generator->levels[generator->level_count] = level;
generator->level_count++;