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:
parent
156e609259
commit
375c4f24b8
12 changed files with 283 additions and 36 deletions
52
gui_qt/dialognoise.cpp
Normal file
52
gui_qt/dialognoise.cpp
Normal 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
30
gui_qt/dialognoise.h
Normal 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
|
|
@ -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);
|
||||
|
|
94
gui_qt/formnoise.cpp
Normal file
94
gui_qt/formnoise.cpp
Normal 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
30
gui_qt/formnoise.h
Normal 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
|
|
@ -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);
|
||||
|
|
|
@ -20,7 +20,8 @@ protected slots:
|
|||
virtual void applyConfigPreview();
|
||||
|
||||
private:
|
||||
Preview* previewHorizon;
|
||||
Preview* previewEast;
|
||||
Preview* previewWest;
|
||||
};
|
||||
|
||||
#endif // _PAYSAGES_QT_FORMSKY_H_
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QPainter>
|
||||
#include <QColorDialog>
|
||||
|
||||
#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();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue