Added layer coverage preview on new textures form

This commit is contained in:
Michaël Lemaire 2013-08-21 23:19:47 +02:00
parent 08b481df7d
commit 171df529fa
8 changed files with 137 additions and 8 deletions

View file

@ -75,7 +75,8 @@ HEADERS += \
lighting/DialogMaterialEditor.h \ lighting/DialogMaterialEditor.h \
common/DrawingWidget.h \ common/DrawingWidget.h \
lighting/SmallPreviewColor.h \ lighting/SmallPreviewColor.h \
lighting/SmallPreviewHues.h lighting/SmallPreviewHues.h \
textures/PreviewLayerCoverage.h
SOURCES += \ SOURCES += \
terrain/widgetheightmap.cpp \ terrain/widgetheightmap.cpp \
@ -130,7 +131,8 @@ SOURCES += \
lighting/DialogMaterialEditor.cpp \ lighting/DialogMaterialEditor.cpp \
common/DrawingWidget.cpp \ common/DrawingWidget.cpp \
lighting/SmallPreviewColor.cpp \ lighting/SmallPreviewColor.cpp \
lighting/SmallPreviewHues.cpp lighting/SmallPreviewHues.cpp \
textures/PreviewLayerCoverage.cpp
FORMS += \ FORMS += \
terrain/dialogterrainpainting.ui \ terrain/dialogterrainpainting.ui \

View file

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

View file

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

View file

@ -5,6 +5,7 @@
#include "../common/freelayerhelper.h" #include "../common/freelayerhelper.h"
#include "rendering/scenery.h" #include "rendering/scenery.h"
#include "previewmaterial.h" #include "previewmaterial.h"
#include "editing/textures/PreviewLayerCoverage.h"
MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm) 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->setRenderButton(ui->button_render);
form_helper->startManaging(); 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())); 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_coverage->setEnabled(true);
ui->preview_texture->setEnabled(true); ui->preview_texture->setEnabled(true);
preview_layer_coverage->setLayer(layer);
ui->preview_coverage->redraw();
ui->preview_texture->redraw();
} }
} }

View file

@ -10,6 +10,7 @@ class MainTexturesForm;
class FreeFormHelper; class FreeFormHelper;
class FreeLayerHelper; class FreeLayerHelper;
class PreviewLayerCoverage;
class MainTexturesForm : public QWidget class MainTexturesForm : public QWidget
{ {
@ -28,12 +29,14 @@ public slots:
void updateLayers(); void updateLayers();
void selectLayer(int layer); void selectLayer(int layer);
void selectPreset(int preset);
private: private:
Ui::MainTexturesForm *ui; Ui::MainTexturesForm *ui;
TexturesDefinition* textures; TexturesDefinition* textures;
FreeFormHelper* form_helper; FreeFormHelper* form_helper;
FreeLayerHelper* layer_helper; FreeLayerHelper* layer_helper;
PreviewLayerCoverage* preview_layer_coverage;
}; };
#endif // MAINTEXTURESFORM_H #endif // MAINTEXTURESFORM_H

View file

@ -98,12 +98,6 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP
double texturesGetMaximalDisplacement(TexturesDefinition* textures); 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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,2 +1,41 @@
#include "tex_preview.h"
#include "private.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;
}

View file

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