2013-06-09 16:08:01 +00:00
|
|
|
#include "widgetterrainbasenoisepreview.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include "tools.h"
|
2013-11-03 14:46:39 +00:00
|
|
|
#include "NoiseGenerator.h"
|
2013-06-09 16:08:01 +00:00
|
|
|
|
|
|
|
WidgetTerrainBaseNoisePreview::WidgetTerrainBaseNoisePreview(QWidget* parent) :
|
2013-08-18 15:12:54 +00:00
|
|
|
DrawingWidget(parent)
|
2013-06-09 16:08:01 +00:00
|
|
|
{
|
|
|
|
_noise = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WidgetTerrainBaseNoisePreview::setNoise(NoiseGenerator* noise)
|
|
|
|
{
|
|
|
|
_noise = noise;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2013-08-18 15:12:54 +00:00
|
|
|
void WidgetTerrainBaseNoisePreview::doDrawing(QPainter* painter)
|
2013-06-09 16:08:01 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
painter->fillRect(rect(), QColor(20, 40, 80));
|
|
|
|
painter->setPen(QColor(220, 210, 180));
|
2013-06-09 16:08:01 +00:00
|
|
|
|
|
|
|
int height = this->height();
|
|
|
|
|
|
|
|
if (_noise)
|
|
|
|
{
|
2013-08-18 15:12:54 +00:00
|
|
|
//QRect boundaries = event->region().boundingRect();
|
|
|
|
QRect boundaries = rect(); // TODO Limit to updated region
|
2013-06-09 16:08:01 +00:00
|
|
|
double value, factor;
|
|
|
|
double minvalue, maxvalue;
|
|
|
|
|
2013-11-03 14:46:39 +00:00
|
|
|
_noise->getRange(&minvalue, &maxvalue);
|
2013-06-09 16:08:01 +00:00
|
|
|
factor = ((double)height) / (maxvalue - minvalue);
|
|
|
|
|
|
|
|
for (int x = boundaries.left(); x <= boundaries.right(); x++)
|
|
|
|
{
|
2013-11-03 14:46:39 +00:00
|
|
|
value = _noise->get1DTotal(100.0 * ((double)x) / factor);
|
2013-06-09 16:08:01 +00:00
|
|
|
|
2013-08-18 15:12:54 +00:00
|
|
|
painter->drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
|
2013-06-09 16:08:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|