paysages: Qt noise dialog (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@223 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-16 21:29:21 +00:00 committed by ThunderK
parent 156e609259
commit 375c4f24b8
12 changed files with 283 additions and 36 deletions

52
gui_qt/dialognoise.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "dialognoise.h"
#include <QVBoxLayout>
#include <QImage>
#include <QColor>
#include <QPainter>
#include <QScrollArea>
#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);
}

30
gui_qt/dialognoise.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef _PAYSAGES_QT_DIALOGNOISE_H_
#define _PAYSAGES_QT_DIALOGNOISE_H_
#include <QDialog>
#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

View file

@ -71,6 +71,7 @@ DialogRender::DialogRender(QWidget *parent, int quality, int width, int height):
_current_dialog = this; _current_dialog = this;
setModal(true); setModal(true);
setWindowTitle("Paysages 3D - Render");
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
scroll = new QScrollArea(this); scroll = new QScrollArea(this);

94
gui_qt/formnoise.cpp Normal file
View file

@ -0,0 +1,94 @@
#include "formnoise.h"
#include "tools.h"
#include <QColor>
#include <QSlider>
#include <math.h>
#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();*/
}

30
gui_qt/formnoise.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef _PAYSAGES_QT_FORMNOISE_H_
#define _PAYSAGES_QT_FORMNOISE_H_
#include <QWidget>
#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

View file

@ -13,10 +13,10 @@
static SkyDefinition _definition; static SkyDefinition _definition;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewHorizon:public Preview class PreviewEast:public Preview
{ {
public: public:
PreviewHorizon(QWidget* parent): PreviewEast(QWidget* parent):
Preview(parent) Preview(parent)
{ {
} }
@ -26,9 +26,30 @@ protected:
Vector3 eye = {0.0, 0.0, 0.0}; Vector3 eye = {0.0, 0.0, 0.0};
Vector3 look; Vector3 look;
look.x = cos(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0)); look.x = 100.0;
look.y = -sin(M_PI * (y / 256.0)); look.y = -y;
look.z = sin(M_PI * (x / 128.0 + 0.5)) * cos(M_PI * (y / 256.0)); 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)); return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL));
} }
@ -40,8 +61,10 @@ FormSky::FormSky(QWidget *parent):
{ {
_definition = skyCreateDefinition(); _definition = skyCreateDefinition();
previewHorizon = new PreviewHorizon(this); previewWest = new PreviewWest(this);
addPreview(previewHorizon, QString("Horizon preview")); 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); addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1);
addInputColorGradation("Sun color", &_definition.sun_color); addInputColorGradation("Sun color", &_definition.sun_color);

View file

@ -20,7 +20,8 @@ protected slots:
virtual void applyConfigPreview(); virtual void applyConfigPreview();
private: private:
Preview* previewHorizon; Preview* previewEast;
Preview* previewWest;
}; };
#endif // _PAYSAGES_QT_FORMSKY_H_ #endif // _PAYSAGES_QT_FORMSKY_H_

View file

@ -5,6 +5,8 @@
#include <QPainter> #include <QPainter>
#include <QColorDialog> #include <QColorDialog>
#include "dialognoise.h"
#include "../lib_paysages/shared/functions.h" #include "../lib_paysages/shared/functions.h"
class NoiseSmallPreview:public QWidget class NoiseSmallPreview:public QWidget
@ -62,27 +64,18 @@ void InputNoise::updatePreview()
void InputNoise::applyValue() 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(); BaseInput::applyValue();
} }
void InputNoise::revert() void InputNoise::revert()
{ {
/*((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);*/
BaseInput::revert(); BaseInput::revert();
} }
void InputNoise::editNoise() void InputNoise::editNoise()
{ {
/*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); if (DialogNoise::getNoise(_control, _value))
if (col.isValid())
{ {
((ColorPreview*)_preview)->col = col;
applyValue(); applyValue();
}*/ }
} }

View file

@ -47,6 +47,8 @@ MainWindow::MainWindow(QWidget *parent) :
menu->addAction("Quick render", this, SLOT(quickPreview()), QKeySequence("F2")); menu->addAction("Quick render", this, SLOT(quickPreview()), QKeySequence("F2"));
setCentralWidget(tabs); setCentralWidget(tabs);
setWindowTitle("Paysages 3D");
} }
void MainWindow::refreshAll() void MainWindow::refreshAll()

View file

@ -24,8 +24,10 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
formrender.h \ formrender.h \
inputint.h \ inputint.h \
dialogrender.h \ dialogrender.h \
dialognoise.h \
inputcolorgradation.h \ inputcolorgradation.h \
formsky.h \ formsky.h \
formnoise.h \
inputnoise.h \ inputnoise.h \
tools.h tools.h
FORMS += FORMS +=
@ -40,6 +42,8 @@ SOURCES += \
formrender.cpp \ formrender.cpp \
inputint.cpp \ inputint.cpp \
dialogrender.cpp \ dialogrender.cpp \
dialognoise.cpp \
inputcolorgradation.cpp \ inputcolorgradation.cpp \
formsky.cpp \ formsky.cpp \
formnoise.cpp \
inputnoise.cpp inputnoise.cpp

View file

@ -30,8 +30,6 @@ protected:
Preview::Preview(QWidget* parent) : Preview::Preview(QWidget* parent) :
QWidget(parent) QWidget(parent)
{ {
_previews.append(this);
this->lock = new QMutex(); this->lock = new QMutex();
this->conf_scroll_xmin = 0.0; this->conf_scroll_xmin = 0.0;
this->conf_scroll_xmax = 0.0; this->conf_scroll_xmax = 0.0;
@ -44,12 +42,26 @@ Preview::Preview(QWidget* parent) :
this->xoffset = 0.0; this->xoffset = 0.0;
this->yoffset = 0.0; this->yoffset = 0.0;
this->pixbuf = new QImage(this->size(), QImage::Format_ARGB32); 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->setMinimumSize(256, 256);
this->setMaximumSize(256, 256); this->setMaximumSize(256, 256);
this->resize(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() void Preview::startUpdater()
@ -58,6 +70,8 @@ void Preview::startUpdater()
} }
void Preview::doRender() void Preview::doRender()
{
if (this->alive)
{ {
if (this->need_rerender) if (this->need_rerender)
{ {
@ -69,6 +83,7 @@ void Preview::doRender()
this->renderPixbuf(); this->renderPixbuf();
} }
} }
}
void Preview::redraw() void Preview::redraw()
{ {
@ -118,7 +133,7 @@ void Preview::renderPixbuf()
{ {
this->lock->lock(); this->lock->lock();
if (this->need_rerender) if (this->need_rerender || !this->alive)
{ {
this->lock->unlock(); this->lock->unlock();
break; break;

View file

@ -11,6 +11,8 @@ class Preview:public QWidget
public: public:
Preview(QWidget* parent); Preview(QWidget* parent);
~Preview();
static void startUpdater(); static void startUpdater();
void doRender(); void doRender();
void redraw(); void redraw();
@ -42,9 +44,9 @@ protected:
int mousex; int mousex;
int mousey; int mousey;
int need_rerender; bool alive;
int need_render; bool need_rerender;
//SmallPreviewCallback renderer; bool need_render;
}; };
#endif // _PAYSAGES_QT_PREVIEW_H_ #endif