2012-01-07 16:53:23 +00:00
|
|
|
#include "inputnoise.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
#include "../lib_paysages/shared/functions.h"
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
class NoiseSmallPreview:public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2012-01-08 10:31:01 +00:00
|
|
|
NoiseSmallPreview(QWidget* parent, NoiseGenerator* noise):
|
|
|
|
QWidget(parent),
|
|
|
|
noise(noise)
|
2012-01-07 16:53:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
if (!noise)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
int width = this->width();
|
|
|
|
int height = this->height();
|
|
|
|
double value, factor;
|
|
|
|
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
factor = ((double)(height / 2)) / noiseGetMaxValue(noise);
|
|
|
|
value = noiseGet1DTotal(noise, ((double)x) / factor) * factor;
|
|
|
|
painter.setPen(QColor(255, 255, 255));
|
|
|
|
painter.drawLine(x, 0, x, height / 2 + value);
|
|
|
|
painter.setPen(QColor(0, 0, 0));
|
|
|
|
painter.drawLine(x, height / 2 + value + 1, x, height);
|
|
|
|
}
|
2012-01-07 16:53:23 +00:00
|
|
|
}
|
|
|
|
NoiseGenerator* noise;
|
|
|
|
};
|
|
|
|
|
|
|
|
InputNoise::InputNoise(QWidget* form, QString label, NoiseGenerator* value):
|
|
|
|
BaseInput(form, label),
|
|
|
|
_value(value)
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
_preview = new NoiseSmallPreview(form, value);
|
2012-01-07 16:53:23 +00:00
|
|
|
_preview->setMinimumSize(100, 40);
|
|
|
|
_control = new QPushButton("Edit", form);
|
|
|
|
_control->setMaximumWidth(150);
|
|
|
|
|
|
|
|
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editNoise()));
|
|
|
|
}
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
void InputNoise::updatePreview()
|
|
|
|
{
|
|
|
|
_preview->update();
|
|
|
|
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
void InputNoise::applyValue()
|
|
|
|
{
|
|
|
|
/*_value->r = ((ColorPreview*)_preview)->col.redF();
|
|
|
|
_value->g = ((ColorPreview*)_preview)->col.greenF();
|
|
|
|
_value->b = ((ColorPreview*)_preview)->col.blueF();
|
|
|
|
_value->a = 1.0;*/
|
2012-01-08 10:31:01 +00:00
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
BaseInput::applyValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputNoise::revert()
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
/*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);*/
|
|
|
|
|
|
|
|
BaseInput::revert();
|
2012-01-07 16:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputNoise::editNoise()
|
|
|
|
{
|
|
|
|
/*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control);
|
|
|
|
if (col.isValid())
|
|
|
|
{
|
|
|
|
((ColorPreview*)_preview)->col = col;
|
|
|
|
applyValue();
|
|
|
|
}*/
|
|
|
|
}
|