2012-07-13 12:23:58 +00:00
|
|
|
#include "inputheightmap.h"
|
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QPainter>
|
|
|
|
#include "dialogheightmap.h"
|
|
|
|
|
|
|
|
class SmallPreviewHeightMap:public QWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SmallPreviewHeightMap(QWidget* parent, HeightMap* value) : QWidget(parent)
|
|
|
|
{
|
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2012-07-23 09:58:06 +00:00
|
|
|
double min, max, value, fx, fy;
|
|
|
|
int ivalue;
|
2012-07-13 12:23:58 +00:00
|
|
|
QPainter painter(this);
|
2012-07-23 09:58:06 +00:00
|
|
|
|
|
|
|
heightmapGetLimits(_value, &min, &max);
|
|
|
|
if (max - min < 0.000001)
|
|
|
|
{
|
|
|
|
painter.fillRect(rect(), Qt::black);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fx = 1.0 / (double)(width() - 1);
|
|
|
|
fy = 1.0 / (double)(height() - 1);
|
|
|
|
for (int x = 0; x < width(); x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < height(); y++)
|
|
|
|
{
|
|
|
|
value = heightmapGetRawValue(_value, fx * x, fy * y);
|
|
|
|
ivalue = (int)(255.0 * (value - min) / (max - min));
|
|
|
|
if (ivalue > 255 || ivalue < 0)
|
|
|
|
{
|
|
|
|
ivalue = 128;
|
|
|
|
}
|
|
|
|
painter.setPen(QColor(ivalue, ivalue, ivalue));
|
|
|
|
painter.drawPoint(x, y);
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 12:23:58 +00:00
|
|
|
}
|
|
|
|
HeightMap* _value;
|
|
|
|
};
|
|
|
|
|
2012-08-08 13:30:40 +00:00
|
|
|
InputHeightMap::InputHeightMap(QWidget* form, QString label, HeightMap* value, TerrainCanvas* canvas) : BaseInput(form, label)
|
2012-07-13 12:23:58 +00:00
|
|
|
{
|
|
|
|
_value = value;
|
2012-08-08 13:30:40 +00:00
|
|
|
_canvas = canvas;
|
2012-07-13 12:23:58 +00:00
|
|
|
|
|
|
|
_preview = new SmallPreviewHeightMap(form, value);
|
2012-07-23 09:58:06 +00:00
|
|
|
_preview->setMinimumSize(100, 100);
|
2012-07-13 12:23:58 +00:00
|
|
|
|
|
|
|
_control = new QPushButton(tr("Paint"), form);
|
|
|
|
_control->setMaximumWidth(150);
|
|
|
|
|
|
|
|
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editHeightMap()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputHeightMap::updatePreview()
|
|
|
|
{
|
|
|
|
_preview->update();
|
|
|
|
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputHeightMap::applyValue()
|
|
|
|
{
|
|
|
|
BaseInput::applyValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputHeightMap::revert()
|
|
|
|
{
|
|
|
|
BaseInput::revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputHeightMap::editHeightMap()
|
|
|
|
{
|
2012-08-08 13:30:40 +00:00
|
|
|
if (DialogHeightMap::editHeightMap(_control, _value, _canvas))
|
2012-07-13 12:23:58 +00:00
|
|
|
{
|
|
|
|
applyValue();
|
|
|
|
}
|
|
|
|
}
|