WIP on new material dialog

This commit is contained in:
Michaël Lemaire 2013-08-18 17:13:15 +02:00
parent bc3f47e3b9
commit 08b481df7d
18 changed files with 674 additions and 243 deletions

View file

@ -1,69 +0,0 @@
#include "dialogmaterial.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QWidget>
/**************** 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();
}

View file

@ -1,27 +0,0 @@
#ifndef _PAYSAGES_QT_DIALOGMATERIAL_H_
#define _PAYSAGES_QT_DIALOGMATERIAL_H_
#include <QDialog>
#include <QListWidget>
#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

View file

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

View file

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

View file

@ -4,29 +4,15 @@
#include <QPushButton>
#include <QPainter>
#include <QColorDialog>
#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();
}
}

View file

@ -22,7 +22,8 @@ private slots:
void chooseColor();
private:
Color* _value;
Color* _original;
Color _edited;
};
#endif

View file

@ -4,16 +4,17 @@
#include <QPushButton>
#include <QPainter>
#include <QColorDialog>
#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();
}

View file

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

View file

@ -0,0 +1,45 @@
#ifndef DIALOGMATERIALEDITOR_H
#define DIALOGMATERIALEDITOR_H
#include <QDialog>
#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

View file

@ -0,0 +1,402 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogMaterialEditor</class>
<widget class="QDialog" name="DialogMaterialEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1090</width>
<height>627</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_10">
<property name="spacing">
<number>20</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Material diffusion</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>This controls the way the surface diffuses its inner color in all directions, when a light source reaches it</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="baseColorLabel">
<property name="text">
<string>Base color</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="diffuseFactorLabel">
<property name="text">
<string>Diffuse factor</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="hardnessToLightLabel">
<property name="text">
<string>Hardness to light</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="WidgetSliderDecimal" name="slider_diffuse">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="WidgetSliderDecimal" name="slider_hardness">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="SmallPreviewColor" name="preview_color" native="true">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="WidgetSliderDecimal" name="slider_hue">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="SmallPreviewHues" name="widget_2" native="true">
<property name="minimumSize">
<size>
<width>600</width>
<height>40</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Light reflection</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Amount and direction of light that is directly reflected from an incoming source (useful for shiny things)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="reflectionFactorLabel">
<property name="text">
<string>Reflection factor</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="specularityLabel">
<property name="text">
<string>Specularity</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="WidgetSliderDecimal" name="slider_reflection">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="WidgetSliderDecimal" name="slider_specularity">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Ambient lighting</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Influence of the environment on the material color</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="receiveShadowsLabel">
<property name="text">
<string>Receive shadows</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="WidgetSliderDecimal" name="slider_receive_shadows">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Lighted preview</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="BasePreview" name="preview_lighted" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Actions</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="button_cancel">
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/cancel.png</normaloff>:/buttons/logo/images/cancel.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_revert">
<property name="text">
<string>Revert</string>
</property>
<property name="icon">
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/revert.png</normaloff>:/buttons/logo/images/revert.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_apply">
<property name="text">
<string>Ok</string>
</property>
<property name="icon">
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/apply.png</normaloff>:/buttons/logo/images/apply.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BasePreview</class>
<extends>QWidget</extends>
<header>basepreview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>WidgetSliderDecimal</class>
<extends>QSlider</extends>
<header>common/widgetsliderdecimal.h</header>
</customwidget>
<customwidget>
<class>SmallPreviewColor</class>
<extends>QWidget</extends>
<header>lighting/SmallPreviewColor.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SmallPreviewHues</class>
<extends>QWidget</extends>
<header>lighting/SmallPreviewHues.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../data/ui_pictures.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,24 @@
#include "SmallPreviewColor.h"
#include <QPainter>
#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));
}
}

View file

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

View file

@ -0,0 +1,14 @@
#include "SmallPreviewHues.h"
#include <QPainter>
#include "editing/tools.h"
SmallPreviewHues::SmallPreviewHues(QWidget* parent) : DrawingWidget(parent)
{
}
void SmallPreviewHues::doDrawing(QPainter* painter)
{
painter->fillRect(rect(), Qt::blue);
}

View file

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

View file

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

View file

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

View file

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

View file

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