From fabcec1cfd0de78feb1cde794e827a5d156777e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 21 Feb 2012 13:41:02 +0000 Subject: [PATCH] paysages : ColorGradation dialog. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@271 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseform.cpp | 18 +++++-- gui_qt/baseform.h | 4 +- gui_qt/{preview.cpp => basepreview.cpp} | 34 ++++++------ gui_qt/{preview.h => basepreview.h} | 10 ++-- gui_qt/dialogcolorgradation.cpp | 72 +++++++++++++++++++++---- gui_qt/dialogcolorgradation.h | 2 + gui_qt/dialognoise.cpp | 8 +-- gui_qt/dialognoise.h | 6 +-- gui_qt/formatmosphere.cpp | 4 +- gui_qt/formatmosphere.h | 4 +- gui_qt/formclouds.cpp | 8 +-- gui_qt/formclouds.h | 6 +-- gui_qt/formlighting.h | 4 +- gui_qt/formsky.cpp | 8 +-- gui_qt/formsky.h | 6 +-- gui_qt/formterrain.cpp | 8 +-- gui_qt/formterrain.h | 6 +-- gui_qt/formtextures.h | 6 +-- gui_qt/formwater.cpp | 10 ++-- gui_qt/formwater.h | 6 +-- lib_paysages/auto.c | 34 ++++++------ lib_paysages/color.c | 61 +++++++++++++++++++-- lib_paysages/color.h | 11 +++- lib_paysages/main.c | 2 + lib_paysages/sky.c | 8 +-- 25 files changed, 236 insertions(+), 110 deletions(-) rename gui_qt/{preview.cpp => basepreview.cpp} (94%) rename gui_qt/{preview.h => basepreview.h} (86%) diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index ca13a69..20b1597 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -96,7 +96,7 @@ void BaseForm::configChangeEvent() button_revert->setEnabled(true); } - QList list_previews = previews->findChildren("_form_preview_"); + QList list_previews = previews->findChildren("_form_preview_"); for (int i = 0; i < list_previews.size(); i++) { list_previews[i]->redraw(); @@ -148,7 +148,7 @@ void BaseForm::layerListChanged() 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(preview); @@ -238,7 +238,17 @@ void BaseForm::setLayerCount(int layer_count) { layer_list->addItem(QString("Layer %1").arg(i + 1)); } - layer_list->setCurrentIndex(selected); + if (selected >= 0) + { + if (selected > layer_count) + { + layer_list->setCurrentIndex(layer_count - 1); + } + else + { + layer_list->setCurrentIndex(selected); + } + } } } @@ -261,7 +271,7 @@ void BaseForm::layerSelectedEvent(int layer) inputs[i]->revert(); } - QList list_previews = previews->findChildren("_form_preview_"); + QList list_previews = previews->findChildren("_form_preview_"); for (int i = 0; i < list_previews.size(); i++) { list_previews[i]->redraw(); diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index ce9cfd8..877e4f4 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -4,7 +4,7 @@ #include #include #include -#include "preview.h" +#include "basepreview.h" #include "baseinput.h" #include "../lib_paysages/shared/types.h" #include "../lib_paysages/noise.h" @@ -32,7 +32,7 @@ private slots: void layerListChanged(); protected: - void addPreview(Preview* preview, QString label); + void addPreview(BasePreview* preview, QString label); QPushButton* addButton(QString label); void addInput(BaseInput* input); void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step); diff --git a/gui_qt/preview.cpp b/gui_qt/basepreview.cpp similarity index 94% rename from gui_qt/preview.cpp rename to gui_qt/basepreview.cpp index 3f9e422..ff1f504 100644 --- a/gui_qt/preview.cpp +++ b/gui_qt/basepreview.cpp @@ -1,4 +1,4 @@ -#include "preview.h" +#include "basepreview.h" #include #include @@ -8,7 +8,7 @@ class PreviewDrawer:public QThread { public: - PreviewDrawer(Preview* preview): + PreviewDrawer(BasePreview* preview): QThread(), _preview(preview) { @@ -29,11 +29,11 @@ protected: } } private: - Preview* _preview; + BasePreview* _preview; bool _running; }; -Preview::Preview(QWidget* parent) : +BasePreview::BasePreview(QWidget* parent) : QWidget(parent) { this->lock_drawing = new QMutex(); @@ -65,7 +65,7 @@ Preview::Preview(QWidget* parent) : this->updater = new PreviewDrawer(this); } -Preview::~Preview() +BasePreview::~BasePreview() { alive = false; @@ -77,21 +77,21 @@ Preview::~Preview() 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); } -void Preview::start() +void BasePreview::start() { this->updater->start(); } -void Preview::doRender() +void BasePreview::doRender() { if (this->alive) { @@ -107,12 +107,12 @@ void Preview::doRender() } } -void Preview::redraw() +void BasePreview::redraw() { emit(redrawRequested()); } -void Preview::handleRedraw() +void BasePreview::handleRedraw() { need_rerender = true; lock_drawing->lock(); @@ -121,14 +121,14 @@ void Preview::handleRedraw() lock_drawing->unlock(); } -void Preview::setScaling(double scaling) +void BasePreview::setScaling(double scaling) { // TODO Follow conf_scale this->scaling = scaling; redraw(); } -void Preview::resizeEvent(QResizeEvent* event) +void BasePreview::resizeEvent(QResizeEvent* event) { QImage* image; @@ -147,13 +147,13 @@ void Preview::resizeEvent(QResizeEvent* event) this->lock_drawing->unlock(); } -void Preview::paintEvent(QPaintEvent* event) +void BasePreview::paintEvent(QPaintEvent* event) { QPainter painter(this); painter.drawImage(0, 0, *this->pixbuf); } -void Preview::forceRender() +void BasePreview::forceRender() { this->lock_drawing->lock(); this->pixbuf->fill(0x00000000); @@ -162,7 +162,7 @@ void Preview::forceRender() this->lock_drawing->unlock(); } -void Preview::renderPixbuf() +void BasePreview::renderPixbuf() { QColor col; bool done; @@ -205,7 +205,7 @@ void Preview::renderPixbuf() } } -void Preview::wheelEvent(QWheelEvent* event) +void BasePreview::wheelEvent(QWheelEvent* event) { if (event->orientation() == Qt::Vertical) { diff --git a/gui_qt/preview.h b/gui_qt/basepreview.h similarity index 86% rename from gui_qt/preview.h rename to gui_qt/basepreview.h index 3ed0981..67767e5 100644 --- a/gui_qt/preview.h +++ b/gui_qt/basepreview.h @@ -1,18 +1,18 @@ -#ifndef _PAYSAGES_QT_PREVIEW_H_ -#define _PAYSAGES_QT_PREVIEW_H_ +#ifndef _PAYSAGES_QT_BASEPREVIEW_H_ +#define _PAYSAGES_QT_BASEPREVIEW_H_ #include #include #include #include -class Preview:public QWidget +class BasePreview:public QWidget { Q_OBJECT public: - Preview(QWidget* parent); - ~Preview(); + BasePreview(QWidget* parent); + ~BasePreview(); void start(); void doRender(); diff --git a/gui_qt/dialogcolorgradation.cpp b/gui_qt/dialogcolorgradation.cpp index aeda5d4..09d1e07 100644 --- a/gui_qt/dialogcolorgradation.cpp +++ b/gui_qt/dialogcolorgradation.cpp @@ -9,43 +9,92 @@ #include #include #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 { public: FormColorGradation(QWidget* parent, ColorGradation* gradation):BaseForm(parent, true, true) { + QPushButton* button; _gradation = gradation; + addPreview(new PreviewColorGradation(this, _gradation), "Preview"); + addInputDouble("Position", &_layer.start, 0.0, 1.0, 0.01, 0.1); 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() { - /*if (cloudsAddLayer(&_definition) >= 0) + if (colorGradationAddPart(_gradation) >= 0) { BaseForm::layerAddedEvent(); - }*/ + } } void layerDeletedEvent(int layer) { - /*cloudsDeleteLayer(&_definition, layer); + colorGradationDelPart(_gradation, layer); - BaseForm::layerDeletedEvent(layer);*/ + BaseForm::layerDeletedEvent(layer); } void layerSelectedEvent(int layer) { - _layer = _gradation->parts[layer]; + _layer = colorGradationGetPart(_gradation, layer); BaseForm::layerSelectedEvent(layer); } @@ -60,18 +109,18 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad QDialog(parent) { QWidget* preview; - BaseForm* form; _base = gradation; _current = colorGradationCreate(); + _current = *_base; setLayout(new QHBoxLayout()); preview = new QWidget(this); layout()->addWidget(preview); - form = new FormColorGradation(this, &_current); - layout()->addWidget(form); + _form = new FormColorGradation(this, &_current); + layout()->addWidget(_form); /*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert())); @@ -118,4 +167,5 @@ void DialogColorGradation::revert() void DialogColorGradation::revertToCurrent() { + _form->revertConfig(); } diff --git a/gui_qt/dialogcolorgradation.h b/gui_qt/dialogcolorgradation.h index e66ea20..6c908e7 100644 --- a/gui_qt/dialogcolorgradation.h +++ b/gui_qt/dialogcolorgradation.h @@ -2,6 +2,7 @@ #define _PAYSAGES_QT_DIALOGCOLORGRADATION_H_ #include +#include "baseform.h" #include "../lib_paysages/color.h" @@ -27,6 +28,7 @@ private: private: ColorGradation* _base; ColorGradation _current; + BaseForm* _form; }; #endif diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index 48f44b7..f899d29 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -10,10 +10,10 @@ #include /**************** Previews ****************/ -class PreviewLevel:public Preview +class PreviewLevel:public BasePreview { public: - PreviewLevel(QWidget* parent, NoiseGenerator* noise): Preview(parent) + PreviewLevel(QWidget* parent, NoiseGenerator* noise): BasePreview(parent) { _noise_original = noise; _noise_preview = noiseCreateGenerator(); @@ -47,10 +47,10 @@ private: int _level; }; -class PreviewTotal:public Preview +class PreviewTotal:public BasePreview { public: - PreviewTotal(QWidget* parent, NoiseGenerator* noise): Preview(parent) + PreviewTotal(QWidget* parent, NoiseGenerator* noise): BasePreview(parent) { _noise_original = noise; _noise_preview = noiseCreateGenerator(); diff --git a/gui_qt/dialognoise.h b/gui_qt/dialognoise.h index c17a6b9..a6192ce 100644 --- a/gui_qt/dialognoise.h +++ b/gui_qt/dialognoise.h @@ -3,7 +3,7 @@ #include #include -#include "preview.h" +#include "basepreview.h" #include "../lib_paysages/noise.h" @@ -38,8 +38,8 @@ private: NoiseGenerator* _current; int _current_level; NoiseLevel _current_level_params; - Preview* previewLevel; - Preview* previewTotal; + BasePreview* previewLevel; + BasePreview* previewTotal; QListWidget* levels; QSlider* slider_height; QSlider* slider_scaling; diff --git a/gui_qt/formatmosphere.cpp b/gui_qt/formatmosphere.cpp index 7e46732..c96a2eb 100644 --- a/gui_qt/formatmosphere.cpp +++ b/gui_qt/formatmosphere.cpp @@ -9,11 +9,11 @@ static AtmosphereDefinition _definition; /**************** Previews ****************/ -class PreviewAtmosphereColor:public Preview +class PreviewAtmosphereColor:public BasePreview { public: PreviewAtmosphereColor(QWidget* parent): - Preview(parent) + BasePreview(parent) { _renderer = rendererCreate(); _preview_definition = atmosphereCreateDefinition(); diff --git a/gui_qt/formatmosphere.h b/gui_qt/formatmosphere.h index 20b6b93..52d6347 100644 --- a/gui_qt/formatmosphere.h +++ b/gui_qt/formatmosphere.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMATMOSPHERE_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormAtmosphere : public BaseForm @@ -20,7 +20,7 @@ protected slots: virtual void configChangeEvent(); private: - Preview* previewColor; + BasePreview* previewColor; }; #endif diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index c4eccc4..47c4b60 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -12,10 +12,10 @@ static CloudsDefinition _definition; static CloudsLayerDefinition _layer; /**************** Previews ****************/ -class PreviewCloudsCoverage:public Preview +class PreviewCloudsCoverage:public BasePreview { public: - PreviewCloudsCoverage(QWidget* parent):Preview(parent) + PreviewCloudsCoverage(QWidget* parent):BasePreview(parent) { _renderer = rendererCreate(); _renderer.render_quality = 3; @@ -51,10 +51,10 @@ private: CloudsLayerDefinition _preview_layer; }; -class PreviewCloudsColor:public Preview +class PreviewCloudsColor:public BasePreview { public: - PreviewCloudsColor(QWidget* parent):Preview(parent) + PreviewCloudsColor(QWidget* parent):BasePreview(parent) { LightDefinition light; diff --git a/gui_qt/formclouds.h b/gui_qt/formclouds.h index 84a900e..1fb0e05 100644 --- a/gui_qt/formclouds.h +++ b/gui_qt/formclouds.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMCLOUDS_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormClouds : public BaseForm @@ -25,8 +25,8 @@ protected: virtual void layerSelectedEvent(int layer); private: - Preview* previewCoverage; - Preview* previewColor; + BasePreview* previewCoverage; + BasePreview* previewColor; }; #endif diff --git a/gui_qt/formlighting.h b/gui_qt/formlighting.h index acfd37e..64175ab 100644 --- a/gui_qt/formlighting.h +++ b/gui_qt/formlighting.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMLIGHTING_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormLighting : public BaseForm @@ -20,7 +20,7 @@ protected slots: virtual void configChangeEvent(); private: - Preview* previewColor; + BasePreview* previewColor; }; #endif diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index 37104ce..ec7fadb 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -14,11 +14,11 @@ static SkyDefinition _definition; /**************** Previews ****************/ -class PreviewSkyEast:public Preview +class PreviewSkyEast:public BasePreview { public: PreviewSkyEast(QWidget* parent): - Preview(parent) + BasePreview(parent) { _renderer = rendererCreate(); _preview_definition = skyCreateDefinition(); @@ -44,11 +44,11 @@ private: SkyDefinition _preview_definition; }; -class PreviewSkyWest:public Preview +class PreviewSkyWest:public BasePreview { public: PreviewSkyWest(QWidget* parent): - Preview(parent) + BasePreview(parent) { _renderer = rendererCreate(); _preview_definition = skyCreateDefinition(); diff --git a/gui_qt/formsky.h b/gui_qt/formsky.h index 2a792dc..29bfda4 100644 --- a/gui_qt/formsky.h +++ b/gui_qt/formsky.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMSKY_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormSky : public BaseForm @@ -20,8 +20,8 @@ protected slots: virtual void configChangeEvent(); private: - Preview* previewEast; - Preview* previewWest; + BasePreview* previewEast; + BasePreview* previewWest; }; #endif // _PAYSAGES_QT_FORMSKY_H_ diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index e7c2275..45b8e79 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -12,10 +12,10 @@ static TerrainDefinition _definition; /**************** Previews ****************/ -class PreviewTerrainHeight:public Preview +class PreviewTerrainHeight:public BasePreview { public: - PreviewTerrainHeight(QWidget* parent):Preview(parent) + PreviewTerrainHeight(QWidget* parent):BasePreview(parent) { _preview_definition = terrainCreateDefinition(); } @@ -35,10 +35,10 @@ private: TerrainDefinition _preview_definition; }; -class PreviewTerrainColor:public Preview +class PreviewTerrainColor:public BasePreview { public: - PreviewTerrainColor(QWidget* parent):Preview(parent) + PreviewTerrainColor(QWidget* parent):BasePreview(parent) { _renderer = rendererCreate(); _renderer.applyTextures = _applyTextures; diff --git a/gui_qt/formterrain.h b/gui_qt/formterrain.h index 14877b0..15bf5a8 100644 --- a/gui_qt/formterrain.h +++ b/gui_qt/formterrain.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMTERRAIN_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormTerrain : public BaseForm @@ -20,8 +20,8 @@ protected slots: virtual void configChangeEvent(); private: - Preview* previewHeight; - Preview* previewColor; + BasePreview* previewHeight; + BasePreview* previewColor; }; #endif diff --git a/gui_qt/formtextures.h b/gui_qt/formtextures.h index 56276aa..a5b94f9 100644 --- a/gui_qt/formtextures.h +++ b/gui_qt/formtextures.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMTEXTURES_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormTextures : public BaseForm @@ -20,8 +20,8 @@ protected slots: virtual void configChangeEvent(); private: - Preview* previewCoverage; - Preview* previewColor; + BasePreview* previewCoverage; + BasePreview* previewColor; }; #endif diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 39d6823..28ad82b 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -1,4 +1,4 @@ -#include "preview.h" +#include "basepreview.h" #include "formwater.h" #include @@ -17,10 +17,10 @@ static WaterDefinition _definition; /**************** Previews ****************/ -class PreviewWaterCoverage:public Preview +class PreviewWaterCoverage:public BasePreview { public: - PreviewWaterCoverage(QWidget* parent):Preview(parent) + PreviewWaterCoverage(QWidget* parent):BasePreview(parent) { _water = waterCreateDefinition(); _terrain = terrainCreateDefinition(); @@ -51,10 +51,10 @@ private: TerrainDefinition _terrain; }; -class PreviewWaterColor:public Preview +class PreviewWaterColor:public BasePreview { public: - PreviewWaterColor(QWidget* parent):Preview(parent) + PreviewWaterColor(QWidget* parent):BasePreview(parent) { LightDefinition light; diff --git a/gui_qt/formwater.h b/gui_qt/formwater.h index 76093ba..1305779 100644 --- a/gui_qt/formwater.h +++ b/gui_qt/formwater.h @@ -2,7 +2,7 @@ #define _PAYSAGES_QT_FORMWATER_H_ #include -#include "preview.h" +#include "basepreview.h" #include "baseform.h" class FormWater : public BaseForm @@ -17,8 +17,8 @@ public slots: virtual void applyConfig(); private: - Preview* previewCoverage; - Preview* previewColor; + BasePreview* previewCoverage; + BasePreview* previewColor; }; #endif // _PAYSAGES_QT_FORMWATER_H_ diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 1a2a175..19450f9 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -108,23 +108,23 @@ void autoGenRealisticLandscape(int seed) /* Sky */ sky = skyCreateDefinition(); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&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); - colorGradationAddRgba(&sky.haze_color, 0.8, 0.05, 0.05, 0.08, 1.0); + colorGradationQuickAddRgba(&sky.sun_color, 0.3, 1.0, 0.91, 0.8, 1.0); + colorGradationQuickAddRgba(&sky.sun_color, 0.5, 1.0, 0.95, 0.9, 1.0); + colorGradationQuickAddRgba(&sky.sun_color, 0.7, 1.0, 0.91, 0.8, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.2, 0.03, 0.03, 0.05, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.25, 0.25, 0.33, 0.37, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.35, 0.52, 0.63, 0.8, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.65, 0.52, 0.63, 0.8, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.75, 0.25, 0.33, 0.37, 1.0); + colorGradationQuickAddRgba(&sky.zenith_color, 0.8, 0.03, 0.03, 0.05, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.2, 0.05, 0.05, 0.08, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.25, 0.55, 0.42, 0.42, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.3, 0.6, 0.6, 0.6, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.4, 0.92, 0.93, 1.0, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.6, 0.92, 0.93, 1.0, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.7, 0.6, 0.6, 0.8, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.75, 0.62, 0.50, 0.42, 1.0); + colorGradationQuickAddRgba(&sky.haze_color, 0.8, 0.05, 0.05, 0.08, 1.0); sky.daytime = 0.0; sky.haze_height = 0.75; sky.haze_smoothing = 0.3; diff --git a/lib_paysages/color.c b/lib_paysages/color.c index b2360b8..f8a7470 100644 --- a/lib_paysages/color.c +++ b/lib_paysages/color.c @@ -2,6 +2,7 @@ #include #include +#include #include "shared/constants.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_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) { 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) { @@ -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; col.r = r; col.g = g; col.b = b; col.a = a; - colorGradationAdd(gradation, value, &col); + colorGradationQuickAdd(gradation, value, &col); } Color colorGradationGet(ColorGradation* gradation, double value) diff --git a/lib_paysages/color.h b/lib_paysages/color.h index ff7727d..b9a8527 100644 --- a/lib_paysages/color.h +++ b/lib_paysages/color.h @@ -8,6 +8,8 @@ extern "C" { #endif +void colorInit(); + void colorSave(FILE* f, Color* col); void colorLoad(FILE* f, Color* col); unsigned int colorTo32BitRGBA(Color* col); @@ -21,8 +23,13 @@ double colorGetValue(Color* col); ColorGradation colorGradationCreate(); void colorGradationSave(FILE* f, ColorGradation* gradation); void colorGradationLoad(FILE* f, ColorGradation* gradation); -void colorGradationAdd(ColorGradation* gradation, double value, Color* col); -void colorGradationAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a); +int colorGradationGetPartCount(ColorGradation* gradation); +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); #ifdef __cplusplus diff --git a/lib_paysages/main.c b/lib_paysages/main.c index 042b341..a38bee4 100644 --- a/lib_paysages/main.c +++ b/lib_paysages/main.c @@ -8,6 +8,7 @@ #include "shared/constants.h" #include "auto.h" +#include "color.h" #include "system.h" #include "camera.h" #include "scenery.h" @@ -21,6 +22,7 @@ void paysagesInit() ilInit(); iluInit(); + colorInit(); sceneryInit(); renderInit(); diff --git a/lib_paysages/sky.c b/lib_paysages/sky.c index 0203213..cd9876e 100644 --- a/lib_paysages/sky.c +++ b/lib_paysages/sky.c @@ -80,10 +80,10 @@ void skyValidateDefinition(SkyDefinition* definition) haze = colorGradationGet(&definition->haze_color, definition->daytime); definition->_sky_gradation = colorGradationCreate(); - colorGradationAdd(&definition->_sky_gradation, 0.0, &haze); - colorGradationAdd(&definition->_sky_gradation, definition->haze_height - definition->haze_smoothing, &haze); - colorGradationAdd(&definition->_sky_gradation, definition->haze_height, &zenith); - colorGradationAdd(&definition->_sky_gradation, 1.0, &zenith); + colorGradationQuickAdd(&definition->_sky_gradation, 0.0, &haze); + colorGradationQuickAdd(&definition->_sky_gradation, definition->haze_height - definition->haze_smoothing, &haze); + colorGradationQuickAdd(&definition->_sky_gradation, definition->haze_height, &zenith); + colorGradationQuickAdd(&definition->_sky_gradation, 1.0, &zenith); } int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)