From 08b481df7dff3b91ef3a10bbabc556668951fa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 18 Aug 2013 17:13:15 +0200 Subject: [PATCH] WIP on new material dialog --- src/editing/dialogmaterial.cpp | 69 --- src/editing/dialogmaterial.h | 27 -- src/editing/formmaterial.cpp | 31 -- src/editing/formmaterial.h | 27 -- src/editing/inputcolor.cpp | 35 +- src/editing/inputcolor.h | 3 +- src/editing/inputmaterial.cpp | 11 +- src/editing/lighting/DialogMaterialEditor.cpp | 70 +++ src/editing/lighting/DialogMaterialEditor.h | 45 ++ src/editing/lighting/DialogMaterialEditor.ui | 402 ++++++++++++++++++ src/editing/lighting/SmallPreviewColor.cpp | 24 ++ src/editing/lighting/SmallPreviewColor.h | 21 + src/editing/lighting/SmallPreviewHues.cpp | 14 + src/editing/lighting/SmallPreviewHues.h | 18 + src/editing/paysages-qt.pro | 19 +- src/editing/previewmaterial.cpp | 55 ++- src/editing/previewmaterial.h | 37 +- src/rendering/tools/lighting.h | 9 +- 18 files changed, 674 insertions(+), 243 deletions(-) delete mode 100644 src/editing/dialogmaterial.cpp delete mode 100644 src/editing/dialogmaterial.h delete mode 100644 src/editing/formmaterial.cpp delete mode 100644 src/editing/formmaterial.h create mode 100644 src/editing/lighting/DialogMaterialEditor.cpp create mode 100644 src/editing/lighting/DialogMaterialEditor.h create mode 100644 src/editing/lighting/DialogMaterialEditor.ui create mode 100644 src/editing/lighting/SmallPreviewColor.cpp create mode 100644 src/editing/lighting/SmallPreviewColor.h create mode 100644 src/editing/lighting/SmallPreviewHues.cpp create mode 100644 src/editing/lighting/SmallPreviewHues.h diff --git a/src/editing/dialogmaterial.cpp b/src/editing/dialogmaterial.cpp deleted file mode 100644 index a988281..0000000 --- a/src/editing/dialogmaterial.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "dialogmaterial.h" - -#include -#include -#include -#include - -/**************** Dialog form ****************/ -DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : DialogWithPreview(parent) -{ - QPushButton* button; - QWidget* buttons; - - setLayout(new QVBoxLayout()); - - _form = new FormMaterial(this, material); - _form->hideButtons(); - layout()->addWidget(_form); - - buttons = new QWidget(this); - buttons->setLayout(new QHBoxLayout()); - layout()->addWidget(buttons); - layout()->setAlignment(buttons, Qt::AlignBottom); - - button = new QPushButton(tr("Cancel"), buttons); - button->setIcon(QIcon(getDataPath("images/cancel.png"))); - buttons->layout()->addWidget(button); - QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject())); - - button = new QPushButton(tr("Revert"), buttons); - button->setIcon(QIcon(getDataPath("images/revert.png"))); - buttons->layout()->addWidget(button); - QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert())); - - button = new QPushButton(tr("Validate"), buttons); - button->setIcon(QIcon(getDataPath("images/apply.png"))); - buttons->layout()->addWidget(button); - QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); - - setWindowTitle(tr("Paysages 3D - Material editor")); -} - -bool DialogMaterial::getMaterial(QWidget* parent, SurfaceMaterial* material) -{ - int result; - - DialogMaterial* dialog = new DialogMaterial(parent, material); - result = dialog->exec(); - - if (result) - { - dialog->_form->getMaterial(material); - } - - delete dialog; - - return (result != 0) ? true : false; -} - -void DialogMaterial::accept() -{ - _form->applyConfig(); - QDialog::accept(); -} - -void DialogMaterial::revert() -{ - _form->revertConfig(); -} diff --git a/src/editing/dialogmaterial.h b/src/editing/dialogmaterial.h deleted file mode 100644 index b41a5c0..0000000 --- a/src/editing/dialogmaterial.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _PAYSAGES_QT_DIALOGMATERIAL_H_ -#define _PAYSAGES_QT_DIALOGMATERIAL_H_ - -#include -#include -#include "basepreview.h" -#include "formmaterial.h" -#include "tools.h" - -#include "rendering/shared/types.h" - -class DialogMaterial : public DialogWithPreview -{ - Q_OBJECT -public: - explicit DialogMaterial(QWidget* parent, SurfaceMaterial* material); - static bool getMaterial(QWidget* parent, SurfaceMaterial* material); - -public slots: - virtual void accept(); - void revert(); - -private: - FormMaterial* _form; -}; - -#endif diff --git a/src/editing/formmaterial.cpp b/src/editing/formmaterial.cpp deleted file mode 100644 index 2ac233e..0000000 --- a/src/editing/formmaterial.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "formmaterial.h" - -#include "previewmaterial.h" - -/**************** Form ****************/ -FormMaterial::FormMaterial(QWidget* parent, SurfaceMaterial* material) : BaseForm(parent) -{ - _initial = material; - _material = *_initial; - - addInputColor(tr("Base color"), &_material.base); - addInputDouble(tr("Light reflection"), &_material.reflection, 0.0, 1.0, 0.01, 0.1); - addInputDouble(tr("Light reflection shininess"), &_material.shininess, 0.0, 30.0, 0.1, 1.0); - - _preview_color = new PreviewMaterial(this, &_material); - addPreview(_preview_color, tr("Lighting preview")); - - revertConfig(); -} - -void FormMaterial::getMaterial(SurfaceMaterial* material) -{ - *material = _material; -} - -void FormMaterial::revertConfig() -{ - _material = *_initial; - - BaseForm::revertConfig(); -} diff --git a/src/editing/formmaterial.h b/src/editing/formmaterial.h deleted file mode 100644 index f34de50..0000000 --- a/src/editing/formmaterial.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _PAYSAGES_QT_FORMMATERIAL_H_ -#define _PAYSAGES_QT_FORMMATERIAL_H_ - -#include "basepreview.h" -#include "baseform.h" - -#include "rendering/shared/types.h" - -class FormMaterial : public BaseForm -{ - Q_OBJECT - -public: - FormMaterial(QWidget* parent, SurfaceMaterial* material); - void getMaterial(SurfaceMaterial* material); - -public slots: - virtual void revertConfig(); -// virtual void applyConfig(); - -private: - BasePreview* _preview_color; - SurfaceMaterial* _initial; - SurfaceMaterial _material; -}; - -#endif diff --git a/src/editing/inputcolor.cpp b/src/editing/inputcolor.cpp index db6bdbe..0da244e 100644 --- a/src/editing/inputcolor.cpp +++ b/src/editing/inputcolor.cpp @@ -4,29 +4,15 @@ #include #include #include -#include "tools.h" -class ColorPreview:public QWidget -{ -public: - ColorPreview(QWidget* parent): - QWidget(parent) - { - } - - void paintEvent(QPaintEvent*) - { - QPainter painter(this); - painter.fillRect(this->rect(), col); - } - QColor col; -}; +#include "editing/lighting/SmallPreviewColor.h" +#include "editing/tools.h" InputColor::InputColor(QWidget* form, QString label, Color* value): BaseInput(form, label), - _value(value) + _original(value) { - _preview = new ColorPreview(form); + _preview = new SmallPreviewColor(form, &_edited); _preview->setMinimumSize(50, 20); _control = new QPushButton(tr("Edit"), form); _control->setMaximumWidth(150); @@ -42,25 +28,24 @@ void InputColor::updatePreview() void InputColor::applyValue() { - _value->r = ((ColorPreview*)_preview)->col.redF(); - _value->g = ((ColorPreview*)_preview)->col.greenF(); - _value->b = ((ColorPreview*)_preview)->col.blueF(); - _value->a = 1.0; + *_original = _edited; BaseInput::applyValue(); } void InputColor::revert() { - ((ColorPreview*)_preview)->col = colorToQColor(*_value); + _edited = *_original; BaseInput::revert(); } void InputColor::chooseColor() { - QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control); + QColor col = QColorDialog::getColor(colorToQColor(_edited), _control); if (col.isValid()) { - ((ColorPreview*)_preview)->col = col; + _edited.r = col.redF(); + _edited.g = col.greenF(); + _edited.b = col.blueF(); applyValue(); } } diff --git a/src/editing/inputcolor.h b/src/editing/inputcolor.h index 7418e8d..a3bb3c2 100644 --- a/src/editing/inputcolor.h +++ b/src/editing/inputcolor.h @@ -22,7 +22,8 @@ private slots: void chooseColor(); private: - Color* _value; + Color* _original; + Color _edited; }; #endif diff --git a/src/editing/inputmaterial.cpp b/src/editing/inputmaterial.cpp index 899c172..771f202 100644 --- a/src/editing/inputmaterial.cpp +++ b/src/editing/inputmaterial.cpp @@ -4,16 +4,17 @@ #include #include #include -#include "dialogmaterial.h" -#include "previewmaterial.h" + +#include "editing/lighting/DialogMaterialEditor.h" +#include "editing/previewmaterial.h" InputMaterial::InputMaterial(QWidget* form, QString label, SurfaceMaterial* value) : BaseInput(form, label) { _value = value; - + _preview = new SmallMaterialPreview(form, value); _preview->setMinimumSize(100, 40); - + _control = new QPushButton(tr("Edit"), form); _control->setMaximumWidth(150); @@ -39,7 +40,7 @@ void InputMaterial::revert() void InputMaterial::editMaterial() { - if (DialogMaterial::getMaterial(_control, _value)) + if (DialogMaterialEditor::getMaterial(_control, _value)) { applyValue(); } diff --git a/src/editing/lighting/DialogMaterialEditor.cpp b/src/editing/lighting/DialogMaterialEditor.cpp new file mode 100644 index 0000000..113564c --- /dev/null +++ b/src/editing/lighting/DialogMaterialEditor.cpp @@ -0,0 +1,70 @@ +#include "DialogMaterialEditor.h" +#include "ui_DialogMaterialEditor.h" + +#include "editing/common/freeformhelper.h" + +DialogMaterialEditor::DialogMaterialEditor(QWidget *parent, SurfaceMaterial* material) : +QDialog(parent), +ui(new Ui::DialogMaterialEditor), +preview_lighted(&edited) +{ + ui->setupUi(this); + + original = material; + edited = *original; + + form_helper = new FreeFormHelper(this); + + form_helper->addPreview(ui->preview_lighted, &preview_lighted); + + form_helper->addDoubleInputSlider(ui->slider_hue, &edited.hue); + form_helper->addDoubleInputSlider(ui->slider_diffuse, &edited.diffuse); + form_helper->addDoubleInputSlider(ui->slider_hardness, &edited.hardness); + form_helper->addDoubleInputSlider(ui->slider_reflection, &edited.reflection); + form_helper->addDoubleInputSlider(ui->slider_specularity, &edited.shininess); + form_helper->addDoubleInputSlider(ui->slider_receive_shadows, &edited.receive_shadows); + + form_helper->setRevertButton(ui->button_revert); + + form_helper->startManaging(); + + ui->preview_color->setColor(&edited.base); + + connect(ui->button_apply, SIGNAL(clicked()), this, SLOT(accept())); + connect(ui->button_cancel, SIGNAL(clicked()), this, SLOT(reject())); +} + +DialogMaterialEditor::~DialogMaterialEditor() +{ + delete form_helper; + delete ui; +} + +bool DialogMaterialEditor::getMaterial(QWidget* parent, SurfaceMaterial* material) +{ + DialogMaterialEditor dialog(parent, material); + return dialog.exec() != 0; +} + +void DialogMaterialEditor::refreshFromLocalData() +{ + ui->preview_color->update(); +} + +void DialogMaterialEditor::refreshFromFellowData() +{ +} + +void DialogMaterialEditor::updateLocalDataFromScenery() +{ + // Revert + edited = *original; +} + +void DialogMaterialEditor::commitLocalDataToScenery() +{ +} + +void DialogMaterialEditor::alterRenderer(Renderer* renderer) +{ +} diff --git a/src/editing/lighting/DialogMaterialEditor.h b/src/editing/lighting/DialogMaterialEditor.h new file mode 100644 index 0000000..1cf92a8 --- /dev/null +++ b/src/editing/lighting/DialogMaterialEditor.h @@ -0,0 +1,45 @@ +#ifndef DIALOGMATERIALEDITOR_H +#define DIALOGMATERIALEDITOR_H + +#include + +#include "editing/previewmaterial.h" + +#include "rendering/tools/lighting.h" +#include "rendering/renderer.h" + +namespace Ui { +class DialogMaterialEditor; +} + +class FreeFormHelper; + +class DialogMaterialEditor : public QDialog +{ + Q_OBJECT + +public: + DialogMaterialEditor(QWidget *parent, SurfaceMaterial* material); + ~DialogMaterialEditor(); + + static bool getMaterial(QWidget* parent, SurfaceMaterial* material); + +public slots: + void refreshFromLocalData(); + void refreshFromFellowData(); + void updateLocalDataFromScenery(); + void commitLocalDataToScenery(); + void alterRenderer(Renderer* renderer); + +private: + Ui::DialogMaterialEditor *ui; + + SurfaceMaterial* original; + SurfaceMaterial edited; + + MaterialPreviewRenderer preview_lighted; + + FreeFormHelper* form_helper; +}; + +#endif // DIALOGMATERIALEDITOR_H diff --git a/src/editing/lighting/DialogMaterialEditor.ui b/src/editing/lighting/DialogMaterialEditor.ui new file mode 100644 index 0000000..9943633 --- /dev/null +++ b/src/editing/lighting/DialogMaterialEditor.ui @@ -0,0 +1,402 @@ + + + DialogMaterialEditor + + + + 0 + 0 + 1090 + 627 + + + + Dialog + + + + + + 20 + + + + + Material diffusion + + + true + + + + + + + true + + + + This controls the way the surface diffuses its inner color in all directions, when a light source reaches it + + + true + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Base color + + + + + + + Diffuse factor + + + + + + + Hardness to light + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + + + 80 + 30 + + + + + + + + + + Qt::Horizontal + + + + + + + + 600 + 40 + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Light reflection + + + true + + + + + + + true + + + + Amount and direction of light that is directly reflected from an incoming source (useful for shiny things) + + + true + + + + + + + + + Reflection factor + + + + + + + Specularity + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Ambient lighting + + + true + + + + + + + true + + + + Influence of the environment on the material color + + + + + + + + + Receive shadows + + + + + + + Qt::Horizontal + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Vertical + + + + + + + + + Lighted preview + + + true + + + + + + + 0 + 0 + + + + + 200 + 200 + + + + + 200 + 200 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Actions + + + true + + + + + + Cancel + + + + :/buttons/logo/images/cancel.png:/buttons/logo/images/cancel.png + + + + + + + Revert + + + + :/buttons/logo/images/revert.png:/buttons/logo/images/revert.png + + + + + + + Ok + + + + :/buttons/logo/images/apply.png:/buttons/logo/images/apply.png + + + + + + + + + + + + + BasePreview + QWidget +
basepreview.h
+ 1 +
+ + WidgetSliderDecimal + QSlider +
common/widgetsliderdecimal.h
+
+ + SmallPreviewColor + QWidget +
lighting/SmallPreviewColor.h
+ 1 +
+ + SmallPreviewHues + QWidget +
lighting/SmallPreviewHues.h
+ 1 +
+
+ + + + +
diff --git a/src/editing/lighting/SmallPreviewColor.cpp b/src/editing/lighting/SmallPreviewColor.cpp new file mode 100644 index 0000000..f147b82 --- /dev/null +++ b/src/editing/lighting/SmallPreviewColor.cpp @@ -0,0 +1,24 @@ +#include "SmallPreviewColor.h" + +#include + +#include "editing/tools.h" + +SmallPreviewColor::SmallPreviewColor(QWidget* parent, Color* color) : DrawingWidget(parent) +{ + _color = color; +} + +void SmallPreviewColor::setColor(Color* color) +{ + _color = color; + update(); +} + +void SmallPreviewColor::doDrawing(QPainter* painter) +{ + if (_color) + { + painter->fillRect(rect(), colorToQColor(*_color)); + } +} diff --git a/src/editing/lighting/SmallPreviewColor.h b/src/editing/lighting/SmallPreviewColor.h new file mode 100644 index 0000000..aeb95e8 --- /dev/null +++ b/src/editing/lighting/SmallPreviewColor.h @@ -0,0 +1,21 @@ +#ifndef SMALLPREVIEWCOLOR_H +#define SMALLPREVIEWCOLOR_H + +#include "editing/common/DrawingWidget.h" + +#include "rendering/tools/color.h" + +class SmallPreviewColor: public DrawingWidget +{ + Q_OBJECT +public: + SmallPreviewColor(QWidget* parent, Color* color = 0); + void setColor(Color* color); +protected: + virtual void doDrawing(QPainter* painter); +private: + Color* _color; +}; + +#endif /* SMALLPREVIEWCOLOR_H */ + diff --git a/src/editing/lighting/SmallPreviewHues.cpp b/src/editing/lighting/SmallPreviewHues.cpp new file mode 100644 index 0000000..0270814 --- /dev/null +++ b/src/editing/lighting/SmallPreviewHues.cpp @@ -0,0 +1,14 @@ +#include "SmallPreviewHues.h" + +#include + +#include "editing/tools.h" + +SmallPreviewHues::SmallPreviewHues(QWidget* parent) : DrawingWidget(parent) +{ +} + +void SmallPreviewHues::doDrawing(QPainter* painter) +{ + painter->fillRect(rect(), Qt::blue); +} diff --git a/src/editing/lighting/SmallPreviewHues.h b/src/editing/lighting/SmallPreviewHues.h new file mode 100644 index 0000000..312b92e --- /dev/null +++ b/src/editing/lighting/SmallPreviewHues.h @@ -0,0 +1,18 @@ +#ifndef SMALLPREVIEWHUES_H +#define SMALLPREVIEWHUES_H + +#include "editing/common/DrawingWidget.h" + +#include "rendering/tools/color.h" + +class SmallPreviewHues: public DrawingWidget +{ + Q_OBJECT +public: + SmallPreviewHues(QWidget* parent); +protected: + virtual void doDrawing(QPainter* painter); +}; + +#endif /* SMALLPREVIEWHUES_H */ + diff --git a/src/editing/paysages-qt.pro b/src/editing/paysages-qt.pro index 1b69752..0ca58cc 100644 --- a/src/editing/paysages-qt.pro +++ b/src/editing/paysages-qt.pro @@ -44,14 +44,12 @@ HEADERS += \ formwater.h \ formtextures.h \ formrender.h \ - formmaterial.h \ formclouds.h \ formatmosphere.h \ explorerchunkterrain.h \ explorerchunksky.h \ dialogrender.h \ dialognoise.h \ - dialogmaterial.h \ dialoglayers.h \ dialogexplorer.h \ dialogcurve.h \ @@ -73,7 +71,11 @@ HEADERS += \ common/mainwindow.h \ terrain/dialogbaseterrainnoise.h \ textures/maintexturesform.h \ - common/freelayerhelper.h + common/freelayerhelper.h \ + lighting/DialogMaterialEditor.h \ + common/DrawingWidget.h \ + lighting/SmallPreviewColor.h \ + lighting/SmallPreviewHues.h SOURCES += \ terrain/widgetheightmap.cpp \ @@ -97,14 +99,12 @@ SOURCES += \ formwater.cpp \ formtextures.cpp \ formrender.cpp \ - formmaterial.cpp \ formclouds.cpp \ formatmosphere.cpp \ explorerchunkterrain.cpp \ explorerchunksky.cpp \ dialogrender.cpp \ dialognoise.cpp \ - dialogmaterial.cpp \ dialoglayers.cpp \ dialogexplorer.cpp \ dialogcurve.cpp \ @@ -126,7 +126,11 @@ SOURCES += \ common/mainwindow.cpp \ terrain/dialogbaseterrainnoise.cpp \ textures/maintexturesform.cpp \ - common/freelayerhelper.cpp + common/freelayerhelper.cpp \ + lighting/DialogMaterialEditor.cpp \ + common/DrawingWidget.cpp \ + lighting/SmallPreviewColor.cpp \ + lighting/SmallPreviewHues.cpp FORMS += \ terrain/dialogterrainpainting.ui \ @@ -134,7 +138,8 @@ FORMS += \ terrain/mainterrainform.ui \ common/mainwindow.ui \ terrain/dialogbaseterrainnoise.ui \ - textures/maintexturesform.ui + textures/maintexturesform.ui \ + lighting/DialogMaterialEditor.ui RESOURCES += \ ../../data/ui_pictures.qrc diff --git a/src/editing/previewmaterial.cpp b/src/editing/previewmaterial.cpp index bf0851b..c57d7a3 100644 --- a/src/editing/previewmaterial.cpp +++ b/src/editing/previewmaterial.cpp @@ -7,9 +7,8 @@ #include "rendering/tools/lighting.h" #include "rendering/tools/color.h" -/***** Small static preview *****/ - -SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material) : QWidget(parent) +/***** Shared renderer *****/ +MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material) { _light.color.r = 3.0; _light.color.g = 3.0; @@ -23,21 +22,24 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat _material = material; - _renderer = rendererCreate(); Vector3 camera_location = {0.0, 0.0, 10.0}; - cameraSetLocation(_renderer->render_camera, camera_location); + cameraSetLocation(renderer->render_camera, camera_location); _color_profile = colorProfileCreate(); colorProfileSetToneMapping(_color_profile, TONE_MAPPING_UNCHARTED, 1.0); } -SmallMaterialPreview::~SmallMaterialPreview() +MaterialPreviewRenderer::~MaterialPreviewRenderer() { - rendererDelete(_renderer); colorProfileDelete(_color_profile); } -Color SmallMaterialPreview::getColor(double x, double y) +void MaterialPreviewRenderer::bindEvent(BasePreview* preview) +{ + preview->configScaling(0.05, 2.0, 0.05, 2.0); +} + +Color MaterialPreviewRenderer::getColor2D(double x, double y, double) { double dist = sqrt(x * x + y * y); Vector3 point; @@ -61,7 +63,7 @@ Color SmallMaterialPreview::getColor(double x, double y) } point = v3Normalize(point); - color = lightingApplyOneLight(&_light, _renderer->getCameraLocation(_renderer, point), point, point, _material); + color = lightingApplyOneLight(&_light, renderer->getCameraLocation(renderer, point), point, point, _material); if (dist > 0.95) { color.a = (1.0 - dist) / 0.05; @@ -70,6 +72,19 @@ Color SmallMaterialPreview::getColor(double x, double y) } } +/***** Small static preview *****/ + +SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material): +QWidget(parent), +_renderer(material) +{ +} + +Color SmallMaterialPreview::getColor(double x, double y) +{ + return _renderer.getColor2D(x, y, 1.0); +} + void SmallMaterialPreview::paintEvent(QPaintEvent*) { QPainter painter(this); @@ -92,28 +107,8 @@ void SmallMaterialPreview::paintEvent(QPaintEvent*) { for (int y = 0; y < height; y++) { - painter.setPen(colorToQColor(getColor((double) x * factor - dx, (double) y * factor - dy))); + painter.setPen(colorToQColor(_renderer.getColor2D((double) x * factor - dx, (double) y * factor - dy, 1.0))); painter.drawPoint(x, y); } } } - -/***** Large dynamic preview *****/ - -PreviewMaterial::PreviewMaterial(QWidget* parent, SurfaceMaterial* material) : BasePreview(parent) -{ - _small = new SmallMaterialPreview(this, material); - _small->hide(); - - configScaling(0.05, 2.0, 0.05, 2.0); -} - -PreviewMaterial::~PreviewMaterial() -{ - delete _small; -} - -Color PreviewMaterial::getColor(double x, double y) -{ - return _small->getColor(x, y); -} diff --git a/src/editing/previewmaterial.h b/src/editing/previewmaterial.h index d254709..d2684bc 100644 --- a/src/editing/previewmaterial.h +++ b/src/editing/previewmaterial.h @@ -2,15 +2,30 @@ #define _PAYSAGES_QT_PREVIEWMATERIAL_H_ #include "basepreview.h" +#include "editing/common/previewrenderer.h" #include "rendering/tools/lighting.h" #include "rendering/renderer.h" +class MaterialPreviewRenderer:public PreviewRenderer { + Q_OBJECT +public: + MaterialPreviewRenderer(SurfaceMaterial* material); + ~MaterialPreviewRenderer(); + + virtual void bindEvent(BasePreview* preview); + virtual Color getColor2D(double x, double y, double scaling); + +private: + SurfaceMaterial* _material; + LightDefinition _light; + ColorProfile* _color_profile; +}; + class SmallMaterialPreview:public QWidget { public: SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material); - ~SmallMaterialPreview(); Color getColor(double x, double y); @@ -18,25 +33,7 @@ protected: virtual void paintEvent(QPaintEvent* event); private: - SurfaceMaterial* _material; - LightDefinition _light; - Renderer* _renderer; - ColorProfile* _color_profile; -}; - -class PreviewMaterial:public BasePreview -{ - Q_OBJECT - -public: - PreviewMaterial(QWidget* parent, SurfaceMaterial* material); - ~PreviewMaterial(); - -protected: - virtual Color getColor(double x, double y); - -private: - SmallMaterialPreview* _small; + MaterialPreviewRenderer _renderer; }; #endif diff --git a/src/rendering/tools/lighting.h b/src/rendering/tools/lighting.h index 79ae140..f4c22b9 100644 --- a/src/rendering/tools/lighting.h +++ b/src/rendering/tools/lighting.h @@ -11,9 +11,16 @@ extern "C" { typedef struct { - Color base; + double hue; + double diffuse; + double hardness; + double reflection; double shininess; + + double receive_shadows; + + Color base; } SurfaceMaterial; typedef struct