paysages: Qt GUI (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@219 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-08 10:31:01 +00:00 committed by ThunderK
parent db453d6fa9
commit 06b170e0f5
18 changed files with 171 additions and 50 deletions

View file

@ -105,6 +105,7 @@ void BaseForm::addInput(BaseInput* input)
connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview()));
input->setObjectName("_form_input_");
input->revert();
}
void BaseForm::addInputInt(QString label, int* value, int min, int max, int small_step, int large_step)

View file

@ -8,7 +8,17 @@ BaseInput::BaseInput(QWidget* form, QString label):
_label = new QLabel(label);
}
void BaseInput::updatePreview()
{
}
void BaseInput::applyValue()
{
updatePreview();
emit(valueChanged());
}
void BaseInput::revert()
{
updatePreview();
}

View file

@ -15,9 +15,8 @@ public:
inline QWidget* control() {return _control;}
public slots:
virtual void revert() = 0;
protected slots:
virtual void updatePreview();
virtual void revert();
virtual void applyValue();
signals:

View file

@ -131,14 +131,14 @@ FormWater::FormWater(QWidget *parent):
addPreview(previewCoverage, QString("Coverage preview"));
addPreview(previewColor, QString("Color preview"));
addInputDouble("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0);
addInputDouble("Height", &_definition.height, -10.0, 10.0, 0.1, 1.0);
addInputColor("Surface color", &_definition.main_color);
addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addInputColor("Depth color", &_definition.depth_color);
addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
addInputNoise("Wave noise", _definition.height_noise);
addInputDouble("Wave factor", &_definition.height_noise_factor, 0.0, 3.0, 0.1, 1.0);
addInputDouble("Wave factor", &_definition.height_noise_factor, 0.0, 2.0, 0.01, 0.2);
revertConfig();
}

View file

@ -33,6 +33,12 @@ InputColor::InputColor(QWidget* form, QString label, Color* value):
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(chooseColor()));
}
void InputColor::updatePreview()
{
_preview->update();
BaseInput::updatePreview();
}
void InputColor::applyValue()
{
_value->r = ((ColorPreview*)_preview)->col.redF();
@ -45,7 +51,7 @@ void InputColor::applyValue()
void InputColor::revert()
{
((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);
_preview->update();
BaseInput::revert();
}
void InputColor::chooseColor()

View file

@ -14,10 +14,9 @@ public:
InputColor(QWidget* form, QString label, Color* value);
public slots:
virtual void revert();
protected slots:
virtual void updatePreview();
virtual void applyValue();
virtual void revert();
private slots:
void chooseColor();

View file

@ -5,19 +5,32 @@
#include <QPainter>
#include <QColorDialog>
#include "tools.h"
#include "../lib_paysages/shared/functions.h"
class ColorGradationPreview:public QWidget
{
public:
ColorGradationPreview(QWidget* parent):
QWidget(parent)
ColorGradationPreview(QWidget* parent, ColorGradation* gradation):
QWidget(parent),
gradation(gradation)
{
}
void paintEvent(QPaintEvent* event)
{
/*QPainter painter(this);
painter.fillRect(this->rect(), col);*/
QPainter painter(this);
int width = this->width();
int height = this->height();
for (int x = 0; x < width; x++)
{
painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width)));
painter.drawLine(x, 0, x, height - 1);
}
}
ColorGradation* gradation;
};
@ -25,14 +38,21 @@ InputColorGradation::InputColorGradation(QWidget* form, QString label, ColorGrad
BaseInput(form, label),
_value(value)
{
_preview = new ColorGradationPreview(form);
_preview = new ColorGradationPreview(form, value);
_preview->setMinimumSize(200, 20);
_control = new QPushButton("Edit", form);
_control->setMaximumWidth(150);
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editGradation()));
}
void InputColorGradation::updatePreview()
{
_preview->update();
BaseInput::updatePreview();
}
void InputColorGradation::applyValue()
{
/*_value->r = ((ColorPreview*)_preview)->col.redF();
@ -44,8 +64,7 @@ void InputColorGradation::applyValue()
void InputColorGradation::revert()
{
/*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);
_preview->update();*/
BaseInput::revert();
}
void InputColorGradation::editGradation()

View file

@ -14,10 +14,9 @@ public:
InputColorGradation(QWidget* form, QString label, ColorGradation* value);
public slots:
virtual void revert();
protected slots:
virtual void updatePreview();
virtual void applyValue();
virtual void revert();
private slots:
void editGradation();

View file

@ -1,6 +1,7 @@
#include "inputdouble.h"
#include <QLabel>
#include "math.h"
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step):
BaseInput(form, label),
@ -12,11 +13,11 @@ InputDouble::InputDouble(QWidget* form, QString label, double* value, double min
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(min / small_step);
slider->setMaximum(max / small_step);
slider->setValue(*value / small_step);
slider->setMinimum(0);
slider->setMaximum(round((max - min) / small_step));
slider->setValue(round((*value - min) / small_step));
slider->setTickInterval(large_step / small_step);
slider->setTickInterval(round(large_step / small_step));
slider->setTickPosition(QSlider::TicksBelow);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
@ -25,15 +26,35 @@ InputDouble::InputDouble(QWidget* form, QString label, double* value, double min
_control = slider;
}
void InputDouble::updatePreview()
{
((QLabel*)_preview)->setText(QString::number(*value, 'g', 3));
BaseInput::updatePreview();
}
void InputDouble::applyValue()
{
*value = ((double)slider->value()) * small_step;
((QLabel*)_preview)->setText(QString("%1").arg(*value));
int ivalue = slider->value();
if (ivalue == slider->maximum())
{
*value = max;
}
else
{
*value = min + ((double)ivalue) * small_step;
}
if (fabs(*value) < 0.0000001)
{
*value = 0.0;
}
BaseInput::applyValue();
}
void InputDouble::revert()
{
slider->setValue(*value / small_step);
slider->setValue(round((*value - min) / small_step));
BaseInput::revert();
}

View file

@ -13,10 +13,9 @@ public:
InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step);
public slots:
virtual void revert();
protected slots:
virtual void updatePreview();
virtual void applyValue();
virtual void revert();
private:
QSlider* slider;

View file

@ -25,10 +25,16 @@ InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, i
_control = slider;
}
void InputInt::updatePreview()
{
((QLabel*)_preview)->setText(QString("%1").arg(*value));
BaseInput::updatePreview();
}
void InputInt::applyValue()
{
*value = (int)slider->value();
((QLabel*)_preview)->setText(QString("%1").arg(*value));
BaseInput::applyValue();
}
@ -36,4 +42,6 @@ void InputInt::applyValue()
void InputInt::revert()
{
slider->setValue(*value);
BaseInput::revert();
}

View file

@ -13,10 +13,9 @@ public:
InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step);
public slots:
virtual void revert();
protected slots:
virtual void updatePreview();
virtual void applyValue();
virtual void revert();
private:
QSlider* slider;

View file

@ -5,18 +5,38 @@
#include <QPainter>
#include <QColorDialog>
#include "../lib_paysages/shared/functions.h"
class NoiseSmallPreview:public QWidget
{
public:
NoiseSmallPreview(QWidget* parent):
QWidget(parent)
NoiseSmallPreview(QWidget* parent, NoiseGenerator* noise):
QWidget(parent),
noise(noise)
{
}
void paintEvent(QPaintEvent* event)
{
/*QPainter painter(this);
painter.fillRect(this->rect(), col);*/
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;
};
@ -25,7 +45,7 @@ InputNoise::InputNoise(QWidget* form, QString label, NoiseGenerator* value):
BaseInput(form, label),
_value(value)
{
_preview = new NoiseSmallPreview(form);
_preview = new NoiseSmallPreview(form, value);
_preview->setMinimumSize(100, 40);
_control = new QPushButton("Edit", form);
_control->setMaximumWidth(150);
@ -33,19 +53,28 @@ InputNoise::InputNoise(QWidget* form, QString label, NoiseGenerator* value):
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editNoise()));
}
void InputNoise::updatePreview()
{
_preview->update();
BaseInput::updatePreview();
}
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;*/
BaseInput::applyValue();
}
void InputNoise::revert()
{
/*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);
_preview->update();*/
/*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);*/
BaseInput::revert();
}
void InputNoise::editNoise()

View file

@ -14,10 +14,9 @@ public:
InputNoise(QWidget* form, QString label, NoiseGenerator* value);
public slots:
virtual void revert();
protected slots:
virtual void updatePreview();
virtual void applyValue();
virtual void revert();
private slots:
void editNoise();

View file

@ -1,5 +1,9 @@
#include <QApplication>
#include "mainwindow.h"
#include <QApplication>
#include <QMenuBar>
#include <QFileDialog>
#include "formwater.h"
#include "formsky.h"
#include "formrender.h"
@ -24,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QTabWidget* tabs;
QMenu* menu;
tabs = new QTabWidget(this);
tabs->addTab(new BaseForm(tabs), "Temp");
@ -31,5 +36,28 @@ MainWindow::MainWindow(QWidget *parent) :
tabs->addTab(new FormSky(tabs), "Sky");
tabs->addTab(new FormRender(tabs), "Render");
menu = menuBar()->addMenu("File");
menu->addAction("New", this, SLOT(fileNew()));
menu->addAction("Save", this, SLOT(fileSave()));
menu->addAction("Load", this, SLOT(fileLoad()));
menu->addAction("Quit", this, SLOT(close()));
setCentralWidget(tabs);
}
void MainWindow::fileNew()
{
// TODO
}
void MainWindow::fileSave()
{
QString filepath = QFileDialog::getSaveFileName(this);
autoSave((char*)filepath.toStdString().c_str());
}
void MainWindow::fileLoad()
{
QString filepath = QFileDialog::getOpenFileName(this);
autoLoad((char*)filepath.toStdString().c_str());
}

View file

@ -13,6 +13,11 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
public slots:
void fileNew();
void fileSave();
void fileLoad();
};
#endif // _PAYSAGES_QT_MAINWINDOW_H_

View file

@ -197,7 +197,7 @@ void autoGenRealisticLandscape(int seed)
noiseAddLevelSimple(cloud.noise, 50.0 / 800.0, 0.001);
noiseAddLevelSimple(cloud.noise, 50.0 / 1000.0, 0.0005);
layer = cloudsAddLayer();
cloudsSetDefinition(layer, cloud);
//cloudsSetDefinition(layer, cloud);
/* Water */
water.height = 0.0;
@ -311,19 +311,19 @@ void autoGenRealisticLandscape(int seed)
void* _renderFirstPass(void* data)
{
if (!renderSetNextProgressStep(0.0, 0.1))
if (!renderSetNextProgressStep(0.0, 0.01))
{
_is_rendering = 0;
return NULL;
}
skyRender(renderTellProgress);
if (!renderSetNextProgressStep(0.1, 0.3))
if (!renderSetNextProgressStep(0.01, 0.085))
{
_is_rendering = 0;
return NULL;
}
terrainRender(renderTellProgress);
if (!renderSetNextProgressStep(0.3, 0.4))
if (!renderSetNextProgressStep(0.085, 0.1))
{
_is_rendering = 0;
return NULL;
@ -359,7 +359,7 @@ void autoRenderSceneTwoPass(int postonly)
threadJoin(thread);
}
if (renderSetNextProgressStep(0.4, 1.0))
if (renderSetNextProgressStep(0.1, 1.0))
{
renderPostProcess(_cpu_count);
}

View file

@ -50,7 +50,7 @@ void cloudsLoad(FILE* f)
{
int i;
CloudsDefinition* layer;
/* FIXME Delete unused noise generators and add missing ones */
_layers_count = toolsLoadInt(f);