Restored choice and toggles working on preview renderers
This commit is contained in:
parent
684a64158c
commit
7fecdba313
17 changed files with 220 additions and 144 deletions
|
@ -16,92 +16,7 @@
|
|||
#include "BasePreview.h"
|
||||
#include "CloudsDefinition.h"
|
||||
#include "CameraDefinition.h"
|
||||
|
||||
/**************** Previews ****************/
|
||||
class PreviewRenderLandscape : public BasePreview
|
||||
{
|
||||
public:
|
||||
PreviewRenderLandscape(QWidget* parent) : BasePreview(parent)
|
||||
{
|
||||
_renderer = new SoftwareRenderer();
|
||||
_renderer->getCameraLocation = _getCameraLocation;
|
||||
lightingManagerDisableSpecularity(_renderer->lighting);
|
||||
|
||||
_no_clouds = new CloudsDefinition(NULL);
|
||||
_clouds_enabled = true;
|
||||
|
||||
addOsd(QString("geolocation"));
|
||||
addToggle("clouds", tr("Clouds"), false);
|
||||
|
||||
configHdrToneMapping(true);
|
||||
configScaling(0.5, 200.0, 3.0, 50.0);
|
||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
~PreviewRenderLandscape()
|
||||
{
|
||||
delete _renderer;
|
||||
delete _no_clouds;
|
||||
}
|
||||
|
||||
protected:
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
Vector3 location;
|
||||
double height = _renderer->terrain->getHeight(_renderer, x, y, 1);
|
||||
|
||||
if (height < _renderer->water->getHeightInfo(_renderer).max_height)
|
||||
{
|
||||
return _renderer->water->getResult(_renderer, x, y).final;
|
||||
}
|
||||
else
|
||||
{
|
||||
location.x = x;
|
||||
location.y = height;
|
||||
location.z = y;
|
||||
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
||||
}
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
RenderingScenery::getCurrent()->bindToRenderer(_renderer);
|
||||
if (!_clouds_enabled)
|
||||
{
|
||||
CloudsRendererClass.bind(_renderer, _no_clouds);
|
||||
}
|
||||
|
||||
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
||||
}
|
||||
|
||||
void toggleChangeEvent(QString key, bool value)
|
||||
{
|
||||
if (key == "clouds")
|
||||
{
|
||||
_clouds_enabled = value;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SoftwareRenderer* _renderer;
|
||||
bool _clouds_enabled;
|
||||
CloudsDefinition* _no_clouds;
|
||||
|
||||
static Vector3 _getCameraLocation(Renderer*, Vector3 location)
|
||||
{
|
||||
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
|
||||
}
|
||||
|
||||
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
||||
{
|
||||
AtmosphereResult result;
|
||||
atmosphereInitResult(&result);
|
||||
result.base = base;
|
||||
result.final = base;
|
||||
atmosphereUpdateResult(&result);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
#include "SceneryTopDownPreviewRenderer.h"
|
||||
|
||||
/**************** Form ****************/
|
||||
FormRender::FormRender(QWidget *parent) :
|
||||
|
@ -119,8 +34,10 @@ BaseForm(parent, true)
|
|||
|
||||
disablePreviewsUpdate();
|
||||
|
||||
_preview_landscape = new PreviewRenderLandscape(this);
|
||||
_preview_landscape = new BasePreview(this);
|
||||
_preview_landscape_renderer = new SceneryTopDownPreviewRenderer(RenderingScenery::getCurrent());
|
||||
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
||||
_preview_landscape->setRenderer(_preview_landscape_renderer);
|
||||
|
||||
addInput(new InputCamera(this, tr("Camera"), _camera));
|
||||
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);
|
||||
|
|
|
@ -32,6 +32,7 @@ private:
|
|||
Renderer* _renderer;
|
||||
bool _renderer_inited;
|
||||
BasePreview* _preview_landscape;
|
||||
Base2dPreviewRenderer* _preview_landscape_renderer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,14 @@ void Base2dPreviewRenderer::bindEvent(BasePreview*)
|
|||
{
|
||||
}
|
||||
|
||||
void Base2dPreviewRenderer::toggleChangeEvent(const std::string &, bool)
|
||||
{
|
||||
}
|
||||
|
||||
void Base2dPreviewRenderer::choiceChangeEvent(const std::string &, int)
|
||||
{
|
||||
}
|
||||
|
||||
void Base2dPreviewRenderer::updateEvent()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ public:
|
|||
|
||||
virtual void bindEvent(BasePreview* preview);
|
||||
|
||||
virtual void toggleChangeEvent(const std::string &key, bool value);
|
||||
virtual void choiceChangeEvent(const std::string &key, int position);
|
||||
|
||||
virtual void updateEvent();
|
||||
virtual void cameraEvent(double x, double y, double scaling);
|
||||
virtual Color getColor2D(double x, double y, double scaling);
|
||||
|
|
|
@ -551,7 +551,7 @@ void BasePreview::configScrolling(double xmin, double xmax, double xinit, double
|
|||
redraw();
|
||||
}
|
||||
|
||||
void BasePreview::addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value)
|
||||
void BasePreview::addChoice(const QString &key, const QString &title, const QStringList &choices, int init_value)
|
||||
{
|
||||
_ContextChoice choice;
|
||||
choice.title = title;
|
||||
|
@ -563,11 +563,16 @@ void BasePreview::addChoice(const QString& key, const QString& title, const QStr
|
|||
choiceChangeEvent(key, init_value);
|
||||
}
|
||||
|
||||
void BasePreview::choiceChangeEvent(const QString&, int)
|
||||
void BasePreview::choiceChangeEvent(const QString &key, int position)
|
||||
{
|
||||
if (_renderer)
|
||||
{
|
||||
_renderer->choiceChangeEvent(key.toStdString(), position);
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
void BasePreview::addToggle(const QString& key, const QString& text, bool init_value)
|
||||
void BasePreview::addToggle(const QString &key, const QString &text, bool init_value)
|
||||
{
|
||||
_ContextToggle toggle;
|
||||
toggle.title = text;
|
||||
|
@ -578,8 +583,12 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v
|
|||
toggleChangeEvent(key, init_value);
|
||||
}
|
||||
|
||||
void BasePreview::toggleChangeEvent(QString, bool)
|
||||
void BasePreview::toggleChangeEvent(const QString &key, bool value)
|
||||
{
|
||||
if (_renderer)
|
||||
{
|
||||
_renderer->toggleChangeEvent(key.toStdString(), value);
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
|
|
@ -59,11 +59,11 @@ public:
|
|||
void configScaling(double min, double max, double step, double init, bool logarithmic = true);
|
||||
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
|
||||
|
||||
void addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value);
|
||||
virtual void choiceChangeEvent(const QString& key, int position);
|
||||
void addChoice(const QString &key, const QString &title, const QStringList &choices, int init_value);
|
||||
virtual void choiceChangeEvent(const QString &key, int position);
|
||||
|
||||
void addToggle(const QString& key, const QString& text, bool init_value);
|
||||
virtual void toggleChangeEvent(QString key, bool value);
|
||||
void addToggle(const QString &key, const QString &text, bool init_value);
|
||||
virtual void toggleChangeEvent(const QString &key, bool value);
|
||||
|
||||
protected:
|
||||
virtual void updateData();
|
||||
|
|
|
@ -63,3 +63,11 @@ Color CloudsCoveragePreviewRenderer::getColor2D(double x, double y, double scali
|
|||
return clouds->getColor(this, COLOR_BLUE, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
void CloudsCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
|
||||
{
|
||||
if (key == "3d")
|
||||
{
|
||||
perspective = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
virtual void updateEvent() override;
|
||||
virtual Color getColor2D(double x, double y, double scaling) override;
|
||||
|
||||
virtual void toggleChangeEvent(const std::string &key, bool value) override;
|
||||
|
||||
private:
|
||||
bool perspective;
|
||||
CloudLayerDefinition* layer;
|
||||
|
|
90
src/render/preview/SceneryTopDownPreviewRenderer.cpp
Normal file
90
src/render/preview/SceneryTopDownPreviewRenderer.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
#include "SceneryTopDownPreviewRenderer.h"
|
||||
|
||||
#include "CloudsDefinition.h"
|
||||
#include "BasePreview.h"
|
||||
#include "Scenery.h"
|
||||
|
||||
// TEMP
|
||||
#include "atmosphere/public.h"
|
||||
#include "tools/lighting.h"
|
||||
#include "terrain/public.h"
|
||||
#include "water/public.h"
|
||||
|
||||
static Vector3 _getCameraLocation(Renderer*, Vector3 location)
|
||||
{
|
||||
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
|
||||
}
|
||||
|
||||
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
||||
{
|
||||
AtmosphereResult result;
|
||||
atmosphereInitResult(&result);
|
||||
result.base = base;
|
||||
result.final = base;
|
||||
atmosphereUpdateResult(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
SceneryTopDownPreviewRenderer::SceneryTopDownPreviewRenderer(Scenery* scenery):
|
||||
scenery(scenery)
|
||||
{
|
||||
clouds_enabled = true;
|
||||
}
|
||||
|
||||
void SceneryTopDownPreviewRenderer::bindEvent(BasePreview* preview)
|
||||
{
|
||||
no_clouds = new CloudsDefinition(NULL);
|
||||
clouds_enabled = true;
|
||||
|
||||
// TODO Translation
|
||||
preview->addOsd("geolocation");
|
||||
preview->addToggle("clouds", "Clouds", false);
|
||||
|
||||
preview->configHdrToneMapping(true);
|
||||
preview->configScaling(0.5, 200.0, 3.0, 50.0);
|
||||
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
|
||||
}
|
||||
|
||||
void SceneryTopDownPreviewRenderer::updateEvent()
|
||||
{
|
||||
setScenery(scenery);
|
||||
|
||||
if (not clouds_enabled)
|
||||
{
|
||||
getScenery()->getClouds()->clear();
|
||||
}
|
||||
|
||||
prepare();
|
||||
|
||||
getCameraLocation = _getCameraLocation;
|
||||
lightingManagerDisableSpecularity(lighting);
|
||||
atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
||||
}
|
||||
|
||||
Color SceneryTopDownPreviewRenderer::getColor2D(double x, double y, double scaling)
|
||||
{
|
||||
Vector3 location;
|
||||
double height = terrain->getHeight(this, x, y, 1);
|
||||
|
||||
if (height < water->getHeightInfo(this).max_height)
|
||||
{
|
||||
return water->getResult(this, x, y).final;
|
||||
}
|
||||
else
|
||||
{
|
||||
location.x = x;
|
||||
location.y = height;
|
||||
location.z = y;
|
||||
return terrain->getFinalColor(this, location, scaling);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneryTopDownPreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
|
||||
{
|
||||
if (key == "clouds")
|
||||
{
|
||||
clouds_enabled = value;
|
||||
}
|
||||
}
|
||||
|
31
src/render/preview/SceneryTopDownPreviewRenderer.h
Normal file
31
src/render/preview/SceneryTopDownPreviewRenderer.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef SCENERYTOPDOWNPREVIEWRENDERER_H
|
||||
#define SCENERYTOPDOWNPREVIEWRENDERER_H
|
||||
|
||||
#include "preview_global.h"
|
||||
|
||||
#include "Base2dPreviewRenderer.h"
|
||||
|
||||
namespace paysages {
|
||||
namespace preview {
|
||||
|
||||
class PREVIEWSHARED_EXPORT SceneryTopDownPreviewRenderer : public Base2dPreviewRenderer
|
||||
{
|
||||
public:
|
||||
SceneryTopDownPreviewRenderer(Scenery* scenery);
|
||||
|
||||
protected:
|
||||
virtual void bindEvent(BasePreview* preview) override;
|
||||
virtual void updateEvent() override;
|
||||
virtual Color getColor2D(double x, double y, double scaling) override;
|
||||
virtual void toggleChangeEvent(const std::string &key, bool value) override;
|
||||
|
||||
private:
|
||||
Scenery* scenery;
|
||||
bool clouds_enabled;
|
||||
CloudsDefinition* no_clouds;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SCENERYTOPDOWNPREVIEWRENDERER_H
|
|
@ -70,7 +70,6 @@ static void _alterPreviewRenderer(Renderer* renderer)
|
|||
TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terrain)
|
||||
{
|
||||
_terrain = terrain;
|
||||
_highlight_enabled = true;
|
||||
|
||||
_alterPreviewRenderer(this);
|
||||
}
|
||||
|
@ -78,7 +77,6 @@ TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terr
|
|||
void TerrainShapePreviewRenderer::bindEvent(BasePreview* preview)
|
||||
{
|
||||
preview->addOsd(QString("geolocation"));
|
||||
//preview->addToggle("highlight", tr("Coverage highlight"), true);
|
||||
|
||||
preview->configScaling(20.0, 1000.0, 20.0, 200.0);
|
||||
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
|
@ -89,7 +87,7 @@ void TerrainShapePreviewRenderer::updateEvent()
|
|||
TerrainRendererClass.bind(this, _terrain);
|
||||
}
|
||||
|
||||
Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double)
|
||||
Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double scaling)
|
||||
{
|
||||
double height;
|
||||
|
||||
|
@ -100,24 +98,11 @@ Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double)
|
|||
}
|
||||
else
|
||||
{
|
||||
Color base;
|
||||
|
||||
base = water->getResult(this, x, y).final;
|
||||
|
||||
if (_highlight_enabled)
|
||||
{
|
||||
Color mask = {0.5, 0.5, 1.0, 0.5};
|
||||
colorMask(&base, &mask);
|
||||
}
|
||||
|
||||
return base;
|
||||
return getWaterColor(x, y, scaling);
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainShapePreviewRenderer::toggleChangeEvent(QString key, bool value)
|
||||
Color TerrainShapePreviewRenderer::getWaterColor(double, double, double)
|
||||
{
|
||||
if (key == "highlight")
|
||||
{
|
||||
_highlight_enabled = value;
|
||||
}
|
||||
return COLOR_BLUE;
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ public:
|
|||
explicit TerrainShapePreviewRenderer(TerrainDefinition* terrain);
|
||||
|
||||
protected:
|
||||
virtual void bindEvent(BasePreview* preview);
|
||||
virtual void updateEvent();
|
||||
virtual void bindEvent(BasePreview* preview) override;
|
||||
virtual void updateEvent() override;
|
||||
virtual Color getColor2D(double x, double y, double scaling) override;
|
||||
virtual void toggleChangeEvent(QString key, bool value);
|
||||
|
||||
virtual Color getWaterColor(double x, double y, double scaling);
|
||||
|
||||
TerrainDefinition* _terrain;
|
||||
|
||||
private:
|
||||
bool _highlight_enabled;
|
||||
double _water_height;
|
||||
};
|
||||
|
||||
|
|
|
@ -155,3 +155,19 @@ Color WaterAspectPreviewRenderer::getColor2D(double x, double y, double scaling)
|
|||
|
||||
return water->getResult(this, target_x, target_z).final;
|
||||
}
|
||||
|
||||
void WaterAspectPreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
|
||||
{
|
||||
if (key == "light")
|
||||
{
|
||||
lighting = value;
|
||||
}
|
||||
}
|
||||
|
||||
void WaterAspectPreviewRenderer::choiceChangeEvent(const std::string &key, int position)
|
||||
{
|
||||
if (key == "bg")
|
||||
{
|
||||
background = position;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ public:
|
|||
virtual void cameraEvent(double x, double y, double scaling) override;
|
||||
virtual Color getColor2D(double x, double y, double scaling) override;
|
||||
|
||||
virtual void toggleChangeEvent(const std::string &key, bool value) override;
|
||||
virtual void choiceChangeEvent(const std::string &key, int position) override;
|
||||
|
||||
private:
|
||||
WaterDefinition* definition;
|
||||
bool lighting;
|
||||
|
|
|
@ -22,44 +22,42 @@ WaterCoveragePreviewRenderer::~WaterCoveragePreviewRenderer()
|
|||
|
||||
void WaterCoveragePreviewRenderer::bindEvent(BasePreview* preview)
|
||||
{
|
||||
preview->addOsd("geolocation");
|
||||
TerrainShapePreviewRenderer::bindEvent(preview);
|
||||
|
||||
// TODO Translation
|
||||
preview->addToggle("highlight", "Coverage highlight", true);
|
||||
|
||||
preview->configScaling(20.0, 1000.0, 20.0, 200.0);
|
||||
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
// TODO Keep camera above center (for reflections)
|
||||
}
|
||||
|
||||
void WaterCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
|
||||
{
|
||||
if (key == "highlight")
|
||||
{
|
||||
highlight = value;
|
||||
}
|
||||
}
|
||||
|
||||
void WaterCoveragePreviewRenderer::updateEvent()
|
||||
{
|
||||
getScenery()->setWater(definition);
|
||||
|
||||
RenderingScenery::getCurrent()->getTerrain(_terrain);
|
||||
TerrainShapePreviewRenderer::updateEvent();
|
||||
|
||||
getScenery()->setWater(definition);
|
||||
WaterRendererClass.bind(this, definition);
|
||||
}
|
||||
|
||||
Color WaterCoveragePreviewRenderer::getColor2D(double x, double y, double scaling)
|
||||
Color WaterCoveragePreviewRenderer::getWaterColor(double x, double y, double)
|
||||
{
|
||||
double height;
|
||||
Color base;
|
||||
|
||||
height = terrain->getHeight(this, x, y, 1);
|
||||
if (height > terrain->getWaterHeight(this))
|
||||
base = water->getResult(this, x, y).final;
|
||||
|
||||
if (highlight)
|
||||
{
|
||||
return TerrainShapePreviewRenderer::getColor2D(x, y, scaling);
|
||||
Color mask = {0.5, 0.5, 1.0, 0.5};
|
||||
colorMask(&base, &mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
Color base;
|
||||
|
||||
base = water->getResult(this, x, y).final;
|
||||
|
||||
if (highlight)
|
||||
{
|
||||
Color mask = {0.5, 0.5, 1.0, 0.5};
|
||||
colorMask(&base, &mask);
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ public:
|
|||
|
||||
virtual void bindEvent(BasePreview* preview) override;
|
||||
virtual void updateEvent() override;
|
||||
virtual Color getColor2D(double x, double y, double scaling) override;
|
||||
|
||||
virtual Color getWaterColor(double x, double y, double scaling) override;
|
||||
|
||||
virtual void toggleChangeEvent(const std::string &key, bool value) override;
|
||||
|
||||
private:
|
||||
WaterDefinition* definition;
|
||||
|
|
|
@ -22,7 +22,8 @@ SOURCES += Base2dPreviewRenderer.cpp \
|
|||
CloudsAspectPreviewRenderer.cpp \
|
||||
WaterCoveragePreviewRenderer.cpp \
|
||||
WaterAspectPreviewRenderer.cpp \
|
||||
TerrainShapePreviewRenderer.cpp
|
||||
TerrainShapePreviewRenderer.cpp \
|
||||
SceneryTopDownPreviewRenderer.cpp
|
||||
|
||||
HEADERS += Base2dPreviewRenderer.h\
|
||||
preview_global.h \
|
||||
|
@ -35,7 +36,8 @@ HEADERS += Base2dPreviewRenderer.h\
|
|||
CloudsAspectPreviewRenderer.h \
|
||||
WaterCoveragePreviewRenderer.h \
|
||||
WaterAspectPreviewRenderer.h \
|
||||
TerrainShapePreviewRenderer.h
|
||||
TerrainShapePreviewRenderer.h \
|
||||
SceneryTopDownPreviewRenderer.h
|
||||
|
||||
unix:!symbian {
|
||||
maemo5 {
|
||||
|
|
Loading…
Reference in a new issue