paysages: Qt GUI (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@218 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-07 16:53:23 +00:00 committed by ThunderK
parent a5bc77e798
commit db453d6fa9
21 changed files with 392 additions and 14 deletions

View file

@ -3,6 +3,8 @@
#include "inputdouble.h"
#include "inputint.h"
#include "inputcolor.h"
#include "inputcolorgradation.h"
#include "inputnoise.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
@ -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));
}

View file

@ -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;

73
gui_qt/formsky.cpp Normal file
View file

@ -0,0 +1,73 @@
#include "formsky.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"
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();
}

26
gui_qt/formsky.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef _PAYSAGES_QT_FORMSKY_H_
#define _PAYSAGES_QT_FORMSKY_H_
#include <QWidget>
#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_

View file

@ -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();
}

View file

@ -14,6 +14,7 @@ public:
public slots:
virtual void revertConfig();
virtual void applyConfig();
private:
Preview* previewCoverage;

View file

@ -2,20 +2,58 @@
#include <QLabel>
#include <QPushButton>
#include <QPainter>
#include <QColorDialog>
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();
}
}

View file

@ -19,6 +19,9 @@ public slots:
protected slots:
virtual void applyValue();
private slots:
void chooseColor();
private:
Color* _value;
};

View file

@ -0,0 +1,59 @@
#include "inputcolorgradation.h"
#include <QLabel>
#include <QPushButton>
#include <QPainter>
#include <QColorDialog>
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();
}*/
}

View file

@ -0,0 +1,29 @@
#ifndef _PAYSAGES_QT_INPUTCOLORGRADATION_H_
#define _PAYSAGES_QT_INPUTCOLORGRADATION_H_
#include <QWidget>
#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_

59
gui_qt/inputnoise.cpp Normal file
View file

@ -0,0 +1,59 @@
#include "inputnoise.h"
#include <QLabel>
#include <QPushButton>
#include <QPainter>
#include <QColorDialog>
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();
}*/
}

29
gui_qt/inputnoise.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef _PAYSAGES_QT_INPUTNOISE_H_
#define _PAYSAGES_QT_INPUTNOISE_H_
#include <QWidget>
#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_

View file

@ -1,6 +1,7 @@
#include <QApplication>
#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);

View file

@ -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

View file

@ -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();
}

13
gui_qt/tools.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef _PAYSAGES_QT_TOOLS_H_
#define _PAYSAGES_QT_TOOLS_H_
#include <QColor>
#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_

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -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)

View file

@ -17,6 +17,7 @@ typedef struct
Color depth_color;
double transparency_depth;
NoiseGenerator* height_noise;
double height_noise_factor;
} WaterDefinition;
typedef struct