Michaël Lemaire
375c4f24b8
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@223 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
81 lines
1.7 KiB
C++
81 lines
1.7 KiB
C++
#include "inputnoise.h"
|
|
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QPainter>
|
|
#include <QColorDialog>
|
|
|
|
#include "dialognoise.h"
|
|
|
|
#include "../lib_paysages/shared/functions.h"
|
|
|
|
class NoiseSmallPreview:public QWidget
|
|
{
|
|
public:
|
|
NoiseSmallPreview(QWidget* parent, NoiseGenerator* noise):
|
|
QWidget(parent),
|
|
noise(noise)
|
|
{
|
|
}
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
NoiseGenerator* noise;
|
|
};
|
|
|
|
InputNoise::InputNoise(QWidget* form, QString label, NoiseGenerator* value):
|
|
BaseInput(form, label),
|
|
_value(value)
|
|
{
|
|
_preview = new NoiseSmallPreview(form, value);
|
|
_preview->setMinimumSize(100, 40);
|
|
_control = new QPushButton("Edit", form);
|
|
_control->setMaximumWidth(150);
|
|
|
|
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editNoise()));
|
|
}
|
|
|
|
void InputNoise::updatePreview()
|
|
{
|
|
_preview->update();
|
|
|
|
BaseInput::updatePreview();
|
|
}
|
|
|
|
void InputNoise::applyValue()
|
|
{
|
|
BaseInput::applyValue();
|
|
}
|
|
|
|
void InputNoise::revert()
|
|
{
|
|
BaseInput::revert();
|
|
}
|
|
|
|
void InputNoise::editNoise()
|
|
{
|
|
if (DialogNoise::getNoise(_control, _value))
|
|
{
|
|
applyValue();
|
|
}
|
|
}
|