From 375c4f24b803a021bff872f04888afad2fda0e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 16 Jan 2012 21:29:21 +0000 Subject: [PATCH] paysages: Qt noise dialog (WIP). git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@223 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/dialognoise.cpp | 52 +++++++++++++++++++++++ gui_qt/dialognoise.h | 30 +++++++++++++ gui_qt/dialogrender.cpp | 1 + gui_qt/formnoise.cpp | 94 +++++++++++++++++++++++++++++++++++++++++ gui_qt/formnoise.h | 30 +++++++++++++ gui_qt/formsky.cpp | 37 +++++++++++++--- gui_qt/formsky.h | 3 +- gui_qt/inputnoise.cpp | 15 ++----- gui_qt/mainwindow.cpp | 2 + gui_qt/paysages-qt.pro | 6 ++- gui_qt/preview.cpp | 39 +++++++++++------ gui_qt/preview.h | 10 +++-- 12 files changed, 283 insertions(+), 36 deletions(-) create mode 100644 gui_qt/dialognoise.cpp create mode 100644 gui_qt/dialognoise.h create mode 100644 gui_qt/formnoise.cpp create mode 100644 gui_qt/formnoise.h diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp new file mode 100644 index 0000000..adc847f --- /dev/null +++ b/gui_qt/dialognoise.cpp @@ -0,0 +1,52 @@ +#include "dialognoise.h" + +#include +#include +#include +#include +#include + +#include "../lib_paysages/shared/functions.h" + +DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value): + QDialog(parent) +{ + _base = value; + _current = noiseCreateGenerator(); + + noiseCopy(_base, _current); + + setLayout(new QVBoxLayout()); + _form = new FormNoise(this, _current); + layout()->addWidget(_form); + + setWindowTitle("Paysages 3D - Noise editor"); +} + +bool DialogNoise::getNoise(QWidget* parent, NoiseGenerator* noise) +{ + int result; + + DialogNoise* dialog = new DialogNoise(parent, noise); + result = dialog->exec(); + + delete dialog; + + return (result != 0) ? true : false; +} + +void DialogNoise::closeEvent(QCloseEvent* e) +{ + reject(); +} + +void DialogNoise::accept() +{ + noiseCopy(_current, _base); + reject(); +} + +void DialogNoise::reject() +{ + noiseDeleteGenerator(_current); +} diff --git a/gui_qt/dialognoise.h b/gui_qt/dialognoise.h new file mode 100644 index 0000000..c912638 --- /dev/null +++ b/gui_qt/dialognoise.h @@ -0,0 +1,30 @@ +#ifndef _PAYSAGES_QT_DIALOGNOISE_H_ +#define _PAYSAGES_QT_DIALOGNOISE_H_ + +#include +#include "formnoise.h" + +#include "../lib_paysages/shared/types.h" + +class DialogNoise : public QDialog +{ + Q_OBJECT +public: + explicit DialogNoise(QWidget* parent, NoiseGenerator* noise); + static bool getNoise(QWidget* parent, NoiseGenerator* noise); + +public slots: + virtual void accept(); + virtual void reject(); + +protected: + virtual void closeEvent(QCloseEvent* e); + +private: + NoiseGenerator* _base; + NoiseGenerator* _current; + NoiseLevel _current_level; + FormNoise* _form; +}; + +#endif diff --git a/gui_qt/dialogrender.cpp b/gui_qt/dialogrender.cpp index 69c6547..5497115 100644 --- a/gui_qt/dialogrender.cpp +++ b/gui_qt/dialogrender.cpp @@ -71,6 +71,7 @@ DialogRender::DialogRender(QWidget *parent, int quality, int width, int height): _current_dialog = this; setModal(true); + setWindowTitle("Paysages 3D - Render"); setLayout(new QVBoxLayout()); scroll = new QScrollArea(this); diff --git a/gui_qt/formnoise.cpp b/gui_qt/formnoise.cpp new file mode 100644 index 0000000..5d2c013 --- /dev/null +++ b/gui_qt/formnoise.cpp @@ -0,0 +1,94 @@ +#include "formnoise.h" + +#include "tools.h" + +#include +#include +#include + +#include "../lib_paysages/sky.h" +#include "../lib_paysages/shared/functions.h" +#include "../lib_paysages/shared/constants.h" + +/**************** Previews ****************/ +class PreviewLevel:public Preview +{ +public: + PreviewLevel(QWidget* parent, NoiseGenerator* noise): + Preview(parent), + _noise(noise) + { + } +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));*/ + } +private: + NoiseGenerator* _noise; +}; + +class PreviewTotal:public Preview +{ +public: + PreviewTotal(QWidget* parent, NoiseGenerator* noise): + Preview(parent), + _noise(noise) + { + } +protected: + QColor getColor(double x, double y) + { + if (y > noiseGet1DTotal(_noise, x)) + { + return QColor(255, 255, 255); + } + else + { + return QColor(0, 0, 0); + } + } +private: + NoiseGenerator* _noise; +}; + +/**************** Form ****************/ +FormNoise::FormNoise(QWidget *parent, NoiseGenerator* noise): + BaseForm(parent) +{ + /*_definition = skyCreateDefinition();*/ + + previewLevel = new PreviewLevel(this, noise); + addPreview(previewLevel, QString("Level preview")); + previewTotal = new PreviewTotal(this, noise); + addPreview(previewTotal, QString("Total preview")); + + /*addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1);*/ + + revertConfig(); +} + +void FormNoise::revertConfig() +{ + /*skyCopyDefinition(skyGetDefinition(), &_definition); + BaseForm::revertConfig();*/ +} + +void FormNoise::applyConfig() +{ + /*skySetDefinition(_definition); + BaseForm::applyConfig();*/ +} + +void FormNoise::applyConfigPreview() +{ + /*skyValidateDefinition(&_definition); + BaseForm::applyConfigPreview();*/ +} diff --git a/gui_qt/formnoise.h b/gui_qt/formnoise.h new file mode 100644 index 0000000..ad334cd --- /dev/null +++ b/gui_qt/formnoise.h @@ -0,0 +1,30 @@ +#ifndef _PAYSAGES_QT_FORMNOISE_H_ +#define _PAYSAGES_QT_FORMNOISE_H_ + +#include +#include "preview.h" +#include "baseform.h" + +#include "../lib_paysages/shared/types.h" + +class FormNoise : public BaseForm +{ + Q_OBJECT + +public: + FormNoise(QWidget* parent, NoiseGenerator* noise); + +public slots: + virtual void revertConfig(); + virtual void applyConfig(); + +protected slots: + virtual void applyConfigPreview(); + +private: + Preview* previewLevel; + Preview* previewTotal; + NoiseGenerator* generator; +}; + +#endif diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index 4b9ca46..7118154 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -13,10 +13,10 @@ static SkyDefinition _definition; /**************** Previews ****************/ -class PreviewHorizon:public Preview +class PreviewEast:public Preview { public: - PreviewHorizon(QWidget* parent): + PreviewEast(QWidget* parent): Preview(parent) { } @@ -26,9 +26,30 @@ protected: 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)); + look.x = 100.0; + look.y = -y; + look.z = x; + + return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL)); + } +}; + +class PreviewWest:public Preview +{ +public: + PreviewWest(QWidget* parent): + Preview(parent) + { + } +protected: + QColor getColor(double x, double y) + { + Vector3 eye = {0.0, 0.0, 0.0}; + Vector3 look; + + look.x = -100.0; + look.y = -y; + look.z = -x; return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL)); } @@ -40,8 +61,10 @@ FormSky::FormSky(QWidget *parent): { _definition = skyCreateDefinition(); - previewHorizon = new PreviewHorizon(this); - addPreview(previewHorizon, QString("Horizon preview")); + previewWest = new PreviewWest(this); + addPreview(previewWest, QString("West preview")); + previewEast = new PreviewEast(this); + addPreview(previewEast, QString("East preview")); addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1); addInputColorGradation("Sun color", &_definition.sun_color); diff --git a/gui_qt/formsky.h b/gui_qt/formsky.h index b508575..4a0ebfe 100644 --- a/gui_qt/formsky.h +++ b/gui_qt/formsky.h @@ -20,7 +20,8 @@ protected slots: virtual void applyConfigPreview(); private: - Preview* previewHorizon; + Preview* previewEast; + Preview* previewWest; }; #endif // _PAYSAGES_QT_FORMSKY_H_ diff --git a/gui_qt/inputnoise.cpp b/gui_qt/inputnoise.cpp index d5d05d7..e771a21 100644 --- a/gui_qt/inputnoise.cpp +++ b/gui_qt/inputnoise.cpp @@ -5,6 +5,8 @@ #include #include +#include "dialognoise.h" + #include "../lib_paysages/shared/functions.h" class NoiseSmallPreview:public QWidget @@ -62,27 +64,18 @@ void InputNoise::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);*/ - BaseInput::revert(); } void InputNoise::editNoise() { - /*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); - if (col.isValid()) + if (DialogNoise::getNoise(_control, _value)) { - ((ColorPreview*)_preview)->col = col; applyValue(); - }*/ + } } diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 81c17bb..900d77a 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -47,6 +47,8 @@ MainWindow::MainWindow(QWidget *parent) : menu->addAction("Quick render", this, SLOT(quickPreview()), QKeySequence("F2")); setCentralWidget(tabs); + + setWindowTitle("Paysages 3D"); } void MainWindow::refreshAll() diff --git a/gui_qt/paysages-qt.pro b/gui_qt/paysages-qt.pro index 1d4f536..b2cc76d 100644 --- a/gui_qt/paysages-qt.pro +++ b/gui_qt/paysages-qt.pro @@ -3,7 +3,7 @@ ###################################################################### TEMPLATE = app -TARGET = +TARGET = DEPENDPATH += . INCLUDEPATH += . unix:CONFIG += debug @@ -24,8 +24,10 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \ formrender.h \ inputint.h \ dialogrender.h \ + dialognoise.h \ inputcolorgradation.h \ formsky.h \ + formnoise.h \ inputnoise.h \ tools.h FORMS += @@ -40,6 +42,8 @@ SOURCES += \ formrender.cpp \ inputint.cpp \ dialogrender.cpp \ + dialognoise.cpp \ inputcolorgradation.cpp \ formsky.cpp \ + formnoise.cpp \ inputnoise.cpp diff --git a/gui_qt/preview.cpp b/gui_qt/preview.cpp index 3da72e6..a256b18 100644 --- a/gui_qt/preview.cpp +++ b/gui_qt/preview.cpp @@ -30,8 +30,6 @@ protected: Preview::Preview(QWidget* parent) : QWidget(parent) { - _previews.append(this); - this->lock = new QMutex(); this->conf_scroll_xmin = 0.0; this->conf_scroll_xmax = 0.0; @@ -44,12 +42,26 @@ Preview::Preview(QWidget* parent) : this->xoffset = 0.0; this->yoffset = 0.0; this->pixbuf = new QImage(this->size(), QImage::Format_ARGB32); - this->need_rerender = 0; - this->need_render = 0; + + this->alive = true; + this->need_rerender = false; + this->need_render = false; this->setMinimumSize(256, 256); this->setMaximumSize(256, 256); this->resize(256, 256); + + _previews.append(this); +} + +Preview::~Preview() +{ + _previews.remove(_previews.indexOf(this)); + + lock->lock(); + alive = true; + delete pixbuf; + lock->unlock(); } void Preview::startUpdater() @@ -59,14 +71,17 @@ void Preview::startUpdater() void Preview::doRender() { - if (this->need_rerender) + if (this->alive) { - this->forceRender(); - } - if (this->need_render) - { - this->need_render = 0; - this->renderPixbuf(); + if (this->need_rerender) + { + this->forceRender(); + } + if (this->need_render) + { + this->need_render = 0; + this->renderPixbuf(); + } } } @@ -118,7 +133,7 @@ void Preview::renderPixbuf() { this->lock->lock(); - if (this->need_rerender) + if (this->need_rerender || !this->alive) { this->lock->unlock(); break; diff --git a/gui_qt/preview.h b/gui_qt/preview.h index 288dc96..715818b 100644 --- a/gui_qt/preview.h +++ b/gui_qt/preview.h @@ -11,6 +11,8 @@ class Preview:public QWidget public: Preview(QWidget* parent); + ~Preview(); + static void startUpdater(); void doRender(); void redraw(); @@ -42,9 +44,9 @@ protected: int mousex; int mousey; - int need_rerender; - int need_render; - //SmallPreviewCallback renderer; + bool alive; + bool need_rerender; + bool need_render; }; -#endif // _PAYSAGES_QT_PREVIEW_H_ +#endif