paysages : ColorGradation dialog.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@271 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-02-21 13:41:02 +00:00 committed by ThunderK
parent 22726e02e6
commit fabcec1cfd
25 changed files with 236 additions and 110 deletions

View file

@ -96,7 +96,7 @@ void BaseForm::configChangeEvent()
button_revert->setEnabled(true); button_revert->setEnabled(true);
} }
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_"); QList<BasePreview*> list_previews = previews->findChildren<BasePreview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++) for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->redraw(); list_previews[i]->redraw();
@ -148,7 +148,7 @@ void BaseForm::layerListChanged()
layerSelectedEvent(layer_list->currentIndex()); layerSelectedEvent(layer_list->currentIndex());
} }
void BaseForm::addPreview(Preview* preview, QString label) void BaseForm::addPreview(BasePreview* preview, QString label)
{ {
previews->layout()->addWidget(new QLabel(label, previews)); previews->layout()->addWidget(new QLabel(label, previews));
previews->layout()->addWidget(preview); previews->layout()->addWidget(preview);
@ -238,9 +238,19 @@ void BaseForm::setLayerCount(int layer_count)
{ {
layer_list->addItem(QString("Layer %1").arg(i + 1)); layer_list->addItem(QString("Layer %1").arg(i + 1));
} }
if (selected >= 0)
{
if (selected > layer_count)
{
layer_list->setCurrentIndex(layer_count - 1);
}
else
{
layer_list->setCurrentIndex(selected); layer_list->setCurrentIndex(selected);
} }
} }
}
}
void BaseForm::layerAddedEvent() void BaseForm::layerAddedEvent()
{ {
@ -261,7 +271,7 @@ void BaseForm::layerSelectedEvent(int layer)
inputs[i]->revert(); inputs[i]->revert();
} }
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_"); QList<BasePreview*> list_previews = previews->findChildren<BasePreview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++) for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->redraw(); list_previews[i]->redraw();

View file

@ -4,7 +4,7 @@
#include <QWidget> #include <QWidget>
#include <QPushButton> #include <QPushButton>
#include <QComboBox> #include <QComboBox>
#include "preview.h" #include "basepreview.h"
#include "baseinput.h" #include "baseinput.h"
#include "../lib_paysages/shared/types.h" #include "../lib_paysages/shared/types.h"
#include "../lib_paysages/noise.h" #include "../lib_paysages/noise.h"
@ -32,7 +32,7 @@ private slots:
void layerListChanged(); void layerListChanged();
protected: protected:
void addPreview(Preview* preview, QString label); void addPreview(BasePreview* preview, QString label);
QPushButton* addButton(QString label); QPushButton* addButton(QString label);
void addInput(BaseInput* input); void addInput(BaseInput* input);
void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step); void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step);

View file

@ -1,4 +1,4 @@
#include "preview.h" #include "basepreview.h"
#include <QVector> #include <QVector>
#include <QPainter> #include <QPainter>
@ -8,7 +8,7 @@
class PreviewDrawer:public QThread class PreviewDrawer:public QThread
{ {
public: public:
PreviewDrawer(Preview* preview): PreviewDrawer(BasePreview* preview):
QThread(), QThread(),
_preview(preview) _preview(preview)
{ {
@ -29,11 +29,11 @@ protected:
} }
} }
private: private:
Preview* _preview; BasePreview* _preview;
bool _running; bool _running;
}; };
Preview::Preview(QWidget* parent) : BasePreview::BasePreview(QWidget* parent) :
QWidget(parent) QWidget(parent)
{ {
this->lock_drawing = new QMutex(); this->lock_drawing = new QMutex();
@ -65,7 +65,7 @@ Preview::Preview(QWidget* parent) :
this->updater = new PreviewDrawer(this); this->updater = new PreviewDrawer(this);
} }
Preview::~Preview() BasePreview::~BasePreview()
{ {
alive = false; alive = false;
@ -77,21 +77,21 @@ Preview::~Preview()
delete lock_drawing; delete lock_drawing;
} }
void Preview::updateData() void BasePreview::updateData()
{ {
} }
QColor Preview::getColor(double x, double y) QColor BasePreview::getColor(double x, double y)
{ {
return QColor(0, 0, 0); return QColor(0, 0, 0);
} }
void Preview::start() void BasePreview::start()
{ {
this->updater->start(); this->updater->start();
} }
void Preview::doRender() void BasePreview::doRender()
{ {
if (this->alive) if (this->alive)
{ {
@ -107,12 +107,12 @@ void Preview::doRender()
} }
} }
void Preview::redraw() void BasePreview::redraw()
{ {
emit(redrawRequested()); emit(redrawRequested());
} }
void Preview::handleRedraw() void BasePreview::handleRedraw()
{ {
need_rerender = true; need_rerender = true;
lock_drawing->lock(); lock_drawing->lock();
@ -121,14 +121,14 @@ void Preview::handleRedraw()
lock_drawing->unlock(); lock_drawing->unlock();
} }
void Preview::setScaling(double scaling) void BasePreview::setScaling(double scaling)
{ {
// TODO Follow conf_scale // TODO Follow conf_scale
this->scaling = scaling; this->scaling = scaling;
redraw(); redraw();
} }
void Preview::resizeEvent(QResizeEvent* event) void BasePreview::resizeEvent(QResizeEvent* event)
{ {
QImage* image; QImage* image;
@ -147,13 +147,13 @@ void Preview::resizeEvent(QResizeEvent* event)
this->lock_drawing->unlock(); this->lock_drawing->unlock();
} }
void Preview::paintEvent(QPaintEvent* event) void BasePreview::paintEvent(QPaintEvent* event)
{ {
QPainter painter(this); QPainter painter(this);
painter.drawImage(0, 0, *this->pixbuf); painter.drawImage(0, 0, *this->pixbuf);
} }
void Preview::forceRender() void BasePreview::forceRender()
{ {
this->lock_drawing->lock(); this->lock_drawing->lock();
this->pixbuf->fill(0x00000000); this->pixbuf->fill(0x00000000);
@ -162,7 +162,7 @@ void Preview::forceRender()
this->lock_drawing->unlock(); this->lock_drawing->unlock();
} }
void Preview::renderPixbuf() void BasePreview::renderPixbuf()
{ {
QColor col; QColor col;
bool done; bool done;
@ -205,7 +205,7 @@ void Preview::renderPixbuf()
} }
} }
void Preview::wheelEvent(QWheelEvent* event) void BasePreview::wheelEvent(QWheelEvent* event)
{ {
if (event->orientation() == Qt::Vertical) if (event->orientation() == Qt::Vertical)
{ {

View file

@ -1,18 +1,18 @@
#ifndef _PAYSAGES_QT_PREVIEW_H_ #ifndef _PAYSAGES_QT_BASEPREVIEW_H_
#define _PAYSAGES_QT_PREVIEW_H_ #define _PAYSAGES_QT_BASEPREVIEW_H_
#include <QMutex> #include <QMutex>
#include <QImage> #include <QImage>
#include <QWidget> #include <QWidget>
#include <QThread> #include <QThread>
class Preview:public QWidget class BasePreview:public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
Preview(QWidget* parent); BasePreview(QWidget* parent);
~Preview(); ~BasePreview();
void start(); void start();
void doRender(); void doRender();

View file

@ -9,43 +9,92 @@
#include <QScrollArea> #include <QScrollArea>
#include <QPushButton> #include <QPushButton>
#include "baseform.h" #include "baseform.h"
#include "tools.h"
/**************** Dialog form ****************/ /**************** Preview ****************/
class PreviewColorGradation:public BasePreview
{
public:
PreviewColorGradation(QWidget* parent, ColorGradation* gradation): BasePreview(parent)
{
_gradation_original = gradation;
_gradation_preview = *gradation;
setMinimumSize(300, 30);
setMaximumSize(300, 30);
resize(300, 30);
// TODO No scrolling/scaling
}
protected:
void updateData()
{
_gradation_preview = *_gradation_original;
}
QColor getColor(double x, double y)
{
return colorToQColor(colorGradationGet(&_gradation_preview, x / 600 + 0.5));
}
private:
ColorGradation* _gradation_original;
ColorGradation _gradation_preview;
};
/**************** Form ****************/
class FormColorGradation:public BaseForm class FormColorGradation:public BaseForm
{ {
public: public:
FormColorGradation(QWidget* parent, ColorGradation* gradation):BaseForm(parent, true, true) FormColorGradation(QWidget* parent, ColorGradation* gradation):BaseForm(parent, true, true)
{ {
QPushButton* button;
_gradation = gradation; _gradation = gradation;
addPreview(new PreviewColorGradation(this, _gradation), "Preview");
addInputDouble("Position", &_layer.start, 0.0, 1.0, 0.01, 0.1); addInputDouble("Position", &_layer.start, 0.0, 1.0, 0.01, 0.1);
addInputColor("Color", &_layer.col); addInputColor("Color", &_layer.col);
setLayerCount(gradation->nbparts); button = addButton("Validate");
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(accept()));
button = addButton("Revert");
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(revert()));
button = addButton("Cancel");
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(reject()));
revertConfig();
} }
~FormColorGradation() void revertConfig()
{ {
setLayerCount(colorGradationGetPartCount(_gradation));
}
void configChangeEvent()
{
colorGradationSetPart(_gradation, currentLayer(), _layer);
BaseForm::configChangeEvent();
} }
void layerAddedEvent() void layerAddedEvent()
{ {
/*if (cloudsAddLayer(&_definition) >= 0) if (colorGradationAddPart(_gradation) >= 0)
{ {
BaseForm::layerAddedEvent(); BaseForm::layerAddedEvent();
}*/ }
} }
void layerDeletedEvent(int layer) void layerDeletedEvent(int layer)
{ {
/*cloudsDeleteLayer(&_definition, layer); colorGradationDelPart(_gradation, layer);
BaseForm::layerDeletedEvent(layer);*/ BaseForm::layerDeletedEvent(layer);
} }
void layerSelectedEvent(int layer) void layerSelectedEvent(int layer)
{ {
_layer = _gradation->parts[layer]; _layer = colorGradationGetPart(_gradation, layer);
BaseForm::layerSelectedEvent(layer); BaseForm::layerSelectedEvent(layer);
} }
@ -60,18 +109,18 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad
QDialog(parent) QDialog(parent)
{ {
QWidget* preview; QWidget* preview;
BaseForm* form;
_base = gradation; _base = gradation;
_current = colorGradationCreate(); _current = colorGradationCreate();
_current = *_base;
setLayout(new QHBoxLayout()); setLayout(new QHBoxLayout());
preview = new QWidget(this); preview = new QWidget(this);
layout()->addWidget(preview); layout()->addWidget(preview);
form = new FormColorGradation(this, &_current); _form = new FormColorGradation(this, &_current);
layout()->addWidget(form); layout()->addWidget(_form);
/*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); /*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert())); QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
@ -118,4 +167,5 @@ void DialogColorGradation::revert()
void DialogColorGradation::revertToCurrent() void DialogColorGradation::revertToCurrent()
{ {
_form->revertConfig();
} }

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_QT_DIALOGCOLORGRADATION_H_ #define _PAYSAGES_QT_DIALOGCOLORGRADATION_H_
#include <QDialog> #include <QDialog>
#include "baseform.h"
#include "../lib_paysages/color.h" #include "../lib_paysages/color.h"
@ -27,6 +28,7 @@ private:
private: private:
ColorGradation* _base; ColorGradation* _base;
ColorGradation _current; ColorGradation _current;
BaseForm* _form;
}; };
#endif #endif

View file

@ -10,10 +10,10 @@
#include <QPushButton> #include <QPushButton>
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewLevel:public Preview class PreviewLevel:public BasePreview
{ {
public: public:
PreviewLevel(QWidget* parent, NoiseGenerator* noise): Preview(parent) PreviewLevel(QWidget* parent, NoiseGenerator* noise): BasePreview(parent)
{ {
_noise_original = noise; _noise_original = noise;
_noise_preview = noiseCreateGenerator(); _noise_preview = noiseCreateGenerator();
@ -47,10 +47,10 @@ private:
int _level; int _level;
}; };
class PreviewTotal:public Preview class PreviewTotal:public BasePreview
{ {
public: public:
PreviewTotal(QWidget* parent, NoiseGenerator* noise): Preview(parent) PreviewTotal(QWidget* parent, NoiseGenerator* noise): BasePreview(parent)
{ {
_noise_original = noise; _noise_original = noise;
_noise_preview = noiseCreateGenerator(); _noise_preview = noiseCreateGenerator();

View file

@ -3,7 +3,7 @@
#include <QDialog> #include <QDialog>
#include <QListWidget> #include <QListWidget>
#include "preview.h" #include "basepreview.h"
#include "../lib_paysages/noise.h" #include "../lib_paysages/noise.h"
@ -38,8 +38,8 @@ private:
NoiseGenerator* _current; NoiseGenerator* _current;
int _current_level; int _current_level;
NoiseLevel _current_level_params; NoiseLevel _current_level_params;
Preview* previewLevel; BasePreview* previewLevel;
Preview* previewTotal; BasePreview* previewTotal;
QListWidget* levels; QListWidget* levels;
QSlider* slider_height; QSlider* slider_height;
QSlider* slider_scaling; QSlider* slider_scaling;

View file

@ -9,11 +9,11 @@
static AtmosphereDefinition _definition; static AtmosphereDefinition _definition;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewAtmosphereColor:public Preview class PreviewAtmosphereColor:public BasePreview
{ {
public: public:
PreviewAtmosphereColor(QWidget* parent): PreviewAtmosphereColor(QWidget* parent):
Preview(parent) BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = rendererCreate();
_preview_definition = atmosphereCreateDefinition(); _preview_definition = atmosphereCreateDefinition();

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMATMOSPHERE_H_ #define _PAYSAGES_QT_FORMATMOSPHERE_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormAtmosphere : public BaseForm class FormAtmosphere : public BaseForm
@ -20,7 +20,7 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
private: private:
Preview* previewColor; BasePreview* previewColor;
}; };
#endif #endif

View file

@ -12,10 +12,10 @@ static CloudsDefinition _definition;
static CloudsLayerDefinition _layer; static CloudsLayerDefinition _layer;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewCloudsCoverage:public Preview class PreviewCloudsCoverage:public BasePreview
{ {
public: public:
PreviewCloudsCoverage(QWidget* parent):Preview(parent) PreviewCloudsCoverage(QWidget* parent):BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = rendererCreate();
_renderer.render_quality = 3; _renderer.render_quality = 3;
@ -51,10 +51,10 @@ private:
CloudsLayerDefinition _preview_layer; CloudsLayerDefinition _preview_layer;
}; };
class PreviewCloudsColor:public Preview class PreviewCloudsColor:public BasePreview
{ {
public: public:
PreviewCloudsColor(QWidget* parent):Preview(parent) PreviewCloudsColor(QWidget* parent):BasePreview(parent)
{ {
LightDefinition light; LightDefinition light;

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMCLOUDS_H_ #define _PAYSAGES_QT_FORMCLOUDS_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormClouds : public BaseForm class FormClouds : public BaseForm
@ -25,8 +25,8 @@ protected:
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
private: private:
Preview* previewCoverage; BasePreview* previewCoverage;
Preview* previewColor; BasePreview* previewColor;
}; };
#endif #endif

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMLIGHTING_H_ #define _PAYSAGES_QT_FORMLIGHTING_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormLighting : public BaseForm class FormLighting : public BaseForm
@ -20,7 +20,7 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
private: private:
Preview* previewColor; BasePreview* previewColor;
}; };
#endif #endif

View file

@ -14,11 +14,11 @@
static SkyDefinition _definition; static SkyDefinition _definition;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewSkyEast:public Preview class PreviewSkyEast:public BasePreview
{ {
public: public:
PreviewSkyEast(QWidget* parent): PreviewSkyEast(QWidget* parent):
Preview(parent) BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = rendererCreate();
_preview_definition = skyCreateDefinition(); _preview_definition = skyCreateDefinition();
@ -44,11 +44,11 @@ private:
SkyDefinition _preview_definition; SkyDefinition _preview_definition;
}; };
class PreviewSkyWest:public Preview class PreviewSkyWest:public BasePreview
{ {
public: public:
PreviewSkyWest(QWidget* parent): PreviewSkyWest(QWidget* parent):
Preview(parent) BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = rendererCreate();
_preview_definition = skyCreateDefinition(); _preview_definition = skyCreateDefinition();

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMSKY_H_ #define _PAYSAGES_QT_FORMSKY_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormSky : public BaseForm class FormSky : public BaseForm
@ -20,8 +20,8 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
private: private:
Preview* previewEast; BasePreview* previewEast;
Preview* previewWest; BasePreview* previewWest;
}; };
#endif // _PAYSAGES_QT_FORMSKY_H_ #endif // _PAYSAGES_QT_FORMSKY_H_

View file

@ -12,10 +12,10 @@
static TerrainDefinition _definition; static TerrainDefinition _definition;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewTerrainHeight:public Preview class PreviewTerrainHeight:public BasePreview
{ {
public: public:
PreviewTerrainHeight(QWidget* parent):Preview(parent) PreviewTerrainHeight(QWidget* parent):BasePreview(parent)
{ {
_preview_definition = terrainCreateDefinition(); _preview_definition = terrainCreateDefinition();
} }
@ -35,10 +35,10 @@ private:
TerrainDefinition _preview_definition; TerrainDefinition _preview_definition;
}; };
class PreviewTerrainColor:public Preview class PreviewTerrainColor:public BasePreview
{ {
public: public:
PreviewTerrainColor(QWidget* parent):Preview(parent) PreviewTerrainColor(QWidget* parent):BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = rendererCreate();
_renderer.applyTextures = _applyTextures; _renderer.applyTextures = _applyTextures;

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMTERRAIN_H_ #define _PAYSAGES_QT_FORMTERRAIN_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormTerrain : public BaseForm class FormTerrain : public BaseForm
@ -20,8 +20,8 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
private: private:
Preview* previewHeight; BasePreview* previewHeight;
Preview* previewColor; BasePreview* previewColor;
}; };
#endif #endif

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMTEXTURES_H_ #define _PAYSAGES_QT_FORMTEXTURES_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormTextures : public BaseForm class FormTextures : public BaseForm
@ -20,8 +20,8 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
private: private:
Preview* previewCoverage; BasePreview* previewCoverage;
Preview* previewColor; BasePreview* previewColor;
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
#include "preview.h" #include "basepreview.h"
#include "formwater.h" #include "formwater.h"
#include <QColor> #include <QColor>
@ -17,10 +17,10 @@
static WaterDefinition _definition; static WaterDefinition _definition;
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewWaterCoverage:public Preview class PreviewWaterCoverage:public BasePreview
{ {
public: public:
PreviewWaterCoverage(QWidget* parent):Preview(parent) PreviewWaterCoverage(QWidget* parent):BasePreview(parent)
{ {
_water = waterCreateDefinition(); _water = waterCreateDefinition();
_terrain = terrainCreateDefinition(); _terrain = terrainCreateDefinition();
@ -51,10 +51,10 @@ private:
TerrainDefinition _terrain; TerrainDefinition _terrain;
}; };
class PreviewWaterColor:public Preview class PreviewWaterColor:public BasePreview
{ {
public: public:
PreviewWaterColor(QWidget* parent):Preview(parent) PreviewWaterColor(QWidget* parent):BasePreview(parent)
{ {
LightDefinition light; LightDefinition light;

View file

@ -2,7 +2,7 @@
#define _PAYSAGES_QT_FORMWATER_H_ #define _PAYSAGES_QT_FORMWATER_H_
#include <QWidget> #include <QWidget>
#include "preview.h" #include "basepreview.h"
#include "baseform.h" #include "baseform.h"
class FormWater : public BaseForm class FormWater : public BaseForm
@ -17,8 +17,8 @@ public slots:
virtual void applyConfig(); virtual void applyConfig();
private: private:
Preview* previewCoverage; BasePreview* previewCoverage;
Preview* previewColor; BasePreview* previewColor;
}; };
#endif // _PAYSAGES_QT_FORMWATER_H_ #endif // _PAYSAGES_QT_FORMWATER_H_

View file

@ -108,23 +108,23 @@ void autoGenRealisticLandscape(int seed)
/* Sky */ /* Sky */
sky = skyCreateDefinition(); sky = skyCreateDefinition();
colorGradationAddRgba(&sky.sun_color, 0.3, 1.0, 0.91, 0.8, 1.0); colorGradationQuickAddRgba(&sky.sun_color, 0.3, 1.0, 0.91, 0.8, 1.0);
colorGradationAddRgba(&sky.sun_color, 0.5, 1.0, 0.95, 0.9, 1.0); colorGradationQuickAddRgba(&sky.sun_color, 0.5, 1.0, 0.95, 0.9, 1.0);
colorGradationAddRgba(&sky.sun_color, 0.7, 1.0, 0.91, 0.8, 1.0); colorGradationQuickAddRgba(&sky.sun_color, 0.7, 1.0, 0.91, 0.8, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.2, 0.03, 0.03, 0.05, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.2, 0.03, 0.03, 0.05, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.25, 0.25, 0.33, 0.37, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.25, 0.25, 0.33, 0.37, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.35, 0.52, 0.63, 0.8, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.35, 0.52, 0.63, 0.8, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.65, 0.52, 0.63, 0.8, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.65, 0.52, 0.63, 0.8, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.75, 0.25, 0.33, 0.37, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.75, 0.25, 0.33, 0.37, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.8, 0.03, 0.03, 0.05, 1.0); colorGradationQuickAddRgba(&sky.zenith_color, 0.8, 0.03, 0.03, 0.05, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.2, 0.05, 0.05, 0.08, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.2, 0.05, 0.05, 0.08, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.25, 0.55, 0.42, 0.42, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.25, 0.55, 0.42, 0.42, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.3, 0.6, 0.6, 0.6, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.3, 0.6, 0.6, 0.6, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.4, 0.92, 0.93, 1.0, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.4, 0.92, 0.93, 1.0, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.6, 0.92, 0.93, 1.0, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.6, 0.92, 0.93, 1.0, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.7, 0.6, 0.6, 0.8, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.7, 0.6, 0.6, 0.8, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.75, 0.62, 0.50, 0.42, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.75, 0.62, 0.50, 0.42, 1.0);
colorGradationAddRgba(&sky.haze_color, 0.8, 0.05, 0.05, 0.08, 1.0); colorGradationQuickAddRgba(&sky.haze_color, 0.8, 0.05, 0.05, 0.08, 1.0);
sky.daytime = 0.0; sky.daytime = 0.0;
sky.haze_height = 0.75; sky.haze_height = 0.75;
sky.haze_smoothing = 0.3; sky.haze_smoothing = 0.3;

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h>
#include "shared/constants.h" #include "shared/constants.h"
#include "tools.h" #include "tools.h"
@ -13,6 +14,14 @@ Color COLOR_BLUE = {0.0, 0.0, 1.0, 1.0};
Color COLOR_WHITE = {1.0, 1.0, 1.0, 1.0}; Color COLOR_WHITE = {1.0, 1.0, 1.0, 1.0};
Color COLOR_GREY = {0.5, 0.5, 0.5, 1.0}; Color COLOR_GREY = {0.5, 0.5, 0.5, 1.0};
ColorGradationPart COLORGRADATIONPART_NULL;
void colorInit()
{
COLORGRADATIONPART_NULL.col = COLOR_TRANSPARENT;
COLORGRADATIONPART_NULL.start = 0.0;
}
void colorSave(FILE* f, Color* col) void colorSave(FILE* f, Color* col)
{ {
toolsSaveDouble(f, &col->r); toolsSaveDouble(f, &col->r);
@ -146,7 +155,53 @@ void colorGradationLoad(FILE* f, ColorGradation* gradation)
} }
} }
void colorGradationAdd(ColorGradation* gradation, double value, Color* col) int colorGradationGetPartCount(ColorGradation* gradation)
{
return gradation->nbparts;
}
int colorGradationAddPart(ColorGradation* gradation)
{
if (gradation->nbparts == MAX_COLORGRADATION_PARTS)
{
return -1;
}
else
{
return gradation->nbparts++;
}
}
void colorGradationDelPart(ColorGradation* gradation, int part)
{
if (part >= 0 && part < gradation->nbparts)
{
memmove(gradation->parts + part, gradation->parts + part + 1, sizeof(ColorGradationPart) * (gradation->nbparts - part - 1));
gradation->nbparts--;
}
}
ColorGradationPart colorGradationGetPart(ColorGradation* gradation, int part)
{
if (part >= 0 && part < gradation->nbparts)
{
return gradation->parts[part];
}
else
{
return COLORGRADATIONPART_NULL;
}
}
void colorGradationSetPart(ColorGradation* gradation, int part, ColorGradationPart value)
{
if (part >= 0 && part < gradation->nbparts)
{
gradation->parts[part] = value;
}
}
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col)
{ {
if (gradation->nbparts == MAX_COLORGRADATION_PARTS) if (gradation->nbparts == MAX_COLORGRADATION_PARTS)
{ {
@ -164,14 +219,14 @@ void colorGradationAdd(ColorGradation* gradation, double value, Color* col)
} }
} }
void colorGradationAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a) void colorGradationQuickAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a)
{ {
Color col; Color col;
col.r = r; col.r = r;
col.g = g; col.g = g;
col.b = b; col.b = b;
col.a = a; col.a = a;
colorGradationAdd(gradation, value, &col); colorGradationQuickAdd(gradation, value, &col);
} }
Color colorGradationGet(ColorGradation* gradation, double value) Color colorGradationGet(ColorGradation* gradation, double value)

View file

@ -8,6 +8,8 @@
extern "C" { extern "C" {
#endif #endif
void colorInit();
void colorSave(FILE* f, Color* col); void colorSave(FILE* f, Color* col);
void colorLoad(FILE* f, Color* col); void colorLoad(FILE* f, Color* col);
unsigned int colorTo32BitRGBA(Color* col); unsigned int colorTo32BitRGBA(Color* col);
@ -21,8 +23,13 @@ double colorGetValue(Color* col);
ColorGradation colorGradationCreate(); ColorGradation colorGradationCreate();
void colorGradationSave(FILE* f, ColorGradation* gradation); void colorGradationSave(FILE* f, ColorGradation* gradation);
void colorGradationLoad(FILE* f, ColorGradation* gradation); void colorGradationLoad(FILE* f, ColorGradation* gradation);
void colorGradationAdd(ColorGradation* gradation, double value, Color* col); int colorGradationGetPartCount(ColorGradation* gradation);
void colorGradationAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a); int colorGradationAddPart(ColorGradation* gradation);
void colorGradationDelPart(ColorGradation* gradation, int part);
ColorGradationPart colorGradationGetPart(ColorGradation* gradation, int part);
void colorGradationSetPart(ColorGradation* gradation, int part, ColorGradationPart value);
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col);
void colorGradationQuickAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a);
Color colorGradationGet(ColorGradation* gradation, double value); Color colorGradationGet(ColorGradation* gradation, double value);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -8,6 +8,7 @@
#include "shared/constants.h" #include "shared/constants.h"
#include "auto.h" #include "auto.h"
#include "color.h"
#include "system.h" #include "system.h"
#include "camera.h" #include "camera.h"
#include "scenery.h" #include "scenery.h"
@ -21,6 +22,7 @@ void paysagesInit()
ilInit(); ilInit();
iluInit(); iluInit();
colorInit();
sceneryInit(); sceneryInit();
renderInit(); renderInit();

View file

@ -80,10 +80,10 @@ void skyValidateDefinition(SkyDefinition* definition)
haze = colorGradationGet(&definition->haze_color, definition->daytime); haze = colorGradationGet(&definition->haze_color, definition->daytime);
definition->_sky_gradation = colorGradationCreate(); definition->_sky_gradation = colorGradationCreate();
colorGradationAdd(&definition->_sky_gradation, 0.0, &haze); colorGradationQuickAdd(&definition->_sky_gradation, 0.0, &haze);
colorGradationAdd(&definition->_sky_gradation, definition->haze_height - definition->haze_smoothing, &haze); colorGradationQuickAdd(&definition->_sky_gradation, definition->haze_height - definition->haze_smoothing, &haze);
colorGradationAdd(&definition->_sky_gradation, definition->haze_height, &zenith); colorGradationQuickAdd(&definition->_sky_gradation, definition->haze_height, &zenith);
colorGradationAdd(&definition->_sky_gradation, 1.0, &zenith); colorGradationQuickAdd(&definition->_sky_gradation, 1.0, &zenith);
} }
int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights) int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)