paysages: Made terrain preview work again

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@567 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-05-10 08:10:07 +00:00 committed by ThunderK
parent 319d33e9f2
commit e116d01c29
12 changed files with 131 additions and 34 deletions

View file

@ -30,7 +30,7 @@ release:
make BUILDMODE=release all
tests: all
LD_LIBRARY_PATH=${BUILDPATH} ${BUILDPATH}/paysages-tests
LD_LIBRARY_PATH=${BUILDPATH} CK_DEFAULT_TIMEOUT=30 ${BUILDPATH}/paysages-tests
run_cli: all
LD_LIBRARY_PATH=${BUILDPATH} ${BUILDPATH}/paysages-cli

View file

@ -354,6 +354,8 @@ QWidget(parent)
_transactions_count = 0;
_redraw_requested = false;
_renderer = NULL;
_info = new QLabel(this);
_info->setVisible(false);
_info->setStyleSheet("QLabel { background-color: white; color: black; }");
@ -385,6 +387,12 @@ BasePreview::~BasePreview()
delete _lock_drawing;
}
void BasePreview::setRenderer(PreviewRenderer* renderer)
{
_renderer = renderer;
_renderer->bindEvent(this);
}
void BasePreview::configHdrToneMapping(bool active)
{
_hdr_enabled = active;
@ -436,15 +444,26 @@ void BasePreview::reviveAll()
void BasePreview::updateData()
{
if (_renderer)
{
_renderer->updateEvent();
}
}
void BasePreview::cameraEvent()
{
}
Color BasePreview::getColor(double, double)
Color BasePreview::getColor(double x, double y)
{
if (_renderer)
{
return _renderer->getColor2D(x, y, scaling);
}
else
{
return COLOR_BLACK;
}
}
void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic)

View file

@ -10,6 +10,7 @@
#include <QLabel>
#include <QHash>
#include "previewosd.h"
#include "common/previewrenderer.h"
#include "rendering/tools/pack.h"
#include "rendering/tools/color.h"
@ -36,6 +37,8 @@ public:
BasePreview(QWidget* parent);
~BasePreview();
void setRenderer(PreviewRenderer* renderer);
virtual void savePack(PackStream* stream);
virtual void loadPack(PackStream* stream);
@ -51,23 +54,23 @@ public:
QColor getPixelColor(int x, int y);
protected:
virtual void updateData();
virtual void cameraEvent();
virtual Color getColor(double x, double y);
void addOsd(QString name);
void configHdrToneMapping(bool active);
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 addOsd(QString name);
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);
protected:
virtual void updateData();
virtual void cameraEvent();
virtual Color getColor(double x, double y);
double xoffset;
double yoffset;
double scaling;
@ -96,6 +99,8 @@ private:
QLabel* _info;
PreviewRenderer* _renderer;
int _width;
int _height;

View file

@ -32,17 +32,18 @@ void FreeFormHelper::startManaging()
emit needReverting();
}
void FreeFormHelper::addPreview(BasePreview* preview)
void FreeFormHelper::addPreview(BasePreview* preview, PreviewRenderer* renderer)
{
if (preview && preview->inherits("BasePreview"))
{
_previews.append(preview);
preview->setRenderer(renderer);
}
}
void FreeFormHelper::addPreview(QString widget_name)
void FreeFormHelper::addPreview(QString widget_name, PreviewRenderer* renderer)
{
addPreview(_form_widget->findChild<BasePreview*>(widget_name));
addPreview(_form_widget->findChild<BasePreview*>(widget_name), renderer);
}
void FreeFormHelper::addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min, double max, double small_step, double large_step)

View file

@ -16,8 +16,8 @@ public:
void startManaging();
void addPreview(BasePreview* preview);
void addPreview(QString widget_name);
void addPreview(BasePreview* preview, PreviewRenderer* renderer);
void addPreview(QString widget_name, PreviewRenderer* renderer);
void addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0);
void addDoubleInputSlider(QString widget_name, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0);

View file

@ -0,0 +1,25 @@
#include "previewrenderer.h"
PreviewRenderer::PreviewRenderer(QObject *parent) :
QObject(parent)
{
renderer = rendererCreate();
}
PreviewRenderer::~PreviewRenderer()
{
rendererDelete(renderer);
}
Color PreviewRenderer::getColor2D(double, double, double)
{
return COLOR_BLACK;
}
void PreviewRenderer::bindEvent(BasePreview*)
{
}
void PreviewRenderer::updateEvent()
{
}

View file

@ -0,0 +1,30 @@
#ifndef PREVIEWRENDERER_H
#define PREVIEWRENDERER_H
#include <QObject>
#include "rendering/tools/color.h"
#include "rendering/renderer.h"
class BasePreview;
class PreviewRenderer : public QObject
{
Q_OBJECT
public:
explicit PreviewRenderer(QObject *parent = 0);
~PreviewRenderer();
virtual void bindEvent(BasePreview* preview);
virtual void updateEvent();
virtual Color getColor2D(double x, double y, double scaling);
signals:
public slots:
protected:
Renderer* renderer;
};
#endif // PREVIEWRENDERER_H

View file

@ -69,7 +69,8 @@ HEADERS += \
terrain/mainterrainform.h \
common/freeformhelper.h \
terrain/previewterrainshape.h \
common/widgetsliderdecimal.h
common/widgetsliderdecimal.h \
common/previewrenderer.h
SOURCES += \
widgetheightmap.cpp \
@ -117,7 +118,8 @@ SOURCES += \
terrain/mainterrainform.cpp \
common/freeformhelper.cpp \
terrain/previewterrainshape.cpp \
common/widgetsliderdecimal.cpp
common/widgetsliderdecimal.cpp \
common/previewrenderer.cpp
FORMS += \
terrain/dialogterrainpainting.ui \

View file

@ -2,6 +2,7 @@
#include "ui_mainterrainform.h"
#include "dialogterrainpainting.h"
#include "previewterrainshape.h"
#include "tools.h"
#include "rendering/scenery.h"
@ -15,7 +16,8 @@ MainTerrainForm::MainTerrainForm(QWidget *parent) :
_form_helper = new FreeFormHelper(this);
_form_helper->addPreview("preview_shape");
_renderer_shape = new PreviewTerrainShape(_terrain);
_form_helper->addPreview("preview_shape", _renderer_shape);
_form_helper->addDoubleInputSlider("input_scaling", &_terrain->scaling, 0.1, 3.0, 0.03, 0.3);
_form_helper->addDoubleInputSlider("input_height", &_terrain->height, 0.0, 3.0, 0.01, 0.1);
@ -34,6 +36,7 @@ MainTerrainForm::~MainTerrainForm()
{
delete _form_helper;
delete ui;
delete _renderer_shape;
TerrainDefinitionClass.destroy(_terrain);
}

View file

@ -33,6 +33,8 @@ private:
FreeFormHelper* _form_helper;
TerrainDefinition* _terrain;
PreviewRenderer* _renderer_shape;
};
#endif // MAINTERRAINFORM_H

View file

@ -1,22 +1,30 @@
#include "previewterrainshape.h"
PreviewTerrainShape::PreviewTerrainShape(QWidget *parent) :
BasePreview(parent)
#include "basepreview.h"
PreviewTerrainShape::PreviewTerrainShape(TerrainDefinition* terrain)
{
_renderer = terrainCreatePreviewRenderer();
_terrain = terrain;
addOsd(QString("geolocation"));
configScaling(20.0, 1000.0, 20.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
// TODO Don't delete the base renderer, just alter it
rendererDelete(renderer);
renderer = terrainCreatePreviewRenderer();
}
Color PreviewTerrainShape::getColor(double x, double y)
void PreviewTerrainShape::bindEvent(BasePreview* preview)
{
return terrainGetPreviewColor(_renderer, x, y, scaling);
preview->addOsd(QString("geolocation"));
preview->configScaling(20.0, 1000.0, 20.0, 50.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
void PreviewTerrainShape::updateData()
void PreviewTerrainShape::updateEvent()
{
//TerrainRendererClass.bind(_renderer, _definition);
TerrainRendererClass.bind(renderer, _terrain);
}
Color PreviewTerrainShape::getColor2D(double x, double y, double scaling)
{
return terrainGetPreviewColor(renderer, x, y, scaling);
}

View file

@ -1,21 +1,23 @@
#ifndef PREVIEWTERRAINSHAPE_H
#define PREVIEWTERRAINSHAPE_H
#include "basepreview.h"
#include "common/previewrenderer.h"
#include "rendering/renderer.h"
#include "rendering/terrain/public.h"
class PreviewTerrainShape : public BasePreview
class PreviewTerrainShape : public PreviewRenderer
{
Q_OBJECT
public:
explicit PreviewTerrainShape(QWidget *parent = 0);
explicit PreviewTerrainShape(TerrainDefinition* terrain);
protected:
virtual Color getColor(double x, double y);
virtual void updateData();
virtual void bindEvent(BasePreview* preview);
virtual void updateEvent();
virtual Color getColor2D(double x, double y, double scaling);
private:
Renderer* _renderer;
TerrainDefinition* _terrain;
};
#endif // PREVIEWTERRAINSHAPE_H