paysages: WIP

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@573 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-05-14 20:32:56 +00:00 committed by ThunderK
parent e820d336a8
commit 6420103652
9 changed files with 124 additions and 14 deletions

View file

@ -3,6 +3,10 @@
#include <QDialog>
#include <QVariant>
#include <cmath>
#include "dialogrender.h"
#include "dialogexplorer.h"
#include "rendering/scenery.h"
#include "rendering/renderer.h"
Q_DECLARE_METATYPE(double*)
@ -26,6 +30,7 @@ void FreeFormHelper::startManaging()
connect(this, SIGNAL(needGlobalRefreshing()), _form_widget, SLOT(refreshFromFellowData()));
connect(this, SIGNAL(needReverting()), _form_widget, SLOT(updateLocalDataFromScenery()));
connect(this, SIGNAL(needCommitting()), _form_widget, SLOT(commitLocalDataToScenery()));
connect(this, SIGNAL(needAlterRenderer(Renderer*)), _form_widget, SLOT(alterRenderer(Renderer*)));
emit needLocalRefreshing();
emit needGlobalRefreshing();
@ -50,6 +55,8 @@ void FreeFormHelper::addDoubleInputSlider(WidgetSliderDecimal* slider, double* v
{
if (slider && slider->inherits("WidgetSliderDecimal"))
{
_inputs_decimal.append(slider);
slider->setDecimalRange(min, max, small_step, large_step);
slider->setDecimalValue(*value);
@ -96,6 +103,36 @@ void FreeFormHelper::setRevertButton(QString widget_name)
setRevertButton(_form_widget->findChild<QPushButton*>(widget_name));
}
void FreeFormHelper::setExploreButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_explore = button;
connect(button, SIGNAL(clicked()), this, SLOT(processExploreClicked()));
}
}
void FreeFormHelper::setExploreButton(QString widget_name)
{
setExploreButton(_form_widget->findChild<QPushButton*>(widget_name));
}
void FreeFormHelper::setRenderButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_render = button;
connect(button, SIGNAL(clicked()), this, SLOT(processRenderClicked()));
}
}
void FreeFormHelper::setRenderButton(QString widget_name)
{
setRenderButton(_form_widget->findChild<QPushButton*>(widget_name));
}
void FreeFormHelper::setLabelText(QLabel* label, QString text)
{
if (label && label->inherits("QLabel"))
@ -141,6 +178,22 @@ void FreeFormHelper::processRevertClicked()
{
emit needReverting();
for (int i = 0; i < _previews.size(); i++)
{
_previews[i]->redraw();
}
for (int i = 0; i < _inputs_decimal.size(); i++)
{
WidgetSliderDecimal* slider = _inputs_decimal.at(i);
double* pointer = slider->property("data_pointer").value<double*>();
if (pointer)
{
slider->setDecimalValue(*pointer);
}
}
_data_changed = false;
if (_button_apply)
{
@ -151,11 +204,6 @@ void FreeFormHelper::processRevertClicked()
_button_revert->setEnabled(false);
}
for (int i = 0; i < _previews.size(); i++)
{
_previews[i]->redraw();
}
emit needLocalRefreshing();
}
@ -174,6 +222,42 @@ void FreeFormHelper::processApplyClicked()
}
}
void FreeFormHelper::processExploreClicked()
{
Renderer* renderer;
renderer = sceneryCreateStandardRenderer();
emit needAlterRenderer(renderer);
CameraDefinition* camera = cameraCreateDefinition();
sceneryGetCamera(camera);
DialogExplorer* dialog = new DialogExplorer(_form_widget, camera, false, renderer);
dialog->exec();
delete dialog;
rendererDelete(renderer);
cameraDeleteDefinition(camera);
}
void FreeFormHelper::processRenderClicked()
{
Renderer* renderer;
renderer = sceneryCreateStandardRenderer();
emit needAlterRenderer(renderer);
DialogRender* dialog = new DialogRender(_form_widget, renderer);
RenderParams params = {400, 300, 1, 3};
dialog->startRender(params);
delete dialog;
rendererDelete(renderer);
}
void FreeFormHelper::processDecimalChange(double value)
{
QObject* signal_sender = sender();

View file

@ -47,11 +47,14 @@ signals:
void needGlobalRefreshing();
void needReverting();
void needCommitting();
void needAlterRenderer(Renderer* renderer);
public slots:
void processDataChange();
void processRevertClicked();
void processApplyClicked();
void processExploreClicked();
void processRenderClicked();
void processDecimalChange(double value);
private:
@ -60,6 +63,7 @@ private:
bool _data_changed;
QVector<BasePreview*> _previews;
QVector<WidgetSliderDecimal*> _inputs_decimal;
QPushButton* _button_apply;
QPushButton* _button_revert;

View file

@ -5,7 +5,7 @@
#include <QVBoxLayout>
#include <QLabel>
DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool camera_validable) : QDialog(parent)
DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool camera_validable, Renderer* renderer) : QDialog(parent)
{
QWidget* panel;
QPushButton* button;
@ -14,7 +14,7 @@ DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool c
setWindowTitle(tr("Paysages 3D - Explore"));
setLayout(new QHBoxLayout());
_wanderer = new WidgetExplorer(this, camera);
_wanderer = new WidgetExplorer(this, camera, renderer);
layout()->addWidget(_wanderer);
panel = new QWidget(this);

View file

@ -9,7 +9,7 @@ class DialogExplorer : public QDialog
{
Q_OBJECT
public:
explicit DialogExplorer(QWidget *parent, CameraDefinition* camera, bool camera_validable);
explicit DialogExplorer(QWidget *parent, CameraDefinition* camera, bool camera_validable=false, Renderer* renderer=0);
~DialogExplorer();
protected slots:

View file

@ -26,6 +26,8 @@ MainTerrainForm::MainTerrainForm(QWidget *parent) :
_form_helper->setApplyButton("button_apply");
_form_helper->setRevertButton("button_revert");
_form_helper->setExploreButton("button_explore");
_form_helper->setRenderButton("button_render");
connect(findChild<QPushButton*>("button_dialog_painting"), SIGNAL(clicked()), this, SLOT(buttonPaintingPressed()));
connect(findChild<QPushButton*>("button_goto_textures"), SIGNAL(clicked()), this, SLOT(buttonTexturesPressed()));
@ -70,6 +72,11 @@ void MainTerrainForm::commitLocalDataToScenery()
scenerySetTerrain(_terrain);
}
void MainTerrainForm::alterRenderer(Renderer* renderer)
{
TerrainRendererClass.bind(renderer, _terrain);
}
void MainTerrainForm::buttonPaintingPressed()
{
DialogTerrainPainting dialog(this, _terrain);

View file

@ -24,6 +24,7 @@ public slots:
void refreshFromFellowData();
void updateLocalDataFromScenery();
void commitLocalDataToScenery();
void alterRenderer(Renderer* renderer);
void buttonPaintingPressed();
void buttonTexturesPressed();

View file

@ -360,7 +360,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="button_render">
<property name="text">
<string>Render preview</string>
</property>
@ -371,7 +371,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="button_explore">
<property name="text">
<string>Explore in 3D</string>
</property>

View file

@ -66,7 +66,7 @@ static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
return result;
}
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera) :
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera, Renderer* renderer) :
QGLWidget(parent)
{
setMinimumSize(400, 300);
@ -76,7 +76,16 @@ QGLWidget(parent)
_base_camera = camera;
cameraCopyDefinition(camera, _current_camera);
_renderer = sceneryCreateStandardRenderer();
if (renderer)
{
_renderer = renderer;
_renderer_created = false;
}
else
{
_renderer = sceneryCreateStandardRenderer();
_renderer_created = true;
}
_renderer->render_quality = 3;
_renderer->customData[2] = _base_camera;
_renderer->getCameraLocation = _getCameraLocation;
@ -102,8 +111,12 @@ WidgetExplorer::~WidgetExplorer()
{
delete _chunks[i];
}
rendererDelete(_renderer);
cameraDeleteDefinition(_current_camera);
if (_renderer_created)
{
rendererDelete(_renderer);
}
}
void WidgetExplorer::startRendering()

View file

@ -10,7 +10,7 @@ class WidgetExplorer : public QGLWidget
{
Q_OBJECT
public:
WidgetExplorer(QWidget* parent, CameraDefinition* camera);
WidgetExplorer(QWidget* parent, CameraDefinition* camera, Renderer* renderer=0);
~WidgetExplorer();
void performChunksMaintenance();
@ -38,6 +38,7 @@ private:
CameraDefinition* _base_camera;
Renderer* _renderer;
bool _renderer_created;
bool _inited;
bool _updated;