From db453d6fa9b3f2f42c4a1dec6d50157cda25759e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sat, 7 Jan 2012 16:53:23 +0000 Subject: [PATCH] paysages: Qt GUI (WIP) git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@218 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseform.cpp | 19 +++++++++ gui_qt/baseform.h | 6 ++- gui_qt/formsky.cpp | 73 ++++++++++++++++++++++++++++++++++ gui_qt/formsky.h | 26 ++++++++++++ gui_qt/formwater.cpp | 8 ++-- gui_qt/formwater.h | 1 + gui_qt/inputcolor.cpp | 40 ++++++++++++++++++- gui_qt/inputcolor.h | 3 ++ gui_qt/inputcolorgradation.cpp | 59 +++++++++++++++++++++++++++ gui_qt/inputcolorgradation.h | 29 ++++++++++++++ gui_qt/inputnoise.cpp | 59 +++++++++++++++++++++++++++ gui_qt/inputnoise.h | 29 ++++++++++++++ gui_qt/mainwindow.cpp | 2 + gui_qt/paysages-qt.pro | 17 ++++++-- gui_qt/preview.cpp | 6 +-- gui_qt/tools.h | 13 ++++++ lib_paysages/auto.c | 3 +- lib_paysages/main.c | 2 + lib_paysages/shared/system.h | 5 +++ lib_paysages/water.c | 5 ++- lib_paysages/water.h | 1 + 21 files changed, 392 insertions(+), 14 deletions(-) create mode 100644 gui_qt/formsky.cpp create mode 100644 gui_qt/formsky.h create mode 100644 gui_qt/inputcolorgradation.cpp create mode 100644 gui_qt/inputcolorgradation.h create mode 100644 gui_qt/inputnoise.cpp create mode 100644 gui_qt/inputnoise.h create mode 100644 gui_qt/tools.h diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 84649fa..e9339a0 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -3,6 +3,8 @@ #include "inputdouble.h" #include "inputint.h" #include "inputcolor.h" +#include "inputcolorgradation.h" +#include "inputnoise.h" #include #include @@ -27,12 +29,15 @@ BaseForm::BaseForm(QWidget* parent) : form = new QWidget(this); form->setLayout(new QGridLayout()); + form->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); buttons = new QWidget(this); buttons->setLayout(new QHBoxLayout()); hlayout->addWidget(previews); hlayout->addWidget(form); + hlayout->setAlignment(form, Qt::AlignTop); + vlayout->addWidget(hwidget); vlayout->addWidget(buttons); @@ -93,6 +98,10 @@ void BaseForm::addInput(BaseInput* input) layout->addWidget(input->preview(), row, 1); layout->addWidget(input->control(), row, 2); + input->label()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + input->preview()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + input->control()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview())); input->setObjectName("_form_input_"); @@ -112,3 +121,13 @@ void BaseForm::addInputColor(QString label, Color* value) { addInput(new InputColor(form, label, value)); } + +void BaseForm::addInputColorGradation(QString label, ColorGradation* value) +{ + addInput(new InputColorGradation(form, label, value)); +} + +void BaseForm::addInputNoise(QString label, NoiseGenerator* value) +{ + addInput(new InputNoise(form, label, value)); +} diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 1922dd2..04670ae 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -16,9 +16,11 @@ public: public slots: virtual void revertConfig(); - virtual void applyConfigPreview(); virtual void applyConfig(); +protected slots: + virtual void applyConfigPreview(); + protected: void addPreview(Preview* preview, QString label); QPushButton* addButton(QString label); @@ -26,6 +28,8 @@ protected: void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step); void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step); void addInputColor(QString label, Color* value); + void addInputColorGradation(QString label, ColorGradation* value); + void addInputNoise(QString label, NoiseGenerator* value); private: QWidget* previews; diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp new file mode 100644 index 0000000..4b9ca46 --- /dev/null +++ b/gui_qt/formsky.cpp @@ -0,0 +1,73 @@ +#include "formsky.h" + +#include "tools.h" + +#include +#include +#include + +#include "../lib_paysages/sky.h" +#include "../lib_paysages/shared/functions.h" +#include "../lib_paysages/shared/constants.h" + +static SkyDefinition _definition; + +/**************** Previews ****************/ +class PreviewHorizon:public Preview +{ +public: + PreviewHorizon(QWidget* parent): + Preview(parent) + { + } +protected: + QColor getColor(double x, double y) + { + Vector3 eye = {0.0, 0.0, 0.0}; + Vector3 look; + + look.x = cos(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0)); + look.y = -sin(M_PI * (y / 256.0)); + look.z = sin(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0)); + + return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL)); + } +}; + +/**************** Form ****************/ +FormSky::FormSky(QWidget *parent): + BaseForm(parent) +{ + _definition = skyCreateDefinition(); + + previewHorizon = new PreviewHorizon(this); + addPreview(previewHorizon, QString("Horizon preview")); + + addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1); + addInputColorGradation("Sun color", &_definition.sun_color); + addInputDouble("Sun radius", &_definition.sun_radius, 0.0, 0.3, 0.01, 0.03); + addInputColorGradation("Zenith color", &_definition.zenith_color); + addInputColorGradation("Haze color", &_definition.haze_color); + addInputDouble("Haze height", &_definition.haze_height, 0.0, 1.0, 0.01, 0.1); + addInputDouble("Haze smoothing", &_definition.haze_smoothing, 0.0, 1.0, 0.01, 0.1); + + revertConfig(); +} + +void FormSky::revertConfig() +{ + skyCopyDefinition(skyGetDefinition(), &_definition); + BaseForm::revertConfig(); +} + +void FormSky::applyConfig() +{ + skySetDefinition(_definition); + BaseForm::applyConfig(); +} + +void FormSky::applyConfigPreview() +{ + skyValidateDefinition(&_definition); + BaseForm::applyConfigPreview(); +} diff --git a/gui_qt/formsky.h b/gui_qt/formsky.h new file mode 100644 index 0000000..b508575 --- /dev/null +++ b/gui_qt/formsky.h @@ -0,0 +1,26 @@ +#ifndef _PAYSAGES_QT_FORMSKY_H_ +#define _PAYSAGES_QT_FORMSKY_H_ + +#include +#include "preview.h" +#include "baseform.h" + +class FormSky : public BaseForm +{ + Q_OBJECT + +public: + explicit FormSky(QWidget *parent = 0); + +public slots: + virtual void revertConfig(); + virtual void applyConfig(); + +protected slots: + virtual void applyConfigPreview(); + +private: + Preview* previewHorizon; +}; + +#endif // _PAYSAGES_QT_FORMSKY_H_ diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 65b7b41..4b7f11a 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -137,6 +137,8 @@ FormWater::FormWater(QWidget *parent): 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); revertConfig(); } @@ -147,8 +149,8 @@ void FormWater::revertConfig() BaseForm::revertConfig(); } -/*void FormWater::applyConfig() +void FormWater::applyConfig() { waterSetDefinition(_definition); - //guiUpdate(); -}*/ + BaseForm::applyConfig(); +} diff --git a/gui_qt/formwater.h b/gui_qt/formwater.h index 283bab2..76093ba 100644 --- a/gui_qt/formwater.h +++ b/gui_qt/formwater.h @@ -14,6 +14,7 @@ public: public slots: virtual void revertConfig(); + virtual void applyConfig(); private: Preview* previewCoverage; diff --git a/gui_qt/inputcolor.cpp b/gui_qt/inputcolor.cpp index 593e1d8..5fbfba4 100644 --- a/gui_qt/inputcolor.cpp +++ b/gui_qt/inputcolor.cpp @@ -2,20 +2,58 @@ #include #include +#include +#include + +class ColorPreview:public QWidget +{ +public: + ColorPreview(QWidget* parent): + QWidget(parent) + { + } + + void paintEvent(QPaintEvent* event) + { + QPainter painter(this); + painter.fillRect(this->rect(), col); + } + QColor col; +}; InputColor::InputColor(QWidget* form, QString label, Color* value): BaseInput(form, label), _value(value) { - _preview = new QWidget(form); + _preview = new ColorPreview(form); + _preview->setMinimumSize(50, 20); _control = new QPushButton("Edit", form); + _control->setMaximumWidth(150); + + connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(chooseColor())); } void InputColor::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 InputColor::revert() { + ((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b); + _preview->update(); +} + +void InputColor::chooseColor() +{ + QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); + if (col.isValid()) + { + ((ColorPreview*)_preview)->col = col; + applyValue(); + } } diff --git a/gui_qt/inputcolor.h b/gui_qt/inputcolor.h index 96acca6..121311a 100644 --- a/gui_qt/inputcolor.h +++ b/gui_qt/inputcolor.h @@ -19,6 +19,9 @@ public slots: protected slots: virtual void applyValue(); +private slots: + void chooseColor(); + private: Color* _value; }; diff --git a/gui_qt/inputcolorgradation.cpp b/gui_qt/inputcolorgradation.cpp new file mode 100644 index 0000000..a8351b7 --- /dev/null +++ b/gui_qt/inputcolorgradation.cpp @@ -0,0 +1,59 @@ +#include "inputcolorgradation.h" + +#include +#include +#include +#include + +class ColorGradationPreview:public QWidget +{ +public: + ColorGradationPreview(QWidget* parent): + QWidget(parent) + { + } + + void paintEvent(QPaintEvent* event) + { + /*QPainter painter(this); + painter.fillRect(this->rect(), col);*/ + } + ColorGradation* gradation; +}; + +InputColorGradation::InputColorGradation(QWidget* form, QString label, ColorGradation* value): + BaseInput(form, label), + _value(value) +{ + _preview = new ColorGradationPreview(form); + _preview->setMinimumSize(200, 20); + _control = new QPushButton("Edit", form); + _control->setMaximumWidth(150); + + connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editGradation())); +} + +void InputColorGradation::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 InputColorGradation::revert() +{ + /*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b); + _preview->update();*/ +} + +void InputColorGradation::editGradation() +{ + /*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); + if (col.isValid()) + { + ((ColorPreview*)_preview)->col = col; + applyValue(); + }*/ +} diff --git a/gui_qt/inputcolorgradation.h b/gui_qt/inputcolorgradation.h new file mode 100644 index 0000000..46288c5 --- /dev/null +++ b/gui_qt/inputcolorgradation.h @@ -0,0 +1,29 @@ +#ifndef _PAYSAGES_QT_INPUTCOLORGRADATION_H_ +#define _PAYSAGES_QT_INPUTCOLORGRADATION_H_ + +#include +#include "baseinput.h" + +#include "../lib_paysages/shared/types.h" + +class InputColorGradation:public BaseInput +{ + Q_OBJECT + +public: + InputColorGradation(QWidget* form, QString label, ColorGradation* value); + +public slots: + virtual void revert(); + +protected slots: + virtual void applyValue(); + +private slots: + void editGradation(); + +private: + ColorGradation* _value; +}; + +#endif // _PAYSAGES_QT_INPUTCOLORGRADATION_H_ diff --git a/gui_qt/inputnoise.cpp b/gui_qt/inputnoise.cpp new file mode 100644 index 0000000..fddc3dd --- /dev/null +++ b/gui_qt/inputnoise.cpp @@ -0,0 +1,59 @@ +#include "inputnoise.h" + +#include +#include +#include +#include + +class NoiseSmallPreview:public QWidget +{ +public: + NoiseSmallPreview(QWidget* parent): + QWidget(parent) + { + } + + void paintEvent(QPaintEvent* event) + { + /*QPainter painter(this); + painter.fillRect(this->rect(), col);*/ + } + NoiseGenerator* noise; +}; + +InputNoise::InputNoise(QWidget* form, QString label, NoiseGenerator* value): + BaseInput(form, label), + _value(value) +{ + _preview = new NoiseSmallPreview(form); + _preview->setMinimumSize(100, 40); + _control = new QPushButton("Edit", form); + _control->setMaximumWidth(150); + + connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editNoise())); +} + +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();*/ +} + +void InputNoise::editNoise() +{ + /*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); + if (col.isValid()) + { + ((ColorPreview*)_preview)->col = col; + applyValue(); + }*/ +} diff --git a/gui_qt/inputnoise.h b/gui_qt/inputnoise.h new file mode 100644 index 0000000..89a3772 --- /dev/null +++ b/gui_qt/inputnoise.h @@ -0,0 +1,29 @@ +#ifndef _PAYSAGES_QT_INPUTNOISE_H_ +#define _PAYSAGES_QT_INPUTNOISE_H_ + +#include +#include "baseinput.h" + +#include "../lib_paysages/shared/types.h" + +class InputNoise:public BaseInput +{ + Q_OBJECT + +public: + InputNoise(QWidget* form, QString label, NoiseGenerator* value); + +public slots: + virtual void revert(); + +protected slots: + virtual void applyValue(); + +private slots: + void editNoise(); + +private: + NoiseGenerator* _value; +}; + +#endif // _PAYSAGES_QT_INPUTNOISE_H_ diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 79f2de1..008106f 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -1,6 +1,7 @@ #include #include "mainwindow.h" #include "formwater.h" +#include "formsky.h" #include "formrender.h" #include "../lib_paysages/shared/functions.h" @@ -27,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) : tabs = new QTabWidget(this); tabs->addTab(new BaseForm(tabs), "Temp"); tabs->addTab(new FormWater(tabs), "Water"); + tabs->addTab(new FormSky(tabs), "Sky"); tabs->addTab(new FormRender(tabs), "Render"); setCentralWidget(tabs); diff --git a/gui_qt/paysages-qt.pro b/gui_qt/paysages-qt.pro index 930ec32..1d4f536 100644 --- a/gui_qt/paysages-qt.pro +++ b/gui_qt/paysages-qt.pro @@ -6,9 +6,11 @@ TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . -CONFIG += debug +unix:CONFIG += debug +win32:CONFIG += release -LIBS += -L../lib_paysages/ -lpaysages +unix:LIBS += -L../lib_paysages/ -lpaysages +win32:LIBS += ../libpaysages.a -lDevIL -lILU -lILUT -lglib-2.0 -lgthread-2.0 # Input HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \ @@ -21,7 +23,11 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \ inputcolor.h \ formrender.h \ inputint.h \ - dialogrender.h + dialogrender.h \ + inputcolorgradation.h \ + formsky.h \ + inputnoise.h \ + tools.h FORMS += SOURCES += \ mainwindow.cpp \ @@ -33,4 +39,7 @@ SOURCES += \ inputcolor.cpp \ formrender.cpp \ inputint.cpp \ - dialogrender.cpp + dialogrender.cpp \ + inputcolorgradation.cpp \ + formsky.cpp \ + inputnoise.cpp diff --git a/gui_qt/preview.cpp b/gui_qt/preview.cpp index 0f1c394..3da72e6 100644 --- a/gui_qt/preview.cpp +++ b/gui_qt/preview.cpp @@ -72,9 +72,9 @@ void Preview::doRender() void Preview::redraw() { - lock->lock(); + //lock->lock(); need_rerender = 1; - lock->unlock(); + //lock->unlock(); } void Preview::resizeEvent(QResizeEvent* event) @@ -134,7 +134,7 @@ void Preview::renderPixbuf() done = true; } } - if (done) + if (done && (x == w - 1 || x % 10 == 0)) { this->update(); } diff --git a/gui_qt/tools.h b/gui_qt/tools.h new file mode 100644 index 0000000..471f514 --- /dev/null +++ b/gui_qt/tools.h @@ -0,0 +1,13 @@ +#ifndef _PAYSAGES_QT_TOOLS_H_ +#define _PAYSAGES_QT_TOOLS_H_ + +#include + +#include "../lib_paysages/shared/types.h" + +static inline QColor colorToQColor(Color color) +{ + return QColor(color.r * 255.0, color.g * 255.0, color.b * 255.0, color.a * 255.0); +} + +#endif // _PAYSAGES_QT_TOOLS_H_ diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 1e87105..904f488 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; @@ -213,6 +213,7 @@ void autoGenRealisticLandscape(int seed) water.depth_color.b = 0.3; water.depth_color.a = 1.0; water.height_noise = noiseCreateGenerator(); + water.height_noise_factor = 1.0; noiseGenerateBaseNoise(water.height_noise, 262144); noiseAddLevelsSimple(water.height_noise, 2, 0.2, 0.015); noiseAddLevelsSimple(water.height_noise, 3, 0.03, 0.003); diff --git a/lib_paysages/main.c b/lib_paysages/main.c index a06591c..84a3a91 100644 --- a/lib_paysages/main.c +++ b/lib_paysages/main.c @@ -11,10 +11,12 @@ #include "shared/constants.h" #include "shared/functions.h" #include "shared/globals.h" +#include "shared/system.h" #include "terrain.h" void paysagesInit() { + systemInit(); ilInit(); iluInit(); diff --git a/lib_paysages/shared/system.h b/lib_paysages/shared/system.h index 9822dbe..65a3987 100644 --- a/lib_paysages/shared/system.h +++ b/lib_paysages/shared/system.h @@ -10,6 +10,11 @@ extern "C" { typedef GThread Thread; typedef void*(*ThreadFunction)(void* data); +static inline void systemInit() +{ + g_thread_init(NULL); +} + static inline Thread* threadCreate(ThreadFunction function, void* data) { GError* error; diff --git a/lib_paysages/water.c b/lib_paysages/water.c index 6539d2b..a4f5832 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -56,6 +56,7 @@ void waterSave(FILE* f) toolsSaveDouble(f, _definition.transparency); toolsSaveDouble(f, _definition.reflection); noiseSave(_definition.height_noise, f); + toolsSaveDouble(f, _definition.height_noise_factor); } void waterLoad(FILE* f) @@ -67,6 +68,7 @@ void waterLoad(FILE* f) _definition.transparency = toolsLoadDouble(f); _definition.reflection = toolsLoadDouble(f); noiseLoad(_definition.height_noise, f); + _definition.height_noise_factor = toolsLoadDouble(f); } WaterDefinition waterCreateDefinition() @@ -75,6 +77,7 @@ WaterDefinition waterCreateDefinition() result.height = -1000.0; result.height_noise = noiseCreateGenerator(); + result.height_noise_factor = 1.0; return result; } @@ -118,7 +121,7 @@ WaterQuality waterGetQuality() static inline double _getHeight(WaterDefinition* definition, double x, double z, double detail) { - return definition->height + noiseGet2DDetail(definition->height_noise, x, z, detail); + return definition->height + noiseGet2DDetail(definition->height_noise, x, z, detail) * definition->height_noise_factor; } static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail) diff --git a/lib_paysages/water.h b/lib_paysages/water.h index 58200bb..7497ae4 100644 --- a/lib_paysages/water.h +++ b/lib_paysages/water.h @@ -17,6 +17,7 @@ typedef struct Color depth_color; double transparency_depth; NoiseGenerator* height_noise; + double height_noise_factor; } WaterDefinition; typedef struct