From 06b170e0f5b99a1eaa07cf4d79d89c54240b6f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 8 Jan 2012 10:31:01 +0000 Subject: [PATCH] paysages: Qt GUI (WIP). git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@219 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseform.cpp | 1 + gui_qt/baseinput.cpp | 10 ++++++++ gui_qt/baseinput.h | 5 ++-- gui_qt/formwater.cpp | 4 ++-- gui_qt/inputcolor.cpp | 8 ++++++- gui_qt/inputcolor.h | 5 ++-- gui_qt/inputcolorgradation.cpp | 33 ++++++++++++++++++++------ gui_qt/inputcolorgradation.h | 5 ++-- gui_qt/inputdouble.cpp | 35 +++++++++++++++++++++------ gui_qt/inputdouble.h | 5 ++-- gui_qt/inputint.cpp | 10 +++++++- gui_qt/inputint.h | 5 ++-- gui_qt/inputnoise.cpp | 43 ++++++++++++++++++++++++++++------ gui_qt/inputnoise.h | 5 ++-- gui_qt/mainwindow.cpp | 30 +++++++++++++++++++++++- gui_qt/mainwindow.h | 5 ++++ lib_paysages/auto.c | 10 ++++---- lib_paysages/clouds.c | 2 +- 18 files changed, 171 insertions(+), 50 deletions(-) diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index e9339a0..11d3ad5 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -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) diff --git a/gui_qt/baseinput.cpp b/gui_qt/baseinput.cpp index b2d5f5c..cb6be3c 100644 --- a/gui_qt/baseinput.cpp +++ b/gui_qt/baseinput.cpp @@ -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(); +} diff --git a/gui_qt/baseinput.h b/gui_qt/baseinput.h index e128b59..3d6e162 100644 --- a/gui_qt/baseinput.h +++ b/gui_qt/baseinput.h @@ -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: diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 4b7f11a..896a7ab 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -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(); } diff --git a/gui_qt/inputcolor.cpp b/gui_qt/inputcolor.cpp index 5fbfba4..6a76562 100644 --- a/gui_qt/inputcolor.cpp +++ b/gui_qt/inputcolor.cpp @@ -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() diff --git a/gui_qt/inputcolor.h b/gui_qt/inputcolor.h index 121311a..40ff2cf 100644 --- a/gui_qt/inputcolor.h +++ b/gui_qt/inputcolor.h @@ -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(); diff --git a/gui_qt/inputcolorgradation.cpp b/gui_qt/inputcolorgradation.cpp index a8351b7..6b3948e 100644 --- a/gui_qt/inputcolorgradation.cpp +++ b/gui_qt/inputcolorgradation.cpp @@ -5,19 +5,32 @@ #include #include +#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() diff --git a/gui_qt/inputcolorgradation.h b/gui_qt/inputcolorgradation.h index 46288c5..fe6ff5b 100644 --- a/gui_qt/inputcolorgradation.h +++ b/gui_qt/inputcolorgradation.h @@ -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(); diff --git a/gui_qt/inputdouble.cpp b/gui_qt/inputdouble.cpp index 1bc5dc6..47c6579 100644 --- a/gui_qt/inputdouble.cpp +++ b/gui_qt/inputdouble.cpp @@ -1,6 +1,7 @@ #include "inputdouble.h" #include +#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(); } diff --git a/gui_qt/inputdouble.h b/gui_qt/inputdouble.h index faa0bbf..da73fdf 100644 --- a/gui_qt/inputdouble.h +++ b/gui_qt/inputdouble.h @@ -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; diff --git a/gui_qt/inputint.cpp b/gui_qt/inputint.cpp index 4ef0aac..c168eb1 100644 --- a/gui_qt/inputint.cpp +++ b/gui_qt/inputint.cpp @@ -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(); } diff --git a/gui_qt/inputint.h b/gui_qt/inputint.h index 69a44df..759c705 100644 --- a/gui_qt/inputint.h +++ b/gui_qt/inputint.h @@ -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; diff --git a/gui_qt/inputnoise.cpp b/gui_qt/inputnoise.cpp index fddc3dd..d5d05d7 100644 --- a/gui_qt/inputnoise.cpp +++ b/gui_qt/inputnoise.cpp @@ -5,18 +5,38 @@ #include #include +#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() diff --git a/gui_qt/inputnoise.h b/gui_qt/inputnoise.h index 89a3772..974a130 100644 --- a/gui_qt/inputnoise.h +++ b/gui_qt/inputnoise.h @@ -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(); diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 008106f..b688b9b 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -1,5 +1,9 @@ -#include #include "mainwindow.h" + +#include +#include +#include + #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()); +} diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index 9bbfb63..6675980 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -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_ diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 904f488..d068ae5 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -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); } diff --git a/lib_paysages/clouds.c b/lib_paysages/clouds.c index 9fe28ca..bb9dc89 100644 --- a/lib_paysages/clouds.c +++ b/lib_paysages/clouds.c @@ -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);