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())); connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview()));
input->setObjectName("_form_input_"); input->setObjectName("_form_input_");
input->revert();
} }
void BaseForm::addInputInt(QString label, int* value, int min, int max, int small_step, int large_step) 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); _label = new QLabel(label);
} }
void BaseInput::updatePreview()
{
}
void BaseInput::applyValue() void BaseInput::applyValue()
{ {
updatePreview();
emit(valueChanged()); emit(valueChanged());
} }
void BaseInput::revert()
{
updatePreview();
}

View file

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

View file

@ -131,14 +131,14 @@ FormWater::FormWater(QWidget *parent):
addPreview(previewCoverage, QString("Coverage preview")); addPreview(previewCoverage, QString("Coverage preview"));
addPreview(previewColor, QString("Color 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); addInputColor("Surface color", &_definition.main_color);
addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1); addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Reflection", &_definition.reflection, 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); addInputColor("Depth color", &_definition.depth_color);
addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0); addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
addInputNoise("Wave noise", _definition.height_noise); 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(); revertConfig();
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,10 +25,16 @@ InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, i
_control = slider; _control = slider;
} }
void InputInt::updatePreview()
{
((QLabel*)_preview)->setText(QString("%1").arg(*value));
BaseInput::updatePreview();
}
void InputInt::applyValue() void InputInt::applyValue()
{ {
*value = (int)slider->value(); *value = (int)slider->value();
((QLabel*)_preview)->setText(QString("%1").arg(*value));
BaseInput::applyValue(); BaseInput::applyValue();
} }
@ -36,4 +42,6 @@ void InputInt::applyValue()
void InputInt::revert() void InputInt::revert()
{ {
slider->setValue(*value); 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); InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step);
public slots: public slots:
virtual void revert(); virtual void updatePreview();
protected slots:
virtual void applyValue(); virtual void applyValue();
virtual void revert();
private: private:
QSlider* slider; QSlider* slider;

View file

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

View file

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

View file

@ -1,5 +1,9 @@
#include <QApplication>
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication>
#include <QMenuBar>
#include <QFileDialog>
#include "formwater.h" #include "formwater.h"
#include "formsky.h" #include "formsky.h"
#include "formrender.h" #include "formrender.h"
@ -24,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent) QMainWindow(parent)
{ {
QTabWidget* tabs; QTabWidget* tabs;
QMenu* menu;
tabs = new QTabWidget(this); tabs = new QTabWidget(this);
tabs->addTab(new BaseForm(tabs), "Temp"); tabs->addTab(new BaseForm(tabs), "Temp");
@ -31,5 +36,28 @@ MainWindow::MainWindow(QWidget *parent) :
tabs->addTab(new FormSky(tabs), "Sky"); tabs->addTab(new FormSky(tabs), "Sky");
tabs->addTab(new FormRender(tabs), "Render"); 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); 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: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
public slots:
void fileNew();
void fileSave();
void fileLoad();
}; };
#endif // _PAYSAGES_QT_MAINWINDOW_H_ #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 / 800.0, 0.001);
noiseAddLevelSimple(cloud.noise, 50.0 / 1000.0, 0.0005); noiseAddLevelSimple(cloud.noise, 50.0 / 1000.0, 0.0005);
layer = cloudsAddLayer(); layer = cloudsAddLayer();
cloudsSetDefinition(layer, cloud); //cloudsSetDefinition(layer, cloud);
/* Water */ /* Water */
water.height = 0.0; water.height = 0.0;
@ -311,19 +311,19 @@ void autoGenRealisticLandscape(int seed)
void* _renderFirstPass(void* data) void* _renderFirstPass(void* data)
{ {
if (!renderSetNextProgressStep(0.0, 0.1)) if (!renderSetNextProgressStep(0.0, 0.01))
{ {
_is_rendering = 0; _is_rendering = 0;
return NULL; return NULL;
} }
skyRender(renderTellProgress); skyRender(renderTellProgress);
if (!renderSetNextProgressStep(0.1, 0.3)) if (!renderSetNextProgressStep(0.01, 0.085))
{ {
_is_rendering = 0; _is_rendering = 0;
return NULL; return NULL;
} }
terrainRender(renderTellProgress); terrainRender(renderTellProgress);
if (!renderSetNextProgressStep(0.3, 0.4)) if (!renderSetNextProgressStep(0.085, 0.1))
{ {
_is_rendering = 0; _is_rendering = 0;
return NULL; return NULL;
@ -359,7 +359,7 @@ void autoRenderSceneTwoPass(int postonly)
threadJoin(thread); threadJoin(thread);
} }
if (renderSetNextProgressStep(0.4, 1.0)) if (renderSetNextProgressStep(0.1, 1.0))
{ {
renderPostProcess(_cpu_count); renderPostProcess(_cpu_count);
} }