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:
parent
57e7341ce0
commit
6b9b813753
5 changed files with 153 additions and 43 deletions
|
@ -16,24 +16,32 @@ class PreviewLevel:public Preview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PreviewLevel(QWidget* parent, NoiseGenerator* noise):
|
PreviewLevel(QWidget* parent, NoiseGenerator* noise):
|
||||||
Preview(parent),
|
Preview(parent)
|
||||||
_noise(noise)
|
|
||||||
{
|
{
|
||||||
|
_noise = noise;
|
||||||
|
_level = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLevel(int row)
|
||||||
|
{
|
||||||
|
_level = row;
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
QColor getColor(double x, double y)
|
QColor getColor(double x, double y)
|
||||||
{
|
{
|
||||||
/*Vector3 eye = {0.0, 0.0, 0.0};
|
if ((_level >= 0) && (y > noiseGet1DLevel(_noise, _level, x)))
|
||||||
Vector3 look;
|
{
|
||||||
|
return QColor(255, 255, 255);
|
||||||
look.x = cos(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0));
|
}
|
||||||
look.y = -sin(M_PI * (y / 256.0));
|
else
|
||||||
look.z = sin(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0));
|
{
|
||||||
|
return QColor(0, 0, 0);
|
||||||
return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL));*/
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
NoiseGenerator* _noise;
|
NoiseGenerator* _noise;
|
||||||
|
int _level;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PreviewTotal:public Preview
|
class PreviewTotal:public Preview
|
||||||
|
@ -67,14 +75,11 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
|
||||||
QWidget* previews;
|
QWidget* previews;
|
||||||
QWidget* form;
|
QWidget* form;
|
||||||
QWidget* buttons;
|
QWidget* buttons;
|
||||||
QSlider* slider;
|
|
||||||
QPushButton* button;
|
QPushButton* button;
|
||||||
|
|
||||||
_base = value;
|
_base = value;
|
||||||
_current = noiseCreateGenerator();
|
_current = noiseCreateGenerator();
|
||||||
|
|
||||||
noiseCopy(_base, _current);
|
|
||||||
|
|
||||||
setLayout(new QHBoxLayout());
|
setLayout(new QHBoxLayout());
|
||||||
|
|
||||||
previews = new QWidget(this);
|
previews = new QWidget(this);
|
||||||
|
@ -84,39 +89,56 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
|
||||||
previewLevel = new PreviewLevel(previews, _current);
|
previewLevel = new PreviewLevel(previews, _current);
|
||||||
previews->layout()->addWidget(new QLabel("Level preview"));
|
previews->layout()->addWidget(new QLabel("Level preview"));
|
||||||
previews->layout()->addWidget(previewLevel);
|
previews->layout()->addWidget(previewLevel);
|
||||||
|
previewLevel->setScaling(1.0 / 127.0);
|
||||||
previewTotal = new PreviewTotal(previews, _current);
|
previewTotal = new PreviewTotal(previews, _current);
|
||||||
previews->layout()->addWidget(new QLabel("Total preview"));
|
previews->layout()->addWidget(new QLabel("Total preview"));
|
||||||
previews->layout()->addWidget(previewTotal);
|
previews->layout()->addWidget(previewTotal);
|
||||||
|
previewTotal->setScaling(1.0 / 127.0);
|
||||||
|
|
||||||
form = new QWidget(this);
|
form = new QWidget(this);
|
||||||
form->setLayout(new QVBoxLayout());
|
form->setLayout(new QVBoxLayout());
|
||||||
layout()->addWidget(form);
|
layout()->addWidget(form);
|
||||||
|
|
||||||
form->layout()->addWidget(new QLabel("Layers"));
|
form->layout()->addWidget(new QLabel("Noise components"));
|
||||||
levels = new QListWidget(form);
|
levels = new QListWidget(form);
|
||||||
form->layout()->addWidget(levels);
|
form->layout()->addWidget(levels);
|
||||||
|
QObject::connect(levels, SIGNAL(currentRowChanged(int)), this, SLOT(levelChanged(int)));
|
||||||
|
|
||||||
form->layout()->addWidget(new QLabel("Layer height"));
|
buttons = new QWidget(form);
|
||||||
slider = new QSlider(form);
|
buttons->setLayout(new QHBoxLayout());
|
||||||
slider->setOrientation(Qt::Horizontal);
|
form->layout()->addWidget(buttons);
|
||||||
slider->setMinimumWidth(150);
|
|
||||||
slider->setMaximumWidth(400);
|
button = new QPushButton("Add component", buttons);
|
||||||
slider->setMinimum(0);
|
buttons->layout()->addWidget(button);
|
||||||
slider->setMaximum(1000);
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(addLevel()));
|
||||||
slider->setTickInterval(100);
|
|
||||||
slider->setTickPosition(QSlider::TicksBelow);
|
|
||||||
form->layout()->addWidget(slider);
|
|
||||||
|
|
||||||
form->layout()->addWidget(new QLabel("Layer scaling"));
|
button = new QPushButton("Remove component", buttons);
|
||||||
slider = new QSlider(form);
|
buttons->layout()->addWidget(button);
|
||||||
slider->setOrientation(Qt::Horizontal);
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(removeLevel()));
|
||||||
slider->setMinimumWidth(150);
|
|
||||||
slider->setMaximumWidth(400);
|
form->layout()->addWidget(new QLabel("Component height"));
|
||||||
slider->setMinimum(0);
|
slider_height = new QSlider(form);
|
||||||
slider->setMaximum(1000);
|
slider_height->setOrientation(Qt::Horizontal);
|
||||||
slider->setTickInterval(100);
|
slider_height->setMinimumWidth(150);
|
||||||
slider->setTickPosition(QSlider::TicksBelow);
|
slider_height->setMaximumWidth(400);
|
||||||
form->layout()->addWidget(slider);
|
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 = new QWidget(form);
|
||||||
buttons->setLayout(new QHBoxLayout());
|
buttons->setLayout(new QHBoxLayout());
|
||||||
|
@ -124,14 +146,19 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
|
||||||
|
|
||||||
button = new QPushButton("Validate", buttons);
|
button = new QPushButton("Validate", buttons);
|
||||||
buttons->layout()->addWidget(button);
|
buttons->layout()->addWidget(button);
|
||||||
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
|
|
||||||
button = new QPushButton("Reset", buttons);
|
button = new QPushButton("Reset", buttons);
|
||||||
buttons->layout()->addWidget(button);
|
buttons->layout()->addWidget(button);
|
||||||
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
|
||||||
|
|
||||||
button = new QPushButton("Cancel", buttons);
|
button = new QPushButton("Cancel", buttons);
|
||||||
buttons->layout()->addWidget(button);
|
buttons->layout()->addWidget(button);
|
||||||
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));
|
||||||
|
|
||||||
setWindowTitle("Paysages 3D - Noise editor");
|
setWindowTitle("Paysages 3D - Noise editor");
|
||||||
|
|
||||||
|
revert();
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogNoise::~DialogNoise()
|
DialogNoise::~DialogNoise()
|
||||||
|
@ -164,3 +191,73 @@ void DialogNoise::accept()
|
||||||
noiseCopy(_current, _base);
|
noiseCopy(_current, _base);
|
||||||
QDialog::accept();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -18,22 +18,31 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void accept();
|
virtual void accept();
|
||||||
|
void revert();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent* e);
|
virtual void closeEvent(QCloseEvent* e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void revertToCurrent();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void cancelClicked();
|
void addLevel();
|
||||||
void revertClicked();
|
void removeLevel();
|
||||||
void applyClicked();
|
void levelChanged(int row);
|
||||||
|
void heightChanged(int value);
|
||||||
|
void scalingChanged(int value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NoiseGenerator* _base;
|
NoiseGenerator* _base;
|
||||||
NoiseGenerator* _current;
|
NoiseGenerator* _current;
|
||||||
NoiseLevel _current_level;
|
int _current_level;
|
||||||
|
NoiseLevel _current_level_params;
|
||||||
Preview* previewLevel;
|
Preview* previewLevel;
|
||||||
Preview* previewTotal;
|
Preview* previewTotal;
|
||||||
QListWidget* levels;
|
QListWidget* levels;
|
||||||
|
QSlider* slider_height;
|
||||||
|
QSlider* slider_scaling;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -98,6 +98,13 @@ void Preview::redraw()
|
||||||
//lock->unlock();
|
//lock->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preview::setScaling(double scaling)
|
||||||
|
{
|
||||||
|
// TODO Follow conf_scale
|
||||||
|
this->scaling = scaling;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
void Preview::resizeEvent(QResizeEvent* event)
|
void Preview::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
QImage* image;
|
QImage* image;
|
||||||
|
|
|
@ -17,6 +17,8 @@ public:
|
||||||
static void startUpdater();
|
static void startUpdater();
|
||||||
void doRender();
|
void doRender();
|
||||||
void redraw();
|
void redraw();
|
||||||
|
|
||||||
|
void setScaling(double scaling);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
|
|
|
@ -172,11 +172,6 @@ void noiseClearLevels(NoiseGenerator* generator)
|
||||||
|
|
||||||
void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level)
|
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 = realloc(generator->levels, sizeof(NoiseLevel) * (generator->level_count + 1));
|
||||||
generator->levels[generator->level_count] = level;
|
generator->levels[generator->level_count] = level;
|
||||||
generator->level_count++;
|
generator->level_count++;
|
||||||
|
|
Loading…
Reference in a new issue