From 171df529fac5f47c2ff2f149bc6888b893ff3cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 21 Aug 2013 23:19:47 +0200 Subject: [PATCH] Added layer coverage preview on new textures form --- src/editing/paysages-qt.pro | 6 ++- src/editing/textures/PreviewLayerCoverage.cpp | 38 ++++++++++++++++++ src/editing/textures/PreviewLayerCoverage.h | 24 ++++++++++++ src/editing/textures/maintexturesform.cpp | 10 +++++ src/editing/textures/maintexturesform.h | 3 ++ src/rendering/textures/public.h | 6 --- src/rendering/textures/tex_preview.c | 39 +++++++++++++++++++ src/rendering/textures/tex_preview.h | 19 +++++++++ 8 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 src/editing/textures/PreviewLayerCoverage.cpp create mode 100644 src/editing/textures/PreviewLayerCoverage.h create mode 100644 src/rendering/textures/tex_preview.h diff --git a/src/editing/paysages-qt.pro b/src/editing/paysages-qt.pro index 0ca58cc..d886944 100644 --- a/src/editing/paysages-qt.pro +++ b/src/editing/paysages-qt.pro @@ -75,7 +75,8 @@ HEADERS += \ lighting/DialogMaterialEditor.h \ common/DrawingWidget.h \ lighting/SmallPreviewColor.h \ - lighting/SmallPreviewHues.h + lighting/SmallPreviewHues.h \ + textures/PreviewLayerCoverage.h SOURCES += \ terrain/widgetheightmap.cpp \ @@ -130,7 +131,8 @@ SOURCES += \ lighting/DialogMaterialEditor.cpp \ common/DrawingWidget.cpp \ lighting/SmallPreviewColor.cpp \ - lighting/SmallPreviewHues.cpp + lighting/SmallPreviewHues.cpp \ + textures/PreviewLayerCoverage.cpp FORMS += \ terrain/dialogterrainpainting.ui \ diff --git a/src/editing/textures/PreviewLayerCoverage.cpp b/src/editing/textures/PreviewLayerCoverage.cpp new file mode 100644 index 0000000..156173f --- /dev/null +++ b/src/editing/textures/PreviewLayerCoverage.cpp @@ -0,0 +1,38 @@ +#include "PreviewLayerCoverage.h" + +#include "editing/basepreview.h" +#include "rendering/textures/tex_preview.h" + +void PreviewLayerCoverage::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void PreviewLayerCoverage::setLayer(int layer) +{ + this->layer = layer; +} + +void PreviewLayerCoverage::bindEvent(BasePreview* preview) +{ + preview->addOsd(QString("geolocation")); + + preview->configScaling(20.0, 1000.0, 20.0, 200.0); + preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); +} + +void PreviewLayerCoverage::updateEvent() +{ + if (textures) + { + TexturesPreviewLayerCoverage_bind(renderer, textures); + } +} + +Color PreviewLayerCoverage::getColor2D(double x, double y, double scaling) +{ + if (textures) + { + return TexturesPreviewLayerCoverage_getColor(renderer, x, y, scaling, layer); + } +} diff --git a/src/editing/textures/PreviewLayerCoverage.h b/src/editing/textures/PreviewLayerCoverage.h new file mode 100644 index 0000000..67ce0be --- /dev/null +++ b/src/editing/textures/PreviewLayerCoverage.h @@ -0,0 +1,24 @@ +#ifndef EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H +#define EDITING_TEXTURES_PREVIEWLAYERCOVERAGE_H + +#include "editing/common/previewrenderer.h" + +class BasePreview; + +class PreviewLayerCoverage : public PreviewRenderer +{ +public: + void setTextures(TexturesDefinition* textures); + void setLayer(int layer); + +protected: + virtual void bindEvent(BasePreview* preview); + virtual void updateEvent(); + virtual Color getColor2D(double x, double y, double scaling); + +private: + TexturesDefinition* textures = 0; + int layer; +}; + +#endif diff --git a/src/editing/textures/maintexturesform.cpp b/src/editing/textures/maintexturesform.cpp index 42579c1..602c8b2 100644 --- a/src/editing/textures/maintexturesform.cpp +++ b/src/editing/textures/maintexturesform.cpp @@ -5,6 +5,7 @@ #include "../common/freelayerhelper.h" #include "rendering/scenery.h" #include "previewmaterial.h" +#include "editing/textures/PreviewLayerCoverage.h" MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm) { @@ -28,6 +29,10 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui form_helper->setRenderButton(ui->button_render); form_helper->startManaging(); + preview_layer_coverage = new PreviewLayerCoverage(); + preview_layer_coverage->setTextures(textures); + form_helper->addPreview(ui->preview_coverage, preview_layer_coverage); + connect(layer_helper, SIGNAL(layersChanged()), form_helper, SLOT(processDataChange())); } @@ -79,6 +84,11 @@ void MainTexturesForm::selectLayer(int layer) { ui->preview_coverage->setEnabled(true); ui->preview_texture->setEnabled(true); + + preview_layer_coverage->setLayer(layer); + + ui->preview_coverage->redraw(); + ui->preview_texture->redraw(); } } diff --git a/src/editing/textures/maintexturesform.h b/src/editing/textures/maintexturesform.h index 49ef3f8..496427e 100644 --- a/src/editing/textures/maintexturesform.h +++ b/src/editing/textures/maintexturesform.h @@ -10,6 +10,7 @@ class MainTexturesForm; class FreeFormHelper; class FreeLayerHelper; +class PreviewLayerCoverage; class MainTexturesForm : public QWidget { @@ -28,12 +29,14 @@ public slots: void updateLayers(); void selectLayer(int layer); + void selectPreset(int preset); private: Ui::MainTexturesForm *ui; TexturesDefinition* textures; FreeFormHelper* form_helper; FreeLayerHelper* layer_helper; + PreviewLayerCoverage* preview_layer_coverage; }; #endif // MAINTEXTURESFORM_H diff --git a/src/rendering/textures/public.h b/src/rendering/textures/public.h index a4bfad3..ac92ff7 100644 --- a/src/rendering/textures/public.h +++ b/src/rendering/textures/public.h @@ -98,12 +98,6 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP double texturesGetMaximalDisplacement(TexturesDefinition* textures); -/*Renderer* cloudsCreatePreviewCoverageRenderer(); -Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective); - -Renderer* cloudsCreatePreviewColorRenderer(); -Color cloudsGetPreviewColor(Renderer* renderer, double x, double y);*/ - #ifdef __cplusplus } #endif diff --git a/src/rendering/textures/tex_preview.c b/src/rendering/textures/tex_preview.c index bd0db8d..477b95e 100644 --- a/src/rendering/textures/tex_preview.c +++ b/src/rendering/textures/tex_preview.c @@ -1,2 +1,41 @@ +#include "tex_preview.h" #include "private.h" +#include "rendering/scenery.h" +#include "rendering/tools.h" + +void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition) +{ + TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); + sceneryGetTerrain(renderer->terrain->definition); + TerrainRendererClass.bind(renderer, terrain); + TerrainDefinitionClass.destroy(terrain); + + TexturesRendererClass.bind(renderer, definition); +} + +Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double y, double scaling, int layer) +{ + UNUSED(scaling); + + TexturesLayerDefinition* layerdef; + TerrainResult terrain; + double presence; + Color result; + + layerdef = (TexturesLayerDefinition*)layersGetLayer(renderer->textures->definition->layers, layer); + if (layerdef) + { + terrain = renderer->terrain->getResult(renderer, x, y, 1, 1); + presence = texturesGetLayerBasePresence(layerdef, terrain); + + result.r = result.g = result.b = presence; + result.a = 1.0; + } + else + { + result = COLOR_BLACK; + } + + return result; +} diff --git a/src/rendering/textures/tex_preview.h b/src/rendering/textures/tex_preview.h new file mode 100644 index 0000000..17ef7da --- /dev/null +++ b/src/rendering/textures/tex_preview.h @@ -0,0 +1,19 @@ +#ifndef TEX_PREVIEW_H +#define TEX_PREVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "rendering/renderer.h" +#include "rendering/textures/public.h" + +/* Single layer coverage */ +void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition); +Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double y, double scaling, int layer); + +#ifdef __cplusplus +} +#endif + +#endif